easypost 2.4.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: 022e41326d9ad6741c522ddc51cdee8169a0132a
4
- data.tar.gz: 389053b0e140ead7d54488ced5c215f79d4a9930
3
+ metadata.gz: 8c4cdf8c957478f42068e095c2c3a84f6ec141c4
4
+ data.tar.gz: a44a1d79a8e7c2343038f95e0cc933298e03f837
5
5
  SHA512:
6
- metadata.gz: b4dd67994b147e1de7d0ba0b513e0e44203e10ecaa236c7a15d475b956746c5a2720d7fec643aaece62731bbc7e05b2a14748df432a6761f1c17de6a2f9dda5c
7
- data.tar.gz: d2a15deccdee35141fb29bf0da7eb1c6d71fdb76520c40eed8ed3eb0fa0b7ed0c28ef5e354c31f3704d54d637b860851f5c35736c2ff87cd6e14e5b86e82924d
6
+ metadata.gz: eb9664b47721a6f14be45a0d7042875990e3454d7c21cde4be66d104dc7e9b8358be8ddf9106b1212086aa4cdc80d4a3bc1c32a9a2ca339edf2685112a322e52
7
+ data.tar.gz: a7956f59bd5ba39691e597486fc5fbad1aa2d90d3357cc63d5f3373177f2ba34fbb3d60f9aaa0f28b5e82d6187df2f5eec5747bb97c83cb0c3130e3b0f188565
data/CHANGELOG CHANGED
@@ -1,7 +1,38 @@
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
+
1
31
  === 2.4.0 2016-12-08
2
32
 
3
33
  * Add report resource to ruby client
4
34
 
35
+
5
36
  === 2.3.0 2016-11-25
6
37
 
7
38
  * Updated dependencies to allow rest-client 2.0.0 and above
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.4.0
1
+ 2.7.1
@@ -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
@@ -1,44 +1,28 @@
1
1
  module EasyPost
2
2
  class Report < Resource
3
- REPORT_TYPES = { shprep: 'shipment', plrep: 'payment_log', trkrep: 'tracker' }
4
-
5
3
  def self.create(params={}, api_key=nil)
6
- url = self.url
4
+ url = "#{self.url}/#{params[:type]}"
7
5
  wrapped_params = {}
8
6
  wrapped_params[class_name.to_sym] = params
9
7
 
10
- if REPORT_TYPES.values.include?(params[:type].to_s)
11
- url += "/#{params[:type]}"
12
- else
13
- raise Error.new("Undetermined Report Type")
14
- end
15
-
16
8
  response, api_key = EasyPost.request(:post, url, api_key, params)
17
9
  return Util.convert_to_easypost_object(response, api_key)
18
10
  end
19
11
 
20
12
  def self.retrieve(params, api_key=nil)
21
- url = self.url
22
- obj_id = params[:id].split("_")[0]
23
-
24
- if REPORT_TYPES.has_key?(obj_id.to_sym)
25
- url += "/#{REPORT_TYPES[obj_id.to_sym]}/#{params[:id]}"
13
+ id = if params.is_a?(String)
14
+ params
26
15
  else
27
- raise Error.new("Undetermined Report Type")
16
+ params[:id]
28
17
  end
29
18
 
30
- response, api_key = EasyPost.request(:get, url, api_key, params)
31
- return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
19
+ instance = self.new(id, api_key)
20
+ instance.refresh
21
+ return instance
32
22
  end
33
23
 
34
24
  def self.all(filters={}, api_key=nil)
35
- url = self.url
36
-
37
- if REPORT_TYPES.values.include?(filters[:type].to_s)
38
- url += "/#{filters[:type]}"
39
- else
40
- raise Error.new("Undetermined Report Type")
41
- end
25
+ url = "#{self.url}/#{filters[:type]}"
42
26
 
43
27
  response, api_key = EasyPost.request(:get, url, api_key, filters)
44
28
  return EasyPost::Util::convert_to_easypost_object(response, api_key) if response
@@ -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
@@ -39,7 +39,11 @@ module EasyPost
39
39
  'PrintJob' => PrintJob,
40
40
  'CarrierAccount' => CarrierAccount,
41
41
  'User' => User,
42
- 'Report' => Report
42
+ 'Report' => Report,
43
+ 'ShipmentReport' => Report,
44
+ 'PaymentLogReport' => Report,
45
+ 'TrackerReport' => Report,
46
+ 'Webhook' => Webhook
43
47
  }
44
48
 
