51tracking 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1609d4e5c78c3f90bd99cfc8809cad0fab850ecf60aec8d573958b2d1723897a
4
+ data.tar.gz: 5d1dc6b34f2d4a932841db364f74c54317d16021b7b40f2c12866c54b451920a
5
+ SHA512:
6
+ metadata.gz: f1cfb4ad2ec4659746189fb909257604e5f98d38a3bb24985e6f1d5ab50c3c06d4319d5cbf1fe46aa7519165b64a383d8dbfed1fbd6e94af83099b5e691583b9
7
+ data.tar.gz: 1e3f2f172f84c672c760fa48c913915e8dfd615a2ec93db2560481bd5867f169d67846e6e15bf83cf1efe2a73e7d19e9f5c0ab369aa770986cb65ab4e41d9a10
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .idea
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "51tracking"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "51tracking"
8
+ spec.version = Tracking51::VERSION
9
+ spec.authors = ["51tracking"]
10
+ spec.email = ["service@51tracking.org"]
11
+
12
+ spec.summary = "The Ruby SDK of 51Tracking API"
13
+ spec.description = "Developed for easy integration with 51Tracking"
14
+ spec.homepage = "https://www.51tracking.com/"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.17"
27
+ spec.add_development_dependency "rspec", "~> 3.12"
28
+ end
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in 51tracking.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 51tracking
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,220 @@
1
+ 51tracking-sdk-ruby
2
+ =================
3
+
4
+ The Ruby SDK of 51Tracking API
5
+
6
+ Contact: <service@51tracking.org>
7
+
8
+ ## Official document
9
+
10
+ [Document](https://www.51tracking.com/v4/api-index/API-)
11
+
12
+
13
+ ## Index
14
+ 1. [Installation](https://github.com/51tracking/51tracking-sdk-ruby#installation)
15
+ 2. [Testing](https://github.com/51tracking/51tracking-sdk-ruby#testing)
16
+ 3. [Error Handling](https://github.com/51tracking/51tracking-sdk-ruby#error-handling)
17
+ 4. SDK
18
+ 1. [Couriers](https://github.com/51tracking/51tracking-sdk-ruby#couriers)
19
+ 2. [Trackings](https://github.com/51tracking/51tracking-sdk-ruby#trackings)
20
+ 3. [Air Waybill](https://github.com/51tracking/51tracking-sdk-ruby#air-waybill)
21
+
22
+
23
+ ## Installation
24
+
25
+ ```
26
+ gem install 51tracking
27
+ ```
28
+
29
+ ## Quick Start
30
+
31
+ ```ruby
32
+ require '51tracking'
33
+
34
+ Tracking51.api_key = 'you api key'
35
+
36
+ begin
37
+ response = Tracking51::Courier.get_all_couriers
38
+ puts response
39
+ rescue Tracking51::Tracking51Exception => e
40
+ puts "Caught Custom Exception: #{e.message}"
41
+ end
42
+
43
+ ```
44
+
45
+ ## Testing
46
+ ```
47
+ rspec
48
+ ```
49
+
50
+ ## Error handling
51
+
52
+ **Throw** by the new SDK client
53
+
54
+ ```ruby
55
+ require '51tracking'
56
+
57
+ Tracking51.api_key = ''
58
+
59
+ begin
60
+ response = Tracking51::Courier.get_all_couriers
61
+ puts response
62
+ rescue Tracking51::Tracking51Exception => e
63
+ puts "Caught Custom Exception: #{e.message}"
64
+ end
65
+
66
+ # API Key is missing
67
+ ```
68
+
69
+ **Throw** by the parameter validation in function
70
+
71
+ ```ruby
72
+ require '51tracking'
73
+
74
+ Tracking51.api_key = 'you api key'
75
+
76
+ begin
77
+ params = { "tracking_number" => "" }
78
+ response = Tracking51::Courier.detect(params)
79
+ puts response
80
+ rescue Tracking51::Tracking51Exception => e
81
+ puts "Caught Custom Exception: #{e.message}"
82
+ end
83
+
84
+ # Tracking number cannot be empty
85
+ ```
86
+ ## Examples
87
+
88
+ ## Couriers
89
+ ##### 返回所有支持的快递公司列表
90
+ https://api.51Tracking.com/v4/couriers/all
91
+ ```ruby
92
+ begin
93
+ response = Tracking51::Courier.get_all_couriers
94
+ puts response
95
+ rescue Tracking51::Tracking51Exception => e
96
+ puts "Caught Custom Exception: #{e.message}"
97
+ end
98
+ ```
99
+
100
+ ## Trackings
101
+ ##### 单个物流单号实时添加且查询
102
+ https://api.51Tracking.com/v4/trackings/create
103
+ ```ruby
104
+ begin
105
+ params = {"tracking_number" => "92612913029511573130094547","courier_code"=>"usps"}
106
+ response = Tracking51::Tracking.create_tracking(params)
107
+ puts response
108
+ rescue Tracking51::Tracking51Exception => e
109
+ puts "Caught Custom Exception: #{e.message}"
110
+ end
111
+ ```
112
+
113
+ ##### 获取多个物流单号的查询结果
114
+ https://api.51Tracking.com/v4/trackings/get
115
+ ```ruby
116
+ begin
117
+ # Perform queries based on various conditions
118
+ # params = {"tracking_numbers" => "92612903029511573130094547","courier_code"=>"usps"}
119
+ # params = {"tracking_numbers" => "92612903029511573130094547,92612903029511573030094548","courier_code"=>"usps"}
120
+ params = {"created_date_min" => "2023-08-23T14:00:00+08:00","created_date_max"=>"2023-08-23T15:04:00+08:00"}
121
+ response = Tracking51::Tracking.get_tracking_results(params)
122
+ puts response
123
+ rescue Tracking51::Tracking51Exception => e
124
+ puts "Caught Custom Exception: #{e.message}"
125
+ end
126
+ ```
127
+
128
+ ##### 添加多个物流单号(一次调用最多创建 40 个物流单号)
129
+ https://api.51Tracking.com/v4/trackings/batch
130
+ ```ruby
131
+ begin
132
+ params = [{"tracking_number" => "92612903029611573130094547","courier_code"=>"usps"},{"tracking_number" => "92612903029711573130094547","courier_code"=>"usps"}]
133
+ response = Tracking51::Tracking.batch_create_trackings(params)
134
+ puts response
135
+ rescue Tracking51::Tracking51Exception => e
136
+ puts "Caught Custom Exception: #{e.message}"
137
+ end
138
+ ```
139
+
140
+ ##### 根据ID更新物流信息
141
+ https://api.51Tracking.com/v4/trackings/update/{id}
142
+ ```ruby
143
+ begin
144
+ params = {"customer_name" => "New name","note"=>"New tests order note"}
145
+ id_string = '9a3aec583781c7096cf744d68287d3d1'
146
+ response = Tracking51::Tracking.update_tracking_by_id(id_string, params)
147
+ puts response
148
+ rescue Tracking51::Tracking51Exception => e
149
+ puts "Caught Custom Exception: #{e.message}"
150
+ end
151
+ ```
152
+
153
+ ##### 通过ID删除单号
154
+ https://api.51Tracking.com/v4/trackings/delete/{id}
155
+ ```ruby
156
+ begin
157
+ id_string = '9a3aec583781c7096cf744d68287d3d1'
158
+ response = Tracking51::Tracking.delete_tracking_by_id(id_string)
159
+ puts response
160
+ rescue Tracking51::Tracking51Exception => e
161
+ puts "Caught Custom Exception: #{e.message}"
162
+ end
163
+ ```
164
+
165
+ ##### 通过ID重新查询过期的单号
166
+ https://api.51Tracking.com/v4/trackings/retrack/{id}
167
+ ```ruby
168
+ begin
169
+ id_string = '9a3aec583781c7096cf744d68287d3d1'
170
+ response = Tracking51::Tracking.retrack_tracking_by_id(id_string)
171
+ puts response
172
+ rescue Tracking51::Tracking51Exception => e
173
+ puts "Caught Custom Exception: #{e.message}"
174
+ end
175
+ ```
176
+ ## Air Waybill
177
+ ##### 查询航空运单的结果
178
+ https://api.51Tracking.com/v4/awb
179
+ ```ruby
180
+ begin
181
+ params = {"awb_number" => "235-69030430"}
182
+ response = Tracking51::AirWaybill.create_an_air_waybill(params)
183
+ puts response
184
+ rescue Tracking51::Tracking51Exception => e
185
+ puts "Caught Custom Exception: #{e.message}"
186
+ end
187
+ ```
188
+
189
+ ## 响应状态码
190
+
191
+ 51Tracking 使用传统的HTTP状态码来表明 API 请求的状态。通常,2xx形式的状态码表示请求成功,4XX形式的状态码表请求发生错误(比如:必要参数缺失),5xx格式的状态码表示 51tracking 的服务器可能发生了问题。
192
+
193
+ | Http CODE | META CODE | TYPE | MESSAGE |
194
+ |-----------|-----------|--------------------|-------------------------------------------|
195
+ | 200 | 200 | <code>成功</code> | 请求响应成功。 |
196
+ | 400 | 400 | <code>错误请求</code> | 请求类型错误。请查看 API 文档以了解此 API 的请求类型。 |
197
+ | 400 | 4101 | <code>错误请求</code> | 物流单号已存在。 |
198
+ | 400 | 4102 | <code>错误请求</code> | 物流单号不存在。请先使用「Create接口」将单号添加至系统。 |
199
+ | 400 | 4103 | <code>错误请求</code> | 您已超出 API 调用的创建数量。每次创建的最大数量为 40 个快递单号。 |
200
+ | 400 | 4110 | <code>错误请求</code> | 物流单号(tracking_number) 不符合规则。 |
201
+ | 400 | 4111 | <code>错误请求</code> | 物流单号(tracking_number)为必填字段。 |
202
+ | 400 | 4112 | <code>错误请求</code> | 查询ID无效。 |
203
+ | 400 | 4113 | <code>错误请求</code> | 不允许重新查询。您只能重新查询过期的物流单号。 |
204
+ | 400 | 4120 | <code>错误请求</code> | 物流商简码(courier_code)的值无效。 |
205
+ | 400 | 4121 | <code>错误请求</code> | 无法识别物流商。 |
206
+ | 400 | 4122 | <code>错误请求</code> | 特殊物流商字段缺失或填写不符合规范。 |
207
+ | 400 | 4130 | <code>错误请求</code> | 请求参数的格式无效。 |
208
+ | 400 | 4160 | <code>错误请求</code> | 空运单号(awb_number)是必需的或有效的格式。 |
209
+ | 400 | 4161 | <code>错误请求</code> | 此空运航空不支持查询。 |
210
+ | 400 | 4165 | <code>错误请求</code> | 查询失败:未创建空运单号。 |
211
+ | 400 | 4166 | <code>错误请求</code> | 删除未创建的空运单号失败。 |
212
+ | 400 | 4167 | <code>错误请求</code> | 空运单号已存在,无需再次创建。 |
213
+ | 400 | 4190 | <code>错误请求</code> | 当前查询额度不足。 |
214
+ | 401 | 401 | <code>未经授权</code> | 身份验证失败或没有权限。请检查并确保您的 API 密钥正确无误。 |
215
+ | 403 | 403 | <code>禁止</code> | 禁止访问。请求被拒绝或不允许访问。 |
216
+ | 404 | 404 | <code>未找到</code> | 页面不存在。请检查并确保您的链接正确无误。 |
217
+ | 429 | 429 | <code>太多请求</code> | 超出 API 请求限制,请稍后重试。请查看 API 文档以了解此 API 的限制。 |
218
+ | 500 | 511 | <code>服务器错误</code> | 服务器错误。请联系我们: service@51Tracking.org。 |
219
+ | 500 | 512 | <code>服务器错误</code> | 服务器错误。请联系我们:service@51Tracking.org。 |
220
+ | 500 | 513 | <code>服务器错误</code> | 服务器错误。请联系我们: service@51Tracking.org。 |
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require '51tracking'
3
+
4
+ Tracking51.api_key = 'you api key'
5
+
6
+ begin
7
+ params = {"awb_number" => "235-69030430"}
8
+ response = Tracking51::AirWaybill.create_an_air_waybill(params)
9
+ puts response
10
+ rescue Tracking51::Tracking51Exception => e
11
+ puts "Caught Custom Exception: #{e.message}"
12
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require '51tracking'
3
+
4
+ Tracking51.api_key = 'you api key'
5
+
6
+ begin
7
+ response = Tracking51::Courier.get_all_couriers
8
+ puts response
9
+ rescue Tracking51::Tracking51Exception => e
10
+ puts "Caught Custom Exception: #{e.message}"
11
+ end
12
+
13
+
14
+ begin
15
+ params = {"tracking_number" => "92612903029511573030094547"}
16
+ response = Tracking51::Courier.detect(params)
17
+ puts response
18
+ rescue Tracking51::Tracking51Exception => e
19
+ puts "Caught Custom Exception: #{e.message}"
20
+ end
@@ -0,0 +1,55 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require '51tracking'
3
+
4
+ Tracking51.api_key = 'you api key'
5
+
6
+ begin
7
+ params = {"tracking_number" => "92612913029511573130094547","courier_code"=>"usps"}
8
+ response = Tracking51::Tracking.create_tracking(params)
9
+ puts response
10
+ rescue Tracking51::Tracking51Exception => e
11
+ puts "Caught Custom Exception: #{e.message}"
12
+ end
13
+
14
+ begin
15
+ # params = {"tracking_numbers" => "92612903029511573130094547","courier_code"=>"usps"}
16
+ # params = {"tracking_numbers" => "92612903029511573130094547,92612903029511573030094548","courier_code"=>"usps"}
17
+ params = {"created_date_min" => "2023-10-09T06:00:00+00:00","created_date_max"=>"2023-10-10T13:45:00+00:00"}
18
+ response = Tracking51::Tracking.get_tracking_results(params)
19
+ puts response
20
+ rescue Tracking51::Tracking51Exception => e
21
+ puts "Caught Custom Exception: #{e.message}"
22
+ end
23
+
24
+ begin
25
+ params = [{"tracking_number" => "92612903029611573130094547","courier_code"=>"usps"},{"tracking_number" => "92612903029711573130094547","courier_code"=>"usps"}]
26
+ response = Tracking51::Tracking.batch_create_trackings(params)
27
+ puts response
28
+ rescue Tracking51::Tracking51Exception => e
29
+ puts "Caught Custom Exception: #{e.message}"
30
+ end
31
+
32
+ begin
33
+ params = {"customer_name" => "New name","note"=>"New tests order note"}
34
+ id_string = '9a3aec583781c7096cf744d68287d3d1'
35
+ response = Tracking51::Tracking.update_tracking_by_id(id_string, params)
36
+ puts response
37
+ rescue Tracking51::Tracking51Exception => e
38
+ puts "Caught Custom Exception: #{e.message}"
39
+ end
40
+
41
+ begin
42
+ id_string = '9a3aec583781c7096cf744d68287d3d1'
43
+ response = Tracking51::Tracking.delete_tracking_by_id(id_string)
44
+ puts response
45
+ rescue Tracking51::Tracking51Exception => e
46
+ puts "Caught Custom Exception: #{e.message}"
47
+ end
48
+
49
+ begin
50
+ id_string = '9a3aec583781c7096cf744d68287d3d1'
51
+ response = Tracking51::Tracking.retrack_tracking_by_id(id_string)
52
+ puts response
53
+ rescue Tracking51::Tracking51Exception => e
54
+ puts "Caught Custom Exception: #{e.message}"
55
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/request'
2
+
3
+ module Tracking51
4
+ class AirWaybill
5
+ def self.create_an_air_waybill(params = {})
6
+ if params["awb_number"].to_s.empty?
7
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrMissingAwbNumber)
8
+ end
9
+ if params["awb_number"].length != 12
10
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrInvalidAirWaybillFormat)
11
+ end
12
+ Tracking51::Request.make_request('post',"awb",params)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+
2
+ module Tracking51
3
+ class Consts
4
+ ErrEmptyAPIKey = 'API Key is missing';
5
+ ErrMissingTrackingNumber = 'Tracking number cannot be empty';
6
+ ErrMissingCourierCode = 'Courier Code cannot be empty';
7
+ ErrMissingAwbNumber = 'Awb number cannot be empty';
8
+ ErrMaxTrackingNumbersExceeded = 'Max. 40 tracking numbers create in one call';
9
+ ErrEmptyId = 'Id cannot be empty';
10
+ ErrInvalidAirWaybillFormat = 'The air waybill number format is invalid and can only be 12 digits in length';
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/request'
2
+
3
+ module Tracking51
4
+ class Courier
5
+ @@api_module = 'couriers'
6
+ def self.get_all_couriers
7
+ Tracking51::Request.make_request('get',"#@@api_module/all")
8
+ end
9
+ def self.detect(params = {})
10
+ if params["tracking_number"].to_s.empty?
11
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrMissingTrackingNumber)
12
+ end
13
+ Tracking51::Request.make_request('post',"#@@api_module/detect",params)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+
2
+ module Tracking51
3
+ class Tracking51Exception < StandardError
4
+ def initialize(message = '')
5
+ super(message)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,83 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module Tracking51
6
+ class Request
7
+ @@apiBaseUrl = 'api.51Tracking.com'
8
+ @@apiPort = 443
9
+ @@apiVersion = 'v4'
10
+ @@timeout = 10
11
+
12
+ def self.get_request_url(path)
13
+ pact = @@apiPort == 443 ? 'https' : 'http'
14
+ url = pact+'://'+@@apiBaseUrl+'/'+@@apiVersion+'/'+path
15
+ return url
16
+ end
17
+
18
+ def self.get_request_header(apiKey)
19
+ headers = {}
20
+ headers['Accept'] = 'application/json'
21
+ headers['Content-Type'] = 'application/json'
22
+ headers['Tracking-Api-Key'] = apiKey
23
+ return headers
24
+ end
25
+
26
+ def self.make_request(method = 'GET', path = '', params = nil)
27
+
28
+ if Tracking51.api_key.to_s.empty?
29
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrEmptyAPIKey)
30
+ end
31
+
32
+ url = get_request_url(path)
33
+
34
+ headers = get_request_header(Tracking51.api_key)
35
+
36
+
37
+ uri = URI.parse(url)
38
+
39
+ if method.downcase == 'get' && params!=nil
40
+ query_string = URI.encode_www_form(params)
41
+ uri.query = query_string
42
+ end
43
+
44
+ http = Net::HTTP.new(uri.host, uri.port)
45
+
46
+ http.use_ssl = uri.scheme == 'https'
47
+
48
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
49
+
50
+ http.open_timeout = 10
51
+
52
+ http.read_timeout = 10
53
+
54
+ request_class = case method.downcase
55
+ when 'get' then Net::HTTP::Get
56
+ when 'post' then Net::HTTP::Post
57
+ when 'put' then Net::HTTP::Put
58
+ when 'delete' then Net::HTTP::Delete
59
+ else raise ArgumentError, "Invalid HTTP method: #{method}"
60
+ end
61
+
62
+ request = request_class.new(uri.request_uri)
63
+
64
+ headers.each { |key, value| request[key] = value }
65
+
66
+ if params!=nil && (method.downcase == 'post' || method.downcase == 'put')
67
+ request.body = params.to_json
68
+ end
69
+
70
+ begin
71
+ response = http.request(request)
72
+ begin
73
+ parsed_response = JSON.parse(response.body)
74
+ parsed_response
75
+ rescue JSON::ParserError
76
+ response.body
77
+ end
78
+ rescue StandardError => e
79
+ { 'error' => e.message }
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/request'
2
+
3
+ module Tracking51
4
+ class Tracking
5
+ @@api_module = 'trackings'
6
+
7
+ def self.create_tracking(params = {})
8
+ if params["tracking_number"].to_s.empty?
9
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrMissingTrackingNumber)
10
+ end
11
+ if params["courier_code"].to_s.empty?
12
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrMissingCourierCode)
13
+ end
14
+ Tracking51::Request.make_request('post',"#@@api_module/create",params)
15
+ end
16
+
17
+ def self.get_tracking_results(params = {})
18
+ Tracking51::Request.make_request('get',"#@@api_module/get",params)
19
+ end
20
+
21
+ def self.batch_create_trackings(params = [])
22
+ if params.length > 40
23
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrMaxTrackingNumbersExceeded)
24
+ end
25
+ params.each do |item|
26
+ if item["tracking_number"].to_s.empty?
27
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrMissingTrackingNumber)
28
+ end
29
+ if item["courier_code"].to_s.empty?
30
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrMissingCourierCode)
31
+ end
32
+ end
33
+ Tracking51::Request.make_request('post',"#@@api_module/batch",params)
34
+ end
35
+
36
+ def self.update_tracking_by_id(id_string, params = {})
37
+ if id_string.to_s.empty?
38
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrEmptyId)
39
+ end
40
+ Tracking51::Request.make_request('put',"#@@api_module/update/"+id_string,params)
41
+ end
42
+
43
+ def self.delete_tracking_by_id(id_string)
44
+ if id_string.to_s.empty?
45
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrEmptyId)
46
+ end
47
+ Tracking51::Request.make_request('delete',"#@@api_module/delete/"+id_string)
48
+ end
49
+
50
+ def self.retrack_tracking_by_id(id_string)
51
+ if id_string.to_s.empty?
52
+ raise Tracking51::Tracking51Exception.new(Tracking51::Consts::ErrEmptyId)
53
+ end
54
+ Tracking51::Request.make_request('post',"#@@api_module/retrack/"+id_string)
55
+ end
56
+ end
57
+ end
data/lib/51tracking.rb ADDED
@@ -0,0 +1,16 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require '51tracking/const'
4
+ require '51tracking/exception'
5
+ require '51tracking/courier'
6
+ require '51tracking/tracking'
7
+ require '51tracking/air_waybill'
8
+
9
+ module Tracking51
10
+ class << self
11
+ attr_accessor :api_key
12
+ end
13
+
14
+ VERSION = '0.1.1'
15
+ end
16
+
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: 51tracking
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - 51tracking
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ description: Developed for easy integration with 51Tracking
42
+ email:
43
+ - service@51tracking.org
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - 51tracking.gemspec
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - examples/air_waybill_example.rb
54
+ - examples/courier_example.rb
55
+ - examples/tracking_example.rb
56
+ - lib/51tracking.rb
57
+ - lib/51tracking/air_waybill.rb
58
+ - lib/51tracking/const.rb
59
+ - lib/51tracking/courier.rb
60
+ - lib/51tracking/exception.rb
61
+ - lib/51tracking/request.rb
62
+ - lib/51tracking/tracking.rb
63
+ homepage: https://www.51tracking.com/
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.4.20
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: The Ruby SDK of 51Tracking API
86
+ test_files: []