easypost 3.1.4 → 3.1.5

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.
@@ -1,15 +1,13 @@
1
- module EasyPost
2
- class Tracker < Resource
3
- def self.create_list(params={}, api_key=nil)
4
- url = self.url + '/create_list'
5
- response = EasyPost.make_request(:post, url, api_key, params)
6
- return true
7
- end
1
+ class EasyPost::Tracker < EasyPost::Resource
2
+ def self.create_list(params={}, api_key=nil)
3
+ url = self.url + '/create_list'
4
+ response = EasyPost.make_request(:post, url, api_key, params)
5
+ return true
6
+ end
8
7
 
9
- def self.all_updated(params={}, api_key=nil)
10
- url = self.url + '/all_updated'
11
- response = EasyPost.make_request(:get, url, api_key, params)
12
- return Util.convert_to_easypost_object(response, api_key)
13
- end
8
+ def self.all_updated(params={}, api_key=nil)
9
+ url = self.url + '/all_updated'
10
+ response = EasyPost.make_request(:get, url, api_key, params)
11
+ return EasyPost::Util.convert_to_easypost_object(response, api_key)
14
12
  end
15
13
  end
@@ -1,47 +1,45 @@
1
- module EasyPost
2
- class User < Resource
3
- def self.create(params={}, api_key=nil)
4
- response = EasyPost.make_request(:post, self.url, api_key, {self.class_name.to_sym => params})
5
- return Util.convert_to_easypost_object(response, api_key)
6
- end
1
+ class EasyPost::User < EasyPost::Resource
2
+ def self.create(params={}, api_key=nil)
3
+ response = EasyPost.make_request(:post, self.url, api_key, {self.class_name.to_sym => params})
4
+ return EasyPost::Util.convert_to_easypost_object(response, api_key)
5
+ end
7
6
 
8
- def save
9
- if @unsaved_values.length > 0
10
- values = {}
11
- @unsaved_values.each { |k| values[k] = @values[k] }
7
+ def save
8
+ if @unsaved_values.length > 0
9
+ values = {}
10
+ @unsaved_values.each { |k| values[k] = @values[k] }
12
11
 
13
- wrapped_params = {user: values}
12
+ wrapped_params = {user: values}
14
13
 
15
- response = EasyPost.make_request(:put, url, @api_key, wrapped_params)
16
- refresh_from(response, api_key)
17
- end
18
- return self
14
+ response = EasyPost.make_request(:put, url, @api_key, wrapped_params)
15
+ refresh_from(response, api_key)
19
16
  end
17
+ return self
18
+ end
20
19
 
21
- def self.retrieve_me
22
- self.all
23
- end
20
+ def self.retrieve_me
21
+ self.all
22
+ end
24
23
 
25
- def self.all_api_keys
26
- response = EasyPost.make_request(:get, "/api_keys", @api_key)
27
- return Util.convert_to_easypost_object(response, api_key)
28
- end
24
+ def self.all_api_keys
25
+ response = EasyPost.make_request(:get, "/api_keys", @api_key)
26
+ return EasyPost::Util.convert_to_easypost_object(response, api_key)
27
+ end
28
+
29
+ def api_keys
30
+ api_keys = EasyPost::User.all_api_keys
29
31
 
30
- def api_keys
31
- api_keys = EasyPost::User.all_api_keys
32
-
33
- if api_keys.id == self.id
34
- my_api_keys = api_keys.keys
35
- else
36
- for child in api_keys.children
37
- if child.id == self.id
38
- my_api_keys = child.keys
39
- break
40
- end
32
+ if api_keys.id == self.id
33
+ my_api_keys = api_keys.keys
34
+ else
35
+ for child in api_keys.children
36
+ if child.id == self.id
37
+ my_api_keys = child.keys
38
+ break
41
39
  end
42
40
  end
43
-
44
- my_api_keys
45
41
  end
42
+
43
+ my_api_keys
46
44
  end
47
45
  end
@@ -1,112 +1,110 @@
1
- module EasyPost
2
- module Util
3
- def self.objects_to_ids(obj)
4
- case obj
5
- when Resource
6
- return {:id => obj.id}
7
- when Hash
8
- result = {}
9
- obj.each { |k, v| result[k] = objects_to_ids(v) unless v.nil? }
10
- return result
11
- when Array
12
- return obj.map { |v| objects_to_ids(v) }
13
- else
14
- return obj
15
- end
1
+ module EasyPost::Util
2
+ def self.objects_to_ids(obj)
3
+ case obj
4
+ when EasyPost::Resource
5
+ return {:id => obj.id}
6
+ when Hash
7
+ result = {}
8
+ obj.each { |k, v| result[k] = objects_to_ids(v) unless v.nil? }
9
+ return result
10
+ when Array
11
+ return obj.map { |v| objects_to_ids(v) }
12
+ else
13
+ return obj
16
14
  end
15
+ end
17
16
 
