lob 1.13.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +0 -4
  4. data/CHANGELOG.md +10 -0
  5. data/README.md +2 -7
  6. data/Rakefile +0 -19
  7. data/lib/lob.rb +2 -8
  8. data/lib/lob/v1/address.rb +3 -4
  9. data/lib/lob/v1/area.rb +1 -1
  10. data/lib/lob/v1/bank_account.rb +1 -9
  11. data/lib/lob/v1/check.rb +1 -5
  12. data/lib/lob/v1/country.rb +1 -1
  13. data/lib/lob/v1/job.rb +1 -9
  14. data/lib/lob/v1/letter.rb +1 -11
  15. data/lib/lob/v1/object.rb +1 -1
  16. data/lib/lob/v1/postcard.rb +1 -9
  17. data/lib/lob/v1/resource.rb +0 -16
  18. data/lib/lob/v1/route.rb +1 -1
  19. data/lib/lob/v1/service.rb +1 -1
  20. data/lib/lob/v1/setting.rb +1 -1
  21. data/lib/lob/v1/state.rb +1 -1
  22. data/lib/lob/version.rb +1 -1
  23. data/lob.gemspec +0 -1
  24. data/spec/lob/v1/address_spec.rb +21 -34
  25. data/spec/lob/v1/area_spec.rb +15 -31
  26. data/spec/lob/v1/bank_account_spec.rb +57 -80
  27. data/spec/lob/v1/check_spec.rb +44 -69
  28. data/spec/lob/v1/country_spec.rb +1 -4
  29. data/spec/lob/v1/job_spec.rb +114 -144
  30. data/spec/lob/v1/letter_spec.rb +39 -58
  31. data/spec/lob/v1/object_spec.rb +31 -49
  32. data/spec/lob/v1/postcard_spec.rb +65 -89
  33. data/spec/lob/v1/resource_spec.rb +1 -6
  34. data/spec/lob/v1/route_spec.rb +3 -7
  35. data/spec/lob/v1/service_spec.rb +1 -4
  36. data/spec/lob/v1/setting_spec.rb +4 -12
  37. data/spec/lob/v1/state_spec.rb +1 -4
  38. data/spec/lob_spec.rb +2 -6
  39. data/spec/samples/8.5x11.pdf +0 -0
  40. data/spec/samples/postcardback.pdf +2288 -1
  41. data/spec/samples/postcardfront.pdf +1550 -0
  42. data/spec/spec_helper.rb +0 -6
  43. metadata +8 -19
  44. data/lib/lob/v1/packaging.rb +0 -21
  45. data/spec/lob/v1/packaging_spec.rb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: acd5e9c0fe20145d83f62c1c915f0b2ca6893e7e
4
- data.tar.gz: 2edc15946a536dcac2b9ade028754a5b30db385e
3
+ metadata.gz: 4ceb1823e07362d2a8fbadfa23749bc78c6e49b8
4
+ data.tar.gz: 2ac14476bb2ba3c2ab7bd76bb9f0d644ce90dad1
5
5
  SHA512:
6
- metadata.gz: 296539b5631661d1c11290efb7bc42fea6f2475305aab47f6cd9e1939b4dff1bf286a78e1b5a75b75717590af722ffca702cc2ab09231b6a59736f1106ec8edd
7
- data.tar.gz: 45a9466effaa2ead82c9bbb0607ee507c957f332d69f203a72367a6068506bfe9499f4ee3a70fd2e07a6b90fa000890155ea2756efd1c3afc43e7f50d14cfde3
6
+ metadata.gz: ca4df9c124eb0ff74fb7c048ff8ae58a3ef7b5caa273cb21c56a461985d856197f34e8f751ee92cee5cccd5d01d00017728cc7009df63acc18a7dbeb2e620b3a
7
+ data.tar.gz: 080a64c572bed68a9c10ccd4e2a99b3ac93feb952003921fac1094bde74745fdd44594214a45317507aa31cfb1f574d930c079f20d5fd773461195c4457a9cc1
data/.gitignore CHANGED
@@ -16,4 +16,3 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
- spec/vcr_cassettes/
@@ -12,8 +12,4 @@ env:
12
12
  JRUBY_OPTS=--2.0
