easypost 3.1.4 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +9 -0
  3. data/.github/CODEOWNERS +2 -0
  4. data/.github/ISSUE_TEMPLATE/bug_report.yml +81 -0
  5. data/.github/ISSUE_TEMPLATE/feature_request.yml +37 -0
  6. data/.github/PULL_REQUEST_TEMPLATE.md +22 -0
  7. data/.github/workflows/ci.yml +71 -0
  8. data/.gitignore +27 -17
  9. data/.gitmodules +3 -0
  10. data/CHANGELOG.md +378 -0
  11. data/Gemfile +2 -0
  12. data/Makefile +70 -0
  13. data/README.md +193 -74
  14. data/Rakefile +2 -1
  15. data/UPGRADE_GUIDE.md +181 -0
  16. data/VERSION +1 -1
  17. data/bin/easypost-irb +5 -3
  18. data/easypost.gemspec +27 -20
  19. data/lib/easypost/client.rb +178 -0
  20. data/lib/easypost/connection.rb +64 -0
  21. data/lib/easypost/constants.rb +15 -0
  22. data/lib/easypost/errors/api/api_error.rb +108 -0
  23. data/lib/easypost/errors/api/bad_request_error.rb +6 -0
  24. data/lib/easypost/errors/api/connection_error.rb +6 -0
  25. data/lib/easypost/errors/api/external_api_error.rb +18 -0
  26. data/lib/easypost/errors/api/forbidden_error.rb +6 -0
  27. data/lib/easypost/errors/api/gateway_timeout_error.rb +6 -0
  28. data/lib/easypost/errors/api/internal_server_error.rb +6 -0
  29. data/lib/easypost/errors/api/invalid_request_error.rb +6 -0
  30. data/lib/easypost/errors/api/method_not_allowed_error.rb +6 -0
  31. data/lib/easypost/errors/api/not_found_error.rb +6 -0
  32. data/lib/easypost/errors/api/payment_error.rb +6 -0
  33. data/lib/easypost/errors/api/proxy_error.rb +6 -0
  34. data/lib/easypost/errors/api/rate_limit_error.rb +6 -0
  35. data/lib/easypost/errors/api/redirect_error.rb +6 -0
  36. data/lib/easypost/errors/api/retry_error.rb +6 -0
  37. data/lib/easypost/errors/api/service_unavailable_error.rb +6 -0
  38. data/lib/easypost/errors/api/ssl_error.rb +6 -0
  39. data/lib/easypost/errors/api/timeout_error.rb +6 -0
  40. data/lib/easypost/errors/api/unauthorized_error.rb +6 -0
  41. data/lib/easypost/errors/api/unknown_api_error.rb +6 -0
  42. data/lib/easypost/errors/easy_post_error.rb +7 -0
  43. data/lib/easypost/errors/end_of_pagination_error.rb +7 -0
  44. data/lib/easypost/errors/filtering_error.rb +4 -0
  45. data/lib/easypost/errors/invalid_object_error.rb +4 -0
  46. data/lib/easypost/errors/invalid_parameter_error.rb +11 -0
  47. data/lib/easypost/errors/missing_parameter_error.rb +9 -0
  48. data/lib/easypost/errors/signature_verification_error.rb +4 -0
  49. data/lib/easypost/errors.rb +32 -0
  50. data/lib/easypost/hooks/request_context.rb +16 -0
  51. data/lib/easypost/hooks/response_context.rb +23 -0
  52. data/lib/easypost/hooks.rb +34 -0
  53. data/lib/easypost/http_client.rb +117 -0
  54. data/lib/easypost/internal_utilities.rb +66 -0
  55. data/lib/easypost/models/address.rb +5 -0
  56. data/lib/easypost/models/api_key.rb +5 -0
  57. data/lib/easypost/models/base.rb +58 -0
  58. data/lib/easypost/models/batch.rb +5 -0
  59. data/lib/easypost/models/brand.rb +5 -0
  60. data/lib/easypost/models/carbon_offset.rb +5 -0
  61. data/lib/easypost/models/carrier_account.rb +5 -0
  62. data/lib/easypost/models/customs_info.rb +5 -0
  63. data/lib/easypost/models/customs_item.rb +5 -0
  64. data/lib/easypost/models/end_shipper.rb +5 -0
  65. data/lib/easypost/models/error.rb +21 -0
  66. data/lib/easypost/models/event.rb +5 -0
  67. data/lib/easypost/models/insurance.rb +6 -0
  68. data/lib/easypost/models/order.rb +9 -0
  69. data/lib/easypost/models/parcel.rb +5 -0
  70. data/lib/easypost/models/payload.rb +5 -0
  71. data/lib/easypost/models/payment_method.rb +5 -0
  72. data/lib/easypost/models/pickup.rb +9 -0
  73. data/lib/easypost/models/pickup_rate.rb +5 -0
  74. data/lib/easypost/models/postage_label.rb +5 -0
  75. data/lib/easypost/models/rate.rb +5 -0
  76. data/lib/easypost/models/referral.rb +5 -0
  77. data/lib/easypost/models/refund.rb +5 -0
  78. data/lib/easypost/models/report.rb +5 -0
  79. data/lib/easypost/models/scan_form.rb +6 -0
  80. data/lib/easypost/models/shipment.rb +10 -0
  81. data/lib/easypost/models/tax_identifier.rb +6 -0
  82. data/lib/easypost/models/tracker.rb +5 -0
  83. data/lib/easypost/models/user.rb +5 -0
  84. data/lib/easypost/models/webhook.rb +6 -0
  85. data/lib/easypost/models.rb +35 -0
  86. data/lib/easypost/services/address.rb +50 -0
  87. data/lib/easypost/services/api_key.rb +8 -0
  88. data/lib/easypost/services/base.rb +27 -0
  89. data/lib/easypost/services/batch.rb +53 -0
  90. data/lib/easypost/services/beta_rate.rb +12 -0
  91. data/lib/easypost/services/beta_referral_customer.rb +40 -0
  92. data/lib/easypost/services/billing.rb +75 -0
  93. data/lib/easypost/services/carrier_account.rb +44 -0
  94. data/lib/easypost/services/carrier_metadata.rb +22 -0
  95. data/lib/easypost/services/customs_info.rb +17 -0
  96. data/lib/easypost/services/customs_item.rb +15 -0
  97. data/lib/easypost/services/end_shipper.rb +31 -0
  98. data/lib/easypost/services/event.rb +32 -0
  99. data/lib/easypost/services/insurance.rb +26 -0
  100. data/lib/easypost/services/order.rb +30 -0
  101. data/lib/easypost/services/parcel.rb +16 -0
  102. data/lib/easypost/services/pickup.rb +40 -0
  103. data/lib/easypost/services/rate.rb +8 -0
  104. data/lib/easypost/services/referral_customer.rb +103 -0
  105. data/lib/easypost/services/refund.rb +26 -0
  106. data/lib/easypost/services/report.rb +42 -0
  107. data/lib/easypost/services/scan_form.rb +25 -0
  108. data/lib/easypost/services/shipment.rb +106 -0
  109. data/lib/easypost/services/tracker.rb +38 -0
  110. data/lib/easypost/services/user.rb +66 -0
  111. data/lib/easypost/services/webhook.rb +34 -0
  112. data/lib/easypost/services.rb +32 -0
  113. data/lib/easypost/util.rb +167 -103
  114. data/lib/easypost/utilities/constants.rb +5 -0
  115. data/lib/easypost/utilities/json.rb +23 -0
  116. data/lib/easypost/utilities/static_mapper.rb +73 -0
  117. data/lib/easypost/utilities/system.rb +36 -0
  118. data/lib/easypost/version.rb +3 -1
  119. data/lib/easypost.rb +21 -137
  120. metadata +253 -49
  121. data/.travis.yml +0 -9
  122. data/CHANGELOG +0 -207
  123. data/lib/easypost/address.rb +0 -60
  124. data/lib/easypost/batch.rb +0 -53
  125. data/lib/easypost/carrier_account.rb +0 -8
  126. data/lib/easypost/customs_info.rb +0 -9
  127. data/lib/easypost/customs_item.rb +0 -9
  128. data/lib/easypost/error.rb +0 -33
  129. data/lib/easypost/event.rb +0 -10
  130. data/lib/easypost/insurance.rb +0 -4
  131. data/lib/easypost/item.rb +0 -10
  132. data/lib/easypost/object.rb +0 -149
  133. data/lib/easypost/order.rb +0 -30
  134. data/lib/easypost/parcel.rb +0 -4
  135. data/lib/easypost/pickup.rb +0 -30
  136. data/lib/easypost/pickup_rate.rb +0 -5
  137. data/lib/easypost/postage_label.rb +0 -4
  138. data/lib/easypost/print_job.rb +0 -6
  139. data/lib/easypost/printer.rb +0 -28
  140. data/lib/easypost/rate.rb +0 -4
  141. data/lib/easypost/refund.rb +0 -4
  142. data/lib/easypost/report.rb +0 -31
  143. data/lib/easypost/resource.rb +0 -77
  144. data/lib/easypost/scan_form.rb +0 -8
  145. data/lib/easypost/shipment.rb +0 -120
  146. data/lib/easypost/tracker.rb +0 -15
  147. data/lib/easypost/user.rb +0 -47
  148. data/lib/easypost/webhook.rb +0 -31
