easypost 2.2.0 → 2.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8deaad3af93387997d1bd5b4c3112ec58628a6bb
4
- data.tar.gz: 16fef7e30f4b5de916e6057ef31b901a6d9c47ea
3
+ metadata.gz: 8c4cdf8c957478f42068e095c2c3a84f6ec141c4
4
+ data.tar.gz: a44a1d79a8e7c2343038f95e0cc933298e03f837
5
5
  SHA512:
6
- metadata.gz: 6e3442b420f010160a89409c46893793949b993510d9807bdea7a5faed1eb806ee5ed7895d81c2fee6cc599090ffce3c4f2c0104ee49ec0ec2af1517b310bf0b
7
- data.tar.gz: b07d522882ee05908622130530b9ae2820c65f79be71887ad380499bc7e72be62065376888f0ccb68ef9d79c2995ea1088d68b6ebb606d136e6295bbe7e39718
6
+ metadata.gz: eb9664b47721a6f14be45a0d7042875990e3454d7c21cde4be66d104dc7e9b8358be8ddf9106b1212086aa4cdc80d4a3bc1c32a9a2ca339edf2685112a322e52
7
+ data.tar.gz: a7956f59bd5ba39691e597486fc5fbad1aa2d90d3357cc63d5f3373177f2ba34fbb3d60f9aaa0f28b5e82d6187df2f5eec5747bb97c83cb0c3130e3b0f188565
data/CHANGELOG CHANGED
@@ -1,3 +1,43 @@
1
+ === 2.7.1 2017-05-25
2
+
3
+ * Allow reports to be retrieved without passing a type
4
+
5
+
6
+ === 2.7.0 2017-04-04
7
+
8
+ * Changed Report CRUD signatures. requires report type to be passed
9
+
10
+
11
+ === 2.6.2 2017-02-14
12
+
13
+ * Added get_rates method for Orders
14
+
15
+
16
+ === 2.6.1 2017-01-19
17
+
18
+ * Updated create method for ScanForms
19
+
20
+
21
+ === 2.6.0 2017-01-17
22
+
23
+ * Add basic CRUD methods for Webhooks
24
+
25
+
26
+ === 2.5.0 2016-12-19
27
+
28
+ * Add prefixes to report in utils
29
+
30
+
31
+ === 2.4.0 2016-12-08
32
+
33
+ * Add report resource to ruby client
34
+
35
+
36
+ === 2.3.0 2016-11-25
37
+
38
+ * Updated dependencies to allow rest-client 2.0.0 and above
39
+
40
+
1
41
  === 2.2.0 2016-07-26
2
42
 
3
43
  * Added standalone Insurance model
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
1
  source 'https://rubygems.org'
2
- gemspec
2
+ gemspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.7.1
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.0.0
data/easypost.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'rest-client', '~> 1.4'
21
+ spec.add_dependency 'rest-client', '>= 1.4'
22
22
  spec.add_dependency 'multi_json', '>= 1.3.0'
23
23
  spec.add_development_dependency 'bundler', '~> 1.7'
24
24
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -1,6 +1,13 @@
1
1
  module EasyPost
2
2
  class Order < Resource
3
3
 
4
+ def get_rates(params={})
5
+ response, api_key = EasyPost.request(:get, url + '/rates', @api_key, params)
6
+ self.refresh_from(response, @api_key, true)
7
+
8
+ return self
9
+ end
10
+
4
11
  def buy(params={})
5
12
  if params.instance_of?(EasyPost::Rate)
6
13
  temp = params.clone