13
13
  - LOB_API_KEY=test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc
14
14
 
15
- before_script:
16
- - bundle exec rake dev:setup
17
- - rm -rf spec/vcr_cassettes
18
-
19
15
  script: bundle exec rake test
@@ -1,3 +1,13 @@
1
+ ## 2.0.0
2
+
3
+ Version 2.0.0 introduces several breaking changes. It requires a minimum API version of `2015-04-11`.
4
+
5
+ * The lob-ruby gem no longer converts `city`, `state`, etc. parameters into `address_city`, `address_state`, etc. This change was made to be more consistent with the API and other Lob wrappers, and to prevent confusion.
6
+ * The wrapper now returns the raw JSON from the API in all `list` endpoints rather than just the `data` field in the response. This will allow access to additional fields like `count` and `offset`.
7
+ * The `packagings` endpoint is not longer supporter in the API, and therefore has been taken out of lob-ruby.
8
+
9
+ In addition to these breaking changes, the test suite was cleaned up by removing the unnecessary VCR gem and committing sample upload files to the repository rather than downloading them in rake task.
10
+
1
11
  ## [**1.13.0**](https://github.com/lob/lob-ruby/releases/tag/v1.13.0)
2
12
  - [**#112**] (https://github.com/lob/lob-ruby/pull/112) removes Rack dependency
3
13
 
data/README.md CHANGED
@@ -180,11 +180,7 @@ Make sure you have Ruby 2.0 installed. Copy and paste the following commands in
180
180
 
181
181
  ## Testing
182
182
 
183
- To run the tests, download the required sample files by running the following command:
184
-
185
- bundle exec rake dev:setup
186
-
187
- Tests are written using MiniTest, a testing library that comes with Ruby stdlib. The remote responses are tested using [vcr](https://github.com/vcr/vcr).
183
+ Tests are written using MiniTest, a testing library that comes with Ruby stdlib.
188
184
 
189
185
  You'll need to pass in your Lob.com API as the environment variable `LOB_API_KEY`, to run the tests. Be sure to use your Test API key, and not the Live one.
190
186
 
@@ -192,8 +188,6 @@ Here's how you can run the tests:
192
188
 
193
189
  LOB_API_KEY=your_test_api_key bundle exec rake test
194
190
 
195
- When you make changes to failed tests, then clear out the vcr cassettes to re-record the http requests. You can clear out all the cassettes by running `rm -rf spec/vcr_cassettes`.
196
-
197
191
  You can also configure, TravisCI for your fork of the repository and it'll run the tests for you, when you push.
198
192
 
199
193
  =======================
@@ -201,3 +195,4 @@ You can also configure, TravisCI for your fork of the repository and it'll run t
201
195
  Copyright © 2013 Lob.com
202
196
 
203
197
  Released under the MIT License, which can be found in the repository in `LICENSE.txt`.
198
+
data/Rakefile CHANGED
@@ -1,27 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
-
5
4
  Rake::TestTask.new do |t|
6
5
  t.libs.push "lib", "spec"
7
6
  t.test_files = FileList['spec/**/*_spec.rb']
8
7
  t.verbose = true
9
8
  end
10
-
11
-
12
- namespace :dev do
13
-
14
- desc "Download sample files to run tests with"
15
- task :setup do
16
- Dir.mkdir("spec/samples") unless File.exist?("spec/samples")
17
- files = [
18
- {url: "https://lob.com/postcardfront.pdf", name: "postcardfront.pdf"},
19
- {url: "https://lob.com/postcardback.pdf", name: "postcardback.pdf"},
20
- {url: "https://s3-us-west-2.amazonaws.com/lob-assets/letter-goblue.pdf", name: "8.5x11.pdf"},
21
- ]
22
- files.each do |f|
23
- system "curl #{f[:url]} -o spec/samples/#{f[:name]}"
24
- end
25
-
26
- end
27
- end
data/lib/lob.rb CHANGED
@@ -19,12 +19,6 @@ module Lob
19
19
  alias :config :configure
20
20
  end
21
21
 
22
- def self.require_options(options, *keys)
23
- keys.each do |key|
24
- raise ArgumentError.new(":#{key} is required") unless options.key?(key)
25
- end
26
- end
27
-
28
22
  def self.submit(method, url, parameters={})
29
23
  clientVersion = Lob::VERSION
30
24
 
@@ -55,9 +49,9 @@ module Lob
55
49
  def self.handle_api_error(error)
56
50
  begin
57
51
  response = JSON.parse(error.http_body)
58
- message = response["error"]["message"]
52
+ message = response.fetch("error").fetch("message")
59
53
  raise InvalidRequestError.new(message, error.http_code, error.http_body, error.response)
60
- rescue JSON::ParserError
54
+ rescue JSON::ParserError, KeyError
61
55
  raise LobError.new("Invalid response object: #{}", error.http_code, error.http_body)
62
56
  end
63
57
  end
@@ -7,12 +7,11 @@ module Lob
7
7
  end
8
8
 
9
9
  def verify(options={})
10
- params = @resource.format_address_params(options, false)
11
- Lob.submit(:post, address_verify_url, params)
10
+ Lob.submit(:post, address_verify_url, options)
12
11
  end
13
12
 
14
13
  def list(options={})
15
- Lob.submit(:get, address_url, options)["data"] || []
14
+ Lob.submit(:get, address_url, options)
16
15
  end
17
16
 
18
17
  def find(address_id)
@@ -20,7 +19,7 @@ module Lob
20
19
  end
21
20
 
22
21
  def create(options = {})
23
- Lob.submit :post, address_url, @resource.format_address_params(options)
22
+ Lob.submit :post, address_url, options
24
23
  end
25
24
 
26
25
  def destroy(address_id)
@@ -6,7 +6,7 @@ module Lob
6
6
  end
7
7
 
8
8
  def list(options = {})
9
- Lob.submit(:get, area_url, options)["data"] || []
9
+ Lob.submit(:get, area_url, options)
10
10
  end
11
11
 
12
12
  def find(lob_object_id)
@@ -7,7 +7,7 @@ module Lob
7
7
  end
8
8
 
9
9
  def list(options={})
10
- Lob.submit(:get, bank_account_url, options)["data"] || []
10
+ Lob.submit(:get, bank_account_url, options)
11
11
  end
12
12
 
13
13
  def find(bank_account_id)
@@ -15,14 +15,6 @@ module Lob
15
15
  end
16
16
 
17
17
  def create(options = {})
18
- if !options[:bank_address].is_a?(String)
19
- options[:bank_address] = @resource.format_address_params(options[:bank_address])
20
- end
21
-
22
- if !options[:account_address].is_a?(String)
23
- options[:account_address] = @resource.format_address_params(options[:account_address])
24
- end
25
-
26
18
  Lob.submit :post, bank_account_url, options
27
19
  end
28
20
 
@@ -7,7 +7,7 @@ module Lob
7
7
  end
8
8
 
9
9
  def list(options={})
10
- Lob.submit(:get, check_url, options)["data"] || []
10
+ Lob.submit(:get, check_url, options)
11
11
  end
12
12
 
13
13
  def find(check_id)
@@ -15,10 +15,6 @@ module Lob
15
15
  end
16
16
 
17
17
  def create(options = {})
18
- if !options[:to].is_a?(String)
19
- options[:to] = @resource.format_address_params(options[:to])
20
- end
21
-
22
18
  Lob.submit :post, check_url, options
23
19
  end
24
20
 
@@ -7,7 +7,7 @@ module Lob
7
7
  end
8
8
 
9
9
  def list(options={})
10
- Lob.submit(:get, country_url, options)["data"] || []
10
+ Lob.submit(:get, country_url, options)
11
11
  end
12
12
 
13
13
  private
@@ -7,7 +7,7 @@ module Lob
7
7
  end
8
8
 
9
9
  def list(options={})
10
- Lob.submit(:get, job_url, options)["data"] || []
10
+ Lob.submit(:get, job_url, options)
11
11
  end
12
12
 
13
13
  def find(job_id)
@@ -24,14 +24,6 @@ module Lob
24
24
  end
25
25
  options.delete(:objects)
26
26
 
27
- if options[:to] && !options[:to].is_a?(String)
28
- options[:to] = @resource.format_address_params(options[:to])
29
- end
30
-
31
- if options[:from] && !options[:from].is_a?(String)
32
- options[:from] = @resource.format_address_params(options[:from])
33
- end
34
-
35
27
  Lob.submit :post, job_url, options
36
28
  end
37
29
 
@@ -7,7 +7,7 @@ module Lob
7
7
  end
8
8
 
9
9
  def list(options={})
10
- Lob.submit(:get, letter_url, options)["data"] || []
10
+ Lob.submit(:get, letter_url, options)
11
11
  end
12
12
 
13
13
  def find(job_id)
@@ -15,19 +15,9 @@ module Lob
15
15
  end
16
16
 
17
17
  def create(options = {})
18
-
19
- if options[:to] && !options[:to].is_a?(String)
20
- options[:to] = @resource.format_address_params(options[:to])
21
- end
22
-
23
- if options[:from] && !options[:from].is_a?(String)
24
- options[:from] = @resource.format_address_params(options[:from])
25
- end
26
-
27
18
  Lob.submit :post, letter_url, options
28
19
  end
29
20
 
30
-
31
21
  private
32
22
 
33
23
  def letter_url(job_id = nil)
@@ -7,7 +7,7 @@ module Lob
7
7
  end
8
8
 
9
9
  def list(options = {})
10
- Lob.submit(:get, object_url, options)["data"] || []
10
+ Lob.submit(:get, object_url, options)
11
11
  end
12
12
 
13
13
  def find(lob_object_id)
@@ -7,7 +7,7 @@ module Lob
7
7
  end
8
8
 
9
9
  def list(options={})
10
- Lob.submit(:get, postcard_url, options)["data"] || []
10
+ Lob.submit(:get, postcard_url, options)
11
11
  end
12
12
 
13
13
  def find(postcard_id)
@@ -15,14 +15,6 @@ module Lob
15
15
  end
16
16
 
17
17
  def create(options = {})
18
- if options[:to] && !options[:to].is_a?(String)
19
- options[:to] = @resource.format_address_params(options[:to])
20
- end
21
-
22
- if options[:from] && !options[:from].is_a?(String)
23
- options[:from] = @resource.format_address_params(options[:from])
24
- end
25
-
26
18
  Lob.submit :post, postcard_url, options
27
19
  end
28
20
 
@@ -72,22 +72,6 @@ module Lob
72
72
  "#{base_url}/#{resource_type}#{'/' + resource_id if resource_id}"
73
73
  end
74
74
 
75
- #NOTE to format address param names into API-compatible ones
76
- def format_address_params(params, check_required_options=true)
77
- if check_required_options
78
- Lob.require_options(params, :name, :address_line1, :city, :state, :zip, :country)
79
- end
80
-
81
- new_params = params.clone
82
-
83
- [:city, :state, :zip, :country].each do |option|
84
- new_params["address_#{option}".to_sym] = params[option] if params[option]
85
- new_params.delete(option)
86
- end
87
-
88
- new_params
89
- end
90
-
91
75
  end
92
76
  end
93
77
  end
@@ -6,7 +6,7 @@ module Lob
6
6
  end
7
7
 
8
8
  def list(options = {})
9
- Lob.submit(:get, route_url, options)["data"] || []
9
+ Lob.submit(:get, route_url, options)
10
10
  end
11
11
 
12
12
  private
@@ -7,7 +7,7 @@ module Lob
7
7
  end
8
8
 
9
9
  def list(options={})
10
- Lob.submit(:get, service_url, options)["data"] || []
10
+ Lob.submit(:get, service_url, options)
11
11
  end
12
12
 
13
13
  private
@@ -7,7 +7,7 @@ module Lob
7
7
  end
8
8
 
9
9
  def list(options={})
10
- Lob.submit(:get, setting_url, options)["data"] || []
10
+ Lob.submit(:get, setting_url, options)
11
11
  end
12
12
 
13
13
  def find(setting_id)
@@ -7,7 +7,7 @@ module Lob
7
7
  end
8
8
 
9
9
  def list(options={})
10
- Lob.submit(:get, state_url, options)["data"] || []
10
+ Lob.submit(:get, state_url, options)
11
11
  end
12
12
 
13
13
  private
@@ -1,3 +1,3 @@
1
1
  module Lob
2
- VERSION = "1.13.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -27,7 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "minitest", "~> 5.6.1"
28
28
  spec.add_development_dependency "webmock", "~> 1.2"
29
29
  spec.add_development_dependency "travis-lint", "~> 2.0.0"
30
- spec.add_development_dependency "vcr", "~> 2.9.2"
31
30
  spec.add_development_dependency "coveralls", "~> 0.8.1"
32
31
  spec.add_development_dependency "simplecov", "~> 0.10.0"
33
32
  spec.add_development_dependency "pry", "~> 0.10.0"
@@ -6,10 +6,10 @@ describe Lob::V1::Address do
6
6
  {
7
7
  name: "John Doe",
8
8
  address_line1: "325 Berry Street",
9
- city: "San Francisco",
10
- state: "CA",
11
- country: "US",
12
- zip: 94158
9
+ address_city: "San Francisco",
10
+ address_state: "CA",
11
+ address_country: "US",
12
+ address_zip: 94158
13
13
  }
14
14
  }
15
15
 
@@ -18,62 +18,49 @@ describe Lob::V1::Address do
18
18
  describe "verify" do
19
19
 
20
20
  it "should verify an address" do
21
- VCR.use_cassette('verify_address') do
22
- result = subject.addresses.verify(
23
- address_line1: sample_params[:address_line1],
24
- city: sample_params[:city],
25
- state: sample_params[:state],
26
- zip: sample_params[:zip]
27
- )
28
-
29
- result["address"]["address_country"].must_equal("US")
30
- end
21
+ result = subject.addresses.verify(
22
+ address_line1: sample_params[:address_line1],
23
+ address_city: sample_params[:address_city],
24
+ address_state: sample_params[:address_state],
25
+ address_zip: sample_params[:address_zip]
26
+ )
27
+
28
+ result["address"]["address_country"].must_equal("US")
31
29
  end
32
30
  end
33
31
 
34
32
 
35
33
  describe "list" do
36
34
  it "should list addresses" do
37
- VCR.use_cassette('list_addresses') do
38
- new_address = subject.addresses.create sample_params
39
-
40
- list_result = subject.addresses.list
41
- assert /#{new_address["name"]}/i =~ list_result.to_s
42
- end
35
+ assert subject.addresses.list["object"] == "list"
43
36
  end
44
37
  end
45
38
 
46
39
 
47
40
  describe "create" do
48
41
  it "should create an address" do
49
- VCR.use_cassette('create_address') do
50
- result = subject.addresses.create sample_params
51
- assert /#{result["name"]}/i =~ sample_params[:name]
52
- end
42
+ result = subject.addresses.create sample_params
43
+ assert /#{result["name"]}/i =~ sample_params[:name]
53
44
  end
54
45
  end
55
46
 
56
47
 
57
48
  describe "find" do
58
49
  it "should find an address" do
59
- VCR.use_cassette('find_address') do
60
- new_address = subject.addresses.create sample_params
50
+ new_address = subject.addresses.create sample_params
61
51
 
62
- find_result = subject.addresses.find(new_address["id"])
63
- assert /#{find_result["name"]}/i =~ sample_params[:name]
64
- end
52
+ find_result = subject.addresses.find(new_address["id"])
53
+ assert /#{find_result["name"]}/i =~ sample_params[:name]
65
54
  end
66
55
  end
67
56
 
68
57
 
69
58
  describe "destroy" do
70
59
  it "should delete an address" do
71
- VCR.use_cassette('delete_address') do
72
- new_address = subject.addresses.create sample_params
60
+ new_address = subject.addresses.create sample_params
73
61
 
74
- delete_result = subject.addresses.destroy(new_address["id"])
75
- assert_equal(new_address["id"], delete_result["id"])
76
- end
62
+ delete_result = subject.addresses.destroy(new_address["id"])
63
+ assert_equal(new_address["id"], delete_result["id"])
77
64
  end
78
65
  end
79
66
  end