18
- def self.normalize_string_list(lst)
19
- lst = lst.is_a?(String) ? lst.split(',') : Array(lst)
20
- lst.map(&:to_s).map(&:downcase).map(&:strip)
21
- end
17
+ def self.normalize_string_list(lst)
18
+ lst = lst.is_a?(String) ? lst.split(',') : Array(lst)
19
+ lst.map(&:to_s).map(&:downcase).map(&:strip)
20
+ end
22
21
 
23
- def self.convert_to_easypost_object(response, api_key, parent=nil, name=nil)
24
- types = {
25
- 'Address' => Address,
26
- 'ScanForm' => ScanForm,
27
- 'CustomsItem' => CustomsItem,
28
- 'CustomsInfo' => CustomsInfo,
29
- 'Parcel' => Parcel,
30
- 'Shipment' => Shipment,
31
- 'Rate' => Rate,
32
- 'Refund' => Refund,
33
- 'Event' => Event,
34
- 'Batch' => Batch,
35
- 'Tracker' => Tracker,
36
- 'Item' => Item,
37
- 'Insurance' => Insurance,
38
- 'Order' => Order,
39
- 'Pickup' => Pickup,
40
- 'PickupRate' => PickupRate,
41
- 'PostageLabel' => PostageLabel,
42
- 'Printer' => Printer,
43
- 'PrintJob' => PrintJob,
44
- 'CarrierAccount' => CarrierAccount,
45
- 'User' => User,
46
- 'Report' => Report,
47
- 'ShipmentReport' => Report,
48
- 'PaymentLogReport' => Report,
49
- 'TrackerReport' => Report,
50
- 'RefundReport' => Report,
51
- 'ShipmentInvoiceReport' => Report,
52
- 'Webhook' => Webhook
53
- }
22
+ def self.convert_to_easypost_object(response, api_key, parent=nil, name=nil)
23
+ types = {
24
+ 'Address' => EasyPost::Address,
25
+ 'ScanForm' => EasyPost::ScanForm,
26
+ 'CustomsItem' => EasyPost::CustomsItem,
27
+ 'CustomsInfo' => EasyPost::CustomsInfo,
28
+ 'Parcel' => EasyPost::Parcel,
29
+ 'Shipment' => EasyPost::Shipment,
30
+ 'Rate' => EasyPost::Rate,
31
+ 'Refund' => EasyPost::Refund,
32
+ 'Event' => EasyPost::Event,
33
+ 'Batch' => EasyPost::Batch,
34
+ 'Tracker' => EasyPost::Tracker,
35
+ 'Item' => EasyPost::Item,
36
+ 'Insurance' => EasyPost::Insurance,
37
+ 'Order' => EasyPost::Order,
38
+ 'Pickup' => EasyPost::Pickup,
39
+ 'PickupRate' => EasyPost::PickupRate,
40
+ 'PostageLabel' => EasyPost::PostageLabel,
41
+ 'Printer' => EasyPost::Printer,
42
+ 'PrintJob' => EasyPost::PrintJob,
43
+ 'CarrierAccount' => EasyPost::CarrierAccount,
44
+ 'User' => EasyPost::User,
45
+ 'Report' => EasyPost::Report,
46
+ 'ShipmentReport' => EasyPost::Report,
47
+ 'PaymentLogReport' => EasyPost::Report,
48
+ 'TrackerReport' => EasyPost::Report,
49
+ 'RefundReport' => EasyPost::Report,
50
+ 'ShipmentInvoiceReport' => EasyPost::Report,
51
+ 'Webhook' => EasyPost::Webhook
52
+ }
54
53
 
55
- prefixes = {
56
- 'adr' => Address,
57
- 'sf' => ScanForm,
58
- 'cstitem' => CustomsItem,
59
- 'cstinfo' => CustomsInfo,
60
- 'prcl' => Parcel,
61
- 'shp' => Shipment,
62
- 'rate' => Rate,
63
- 'rfnd' => Refund,
64
- 'evt' => Event,
65
- 'batch' => Batch,
66
- 'trk' => Tracker,
67
- 'item' => Item,
68
- 'ins' => Insurance,
69
- 'order' => Order,
70
- 'pickup' => Pickup,
71
- 'pickuprate' => PickupRate,
72
- 'pl' => PostageLabel,
73
- 'printer' => Printer,
74
- 'printjob' => PrintJob,
75
- 'ca' => CarrierAccount,
76
- 'user' => User,
77
- 'shprep' => Report,
78
- 'plrep' => Report,
79
- 'trkrep' => Report,
80
- 'refrep' => Report,
81
- 'shpinvrep' => Report,
82
- 'hook' => Webhook
83
- }
54
+ prefixes = {
55
+ 'adr' => EasyPost::Address,
56
+ 'sf' => EasyPost::ScanForm,
57
+ 'cstitem' => EasyPost::CustomsItem,
58
+ 'cstinfo' => EasyPost::CustomsInfo,
59
+ 'prcl' => EasyPost::Parcel,
60
+ 'shp' => EasyPost::Shipment,
61
+ 'rate' => EasyPost::Rate,
62
+ 'rfnd' => EasyPost::Refund,
63
+ 'evt' => EasyPost::Event,
64
+ 'batch' => EasyPost::Batch,
65
+ 'trk' => EasyPost::Tracker,
66
+ 'item' => EasyPost::Item,
67
+ 'ins' => EasyPost::Insurance,
68
+ 'order' => EasyPost::Order,
69
+ 'pickup' => EasyPost::Pickup,
70
+ 'pickuprate' => EasyPost::PickupRate,
71
+ 'pl' => EasyPost::PostageLabel,
72
+ 'printer' => EasyPost::Printer,
73
+ 'printjob' => EasyPost::PrintJob,
74
+ 'ca' => EasyPost::CarrierAccount,
75
+ 'user' => EasyPost::User,
76
+ 'shprep' => EasyPost::Report,
77
+ 'plrep' => EasyPost::Report,
78
+ 'trkrep' => EasyPost::Report,
79
+ 'refrep' => EasyPost::Report,
80
+ 'shpinvrep' => EasyPost::Report,
81
+ 'hook' => EasyPost::Webhook
82
+ }
84
83
 
