Skip to content

Commit 17a1cd0

Browse files
committed
first commit
1 parent 9419a2b commit 17a1cd0

20 files changed

+602
-2
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.bundle/
2+
/.yardoc
3+
/_yardoc/
4+
/coverage/
5+
/doc/
6+
/pkg/
7+
/spec/reports/
8+
/tmp/

Gemfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 trackingmore.gemspec
6+
gemspec

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 liaoaiping
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.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
# trackingmore-sdk-ruby
2-
The Ruby SDK of Trackingmore API
1+
trackingmore-sdk-ruby
2+
=================
3+
4+
The Ruby SDK of Tr

examples/air_waybill_example.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2+
require 'trackingmore'
3+
4+
TrackingMore.api_key = 'you api key'
5+
6+
begin
7+
params = {"awb_number" => "235-69030430"}
8+
response = TrackingMore::AirWaybill.create_an_air_waybill(params)
9+
puts response
10+
rescue TrackingMore::TrackingMoreException => e
11+
puts "Caught Custom Exception: #{e.message}"
12+
end

examples/courier_example.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2+
require 'trackingmore'
3+
4+
TrackingMore.api_key = 'you api key'
5+
6+
begin
7+
response = TrackingMore::Courier.get_all_couriers
8+
puts response
9+
rescue TrackingMore::TrackingMoreException => e
10+
puts "Caught Custom Exception: #{e.message}"
11+
end
12+
13+
14+
begin
15+
params = {"tracking_number" => "92612903029511573030094547"}
16+
response = TrackingMore::Courier.detect(params)
17+
puts response
18+
rescue TrackingMore::TrackingMoreException => e
19+
puts "Caught Custom Exception: #{e.message}"
20+
end

examples/tracking_example.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2+
require 'trackingmore'
3+
4+
TrackingMore.api_key = 'you api key'
5+
6+
begin
7+
params = {"tracking_number" => "92612913029511573130094547","courier_code"=>"usps"}
8+
response = TrackingMore::Tracking.create_tracking(params)
9+
puts response
10+
rescue TrackingMore::TrackingMoreException => 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-08-23T14:00:00+08:00","created_date_max"=>"2023-08-23T15:04:00+08:00"}
18+
response = TrackingMore::Tracking.get_tracking_results(params)
19+
puts response
20+
rescue TrackingMore::TrackingMoreException => 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 = TrackingMore::Tracking.batch_create_trackings(params)
27+
puts response
28+
rescue TrackingMore::TrackingMoreException => 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 = TrackingMore::Tracking.update_tracking_by_id(id_string, params)
36+
puts response
37+
rescue TrackingMore::TrackingMoreException => e
38+
puts "Caught Custom Exception: #{e.message}"
39+
end
40+
41+
begin
42+
id_string = '9a3aec583781c7096cf744d68287d3d1'
43+
response = TrackingMore::Tracking.delete_tracking_by_id(id_string)
44+
puts response
45+
rescue TrackingMore::TrackingMoreException => e
46+
puts "Caught Custom Exception: #{e.message}"
47+
end
48+
49+
begin
50+
id_string = '9a3aec583781c7096cf744d68287d3d1'
51+
response = TrackingMore::Tracking.retrack_tracking_by_id(id_string)
52+
puts response
53+
rescue TrackingMore::TrackingMoreException => e
54+
puts "Caught Custom Exception: #{e.message}"
55+
end

lib/trackingmore.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$:.unshift File.dirname(__FILE__)
2+
3+
require 'trackingmore/const'
4+
require 'trackingmore/exception'
5+
require 'trackingmore/courier'
6+
require 'trackingmore/tracking'
7+
require 'trackingmore/air_waybill'
8+
9+
module TrackingMore
10+
class << self
11+
attr_accessor :api_key
12+
end
13+
14+
VERSION = '0.1.0'
15+
end
16+

lib/trackingmore/air_waybill.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require File.dirname(__FILE__) + '/request'
2+
3+
module TrackingMore
4+
class AirWaybill
5+
def self.create_an_air_waybill(params = {})
6+
if params["awb_number"].to_s.empty?
7+
raise TrackingMore::TrackingMoreException.new(TrackingMore::Consts::ErrMissingAwbNumber)
8+
end
9+
if params["awb_number"].length != 12
10+
raise TrackingMore::TrackingMoreException.new(TrackingMore::Consts::ErrInvalidAirWaybillFormat)
11+
end
12+
TrackingMore::Request.make_request('post',"awb",params)
13+
end
14+
end
15+
end

lib/trackingmore/const.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
module TrackingMore
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 commit comments

Comments
 (0)