data/Makefile ADDED
@@ -0,0 +1,70 @@
1
+ ## help - Display help about make targets for this Makefile
2
+ help:
3
+ @cat Makefile | grep '^## ' --color=never | cut -c4- | sed -e "`printf 's/ - /\t- /;'`" | column -s "`printf '\t'`" -t
4
+
5
+ ## build - Builds the project
6
+ build:
7
+ gem build easypost.gemspec --strict
8
+ mkdir -p dist
9
+ mv *.gem dist/
10
+
11
+ ## clean - Cleans the project
12
+ clean:
13
+ rm -rf coverage doc *.gem dist
14
+
15
+ ## coverage - Generate a test coverage report
16
+ coverage:
17
+ make test
18
+
19
+ ## docs - Generate documentation for the library
20
+ docs:
21
+ bundle exec rdoc lib -o docs --title "EasyPost Ruby Docs"
22
+
23
+ ## install-styleguide - Import the style guides (Unix only)
24
+ install-styleguide: | update-examples-submodule
25
+ sh examples/symlink_directory_files.sh examples/style_guides/ruby .
26
+
27
+ ## install - Install globally from source
28
+ install: | update-examples-submodule
29
+ bundle install
30
+
31
+ ## lint - Lint the project
32
+ lint: rubocop scan
33
+
34
+ ## lint-fix - Fix Rubocop errors
35
+ lint-fix: rubocop-fix
36
+
37
+ ## publish - Publishes the built gem to Rubygems
38
+ publish:
39
+ gem push dist/*.gem
40
+
41
+ ## release - Cuts a release for the project on GitHub (requires GitHub CLI)
42
+ # tag = The associated tag title of the release
43
+ release:
44
+ gh release create ${tag} dist/*
45
+
46
+ ## rubocop - lints the project with rubocop
47
+ rubocop:
48
+ bundle exec rubocop
49
+
50
+ ## rubocop-fix - fix rubocop errors
51
+ rubocop-fix:
52
+ bundle exec rubocop -a
53
+
54
+ ## scan - Runs security analysis on the project with Brakeman
55
+ scan:
56
+ bundle exec brakeman lib --force
57
+
58
+ ## test - Test the project (and ignore warnings for test output)
59
+ test:
60
+ bundle exec rspec
61
+
62
+ ## update - Updates dependencies
63
+ update: | update-examples-submodule
64
+
65
+ ## update-examples-submodule - Update the examples submodule
66
+ update-examples-submodule:
67
+ git submodule init
68
+ git submodule update --remote
69
+
70
+ .PHONY: help build clean coverage docs install install-styleguide lint lint-fix publish release rubocop rubocop-fix scan test update update-examples-submodule
data/README.md CHANGED
@@ -1,106 +1,225 @@
1
1
  # EasyPost Ruby Client Library
2
2
 
3
- [![Build Status](https://travis-ci.com/EasyPost/easypost-ruby.svg?branch=master)](https://travis-ci.com/EasyPost/easypost-ruby)
3
+ [![Build Status](https://github.com/EasyPost/easypost-ruby/workflows/CI/badge.svg)](https://github.com/EasyPost/easypost-ruby/actions?query=workflow%3ACI)
4
+ [![Coverage Status](https://coveralls.io/repos/github/EasyPost/easypost-ruby/badge.svg?branch=master)](https://coveralls.io/github/EasyPost/easypost-ruby?branch=master)
5
+ [![Gem Version](https://badge.fury.io/rb/easypost.svg)](https://badge.fury.io/rb/easypost)
4
6
 
7
+ EasyPost, the simple shipping solution. You can sign up for an account at <https://easypost.com>.
5
8
 
6
- EasyPost is a simple shipping API. You can sign up for an account at https://easypost.com
9
+ ## Install
7
10
 
8
- Installation
9
- ---------------
10
-
11
- Install the gem:
12
-
13
- ```
11
+ ```bash
14
12
  gem install easypost
15
13
  ```
16
14
 
17
- Import the EasyPost client in your application:
18
-
19
- ```
15
+ ```ruby
16
+ # Require the library in your project:
20
17
  require 'easypost'
21
18
  ```
22
19
 
23
- Example
24
- ------------------
20
+ ## Usage
21
+
22
+ A simple create & buy shipment example:
25
23
 
26
24
  ```ruby
27
25
  require 'easypost'
28
- EasyPost.api_key = 'cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi'
29
-
30
- to_address = EasyPost::Address.create(
31
- :name => 'Dr. Steve Brule',
32
- :street1 => '179 N Harbor Dr',
33
- :city => 'Redondo Beach',
34
- :state => 'CA',
35
- :zip => '90277',
36
- :country => 'US',
37
- :phone => '310-808-5243'
38
- )
39
- from_address = EasyPost::Address.create(
40
- :company => 'EasyPost',
41
- :street1 => '118 2nd Street',
42
- :street2 => '4th Floor',
43
- :city => 'San Francisco',
44
- :state => 'CA',
45
- :zip => '94105',
46
- :phone => '415-456-7890'
47
- )
48
26
 
49
- parcel = EasyPost::Parcel.create(
50
- :width => 15.2,
51
- :length => 18,
52
- :height => 9.5,
53
- :weight => 35.1
27
+ client = EasyPost::Client.new(api_key: ENV['EASYPOST_TEST_API_KEY'])
28
+
29
+ shipment = client.shipment.create(
30
+ from_address: {
31
+ company: 'EasyPost',
32
+ street1: '118 2nd Street',
33
+ street2: '4th Floor',
34
+ city: 'San Francisco',
35
+ state: 'CA',
36
+ zip: '94105',
37
+ phone: '415-456-7890',
38
+ },
39
+ to_address: {
40
+ name: 'Dr. Steve Brule',
41
+ street1: '179 N Harbor Dr',
42
+ city: 'Redondo Beach',
43
+ state: 'CA',
44
+ zip: '90277',
45
+ country: 'US',
46
+ phone: '310-808-5243',
47
+ },
48
+ parcel: {
49
+ width: 15.2,
50
+ length: 18,
51
+ height: 9.5,
52
+ weight: 35.1,
53
+ },
54
54
  )
55
55
 
56
- customs_item = EasyPost::CustomsItem.create(
57
- :description => 'EasyPost T-shirts',
58
- :quantity => 2,
59
- :value => 23.56,
60
- :weight => 33,
61
- :origin_country => 'us',
62
- :hs_tariff_number => 123456
63
- )
64
- customs_info = EasyPost::CustomsInfo.create(
65
- :integrated_form_type => 'form_2976',
66
- :customs_certify => true,
67
- :customs_signer => 'Dr. Pepper',
68
- :contents_type => 'gift',
69
- :contents_explanation => '', # only required when contents_type => 'other'
70
- :eel_pfc => 'NOEEI 30.37(a)',
71
- :non_delivery_option => 'abandon',
72
- :restriction_type => 'none',
73
- :restriction_comments => '',
74
- :customs_items => [customs_item]
75
- )
56
+ bought_shipment = client.shipment.buy(shipment.id, rate: shipment.lowest_rate)
57
+
58
+ puts bought_shipment
59
+ ```
60
+
61
+ ### Custom Connections
62
+
63
+ Pass in a lambda function as `custom_client_exec` when initializing a client that responds to `call(method, uri, headers, open_timeout, read_timeout, body = nil)` where:
76
64
 
77
- shipment = EasyPost::Shipment.create(
78
- :to_address => to_address,
79
- :from_address => from_address,
80
- :parcel => parcel,
81
- :customs_info => customs_info
65
+ - `uri` is the fully-qualified URL of the EasyPost endpoint, including query parameters (`Uri` object)
66
+ - `method` is the lowercase name of the HTTP method being used for the request (e.g. `:get`, `:post`, `:put`, `:delete`)
67
+ - `headers` is a hash with all headers needed for the request pre-populated, including authorization (`Hash` object)
68
+ - `open_timeout` is the number of seconds to wait for the connection to open (integer)
69
+ - `read_timeout` is the number of seconds to wait for one block to be read (integer)
70
+ - `body` is a string of the body data to be included in the request, or nil (e.g. GET or DELETE request) (string or `nil`)
71
+
72
+ The lambda function should return an object with `code` and `body` attributes, where:
73
+
74
+ - `code` is the HTTP response status code (integer)
75
+ - `body` is the response body (string)
76
+
77
+ #### Faraday
78
+
79
+ ```ruby
80
+ require 'faraday'
81
+
82
+ custom_connection = lambda { |method, uri, headers, _open_timeout, _read_timeout, body = nil|
83
+ conn = Faraday.new(url: uri.to_s, headers: headers) do |faraday|
84
+ faraday.adapter Faraday.default_adapter
85
+ end
86
+ conn.public_send(method, uri.path) { |request|
87
+ request.body = body if body
88
+ }.yield_self do |response|
89
+ OpenStruct.new(code: response.status, body: response.body)
90
+ end
91
+ }
92
+
93
+ my_client = described_class.new(
94
+ api_key: ENV['EASYPOST_API_KEY'],
95
+ custom_client_exec: custom_connection,
82
96
  )
97
+ ```
98
+
99
+ #### Typhoeus
83
100
 
84
- shipment.buy(
85
- :rate => shipment.lowest_rate
101
+ ```ruby
102
+ require 'typhoeus'
103
+
104
+ custom_connection = lambda { |method, uri, headers, _open_timeout, _read_timeout, body = nil|
105
+ Typhoeus.public_send(
106
+ method,
107
+ uri.to_s,
108
+ headers: headers,
109
+ body: body,
110
+ ).yield_self do |response|
111
+ OpenStruct.new(code: response.code, body: response.body)
112
+ end
113
+ }
114
+
115
+ my_client = described_class.new(
116
+ api_key: ENV['EASYPOST_API_KEY'],
117
+ custom_client_exec: custom_connection,
86
118
  )
119
+ ```
87
120
 
88
- shipment.insure(amount: 100)
121
+ ### HTTP Hooks
89
122
 
90
- puts shipment.insurance
123
+ Users can audit HTTP requests and responses being made by the library by subscribing to request and response events. To do so, pass a block to the `subscribe_request_hook` and `subscribe_response_hook` methods of an instance of `EasyPost::Client`:
91
124
 
92
- puts shipment.postage_label.label_url
125
+ ```ruby
126
+ require 'easypost'
93
127
 
128
+ client = EasyPost::Client.new(api_key: ENV['EASYPOST_API_KEY'])
129
+
130
+ # Returns a randomly-generated symbol which you can use to later unsubscribe the request hook
131
+ client.subscribe_request_hook do |request_data|
132
+ # Your code goes here
133
+ end
134
+ # Returns a randomly-generated symbol which you can use to later unsubscribe the response hook
135
+ client.subscribe_response_hook do |response_data|
136
+ # Your code goes here
137
+ end
94
138
  ```
95
139
 
96
- Documentation
97
- --------------------
140
+ You can also name your hook subscriptions by providing an optional parameter to the methods above:
141
+
142
+ ```ruby
143
+ require 'easypost'
98
144
 
99
- Up-to-date documentation at: https://easypost.com/docs
145
+ client = EasyPost::Client.new(api_key: ENV['EASYPOST_API_KEY'])
100
146
 
101
- Tests
102
- --------------------
147
+ request_hook = client.subscribe_request_hook(:my_request_hook) do |request_data|
148
+ # Your code goes here
149
+ end
150
+ response_hook = client.subscribe_response_hook(:my_response_hook) do |response_data|
151
+ # Your code goes here
152
+ end
103
153
 
154
+ puts request_hook # :my_request_hook
155
+ puts response_hook # :my_response_hook
104
156
  ```
105
- rspec spec
157
+
158
+ Keep in mind that subscribing a hook with the same name of an existing hook will replace the existing hook with the new one. A request hook and a response hook can share the same name.
159
+
160
+ #### Custom HTTP Connections with HTTP Hooks
161
+
162
+ If you're using a custom HTTP connection, keep in mind that the `response_data` parameter that a response hook receives *will not be hydrated* with all the response data. You will have to inspect the `client_response_object` property in `response_data` to inspect the response code, response headers and response body.
163
+
164
+ ## Documentation
165
+
166
+ API documentation can be found at: <https://easypost.com/docs/api>.
167
+
168
+ Library documentation can be found on the web at: <https://easypost.github.io/easypost-ruby/> or by building them locally via the `make docs` command.
169
+
170
+ Upgrading major versions of this project? Refer to the [Upgrade Guide](UPGRADE_GUIDE.md).
171
+
172
+ ## Support
173
+
174
+ New features and bug fixes are released on the latest major release of this library. If you are on an older major release of this library, we recommend upgrading to the most recent release to take advantage of new features, bug fixes, and security patches. Older versions of this library will continue to work and be available as long as the API version they are tied to remains active; however, they will not receive updates and are considered EOL.
175
+
176
+ For additional support, see our [org-wide support policy](https://github.com/EasyPost/.github/blob/main/SUPPORT.md).
177
+
178
+ ## Development
179
+
180
+ ```bash
181
+ # Install dependencies
182
+ make install
183
+
184
+ # Install style guide (Unix only)
185
+ make install-style
186
+
187
+ # Lint project
188
+ make lint
189
+ make lint-fix
190
+
191
+ # Run tests (coverage is generated on a successful test suite run)
192
+ EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... make test
193
+
194
+ # Run security analysis
195
+ make scan
196
+
197
+ # Generate library documentation
198
+ make docs
199
+
200
+ # Update submodules
201
+ make update-examples-submodule
106
202
  ```
203
+
204
+ ### Testing
205
+
206
+ The test suite in this project was specifically built to produce consistent results on every run, regardless of when they run or who is running them. This project uses [VCR](https://github.com/vcr/vcr) to record and replay HTTP requests and responses via "cassettes". When the suite is run, the HTTP requests and responses for each test function will be saved to a cassette if they do not exist already and replayed from this saved file if they do, which saves the need to make live API calls on every test run. If you receive errors about a cassette expiring, delete and re-record the cassette to ensure the data is up-to-date.
207
+
208
+ **Sensitive Data:** We've made every attempt to include scrubbers for sensitive data when recording cassettes so that PII or sensitive info does not persist in version control; however, please ensure when recording or re-recording cassettes that prior to committing your changes, no PII or sensitive information gets persisted by inspecting the cassette.
209
+
210
+ **Making Changes:** If you make an addition to this project, the request/response will get recorded automatically for you. When making changes to this project, you'll need to re-record the associated cassette to force a new live API call for that test which will then record the request/response used on the next run.
211
+
212
+ **Test Data:** The test suite has been populated with various helpful fixtures that are available for use, each completely independent from a particular user **with the exception of the USPS carrier account ID** (see [Unit Test API Keys](#unit-test-api-keys) for more information) which has a fallback value of our internal testing user's ID. Some fixtures use hard-coded dates that may need to be incremented if cassettes get re-recorded (such as reports or pickups).
213
+
214
+ #### Unit Test API Keys
215
+
216
+ The following are required on every test run:
217
+
218
+ - `EASYPOST_TEST_API_KEY`
219
+ - `EASYPOST_PROD_API_KEY`
220
+
221
+ Some tests may require an EasyPost user with a particular set of enabled features such as a `Partner` user when creating referrals. We have attempted to call out these functions in their respective docstrings. The following are required when you need to re-record cassettes for applicable tests:
222
+
223
+ - `USPS_CARRIER_ACCOUNT_ID` (eg: one-call buying a shipment for non-EasyPost employees)
224
+ - `PARTNER_USER_PROD_API_KEY` (eg: creating a referral customer)
225
+ - `REFERRAL_CUSTOMER_PROD_API_KEY` (eg: adding a credit card to a referral customer)
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'bundler/gem_tasks'
data/UPGRADE_GUIDE.md ADDED
@@ -0,0 +1,181 @@
1
+ # Upgrade Guide
2
+
3
+ Use the following guide to assist in the upgrade process of the `easypost-ruby` library between major versions.
4
+
5
+ - [Upgrading from 4.x to 5.0](#upgrading-from-4x-to-50)
6
+ - [Upgrading from 3.x to 4.0](#upgrading-from-3x-to-40)
7
+
8
+ ## Upgrading from 4.x to 5.0
9
+
10
+ ### 5.0 High Impact Changes
11
+
12
+ - [New Client object](#50-thread-safe-with-client-object)
13
+ - [Updated Dependencies](#50-updated-dependencies)
14
+ - [Improved Error Handling](#50-improved-error-handling)
15
+
16
+ ### 5.0 Medium Impact Changes
17
+
18
+ - [Corrected Naming Conventions](#50-corrected-naming-conventions)
19
+
20
+ ### 5.0 Low Impact Changes
21
+
22
+ - [Beta Namespace Changed](#50-beta-namespace-changed)
23
+
24
+ ## 5.0 Thread-Safe with Client Object
25
+
26
+ Likelihood of Impact: High
27
+
28
+ This library is now thread-safe with the introduction of a new `Client` object. Instead of defining a global API key that all requests use, you now create an `Client` object and pass your API key to it with optional open and read timeout params. You then call your desired functions against a `service` which are called against a `Client` object:
29
+
30
+ ```ruby
31
+ # Old way
32
+ EasyPost.api_key = ENV['EASYPOST_API_KEY']
33
+ shipment = EasyPost::Shipment.retrieve('shp_...')
34
+
35
+ # New way
36
+ client = EasyPost::Client.new(api_key: ENV['EASYPOST_TEST_API_KEY'])
37
+ shipment = client.shipment.retrieve('shp_...')
38
+ ```
39
+
40
+ All instance methods are now static with the exception of `lowest_rate` as these make API calls and require the Client object(EasyPost objects do not contain an API key to make API calls with).
41
+
42
+ Previously used `.save()` instance methods are now static `.update()` functions where you specify first the ID of the object you are updating and second, the parameters that need updating.
43
+
44
+ ## 5.0 Updated Dependencies
45
+
46
+ Likelihood of Impact: High
47
+
48
+ **Ruby 2.6 Required**
49
+
50
+ easypost-ruby now requires Ruby 2.6 or greater.
51
+
52
+ **Dependencies**
53
+
54
+ All dependencies had minor version bumps.
55
+
56
+ ## 5.0 Improved Error Handling
57
+
58
+ Likelihood of Impact: High
59
+
60
+ There are ~2 dozen new error types that extend either `ApiError` or `EasyPostError`.
61
+
62
+ New ApiErrors (extends EasyPostError):
63
+
64
+ - `ApiError`
65
+ - `ConnectionError`
66
+ - `ExternalApiError`
67
+ - `ForbiddenError`
68
+ - `GatewayTimeoutError`
69
+ - `InternalServerError`
70
+ - `InvalidRequestError`
71
+ - `MethodNotAllowedError`
72
+ - `NotFoundError`
73
+ - `PaymentError`
74
+ - `ProxyError`
75
+ - `RateLimitError`
76
+ - `RedirectError`
77
+ - `RetryError`
78
+ - `ServiceUnavailableError`
79
+ - `SSLError`
80
+ - `TimeoutError`
81
+ - `UnauthorizedError`
82
+ - `UnknownApiError`
83
+
84
+ New EasyPostErrors (extends builtin Exception):
85
+
86
+ - `EasyPostError`
87
+ - `EndOfPaginationError`
88
+ - `FilteringError`
89
+ - `InvalidObjectError`
90
+ - `InvalidParameterError`
91
+ - `MissingParameterError`
92
+ - `SignatureVerificationError`
93
+
94
+ ApiErrors will behave like the previous Error class did. They will include a `message`, `http_status`, and `http_body`. Additionally, a new `code` and `errors` keys are present and populate when available. This class extends the more generic `EasyPostError` which only contains a message, used for errors thrown directly from this library.
95
+
96
+ ## 5.0 Corrected Naming Conventions
97
+
98
+ Likelihood of Impact: Medium
99
+
100
+ Occurances of `referral` are now `referral_customer` and `Referral` are now `ReferralCustomer` to match the documentation and API.
101
+
102
+ Occurances of `smartrate` are now `smart_rate` and `Smartrate` are now `SmartRate` to match the documentation and API.
103
+
104
+ Occurances of `scanform` are now `scan_form` and `Scanform` are now `ScanForm` to match the documentation and API.
105
+
106
+ Rename function `get_smartrates` to `get_smart_rates`
107
+
108
+ Rename function `get_lowest_smartrate` to `get_lowest_smart_rate`
109
+
110
+ ## 5.0 Beta Namespace Changed
111
+
112
+ Likelihood of Impact: Low
113
+
114
+ Previously, the beta namespace was found at `easypost.beta.x` where `x` is the name of your model. Now, the beta namespace is simply prepended to the name of your service: `client.beta_x`. for instance, you can call `client.beta_referral_customer.add_payment_method()`.
115
+
116
+ ## 5.0 Return True For Empty API Response
117
+
118
+ Likelihood of Impact: Low
119
+
120
+ Empty API response functions for `delete` return `true` instead of empty object
121
+
122
+ ## Upgrading from 3.x to 4.0
123
+
124
+ **NOTICE:** v4 is deprecated.
125
+
126
+ ### 4.0 High Impact Changes
127
+
128
+ * [Updating Dependencies](#40-updating-dependencies)
129
+
130
+ ### 4.0 Medium Impact Changes
131
+
132
+ * [Removal of `get_rates` Shipment Method](#40-removal-of-getrates-shipment-method)
133
+
134
+ ### 4.0 Low Impact Changes
135
+
136
+ * [Removal of `Print` and `PrintJob` Objects](#40-removal-of-print-and-printjob-objects)
137
+ * [Removal of `stamp_and_barcode_by_reference` Batch Method](#40-removal-of-stampandbarcodebyreference-batch-method)
138
+ * [Removal of `Address.verify` Parameters](#40-removal-of-addressverify-parameters)
139
+ * [Removal of the `http_status` Property on EasyPost::Error](#40-removal-of-httpstatus-property-on-easyposterror)
140
+
141
+ ## 4.0 Updating Dependencies
142
+
143
+ Likelihood of Impact: High
144
+
145
+ **Ruby 2.5 Required**
146
+
147
+ easypost-ruby now requires Ruby 2.5 or greater.
148
+
149
+ **Dependencies**
150
+
151
+ No production dependencies were altered. Development dependencies were all bumped and `simplecov` and `rubocop` were introduced.
152
+
153
+ ## 4.0 Removal of get_rates Shipment Method
154
+
155
+ Likelihood of Impact: Medium
156
+
157
+ The HTTP method used for the `get_rates` endpoint at the API level has changed from `POST` to `GET` and will only retrieve rates for a shipment instead of regenerating them. A new `/rerate` endpoint has been introduced to replace this functionality; In this library, you can now call the `Shipment.regenerate_rates` method to regenerate rates. Due to the logic change, the `get_rates` method has been removed since a Shipment inherently already has rates associated.
158
+
159
+ ## 4.0 Removal of Print and PrintJob Objects
160
+
161
+ Likelihood of Impact: Low
162
+
163
+ The `Print` and `PrintJob` objects have been removed as they are no longer usable with the current version of the API.
164
+
165
+ ## 4.0 Removal of stamp_and_barcode_by_reference Batch Method
166
+
167
+ Likelihood of Impact: Low
168
+
169
+ The `stamp_and_barcode_by_reference` Batch method has been removed as it is no longer usable with the current version of the API.
170
+
171
+ ## 4.0 Removal of Address.verify Parameters
172
+
173
+ Likelihood of Impact: Low
174
+
175
+ The parameters for the `Address.verify` method were removed as they were unusable, the current version of the API does not allow you to verify an address by specifying a carrier.
176
+
177
+ ## 4.0 Removal of http_status Property on EasyPost::Error
178
+
179
+ Likelihood of Impact: Low
180
+
181
+ The deprecated `http_status` property has been removed in favor of the `status` property on the EasyPost::Error object.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.4
1
+ 5.1.0
data/bin/easypost-irb CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
2
4
  irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
3
5
 
4
- libs = " -r irb/completion"
5
- libs << " -r #{File.dirname(__FILE__) + '/../lib/easypost'}"
6
- puts "Initializing EasyPost..."
6
+ libs = ' -r irb/completion'
7
+ libs << " -r #{"#{File.dirname(__FILE__)}/../lib/easypost"}"
8
+ puts 'Initializing EasyPost...'
7
9
  exec "#{irb} #{libs} --simple-prompt"
data/easypost.gemspec CHANGED
@@ -1,31 +1,38 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require "easypost/version"
5
+ require 'easypost/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
- spec.name = "easypost"
8
+ spec.name = 'easypost'
9
9
  spec.version = EasyPost::VERSION
10
- spec.licenses = ["MIT"]
11
- spec.date = Time.now.strftime("%Y-%m-%d")
12
- spec.summary = "EasyPost Ruby Client Library"
13
- spec.description = "Client library for accessing the EasyPost shipping API via Ruby."
14
- spec.authors = ["Jake Epstein", "Andrew Tribone", "James Brown"]
15
- spec.email = "support@easypost.com"
16
- spec.homepage = "https://www.easypost.com/docs"
10
+ spec.license = 'MIT'
11
+ spec.summary = 'EasyPost Ruby Client Library'
12
+ spec.description = 'Client library for accessing the EasyPost shipping API via Ruby.'
13
+ spec.authors = 'EasyPost Developers'
14
+ spec.email = 'oss@easypost.com'
15
+ spec.homepage = 'https://www.easypost.com/docs'
17
16
 
18
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
- f.match(%r{^(test|spec|features)/})
18
+ f.match(%r{^(docs|examples|spec)/})
20
19
  end
21
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
- spec.require_paths = ["lib"]
24
- spec.required_ruby_version = "~> 2.2"
21
+ spec.require_paths = ['lib']
22
+ spec.required_ruby_version = '>= 2.6'
25
23
 
26
- spec.add_development_dependency "pry", "~> 0.13"
27
- spec.add_development_dependency "rake", "~> 13.0"
28
- spec.add_development_dependency "rspec", "~> 3.9"
29
- spec.add_development_dependency "webmock", "~> 3.8"
30
- spec.add_development_dependency "vcr", "~> 5.1"
24
+ spec.add_development_dependency 'brakeman', '~> 5.4'
25
+ spec.add_development_dependency 'faraday', '~> 2.7.5' # used for integration tests
26
+ spec.add_development_dependency 'pry', '~> 0.14'
27
+ spec.add_development_dependency 'psych', '~> 5.1'
28
+ spec.add_development_dependency 'rake', '~> 13.0'
29
+ spec.add_development_dependency 'rdoc', '~> 6.5'
30
+ spec.add_development_dependency 'rspec', '~> 3.12'
31
+ spec.add_development_dependency 'rubocop', '~> 1.49'
32
+ spec.add_development_dependency 'rubocop-rspec', '2.19' # pin to 2.19 because latest version doesn't support Ruby 2.6
33
+ spec.add_development_dependency 'simplecov', '~> 0.22'
34
+ spec.add_development_dependency 'simplecov-lcov', '~> 0.8'
35
+ spec.add_development_dependency 'typhoeus', '~> 1.4.0' # used for integration tests
36
+ spec.add_development_dependency 'vcr', '~> 6.1'
37
+ spec.add_development_dependency 'webmock', '~> 3.18'
31
38
  end