delibird

package module
v0.0.0-...-da8adbf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2016 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Delibird

License GoDoc Go Report Card Coverage Status Build Status

Deploy

Delibird

Delibird is a shipment tracking library for Golang.

Delibird는 택배사의 배송조회 페이지를 파싱하여 정형화된 형태로 바꿔주는 라이브러리입니다.

Courier List

지원하는 택배사 목록입니다.

Name Contributor
Korean Post / 우체국택배 @purpleworks
CJ KoreaExpress / CJ대한통운 @purpleworks
KG Logis / KG로지스 @serendip811

Installation

$ go get github.com/purpleworks/delibird

Usage

Code
package package_name

import "github.com/purpleworks/delibird"

func GetCjTracking(n string) {
	courier, _ := delibird.NewCourier("CJ")
	data, _ := courier.Parse(n)

	fmt.Println("%s -> %s : %s", data.Sender, data.Receiver, data.StatusText)
}
API Server

Build and run API server:

$ ./build
$ bin/delibird_server

or

$ PORT=8080 bin/delibird_server

Server Configuration

  • ENVIRONMENT: development or production(optimize json output) (default development)
  • PORT: server port (default 9000)
  • ENABLE_CORS: enable cors if true (default false)

Request URL

Request Parameters

COURIER_CODE

Code Name
KPOST Korean Post / 우체국택배
CJ CJ Korea express / CJ대한통운
KG KG Logis / KG로지스

Response

Key Description Example
TrackingNumber 송장번호 1234567890123
CompanyCode 택배사코드 KPOST, CJ, ...
CompanyName 택배사명 CJ대한통운
Sender 보내는분 홈*럼
Receiver 받는분 테*트
Signer 수령인 본인
StatusCode 상태코드 하단 참고
StatusText 상태 배송완료
History 배송 상황(array) 하단 참고

Status Code

  • -1 (UnknownStatus) - 알수없음
  • 1 (Pending) - 접수 대기
  • 2 (Ready) - 영업점 접수 (SM입고)
  • 3 (PickupComplete) - 집화처리
  • 4 (Loading) - 간선상차 / 물건 실음 / 중간 집화지 출발
  • 5 (Unloading) - 간선하차 / 분류 / 중간 집화지 도착
  • 51 (DeleveryStart) - 배송출발
  • 91 (DeleveryComplete) - 배송완료
  • 99 (DoNotDelevery) - 미배달

History

  • Area - 위치
  • Tel - 전화번호
  • Date - 시간(timestamp)
  • DateText - 시간(YYYY-MM-DD hh:mm)
  • StatusCode - 상태코드
  • StatusText - 상태

Response example

{
  "tracking_number": "xxxxxx",
  "company_code": "CJ",
  "company_name": "CJ대한통운",
  "sender": "홈*럼",
  "receiver": "테*트",
  "signer": "경비실",
  "status_code": 91,
  "status_text": "배달완료",
  "history": [
    {
      "area": "송파B직영(차상문)",
      "tel": "02-6937-6842",
      "date": 1460013885,
      "date_text": "2016-04-07 16:24",
      "status_code": 3,
      "status_text": "집화처리"
    },
    {
      "area": "송파B직영(차상문)",
      "tel": "02-6937-6842",
      "date": 1460013885,
      "date_text": "2016-04-07 16:24",
      "status_code": 2,
      "status_text": "SM입고"
    },
    {
      "area": "송파A",
      "tel": "02-6937-6836",
      "date": 1460026859,
      "date_text": "2016-04-07 20:00",
      "status_code": 4,
      "status_text": "간선상차"
    },
    {
      "area": "용인HUB",
      "date": 1460050614,
      "date_text": "2016-04-08 02:36",
      "status_code": 5,
      "status_text": "간선하차"
    },
    {
      "area": "용인HUB",
      "date": 1460050669,
      "date_text": "2016-04-08 02:37",
      "status_code": 5,
      "status_text": "간선하차"
    },
    {
      "area": "용인HUB",
      "date": 1460050694,
      "date_text": "2016-04-08 02:38",
      "status_code": 4,
      "status_text": "간선상차"
    },
    {
      "area": "용인HUB",
      "date": 1460050750,
      "date_text": "2016-04-08 02:39",
      "status_code": 4,
      "status_text": "간선상차"
    },
    {
      "area": "노원",
      "tel": "02-2129-1278",
      "date": 1460067554,
      "date_text": "2016-04-08 07:19",
      "status_code": 5,
      "status_text": "간선하차"
    },
    {
      "area": "서울서노원",
      "tel": "070-4191-7643",
      "date": 1460068287,
      "date_text": "2016-04-08 07:31",
      "status_code": 51,
      "status_text": "배달출발"
    },
    {
      "area": "서울서노원",
      "tel": "070-4191-7643",
      "date": 1460098645,
      "date_text": "2016-04-08 15:57",
      "status_code": 91,
      "status_text": "배달완료"
    }
  ]
}