@@ -0,0 +1,31 @@
1
+ module EasyPost
2
+ class Report < Resource
3
+ def self.create(params={}, api_key=nil)
4
+ url = "#{self.url}/#{params[:type]}"
5
+ wrapped_params = {}
6
+ wrapped_params[class_name.to_sym] = params
7
+
8
+ response, api_key = EasyPost.request(:post, url, api_key, params)
9
+ return Util.convert_to_easypost_object(response, api_key)
10
+ end
11
+
12
+ def self.retrieve(params, api_key=nil)
13
+ id = if params.is_a?(String)
14
+ params
15
+ else
16
+ params[:id]
17
+ end
18
+
19
+ instance = self.new(id, api_key)
20
+ instance.refresh
21
+ return instance
22
+ end
23
+
24
+ def self.all(filters={}, api_key=nil)
25
+ url = "#{self.url}/#{filters[:type]}"
26
+
27
+ response, api_key = EasyPost.request(:get, url, api_key, filters)
28
+ return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
29
+ end
30
+ end
31
+ end
@@ -1,4 +1,8 @@
1
1
  module EasyPost
2
2
  class ScanForm < Resource
3
+ def self.create(params={}, api_key=nil)
4
+ response, api_key = EasyPost.request(:post, self.url, api_key, params)
5
+ return Util.convert_to_easypost_object(response, api_key)
6
+ end
3
7
  end
4
8
  end
data/lib/easypost/util.rb CHANGED
@@ -38,7 +38,12 @@ module EasyPost
38
38
  'Printer' => Printer,
39
39
  'PrintJob' => PrintJob,
40
40
  'CarrierAccount' => CarrierAccount,
41
- 'User' => User
41
+ 'User' => User,
42
+ 'Report' => Report,
43
+ 'ShipmentReport' => Report,
44
+ 'PaymentLogReport' => Report,
45
+ 'TrackerReport' => Report,
46
+ 'Webhook' => Webhook
42
47
  }
43
48
 
44
49
  prefixes = {
@@ -63,7 +68,11 @@ module EasyPost
63
68
  'printer' => Printer,
64
69
  'printjob' => PrintJob,
65
70
  'ca' => CarrierAccount,
66
- 'user' => User
71
+ 'user' => User,
72
+ 'shprep' => Report,
73
+ 'plrep' => Report,
74
+ 'trkrep' => Report,
75
+ 'hook' => Webhook
67
76
  }
68
77
 
69
78
  case response
@@ -0,0 +1,28 @@
1
+ module EasyPost
2
+ class Webhook < Resource
3
+ def update(params={})
4
+ unless self.id
5
+ raise Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
6
+ end
7
+ instance_url = "#{self.class.url}/#{CGI.escape(id)}"
8
+
9
+ response, api_key = EasyPost.request(:put, instance_url, @api_key, params)
10
+ self.refresh_from(response, api_key, true)
11
+
12
+ return self
13
+ end
14
+
15
+ def delete
16
+ # Note: This method is redefined here since the "url" method conflicts with the objects field
17
+ unless self.id
18
+ raise Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
19
+ end
20
+ instance_url = "#{self.class.url}/#{CGI.escape(id)}"
21
+
22
+ response, api_key = EasyPost.request(:delete, instance_url, @api_key)
23
+ refresh_from(response, api_key)
24
+
25
+ return self
26
+ end
27
+ end
28
+ end
data/lib/easypost.rb CHANGED
@@ -31,6 +31,8 @@ require 'easypost/printer'
31
31
  require 'easypost/print_job'
32
32
  require 'easypost/carrier_account'
33
33
  require 'easypost/user'
34
+ require 'easypost/report'
35
+ require 'easypost/webhook'
34
36
 
35
37
  require 'easypost/error'
36
38
 
data/spec/order_spec.rb CHANGED
@@ -1,6 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyPost::Order do
4
+ describe '#get_rates' do
5
+ it 'refreshes rates' do
6
+ order = EasyPost::Order.create(
7
+ to_address: ADDRESS[:california],
8
+ from_address: ADDRESS[:missouri],
9
+ shipments: [{
10
+ parcel: {length: 8, width: 6, height: 4, weight: 12}
11
+ }]
12
+ )
13
+
14
+ expect(order).to be_an_instance_of(EasyPost::Order)
15
+ expect(order.shipments.first).to be_an_instance_of(EasyPost::Shipment)
16
+
17
+ rate_id = order.shipments.first.rates.first.id
18
+ expect(rate_id).not_to be_nil
19
+
20
+ order.get_rates
21
+
22
+ new_rate_id = order.shipments.first.rates.first.id
23
+ expect(new_rate_id).not_to be_nil
24
+ expect(new_rate_id).not_to eq(rate_id)
25
+ end
26
+ end
27
+
4
28
  describe '#create' do
