usps-ruby-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +2 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +41 -0
  6. data/.rubocop_todo.yml +0 -0
  7. data/.travis.yml +6 -0
  8. data/CODE_OF_CONDUCT.md +74 -0
  9. data/Gemfile +8 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +77 -0
  12. data/Rakefile +9 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/lib/data/api/address-information-api.htm +8229 -0
  16. data/lib/data/api/domestic-mail-service-standards-api.htm +11016 -0
  17. data/lib/data/api/evs-international-label-api.htm +33291 -0
  18. data/lib/data/api/evs-label-api.htm +18895 -0
  19. data/lib/data/api/hold-for-pickup-facilities-lookup-api.htm +5530 -0
  20. data/lib/data/api/package-pickup-api.htm +19157 -0
  21. data/lib/data/api/rate-calculator-api.htm +16355 -0
  22. data/lib/data/api/scan-api.htm +5934 -0
  23. data/lib/data/api/service-delivery-calculator-get-locations-api.htm +12548 -0
  24. data/lib/data/api/track-and-confirm-api.htm +21288 -0
  25. data/lib/data/api/uspsreturnslabel-api.htm +9474 -0
  26. data/lib/helpers/erubis_helper.rb +10 -0
  27. data/lib/tasks/api.rake +246 -0
  28. data/lib/usps-ruby-client.rb +30 -0
  29. data/lib/usps/api/endpoints.rb +70 -0
  30. data/lib/usps/api/endpoints/carrier_pickup_schedule.rb +117 -0
  31. data/lib/usps/api/endpoints/city_state_lookup.rb +50 -0
  32. data/lib/usps/api/endpoints/e_vs_express_mail_intl.rb +359 -0
  33. data/lib/usps/api/endpoints/e_vs_first_class_mail_intl.rb +323 -0
  34. data/lib/usps/api/endpoints/e_vs_priority_mail_intl.rb +366 -0
  35. data/lib/usps/api/endpoints/e_vsgxg_get_label.rb +366 -0
  36. data/lib/usps/api/endpoints/e_vsi_cancel.rb +55 -0
  37. data/lib/usps/api/endpoints/hfp_facility_info.rb +71 -0
  38. data/lib/usps/api/endpoints/intl_rate_v2.rb +135 -0
  39. data/lib/usps/api/endpoints/pts_email.rb +73 -0
  40. data/lib/usps/api/endpoints/pts_pod.rb +86 -0
  41. data/lib/usps/api/endpoints/pts_rre.rb +72 -0
  42. data/lib/usps/api/endpoints/ptst_pod.rb +75 -0
  43. data/lib/usps/api/endpoints/rate_v4.rb +140 -0
  44. data/lib/usps/api/endpoints/scan.rb +121 -0
  45. data/lib/usps/api/endpoints/track_v2.rb +62 -0
  46. data/lib/usps/api/endpoints/usps_returns_label.rb +149 -0
  47. data/lib/usps/api/endpoints/verify.rb +75 -0
  48. data/lib/usps/api/endpoints/zip_code_lookup.rb +69 -0
  49. data/lib/usps/api/error.rb +6 -0
  50. data/lib/usps/api/errors/too_many_requests_error.rb +22 -0
  51. data/lib/usps/api/errors/usps_error.rb +30 -0
  52. data/lib/usps/api/templates/_build_xml.erb +7 -0
  53. data/lib/usps/api/templates/_options.erb +6 -0
  54. data/lib/usps/api/templates/_throw_argument_error.erb +3 -0
  55. data/lib/usps/api/templates/endpoints.erb +22 -0
  56. data/lib/usps/api/templates/method.erb +49 -0
  57. data/lib/usps/api/templates/method_spec.erb +22 -0
  58. data/lib/usps/api/xml.rb +8 -0
  59. data/lib/usps/client.rb +37 -0
  60. data/lib/usps/config.rb +50 -0
  61. data/lib/usps/faraday/connection.rb +34 -0
  62. data/lib/usps/faraday/request.rb +39 -0
  63. data/lib/usps/faraday/response/raise_error.rb +16 -0
  64. data/lib/usps/logger.rb +14 -0
  65. data/lib/usps/version.rb +4 -0
  66. data/usps-ruby-client.gemspec +46 -0
  67. metadata +307 -0
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module Usps
3
+ module Faraday
4
+ module Request
5
+ def get(path, options = {})
6
+ request(:get, path, options)
7
+ end
8
+
9
+ def post(path, options = {})
10
+ request(:post, path, options)
11
+ end
12
+
13
+ def put(path, options = {})
14
+ request(:put, path, options)
15
+ end
16
+
17
+ def delete(path, options = {})
18
+ request(:delete, path, options)
19
+ end
20
+
21
+ private
22
+
23
+ def request(method, path, options)
24
+ # options = options.merge(token: token)
25
+ response = connection.send(method) do |request|
26
+ case method
27
+ when :get, :delete
28
+ request.url(path, options)
29
+ when :post, :put
30
+ request.path = path
31
+ request.body = options unless options.empty?
32
+ end
33
+ request.options.merge!(options.delete(:request)) if options.key?(:request)
34
+ end
35
+ response.body
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+ require 'amazing_print'
3
+ module Usps
4
+ module Faraday
5
+ module Response
6
+ class RaiseError < ::Faraday::Response::Middleware
7
+ def on_complete(env)
8
+ raise Usps::Api::Errors::TooManyRequestsError, env.response if env.status == 429
9
+ return unless (body = env.body) && body['Error']
10
+
11
+ raise Usps::Api::Errors::UspsError.new(body['Error'], env.response)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require 'logger'
3
+
4
+ module Usps
5
+ class Logger < ::Logger
6
+ def self.default
7
+ return @default if @default
8
+
9
+ logger = new $stdout
10
+ logger.level = Logger::WARN
11
+ @default = logger
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module Usps
3
+ VERSION = '0.1.0'
4
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
3
+ require_relative 'lib/usps/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'usps-ruby-client'
7
+ spec.version = Usps::VERSION
8
+ spec.authors = ['Joey Paris']
9
+ spec.email = ['joey@leadjig.com']
10
+
11
+ spec.summary = 'An automatically generated USPS API Client'
12
+ spec.description = 'An automatically generated USPS API Client based on the official USPS User Guides'
13
+ spec.homepage = 'https://www.usps.com/business/web-tools-apis/documentation-updates.htm'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/joeyparis/usps-ruby-client"
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = 'exe'
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'activesupport', '~> 6.1'
33
+ spec.add_dependency 'builder', '~> 3.2'
34
+ spec.add_dependency 'faraday', '~> 0.17'
35
+ spec.add_dependency 'faraday_middleware', '~> 0.14'
36
+ spec.add_dependency 'multi_xml', '~> 0.6'
37
+ spec.add_development_dependency 'amazing_print', '~> 1.2'
38
+ spec.add_development_dependency 'erubis', '~> 2.7'
39
+ spec.add_development_dependency 'nokogiri', '~> 1.10'
40
+ spec.add_development_dependency 'pry', '~> 0.13'
41
+ spec.add_development_dependency 'rspec', '~> 3.10'
42
+ spec.add_development_dependency 'rubocop', '~> 1.7'
43
+ spec.add_development_dependency 'rubocop-performance', '~> 1.9'
44
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.1'
45
+ spec.add_development_dependency 'simplecov', '~> 0.21'
46
+ end
metadata ADDED
@@ -0,0 +1,307 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: usps-ruby-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joey Paris
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: builder
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.17'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.17'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday_middleware
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.14'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: multi_xml
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: amazing_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: erubis
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: nokogiri
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.10'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.10'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.13'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.13'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.10'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.10'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.7'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.7'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-performance
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1.9'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1.9'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rubocop-rspec
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '2.1'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '2.1'
195
+ - !ruby/object:Gem::Dependency
196
+ name: simplecov
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '0.21'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '0.21'
209
+ description: An automatically generated USPS API Client based on the official USPS
210
+ User Guides
211
+ email:
212
+ - joey@leadjig.com
213
+ executables: []
214
+ extensions: []
215
+ extra_rdoc_files: []
216
+ files:
217
+ - ".gitattributes"
218
+ - ".gitignore"
219
+ - ".rspec"
220
+ - ".rubocop.yml"
221
+ - ".rubocop_todo.yml"
222
+ - ".travis.yml"
223
+ - CODE_OF_CONDUCT.md
224
+ - Gemfile
225
+ - LICENSE.txt
226
+ - README.md
227
+ - Rakefile
228
+ - bin/console
229
+ - bin/setup
230
+ - lib/data/api/address-information-api.htm
231
+ - lib/data/api/domestic-mail-service-standards-api.htm
232
+ - lib/data/api/evs-international-label-api.htm
233
+ - lib/data/api/evs-label-api.htm
234
+ - lib/data/api/hold-for-pickup-facilities-lookup-api.htm
235
+ - lib/data/api/package-pickup-api.htm
236
+ - lib/data/api/rate-calculator-api.htm
237
+ - lib/data/api/scan-api.htm
238
+ - lib/data/api/service-delivery-calculator-get-locations-api.htm
239
+ - lib/data/api/track-and-confirm-api.htm
240
+ - lib/data/api/uspsreturnslabel-api.htm
241
+ - lib/helpers/erubis_helper.rb
242
+ - lib/tasks/api.rake
243
+ - lib/usps-ruby-client.rb
244
+ - lib/usps/api/endpoints.rb
245
+ - lib/usps/api/endpoints/carrier_pickup_schedule.rb
246
+ - lib/usps/api/endpoints/city_state_lookup.rb
247
+ - lib/usps/api/endpoints/e_vs_express_mail_intl.rb
248
+ - lib/usps/api/endpoints/e_vs_first_class_mail_intl.rb
249
+ - lib/usps/api/endpoints/e_vs_priority_mail_intl.rb
250
+ - lib/usps/api/endpoints/e_vsgxg_get_label.rb
251
+ - lib/usps/api/endpoints/e_vsi_cancel.rb
252
+ - lib/usps/api/endpoints/hfp_facility_info.rb
253
+ - lib/usps/api/endpoints/intl_rate_v2.rb
254
+ - lib/usps/api/endpoints/pts_email.rb
255
+ - lib/usps/api/endpoints/pts_pod.rb
256
+ - lib/usps/api/endpoints/pts_rre.rb
257
+ - lib/usps/api/endpoints/ptst_pod.rb
258
+ - lib/usps/api/endpoints/rate_v4.rb
259
+ - lib/usps/api/endpoints/scan.rb
260
+ - lib/usps/api/endpoints/track_v2.rb
261
+ - lib/usps/api/endpoints/usps_returns_label.rb
262
+ - lib/usps/api/endpoints/verify.rb
263
+ - lib/usps/api/endpoints/zip_code_lookup.rb
264
+ - lib/usps/api/error.rb
265
+ - lib/usps/api/errors/too_many_requests_error.rb
266
+ - lib/usps/api/errors/usps_error.rb
267
+ - lib/usps/api/templates/_build_xml.erb
268
+ - lib/usps/api/templates/_options.erb
269
+ - lib/usps/api/templates/_throw_argument_error.erb
270
+ - lib/usps/api/templates/endpoints.erb
271
+ - lib/usps/api/templates/method.erb
272
+ - lib/usps/api/templates/method_spec.erb
273
+ - lib/usps/api/xml.rb
274
+ - lib/usps/client.rb
275
+ - lib/usps/config.rb
276
+ - lib/usps/faraday/connection.rb
277
+ - lib/usps/faraday/request.rb
278
+ - lib/usps/faraday/response/raise_error.rb
279
+ - lib/usps/logger.rb
280
+ - lib/usps/version.rb
281
+ - usps-ruby-client.gemspec
282
+ homepage: https://www.usps.com/business/web-tools-apis/documentation-updates.htm
283
+ licenses:
284
+ - MIT
285
+ metadata:
286
+ homepage_uri: https://www.usps.com/business/web-tools-apis/documentation-updates.htm
287
+ source_code_uri: https://github.com/joeyparis/usps-ruby-client
288
+ post_install_message:
289
+ rdoc_options: []
290
+ require_paths:
291
+ - lib
292
+ required_ruby_version: !ruby/object:Gem::Requirement
293
+ requirements:
294
+ - - ">="
295
+ - !ruby/object:Gem::Version
296
+ version: 2.5.0
297
+ required_rubygems_version: !ruby/object:Gem::Requirement
298
+ requirements:
299
+ - - ">="
300
+ - !ruby/object:Gem::Version
301
+ version: '0'
302
+ requirements: []
303
+ rubygems_version: 3.1.2
304
+ signing_key:
305
+ specification_version: 4
306
+ summary: An automatically generated USPS API Client
307
+ test_files: []