85
- case response
86
- when Array
87
- return response.map { |i| convert_to_easypost_object(i, api_key, parent) }
88
- when Hash
89
- if cls_name = response[:object]
90
- cls = types[cls_name]
91
- elsif response[:id]
92
- if response[:id].index('_').nil?
93
- cls = EasyPostObject
94
- elsif cls_prefix = response[:id][0..response[:id].index('_')]
95
- cls = prefixes[cls_prefix[0..-2]]
96
- end
97
- elsif response['id']
98
- if response['id'].index('_').nil?
99
- cls = EasyPostObject
100
- elsif cls_prefix = response['id'][0..response['id'].index('_')]
101
- cls = prefixes[cls_prefix[0..-2]]
102
- end
84
+ case response
85
+ when Array
86
+ return response.map { |i| convert_to_easypost_object(i, api_key, parent) }
87
+ when Hash
88
+ if cls_name = response[:object]
89
+ cls = types[cls_name]
90
+ elsif response[:id]
91
+ if response[:id].index('_').nil?
92
+ cls = EasyPost::EasyPostObject
93
+ elsif cls_prefix = response[:id][0..response[:id].index('_')]
94
+ cls = prefixes[cls_prefix[0..-2]]
95
+ end
96
+ elsif response['id']
97
+ if response['id'].index('_').nil?
98
+ cls = EasyPost::EasyPostObject
99
+ elsif cls_prefix = response['id'][0..response['id'].index('_')]
100
+ cls = prefixes[cls_prefix[0..-2]]
103
101
  end
104
-
105
- cls ||= EasyPostObject
106
- return cls.construct_from(response, api_key, parent, name)
107
- else
108
- return response
109
102
  end
103
+
104
+ cls ||= EasyPost::EasyPostObject
105
+ return cls.construct_from(response, api_key, parent, name)
106
+ else
107
+ return response
110
108
  end
111
109
  end
112
110
  end
@@ -1,31 +1,29 @@
1
- module EasyPost
2
- class Webhook < Resource
3
- def update(params={})
4
- # NOTE: This method is redefined here since the "url" method conflicts
5
- # with the objects field
6
- unless self.id
7
- raise Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
8
- end
9
- instance_url = "#{self.class.url}/#{CGI.escape(id)}"
10
-
11
- response = EasyPost.make_request(:put, instance_url, @api_key, params)
12
- self.refresh_from(response, api_key, true)
13
-
14
- return self
1
+ class EasyPost::Webhook < EasyPost::Resource
2
+ def update(params={})
3
+ # NOTE: This method is redefined here since the "url" method conflicts
4
+ # with the objects field
5
+ unless self.id
6
+ raise EasyPost::Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
15
7
  end
8
+ instance_url = "#{self.class.url}/#{CGI.escape(id)}"
16
9
 
17
- def delete
18
- # NOTE: This method is redefined here since the "url" method conflicts
19
- # with the objects field
20
- unless self.id
21
- raise Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
22
- end
23
- instance_url = "#{self.class.url}/#{CGI.escape(id)}"
10
+ response = EasyPost.make_request(:put, instance_url, @api_key, params)
11
+ self.refresh_from(response, api_key, true)
24
12
 
25
- response = EasyPost.make_request(:delete, instance_url, @api_key)
26
- refresh_from(response, api_key)
13
+ return self
14
+ end
27
15
 
28
- return self
16
+ def delete
17
+ # NOTE: This method is redefined here since the "url" method conflicts
18
+ # with the objects field
19
+ unless self.id
20
+ raise EasyPost::Error.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{self.id.inspect}")
29
21
  end
22
+ instance_url = "#{self.class.url}/#{CGI.escape(id)}"
23
+
24
+ response = EasyPost.make_request(:delete, instance_url, @api_key)
25
+ refresh_from(response, api_key)
26
+
27
+ return self
30
28
  end
31
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easypost
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.4
4
+ version: 3.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Epstein
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-09-30 00:00:00.000000000 Z
13
+ date: 2020-12-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pry