5
29
  it 'creates an order out of a single shipment' do
6
30
  order = EasyPost::Order.create(
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe EasyPost::Report do
4
+ TYPE = 'shipment'
5
+ describe '#create' do
6
+ it 'creates a report object' do
7
+ report = EasyPost::Report.create(
8
+ start_date: Date.today - 30,
9
+ end_date: Date.today,
10
+ type: TYPE
11
+ )
12
+ expect(report.object).to eq 'ShipmentReport'
13
+ expect(['available', 'new']).to include(report.status)
14
+ end
15
+ end
16
+
17
+ describe '#retrieve' do
18
+ it 'retrieves a user created report by public_id as a hash' do
19
+ report_1 = EasyPost::Report.create(
20
+ start_date: Date.today - 30,
21
+ end_date: Date.today,
22
+ type: TYPE
23
+ )
24
+ report_2 = EasyPost::Report.retrieve(id: report_1.id)
25
+
26
+ expect(report_2.id).to eq(report_1.id)
27
+ end
28
+
29
+ it 'retrieves a user created report by public_id as a string' do
30
+ report_1 = EasyPost::Report.create(
31
+ start_date: Date.today - 30,
32
+ end_date: Date.today,
33
+ type: TYPE
34
+ )
35
+ report_2 = EasyPost::Report.retrieve(report_1.id)
36
+
37
+ expect(report_2.id).to eq(report_1.id)
38
+ end
39
+ end
40
+
41
+ describe '#all' do
42
+ it 'retrieves all user created reports' do
43
+ report_1 = EasyPost::Report.create(
44
+ start_date: Date.today - 25,
45
+ end_date: Date.today,
46
+ type: TYPE
47
+ )
48
+
49
+ report_2 = EasyPost::Report.create(
50
+ start_date: Date.today - 29,
51
+ end_date: Date.today,
52
+ type: TYPE
53
+ )
54
+ reports = EasyPost::Report.all(type: TYPE)
55
+
56
+ expect(reports.count).to eq 2
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe EasyPost::ScanForm do
4
+ let(:shipment) do
5
+ shipment = EasyPost::Shipment.create(
6
+ to_address: ADDRESS[:canada],
7
+ from_address: ADDRESS[:california],
8
+ parcel: PARCEL[:dimensions],
9
+ customs_info: CUSTOMS_INFO[:shirt]
10
+ )
11
+
12
+ shipment.buy(
13
+ rate: shipment.lowest_rate("usps")
14
+ )
15
+ end
16
+
17
+ describe '#create' do
18
+ it 'purchases postage for an international shipment' do
19
+ scan_form = EasyPost::ScanForm.create(shipments: [shipment])
20
+
21
+ expect(scan_form.id).not_to be_nil
22
+ expect(scan_form.tracking_codes.first).to eq(shipment.tracking_code)
23
+ end
24
+ end
25
+
26
+ describe '#retrieve' do
27
+ let(:scan_form) { EasyPost::ScanForm.create(shipments: [shipment]) }
28
+
29
+ it 'retrieves the same scan_form' do
30
+ scan_form2 = EasyPost::ScanForm.retrieve(scan_form.id)
31
+
32
+ expect(scan_form2.id).to eq(scan_form.id)
33
+ end
34
+ end
35
+
36
+ describe '#all' do
37
+ let!(:scan_form) { EasyPost::ScanForm.create(shipments: [shipment]) }
38
+
39
+ it 'indexes the scan_forms' do
40
+ params = {page_size: 2}
41
+ scan_forms = EasyPost::ScanForm.all(params)
42
+
43
+ expect(scan_forms["scan_forms"].first.id).to eq(scan_form.id)
44
+ end
45
+ end
46
+ end
@@ -45,22 +45,42 @@ describe EasyPost::Shipment do
45
45
  )