Docker

docker build

$ DOCKER_BUILD=1 ./build
$ docker build -t purpleworks/delibird .

docker run

$ docker run --rm \
  -p 9000:9000 \
  -e ENVIRONMENT=production \
  -e ENABLE_CORS=ture \
  purpleworks/delibird

Test

Test with goconvey

$ go get github.com/smartystreets/goconvey
In the browser
$ goconvey
In the terminal
$ go test && go test ./server
$ go test -v && go test -v ./server # include the story

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/purpleworks/delibird

  1. Fork it ( https://github.com/purpleworks/delibird/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

Released under the MIT License.

Documentation

Overview

Package delibird is opensource shipment tracking library

Index

Constants

View Source
const (
	NoCode           string = "NO_CODE_AVAILABLE"
	NoTrackingInfo   string = "NO_TRACKING_INFO"
	ParseError       string = "PARSE_ERROR"
	RequestPageError string = "REQUEST_PAGE_ERROR"
)

Variables

This section is empty.

Functions

func NewCourier

func NewCourier(name string) (Courier, *ApiError)

NewCourier creates courier object by courier company code

func RegisterCourier

func RegisterCourier(name string, courier Courier)

RegisterCourier register new courier

Types

type ApiError

type ApiError struct {
	Code    string
	Message string
}

Error json model

func NewApiError

func NewApiError(code, message string) *ApiError

NewApiError creates ApiError object

func (ApiError) String

func (e ApiError) String() string

String() implement

type Cj

type Cj struct{}

func (Cj) Code

func (t Cj) Code() string

func (Cj) Name

func (t Cj) Name() string

func (Cj) Parse

func (t Cj) Parse(trackingNumber string) (Track, *ApiError)

func (Cj) TrackingUrl

func (t Cj) TrackingUrl() string

type Courier

type Courier interface {
	// Parse html to tracking object
	Parse(invoice string) (Track, *ApiError)
	// Courier code
	Code() string
	// Courier name
	Name() string
}

Courier is the interface representing the standardized methods to parse shipment tracking html

type History

type History struct {
	Area       string         `json:"area"`
	Tel        string         `json:"tel,omitempty"`
	Date       int64          `json:"date"`
	DateText   string         `json:"date_text"`
	StatusCode TrackingStatus `json:"status_code"`
	StatusText string         `json:"status_text"`
}

type Kg

type Kg struct{}

func (Kg) Code

func (t Kg) Code() string

func (Kg) Name

func (t Kg) Name() string

func (Kg) Parse

func (t Kg) Parse(trackingNumber string) (Track, *ApiError)

func (Kg) TrackingUrl

func (t Kg) TrackingUrl() string

type Kpost

type Kpost struct{}

func (Kpost) Code

func (t Kpost) Code() string

func (Kpost) Name

func (t Kpost) Name() string

func (Kpost) Parse

func (t Kpost) Parse(trackingNumber string) (Track, *ApiError)

func (Kpost) TrackingUrl

func (t Kpost) TrackingUrl() string

type Track

type Track struct {
	TrackingNumber string         `json:"tracking_number"`
	CompanyCode    string         `json:"company_code"`
	CompanyName    string         `json:"company_name"`
	Sender         string         `json:"sender"`
	Receiver       string         `json:"receiver"`
	Signer         string         `json:"signer"`
	StatusCode     TrackingStatus `json:"status_code"`
	StatusText     string         `json:"status_text"`
	History        []History      `json:"history"`
}

type TrackingStatus

type TrackingStatus int
const (
	// 알수 없음
	UnknownStatus TrackingStatus = -1
	// 접수 대기
	Pending TrackingStatus = 1
	// 영업점 접수 (SM입고)
	Ready TrackingStatus = 2
	// 집화처리
	PickupComplete TrackingStatus = 3
	// 간선상차 / 물건 실음 / 중간 집화지 출발
	Loading TrackingStatus = 4
	// 간선하차 / 분류 / 중간 집화지 도착
	Unloading TrackingStatus = 5
	// 배송출발
	DeleveryStart TrackingStatus = 51
	// 배송완료
	DeleveryComplete TrackingStatus = 91
	// 미배달
	DoNotDelevery TrackingStatus = 99
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址