45
49
  prefixes = {
@@ -65,6 +69,10 @@ module EasyPost
65
69
  'printjob' => PrintJob,
66
70
  'ca' => CarrierAccount,
67
71
  'user' => User,
72
+ 'shprep' => Report,
73
+ 'plrep' => Report,
74
+ 'trkrep' => Report,
75
+ 'hook' => Webhook
68
76
  }
69
77
 
70
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
@@ -32,6 +32,7 @@ require 'easypost/print_job'
32
32
  require 'easypost/carrier_account'
33
33
  require 'easypost/user'
34
34
  require 'easypost/report'
35
+ require 'easypost/webhook'
35
36
 
36
37
  require 'easypost/error'
37
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(
data/spec/report_spec.rb CHANGED
@@ -1,76 +1,59 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe EasyPost::Report do
4
- [:shipment, :tracker, :payment_log].each do |report_type|
5
- context "report" do
6
- let(:type) { report_type }
7
- let(:type_name) {
8
- case type
9
- when :shipment
10
- "ShipmentReport"
11
- when :tracker
12
- "TrackerReport"
13
- when :payment_log
14
- "PaymentLogReport"
15
- else
16
- raise "Invalid type!"
17
- end
18
- }
19
-
20
- describe '#create' do
21
- it 'creates a report object' do
22
- report = EasyPost::Report.create(
23
- start_date: Date.today - 30,
24
- end_date: Date.today,
25
- type: type
26
- )
27
- expect(report.object).to eq type_name
28
- # will switch that test on when tracker status is deployed
29
- # expect(report.status).to eq 'available'
30
- end
31
- end
32
-
33
- describe '#retrieve' do
34
- it 'retrieves a user created report by public_id' do
35
- report_1 = EasyPost::Report.create(
36
- start_date: Date.today - 30,
37
- end_date: Date.today,
38
- type: type
39
- )
40
- report_2 = EasyPost::Report.retrieve(id: report_1.id)
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
41
16
 
42
- expect(report_1.object).to eq type_name
43
- expect(report_2.object).to eq type_name
44
- expect(report_2.id).to eq(report_1.id)
45
- end
46
- end
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)
47
25
 
48
- describe '#all' do
49
- it 'retrieves all user created reports' do
50
- report_1 = EasyPost::Report.create(
51
- start_date: Date.today - 25,
52
- end_date: Date.today,
53
- type: type
54
- )
26
+ expect(report_2.id).to eq(report_1.id)
27
+ end
55
28
 
56
- report_2 = EasyPost::Report.create(
57
- start_date: Date.today - 29,
58
- end_date: Date.today,
59
- type: type
60
- )
61
- reports = EasyPost::Report.all(type: type)
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)
62
36
 
63
- expect(reports.count).to eq 2
64
- end
65
- end
37
+ expect(report_2.id).to eq(report_1.id)
66
38
  end
67
39
  end
68
40
 
69
- it 'fails to create a report object' do
70
- expect { EasyPost::Report.create(
71
- start_date: Date.today - 30,
72
- end_date: Date.today,
73
- type: 'foobar'
74
- ) }.to raise_exception(EasyPost::Error)
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
75
58
  end
76
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
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easypost
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.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-12-08 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
@@ -126,6 +126,7 @@ files:
126
126
  - lib/easypost/user.rb
127
127
  - lib/easypost/util.rb
128
128
  - lib/easypost/version.rb
129
+ - lib/easypost/webhook.rb
129
130
  - spec/address_spec.rb
130
131
  - spec/batch_spec.rb
131
132
  - spec/carrier_account_spec.rb
@@ -135,11 +136,13 @@ files:
135
136
  - spec/order_spec.rb
136
137
  - spec/pickup_spec.rb
137
138
  - spec/report_spec.rb
139
+ - spec/scan_form_spec.rb
138
140
  - spec/shipment_spec.rb
139
141
  - spec/spec_helper.rb
140
142
  - spec/support/constant.rb
141
143
  - spec/tracker_spec.rb
142
144
  - spec/user_spec.rb
145
+ - spec/webhook_spec.rb
143
146
  homepage: https://www.easypost.com/docs
144
147
  licenses: []
145
148
  metadata: {}
@@ -173,8 +176,10 @@ test_files:
173
176
  - spec/order_spec.rb
174
177
  - spec/pickup_spec.rb
175
178
  - spec/report_spec.rb
179
+ - spec/scan_form_spec.rb
176
180
  - spec/shipment_spec.rb
177
181
  - spec/spec_helper.rb
178
182
  - spec/support/constant.rb
179
183
  - spec/tracker_spec.rb
180
184
  - spec/user_spec.rb
185
+ - spec/webhook_spec.rb