46
46
  expect(shipment.postage_label.label_url.length).to be > 0
47
47
  end
48
- end
49
48
 
50
- it 'creates and returns a tracker with shipment purchase' do
51
- shipment = EasyPost::Shipment.create(
52
- :to_address => ADDRESS[:missouri],
53
- :from_address => ADDRESS[:california],
54
- :parcel => PARCEL[:dimensions]
55
- )
56
- expect(shipment).to be_an_instance_of(EasyPost::Shipment)
49
+ it 'creates and returns a tracker with shipment purchase' do
50
+ shipment = EasyPost::Shipment.create(
51
+ :to_address => ADDRESS[:missouri],
52
+ :from_address => ADDRESS[:california],
53
+ :parcel => PARCEL[:dimensions]
54
+ )
55
+ expect(shipment).to be_an_instance_of(EasyPost::Shipment)
57
56
 
58
- shipment.buy(
59
- :rate => shipment.lowest_rate("usps")
60
- )
57
+ shipment.buy(
58
+ :rate => shipment.lowest_rate("usps")
59
+ )
60
+
61
+ tracker = shipment.tracker
62
+ expect(tracker.shipment_id).to eq(shipment.id)
63
+ end
61
64
 
62
- tracker = shipment.tracker
63
- expect(tracker.shipment_id).to eq(shipment.id)
65
+ it 'purchases postage when only a rate id is provided' do
66
+ shipment = EasyPost::Shipment.create(
67
+ :to_address => ADDRESS[:missouri],
68
+ :from_address => ADDRESS[:california],
69
+ :parcel => PARCEL[:dimensions]
70
+ )
71
+ expect(shipment).to be_an_instance_of(EasyPost::Shipment)
72
+
73
+ rate = shipment.rates.first
74
+ rate_hash = {id: rate.id}
75
+
76
+ shipment.buy(
77
+ :rate => rate_hash
78
+ )
79
+
80
+ expect(shipment.postage_label.label_url.length).to be > 0
81
+ tracker = shipment.tracker
82
+ expect(tracker.shipment_id).to eq(shipment.id)
83
+ end
64
84
  end
65
85
 
66
86
  describe '#insure' do
data/spec/user_spec.rb CHANGED
@@ -64,8 +64,8 @@ describe EasyPost::User do
64
64
  # api_keys = EasyPost::User.all_api_keys
65
65
 
66
66
  # my_keys = api_keys.keys
67
- # expect(my_keys.first.mode).to eq("production")
68
- # expect(my_keys.last.mode).to eq("test")
67
+ # expect(my_keys.first.mode).to eq("test")
68
+ # expect(my_keys.last.mode).to eq("production")
69
69
 
70
70
  # me = EasyPost::User.retrieve_me
