after_ship 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43ff39d94f11902c3bfc5a7acfc36fc4092d5c5a
4
+ data.tar.gz: bab1423202559d88d3341bf209a002a85e9df8d4
5
+ SHA512:
6
+ metadata.gz: 3aff898828a87d686b144230382a77f21b68f0a324830be48dfe1ba87ef1b919aa97a9e420bd3e23501cefc00e0701637b49f416dcf9a0ebcc194db25a31e686
7
+ data.tar.gz: ecc0ca8bcd619d082eb59fa7ec8a52f927fd1d1c30c4a007999a57e27fab92c9bbb783f56b3ee4140e66ce43a8e8b14374371ba57e57fd7609175fe73f9df9f2
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.rubocop-my.yml ADDED
@@ -0,0 +1,2 @@
1
+ Metrics/MethodLength:
2
+ Max: 12
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop-my.yml
data/.travis.yml ADDED
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1.2
5
+ - 1.9.3
6
+ - jruby-19mode
7
+
8
+ branches:
9
+ only:
10
+ - master
11
+
12
+ notifications:
13
+ email:
14
+ on_success: change
15
+ on_failure: always
16
+
17
+ install: "bundle --jobs 4"
18
+ script: "bundle exec rspec"
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --protected
2
+ --private
3
+ --embed-mixins
4
+ lib/**/*.rb
5
+ -
6
+ README.md
7
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in after_ship.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Oldrich Vetesnik
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # AfterShip
2
+
3
+ [![Build Status](https://travis-ci.org/ollie/after_ship.svg?branch=master)](https://travis-ci.org/ollie/after_ship)
4
+
5
+ A smallish library to talking to AfterShip via v3 API.
6
+
7
+ You will need an AfterShip API key, see here https://www.aftership.com/docs/api/3.0.
8
+ The JSON is parsed by MultiJson (https://github.com/intridea/multi_json) so
9
+ you may want to drop in your favorite JSON engine.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'after_ship', git: 'https://github.com/ollie/after_ship.git'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ ## Usage
24
+
25
+ Init the client:
26
+
27
+ ```ruby
28
+ client = AfterShip.new(api_key: 'your-aftership-api-key')
29
+ ```
30
+
31
+ Get a list of trackings
32
+ https://www.aftership.com/docs/api/3.0/tracking/get-trackings
33
+
34
+ ```ruby
35
+ client.trackings
36
+
37
+ # Will return list of Tracking objects:
38
+
39
+ [
40
+ #<AfterShip::Tracking ...>,
41
+ #<AfterShip::Tracking ...>,
42
+ ...
43
+ ]
44
+ ```
45
+
46
+ Get a tracking
47
+ https://www.aftership.com/docs/api/3.0/tracking/get-trackings-slug-tracking_number
48
+
49
+ ```ruby
50
+ client.tracking('tracking-number', 'ups')
51
+
52
+ # Will return Tracking object or raise AfterShip::ResourceNotFoundError
53
+ # if not exists:
54
+
55
+ #<AfterShip::Tracking:0x007fe555bd9560
56
+ @active=false,
57
+ @courier="UPS",
58
+ @created_at=#<DateTime: 2014-05-08T15:25:01+00:00 ((2456786j,55501s,0n),+0s,2299161j)>,
59
+ @updated_at=#<DateTime: 2014-07-18T09:00:47+00:00 ((2456857j,32447s,0n),+0s,2299161j)>>
60
+ @custom_fields={},
61
+ @customer_name=nil,
62
+ @destination_country_iso3="USA",
63
+ @emails=[],
64
+ @expected_delivery=nil,
65
+ @order_id="PL-12480166",
66
+ @order_id_path=nil,
67
+ @origin_country_iso3="IND",
68
+ @shipment_package_count=0,
69
+ @shipment_type="EXPEDITED",
70
+ @signed_by="FRONT DOOR",
71
+ @slug="ups",
72
+ @smses=[],
73
+ @source="api",
74
+ @status="Delivered",
75
+ @tag="Delivered",
76
+ @title="1ZA2207X6790326683",
77
+ @tracked_count=47,
78
+ @tracking_number="1ZA2207X6790326683",
79
+ @unique_token="ly9ueXUJC",
80
+ @checkpoints=[
81
+ #<AfterShip::Checkpoint:0x007fe555bb0340
82
+ @checkpoint_time=#<DateTime: 2014-05-12T14:07:00+00:00 ((2456790j,50820s,0n),+0s,2299161j)>,
83
+ @city="NEW YORK",
84
+ @country_iso3=nil,
85
+ @country_name="US",
86
+ @courier="UPS",
87
+ @created_at=#<DateTime: 2014-05-12T18:34:32+00:00 ((2456790j,66872s,0n),+0s,2299161j)>,
88
+ @message="DELIVERED",
89
+ @slug="ups",
90
+ @state="NY",
91
+ @status="Delivered",
92
+ @tag="Delivered",
93
+ @zip="10075">
94
+ #<AfterShip::Checkpoint ...>,
95
+ ...
96
+ ]>
97
+ ```
98
+
99
+ Create a new tracking
100
+ https://www.aftership.com/docs/api/3.0/tracking/post-trackings
101
+
102
+ ```ruby
103
+ client.create_tracking('tracking-number', 'ups', order_id: 'external-id')
104
+
105
+ # Will return Tracking object or raise AfterShip::InvalidArgumentError
106
+ # if it exists:
107
+
108
+ #<AfterShip::Tracking ...>
109
+ ```
110
+
111
+ Update a tracking
112
+ https://www.aftership.com/docs/api/3.0/tracking/put-trackings-slug-tracking_number
113
+
114
+ ```ruby
115
+ client.update_tracking('tracking-number', 'ups', order_id: 'external-id')
116
+ ```
117
+
118
+ ## Contributing
119
+
120
+ 0. E-mail me or create an issue
121
+ 1. Fork it (https://github.com/ollie/after_ship/fork)
122
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
123
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
124
+ 4. Push to the branch (`git push origin my-new-feature`)
125
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ task default: :combo
2
+
3
+ desc 'Run tests, rubocop and generate documentation'
4
+ task :combo do
5
+ sh 'bundle exec rspec'
6
+ sh('bundle exec rubocop') {} # ignore status > 0
7
+ sh 'bundle exec yardoc'
8
+ end
9
+
10
+ desc 'Same as :combo but build a gem, too'
11
+ task mega_combo: :combo do
12
+ sh 'gem build after_ship.gemspec'
13
+ end
14
+
15
+ desc 'Start a console'
16
+ task :console do
17
+ sh 'bundle exec pry -I ./lib -r ./lib/after_ship.rb'
18
+ end
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'after_ship/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'after_ship'
8
+ spec.version = AfterShip::VERSION
9
+ spec.authors = ['Oldrich Vetesnik']
10
+ spec.email = ['oldrich.vetesnik@gmail.com']
11
+ spec.summary = 'A smallish library to talking to AfterShip via v3 API.'
12
+ spec.homepage = 'https://github.com/ollie/after_ship'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(/^(test|spec|features)\//)
18
+ spec.require_paths = ['lib']
19
+
20
+ # System
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+
23
+ # Test
24
+ spec.add_development_dependency 'rspec', '~> 3.1'
25
+ spec.add_development_dependency 'webmock', '~> 1.19'
26
+ spec.add_development_dependency 'simplecov', '~> 0.9'
27
+
28
+ # Code style, debugging, docs
29
+ spec.add_development_dependency 'rubocop', '~> 0.26'
30
+ spec.add_development_dependency 'pry', '~> 0.10'
31
+ spec.add_development_dependency 'yard', '~> 0.8'
32
+ spec.add_development_dependency 'rake', '~> 10.3'
33
+
34
+ # Networking
35
+ # Fast networking
36
+ spec.add_runtime_dependency 'typhoeus', '~> 0.6'
37
+ # A common interface to multiple JSON libraries
38
+ spec.add_runtime_dependency 'multi_json', '~> 1.10'
39
+ end
@@ -0,0 +1,140 @@
1
+ class AfterShip
2
+ # Wrapper object for AfterShip tracking checkpoint:
3
+ # https://www.aftership.com/docs/api/3.0/tracking/get-trackings-slug-tracking_number
4
+ class Checkpoint
5
+ include Attributes
6
+
7
+ # Tracking number, e.g. +1ZA2207X6794165804+.
8
+ #
9
+ # Should always be available.
10
+ #
11
+ # @return [String]
12
+ attr_reader :slug
13
+
14
+ # Location info (if any)
15
+ #
16
+ # May be empty.
17
+ #
18
+ # @return [String]
19
+ attr_accessor :city
20
+
21
+ # Courier name
22
+ #
23
+ # @return [String]
24
+ attr_accessor :courier
25
+
26
+ # Date and time of the tracking created.
27
+ #
28
+ # Should always be available.
29
+ #
30
+ # @return [DateTime]
31
+ attr_reader :created_at
32
+
33
+ # Country name of the checkpoint, may also contain other location info.
34
+ # Seems to be Alpha-2 code, e.g. +IN+, +DE+.
35
+ #
36
+ # May be empty.
37
+ #
38
+ # @return [String]
39
+ attr_accessor :country_name
40
+
41
+ # Country ISO Alpha-3 (three letters) of the checkpoint.
42
+ #
43
+ # May be empty.
44
+ #
45
+ # @return [String]
46
+ attr_accessor :country_iso3
47
+
48
+ # Checkpoint message
49
+ #
50
+ # Should always be available.
51
+ #
52
+ # @return [String]
53
+ attr_accessor :message
54
+
55
+ # Status of the checkpoint.
56
+ #
57
+ # Should always be available.
58
+ #
59
+ # @return [String]
60
+ attr_reader :tag
61
+
62
+ # Same as tag, except human-friendly:
63
+ #
64
+ # * +Pending+ => +Pending+
65
+ # * +InfoReceived+ => +Info Received+
66
+ # * +InTransit+ => +In Transit+
67
+ # * +OutForDelivery+ => +Out For Delivery+
68
+ # * +AttemptFail+ => +Attempt Failed+
69
+ # * +Delivered+ => +Delivered+
70
+ # * +Exception+ => +Exception+
71
+ # * +Expired+ => +Expired+
72
+ #
73
+ # @return [String]
74
+ attr_accessor :status
75
+
76
+ # Date and time of the checkpoint, provided by courier.
77
+ #
78
+ # Should always be available.
79
+ #
80
+ # @return [DateTime]
81
+ attr_reader :checkpoint_time
82
+
83
+ # Location info (if any).
84
+ #
85
+ # May be empty.
86
+ #
87
+ # @return [String]
88
+ attr_accessor :state
89
+
90
+ # Location info (if any).
91
+ #
92
+ # May be empty.
93
+ #
94
+ # @return [String]
95
+ attr_accessor :zip
96
+
97
+ # Better interface for a checkpoint.
98
+ #
99
+ # @param data [Hash] checkpoint hash
100
+ def initialize(data)
101
+ load_attributes(data)
102
+ end
103
+
104
+ # Tracking number, e.g. +1ZA2207X6794165804+.
105
+ #
106
+ # Should always be available.
107
+ #
108
+ # @return [String]
109
+ def slug=(value)
110
+ @slug = value
111
+ self.courier = value.upcase
112
+ @slug
113
+ end
114
+
115
+ # Date and time of the tracking created.
116
+ #
117
+ # @return [DateTime]
118
+ def created_at=(value)
119
+ @created_at = DateUtils.parse(value)
120
+ end
121
+
122
+ # Status of the checkpoint.
123
+ #
124
+ # Should always be available.
125
+ #
126
+ # @return [String]
127
+ def tag=(value)
128
+ @tag = value
129
+ self.status = TAG_STATUS.fetch(value)
130
+ @tag
131
+ end
132
+
133
+ # Date and time of the checkpoint, provided by courier.
134
+ #
135
+ # @return [DateTime]
136
+ def checkpoint_time=(value)
137
+ @checkpoint_time = DateUtils.parse(value)
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,218 @@
1
+ class AfterShip
2
+ # Wrapper object for AfterShip tracking:
3
+ # https://www.aftership.com/docs/api/3.0/tracking/get-trackings-slug-tracking_number
4
+ class Tracking
5
+ include Attributes
6
+
7
+ # Date and time of the tracking created.
8
+ #
9
+ # @return [DateTime]
10
+ attr_reader :created_at
11
+
12
+ # Date and time of the tracking last updated.
13
+ #
14
+ # @return [DateTime]
15
+ attr_reader :updated_at
16
+
17
+ # Tracking number, e.g. +1ZA2207X6794165804+.
18
+ #
19
+ # @return [String]
20
+ attr_accessor :tracking_number
21
+
22
+ # Unique code of courier.
23
+ #
24
+ # @return [String]
25
+ attr_reader :slug
26
+
27
+ # Courier name
28
+ #
29
+ # @return [String]
30
+ attr_accessor :courier
31
+
32
+ # Whether or not AfterShip will continue tracking the shipments. Value is
33
+ # +false+ when status is +Delivered+ or +Expired+.
34
+ #
35
+ # @return [Boolean]
36
+ attr_accessor :active
37
+
38
+ # Custom fields of the tracking.
39
+ #
40
+ # @return [Hash]
41
+ attr_accessor :custom_fields
42
+
43
+ # Customer name of the tracking.
44
+ #
45
+ # @return [String]
46
+ attr_accessor :customer_name
47
+
48
+ # Destination country of the tracking. ISO Alpha-3 (three letters). If you
49
+ # use postal service to send international shipments, AfterShip will
50
+ # automatically get tracking results from destination postal service based
51
+ # on destination country.
52
+ #
53
+ # @return [String]
54
+ attr_accessor :destination_country_iso3
55
+
56
+ # Email address(es) to receive email notifications. Comma separated for
57
+ # multiple values.
58
+ #
59
+ # @return [Array<String>]
60
+ attr_accessor :emails
61
+
62
+ # Expected delivery date (if any).
63
+ #
64
+ # Empty String,
65
+ # YYYY-MM-DD,
66
+ # YYYY-MM-DDTHH:MM:SS, or
67
+ # YYYY-MM-DDTHH:MM:SS+TIMEZONE.
68
+ #
69
+ # @return [DateTime]
70
+ attr_reader :expected_delivery
71
+
72
+ # Text field for order ID.
73
+ #
74
+ # @return [String]
75
+ attr_accessor :order_id
76
+
77
+ # Text field for order path.
78
+ #
79
+ # @return [String]
80
+ attr_accessor :order_id_path
81
+
82
+ # Origin country of the tracking. ISO Alpha-3 (three letters).
83
+ #
84
+ # @return [String]
85
+ attr_accessor :origin_country_iso3
86
+
87
+ # You can use the value, to direct access the tracking result at this url:
88
+ # https://yourusername.aftership.com/unique_token
89
+ #
90
+ # @return [String]
91
+ attr_accessor :unique_token
92
+
93
+ # Number of packages under the tracking.
94
+ #
95
+ # @return [Number]
96
+ attr_accessor :shipment_package_count
97
+
98
+ # Shipment type provided by carrier (if any).
99
+ #
100
+ # @return [String]
101
+ attr_accessor :shipment_type
102
+
103
+ # Signed by information for delivered shipment (if any).
104
+ #
105
+ # @return [String]
106
+ attr_accessor :signed_by
107
+
108
+ # Phone number(s) to receive sms notifications. The phone number(s) to
109
+ # receive sms notifications. Phone number should begin with <code>+</code>
110
+ # and +Area Code+ before phone number. Comma separated for multiple values.
111
+ #
112
+ # @return [Array<String>]
113
+ attr_accessor :smses
114
+
115
+ # Source of how this tracking is added.
116
+ #
117
+ # @return [String]
118
+ attr_accessor :source
119
+
120
+ # Current status of tracking.
121
+ #
122
+ # Value: +Pending+, +InfoReceived+, +InTransit+, +OutForDelivery+,
123
+ # +AttemptFail+, +Delivered+, +Exception+, +Expired+.
124
+ #
125
+ # See status definition https://www.aftership.com/docs/api/4/delivery-status.
126
+ #
127
+ # @return [String]
128
+ attr_reader :tag
129
+
130
+ # Same as tag, except human-friendly:
131
+ #
132
+ # * +Pending+ => +Pending+
133
+ # * +InfoReceived+ => +Info Received+
134
+ # * +InTransit+ => +In Transit+
135
+ # * +OutForDelivery+ => +Out For Delivery+
136
+ # * +AttemptFail+ => +Attempt Failed+
137
+ # * +Delivered+ => +Delivered+
138
+ # * +Exception+ => +Exception+
139
+ # * +Expired+ => +Expired+
140
+ #
141
+ # @return [String]
142
+ attr_accessor :status
143
+
144
+ # Title of the tracking.
145
+ #
146
+ # @return [String]
147
+ attr_accessor :title
148
+
149
+ # Number of attempts AfterShip tracks at courier's system.
150
+ #
151
+ # @return [Number]
152
+ attr_accessor :tracked_count
153
+
154
+ # Array of Checkpoint describes the checkpoint information.
155
+ #
156
+ # @return [Array<Checkpoint>]
157
+ attr_reader :checkpoints
158
+
159
+ # Better interface for a tracking.
160
+ #
161
+ # @param data [Hash] tracking hash
162
+ def initialize(data)
163
+ @checkpoints = []
164
+ load_attributes(data)
165
+ end
166
+
167
+ # Date and time of the tracking created.
168
+ #
169
+ # @return [DateTime]
170
+ def created_at=(value)
171
+ @created_at = DateTime.parse(value)
172
+ end
173
+
174
+ # Date and time of the tracking last updated.
175
+ #
176
+ # @return [DateTime]
177
+ def updated_at=(value)
178
+ @updated_at = DateTime.parse(value)
179
+ end
180
+
181
+ # Unique code of courier.
182
+ #
183
+ # @return [String]
184
+ def slug=(value)
185
+ @slug = value
186
+ self.courier = value.upcase
187
+ @slug
188
+ end
189
+
190
+ # Expected delivery date (if any).
191
+ #
192
+ # @return [DateTime]
193
+ def expected_delivery=(value)
194
+ @expected_delivery = DateUtils.parse(value)
195
+ end
196
+
197
+ # Current status of tracking.
198
+ #
199
+ # Value: +Pending+, +InfoReceived+, +InTransit+, +OutForDelivery+,
200
+ # +AttemptFail+, +Delivered+, +Exception+, +Expired+.
201
+ #
202
+ # See status definition https://www.aftership.com/docs/api/4/delivery-status.
203
+ #
204
+ # @return [String]
205
+ def tag=(value)
206
+ @tag = value
207
+ self.status = TAG_STATUS.fetch(value)
208
+ @tag
209
+ end
210
+
211
+ # Array of Checkpoint describes the checkpoint information.
212
+ #
213
+ # @return [Array<Checkpoint>]
214
+ def checkpoints=(value)
215
+ @checkpoints = value.map { |data| Checkpoint.new(data) }
216
+ end
217
+ end
218
+ end
@@ -0,0 +1,3 @@
1
+ class AfterShip
2
+ VERSION = '0.0.2'
3
+ end