71
71
  # children_count = me.children.count
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe EasyPost::Webhook do
4
+ let(:url) { "http://example.com" }
5
+ let(:webhook) { EasyPost::Webhook.create({url: url}) }
6
+
7
+ context 'with automated cleanup' do
8
+ after do
9
+ webhook.delete()
10
+ end
11
+
12
+ describe '#create' do
13
+ it 'creates' do
14
+ expect(webhook.id).not_to be_nil
15
+ expect(webhook.url).to eq(url)
16
+ expect(webhook.mode).to eq("test")
17
+ expect(webhook.disabled_at).to be_nil
18
+ expect(webhook.class).to eq(EasyPost::Webhook)
19
+ end
20
+ end
21
+
22
+ describe '#retrieve' do
23
+ it 'retrieves' do
24
+ hook = EasyPost::Webhook.retrieve(webhook.id)
25
+
26
+ expect(hook.id).to eq(webhook.id)
27
+ expect(hook.url).to eq(url)
28
+ expect(hook.mode).to eq("test")
29
+ expect(hook.disabled_at).to be_nil
30
+ expect(hook.class).to eq(EasyPost::Webhook)
31
+ end
32
+ end
33
+
34
+ describe '#index' do
35
+ it 'indexes with the recently created webhook as the last one' do
36
+ webhook
37
+ webhooks = EasyPost::Webhook.all()
38
+
39
+ hook = webhooks["webhooks"].last
40
+
41
+ expect(hook.id).to eq(webhook.id)
42
+ expect(hook.url).to eq(url)
43
+ expect(hook.mode).to eq("test")
44
+ expect(hook.disabled_at).to be_nil
45
+ expect(hook.class).to eq(EasyPost::Webhook)
46
+ end
47
+ end
48
+
49
+ describe '#retrieve' do
50
+ it 'retrieves' do
51
+ hook = webhook.update()
52
+
53
+ expect(hook.id).to eq(webhook.id)
54
+ expect(hook.url).to eq(url)
55
+ expect(hook.mode).to eq("test")
56
+ expect(hook.disabled_at).to be_nil
57
+ expect(hook.class).to eq(EasyPost::Webhook)
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '#delete' do
63
+ it 'deletes the tracker' do
64
+ webhook.delete()
65
+
66
+ begin
67
+ EasyPost::Webhook.retrieve(webhook.id)
68
+ rescue EasyPost::Error => e
69
+ expect(e.http_status).to eq(404)
70
+ expect(e.code).to eq("NOT_FOUND")
71
+ expect(e.message).to eq("The requested resource could not be found.")
72
+ end
73
+ end
74
+ end
75
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easypost
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sawyer Bateman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-26 00:00:00.000000000 Z
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.4'
27
27
  - !ruby/object:Gem::Dependency
@@ -95,6 +95,7 @@ files:
95
95
  - Rakefile
96
96
  - VERSION
97
97
  - bin/easypost-irb
98
+ - circle.yml
98
99
  - easypost.gemspec
99
100
  - lib/easypost.rb
100
101
  - lib/easypost/address.rb
@@ -117,6 +118,7 @@ files:
117
118
  - lib/easypost/printer.rb
118
119
  - lib/easypost/rate.rb
119
120
  - lib/easypost/refund.rb
121
+ - lib/easypost/report.rb
120
122
  - lib/easypost/resource.rb
121
123
  - lib/easypost/scan_form.rb
122
124
  - lib/easypost/shipment.rb
@@ -124,6 +126,7 @@ files:
124
126
  - lib/easypost/user.rb
125
127
  - lib/easypost/util.rb
126
128
  - lib/easypost/version.rb
129
+ - lib/easypost/webhook.rb
127
130
  - spec/address_spec.rb
128
131
  - spec/batch_spec.rb
129
132
  - spec/carrier_account_spec.rb
@@ -132,11 +135,14 @@ files:
132
135
  - spec/item_spec.rb
133
136
  - spec/order_spec.rb
134
137
  - spec/pickup_spec.rb
138
+ - spec/report_spec.rb
139
+ - spec/scan_form_spec.rb
135
140
  - spec/shipment_spec.rb
136
141
  - spec/spec_helper.rb
137
142
  - spec/support/constant.rb
138
143
  - spec/tracker_spec.rb
139
144
  - spec/user_spec.rb
145
+ - spec/webhook_spec.rb
140
146
  homepage: https://www.easypost.com/docs
141
147
  licenses: []
142
148
  metadata: {}
@@ -169,8 +175,11 @@ test_files:
169
175
  - spec/item_spec.rb
170
176
  - spec/order_spec.rb
171
177
  - spec/pickup_spec.rb
178
+ - spec/report_spec.rb
179
+ - spec/scan_form_spec.rb
172
180
  - spec/shipment_spec.rb
173
181
  - spec/spec_helper.rb
174
182
  - spec/support/constant.rb
175
183
  - spec/tracker_spec.rb
176
184
  - spec/user_spec.rb
185
+ - spec/webhook_spec.rb