lob 1.7 → 1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d4aeceb1ade65ead19ded055406c8bab5bca3a9
4
- data.tar.gz: 6c299cf9833d544f30bf16aef7fba96306504cce
3
+ metadata.gz: 2d111537d5990b2be463c22fe1f24b5f707c6b7e
4
+ data.tar.gz: 4605b327af3dcafcb45b0d092576000a65faf074
5
5
  SHA512:
6
- metadata.gz: 0d33be867b0a13cafff7e9fa4f7cdd190fa39b11af000123d0607e45aa18c1a1e8e0a5aa70c3a08179312ae9e361cfd8fdb333f86a622251c491d8b572741d1e
7
- data.tar.gz: 7ce7dd4aae901a8a37fda89d4290ff7feb8f4bacaa66618d97bc397e9722c6474e9baee3a450b14e9230535e5b836efd42db04050aa9555cee72f19e8b1b7737
6
+ metadata.gz: de7f9937d1a207eb86c14d99fd71ffe59efdc0f3c4a91e4356b1b14950ca658efb26f69ebe59c77852096446f02e4fa8de75b2449dc36c4d81d3099b1982d82c
7
+ data.tar.gz: cbd24374e3d79375530826112701f91f9b2e4ec41dbd3e0da04bdf37c89b35cfcf1445f18b434c16845416b22a886243f711abb2027bf1479b3ab32db610aa2d
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## [**1.8**](https://github.com/lob/lob-ruby/releases/tag/v1.8)
2
+ - [**#69**] (https://github.com/lob/lob-ruby/pull/69) fixed spelling in documentation
3
+ - [**#71**] (https://github.com/lob/lob-ruby/pull/71) fixed syntax in documentation
4
+ - [**#73**] (https://github.com/lob/lob-ruby/pull/73) fixed failing tests
5
+ - [**#74**] (https://github.com/lob/lob-ruby/pull/74) added support for setting api_version
6
+ - [**#75**] (https://github.com/lob/lob-ruby/pull/75) added version module
7
+ - [**#76**] (https://github.com/lob/lob-ruby/pull/76) better error handling
8
+
9
+
10
+ ## [**1.7**](https://github.com/lob/lob-ruby/releases/tag/v1.7)
11
+ - [**#64**] (https://github.com/lob/lob-ruby/pull/64) changed asset URLs to use lob-assets bucket
data/README.md CHANGED
@@ -73,10 +73,8 @@ Lob.api_key = "your-api-key"
73
73
 
74
74
  ```ruby
75
75
  Lob.configure do |config|
76
- config.api_key = "your-api-key" # get your own at http://lob.com :)
77
- config.api_version = "v1" # default version
78
- config.protocol = "https" # default protocol
79
- config.api_host = "api.lob.com" # ofcourse it's Lob
76
+ config.api_key = "your-api-key" # get your own at http://lob.com :)
77
+ config.api_version = "2014-12-18" # override the API version
80
78
  end
81
79
  ```
82
80
 
@@ -564,7 +562,7 @@ You'll have to specify front, back, and either zip_codes or routes
564
562
  back: "https://s3-us-west-2.amazonaws.com/lob-assets/areaback.pdf",
565
563
  routes: ["94158-C001", "94107-C031"],
566
564
  target_type: "all",
567
- full_blled = "1"
565
+ full_bleed: "1"
568
566
  )
569
567
 
570
568
  # create an area request with zip_codes
@@ -574,7 +572,7 @@ You'll have to specify front, back, and either zip_codes or routes
574
572
  back: "https://s3-us-west-2.amazonaws.com/lob-assets/areaback.pdf",
575
573
  zip_codes: ["95678", "94158"],
576
574
  target_type: "all",
577
- full_blled = "1"
575
+ full_bleed: "1"
578
576
  )
579
577
  ```
580
578
 
data/lib/lob.rb CHANGED
@@ -1,22 +1,20 @@
1
1
  require "rest-client"
2
2
  require "json"
3
- require "lob/lob_error"
3
+ require "lob/version"
4
+ require "lob/errors/lob_error"
5
+ require "lob/errors/invalid_request_error"
4
6
 
5
7
  # Dynamically require files
6
8
  Dir[File.join(File.dirname(__FILE__), 'lob', 'v*', '*.rb')].each {|file| require file }
7
9
 
8
10
  module Lob
9
11
  class << self
10
- attr_accessor :api_key,
11
- :api_version,
12
- :protocol,
13
- :api_host
12
+ attr_accessor :api_key, :api_version, :protocol, :api_host
14
13
 
15
14
  def configure
16
15
  yield self
17
16
  true
18
17
  end
19
-
20
18
  alias :config :configure
21
19
  end
22
20
 
@@ -26,61 +24,53 @@ module Lob
26
24
  end
27
25
  end
28
26
 
29
-
30
27
  def self.submit(method, url, parameters={})
31
- clientVersion = Gem.latest_spec_for('lob').version.to_s
28
+ clientVersion = Lob::VERSION
32
29
 
33
- if method == :get || method == :delete
34
- JSON(RestClient.send(method, url, {
35
- user_agent: 'Lob/v1 RubyBindings/' + clientVersion,
36
- params: parameters
37
- }))
38
- else
39
- JSON(RestClient.send(method, url, parameters, {
40
- user_agent: 'Lob/v1 RubyBindings/' + clientVersion
41
- }))
42
- end
43
- # :nocov:
44
- rescue => e
45
30
  begin
46
- # Parse the error to raise a nice Lob::Error
47
- json = JSON(e.http_body)
48
-
49
- if json.has_key? 'errors'
50
- error_message = json["errors"].first.values.first
51
- elsif json.has_key? 'message'
52
- error_message = json["message"]
31
+ if method == :get || method == :delete
32
+ JSON.parse(RestClient.send(method, url, {
33
+ user_agent: 'Lob/v1 RubyBindings/' + clientVersion,
34
+ params: parameters,
35
+ "Lob-Version" => self.api_version
36
+ }))
53
37
  else
54
- error_message = "Unknown error: #{json}"
38
+ JSON.parse(RestClient.send(method, url, parameters, {
39
+ user_agent: 'Lob/v1 RubyBindings/' + clientVersion,
40
+ "Lob-Version" => self.api_version
41
+ }))
55
42
  end
56
43
 
57
- raise Lob::Error.new(error_message)
58
- rescue
59
- # If error parsing failed re-raise the original error
60
- raise e
44
+ rescue RestClient::ExceptionWithResponse => e
45
+ handle_api_error(e)
61
46
  end
62
- # :nocov:
63
47
  end
64
48
 
65
49
  def self.load(options={})
66
50
  Lob(options)
67
51
  end
68
- end
69
52
 
53
+ def self.handle_api_error(error)
54
+ begin
55
+ response = JSON.parse(error.http_body)
56
+ error_obj = response["errors"].first
57
+ message = error_obj["message"]
58
+ raise InvalidRequestError.new(message, error.http_code, error.http_body, error.response)
59
+ rescue JSON::ParserError
60
+ raise LobError.new("Invalid response object: #{}", error.http_code, error.http_body)
61
+ end
62
+ end
63
+ end
70
64
 
71
65
  def Lob(options={})
72
66
  options[:api_host] ||= Lob.api_host || "api.lob.com"
73
67
  options[:protocol] ||= Lob.protocol || "https"
74
- options[:api_version] ||= Lob.api_version || "v1"
68
+ options[:api_version] ||= Lob.api_version
75
69
  options[:api_key] ||= Lob.api_key
76
70
 
77
71
  if options[:api_key].nil?
78
72
  raise ArgumentError.new(":api_key is a required argument to initialize Lob")
79
73
  end
80
74
 
81
- if Dir[File.join(File.dirname(__FILE__), 'lob', options[:api_version])].empty?
82
- raise Lob::VersionInvalidError.new("api version #{options[:api_version]} doesn't exist")
83
- end
84
-
85
- Lob.const_get(options[:api_version].capitalize).const_get("Resource").new(options)
75
+ Lob::V1::Resource.new(options)
86
76
  end
@@ -0,0 +1,4 @@
1
+ module Lob
2
+ class InvalidRequestError < LobError
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ module Lob
2
+ class LobError < StandardError
3
+ attr_reader :message, :http_status, :http_body, :json_body
4
+
5
+ def initialize(message=nil, http_status=nil, http_body=nil, json_body=nil)
6
+ @message = message
7
+ @http_status = http_status
8
+ @http_body = http_body
9
+ @json_body = json_body
10
+ end
11
+
12
+ def to_s
13
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
14
+ "#{status_string}#{@message}"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Lob
2
+ VERSION = "1.8"
3
+ end
data/lob.gemspec CHANGED
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
4
3
 
4
+ require "lob/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "lob"
8
- spec.version = "1.7"
8
+ spec.version = Lob::VERSION
9
9
  spec.authors = ["Lob"]
10
10
  spec.email = ["support@lob.com"]
11
11
  spec.description = %q{Lob API Ruby wrapper}
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lob::LobError do
4
+
5
+ describe "#to_s" do
6
+ it "should return a string with the status code and message" do
7
+ error = Lob::LobError.new("hello", 404)
8
+ error.to_s.must_equal("(Status 404) hello")
9
+ end
10
+
11
+ it "should returna a message without the status code if not provided" do
12
+ error = Lob::LobError.new("hello")
13
+ error.to_s.must_equal("hello")
14
+ end
15
+ end
16
+
17
+ end
@@ -13,7 +13,7 @@ describe Lob::V1::Address do
13
13
  }
14
14
  }
15
15
 
16
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
16
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
17
17
 
18
18
  describe "verify" do
19
19
 
@@ -9,7 +9,7 @@ describe Lob::V1::Area do
9
9
  }
10
10
  end
11
11
 
12
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
12
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
13
13
 
14
14
  describe "list" do
15
15
  it "should list areas" do
@@ -59,18 +59,7 @@ describe Lob::V1::Area do
59
59
 
60
60
  it "should create an area object with zip_codes" do
61
61
  VCR.use_cassette('create_area_object_with_zip') do
62
- @sample_area_params.delete("routes")
63
- @sample_area_params[:zip_codes] = "94158"
64
- result = subject.areas.create @sample_area_params
65
-
66
- result["object"].must_equal("area")
67
- end
68
- end
69
-
70
- it "should error without routes required params" do
71
- VCR.use_cassette('create_area_object_with_zip') do
72
- @sample_area_params.delete("routes")
73
- @sample_area_params[:zip_codes] = "94158"
62
+ @sample_area_params[:routes] = ["94158"];
74
63
  result = subject.areas.create @sample_area_params
75
64
 
76
65
  result["object"].must_equal("area")
@@ -20,7 +20,7 @@ describe Lob::V1::BankAccount do
20
20
  }
21
21
  end
22
22
 
23
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
23
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
24
24
 
25
25
  describe "list" do
26
26
  it "should list bank accounts" do
@@ -20,7 +20,7 @@ describe Lob::V1::Check do
20
20
  }
21
21
  end
22
22
 
23
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
23
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
24
24
 
25
25
  describe "list" do
26
26
  it "should list checks" do
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lob::V1::Country do
4
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
4
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
5
5
 
6
6
  describe "list" do
7
7
  it "should list countries" do
@@ -19,7 +19,7 @@ describe Lob::V1::Job do
19
19
  @test_setting_id = 201
20
20
  end
21
21
 
22
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
22
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
23
23
 
24
24
 
25
25
  describe "list" do
@@ -9,8 +9,7 @@ describe Lob::V1::Object do
9
9
  @test_setting_id = 201
10
10
  end
11
11
 
12
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
13
-
12
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
14
13
 
15
14
  describe "list" do
16
15
  it "should list objects" do
@@ -28,7 +27,6 @@ describe Lob::V1::Object do
28
27
  end
29
28
  end
30
29
 
31
-
32
30
  describe "create" do
33
31
  it "should create an object with file url" do
34
32
  VCR.use_cassette('create_object_with_url') do
@@ -55,8 +53,21 @@ describe Lob::V1::Object do
55
53
  result["name"].must_equal(@sample_params[:name])
56
54
  end
57
55
  end
58
- end
59
56
 
57
+ it "should create an object with a new api version" do
58
+ Lob.api_version = "2014-12-18"
59
+ VCR.use_cassette("create_object_with_new_version") do
60
+ result = subject.objects.create(
61
+ name: @sample_params[:name],
62
+ file: "https://s3-us-west-2.amazonaws.com/lob-assets/test.pdf",
63
+ setting: @test_setting_id
64
+ )
65
+
66
+ result["name"].must_equal(@sample_params[:name])
67
+ end
68
+ Lob.api_version = "2014-11-24"
69
+ end
70
+ end
60
71
 
61
72
  describe "find" do
62
73
  it "should find an object" do
@@ -74,7 +85,6 @@ describe Lob::V1::Object do
74
85
  end
75
86
  end
76
87
 
77
-
78
88
  describe "destroy" do
79
89
  it "should delete an object" do
80
90
  VCR.use_cassette('delete_object') do
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Lob::V1::Packaging do
4
4
 
5
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
5
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
6
6
 
7
7
  describe "list" do
8
8
  it "should list packagings" do
@@ -20,7 +20,7 @@ describe Lob::V1::Postcard do
20
20
  }
21
21
  end
22
22
 
23
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
23
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
24
24
 
25
25
  describe "list" do
26
26
  it "should list postcards" do
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lob::V1::Route do
4
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
4
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
5
5
 
6
6
  describe "list" do
7
7
  it "should list routes" do
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Lob::V1::Service do
4
4
 
5
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
5
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
6
6
 
7
7
  describe "list" do
8
8
  it "should list services" do
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Lob::V1::Setting do
4
4
 
5
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
5
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
6
6
 
7
7
  describe "list" do
8
8
  it "should list settings" do
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lob::V1::State do
4
- subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
4
+ subject { Lob(api_key: ENV["LOB_API_KEY"]) }
5
5
 
6
6
  describe "list" do
7
7
  it "should list states" do
data/spec/lob_spec.rb CHANGED
@@ -2,16 +2,7 @@ require "spec_helper"
2
2
 
3
3
  describe Lob do
4
4
  it "should return the resource object for the valid version" do
5
- Lob(api_key: "test", api_version: "v1").must_be_kind_of(Lob::V1::Resource)
6
- end
7
-
8
- it "should raise an error if the version doesn't exist" do
9
- ->{Lob(api_key: "test", api_version: "test")}.must_raise(Lob::VersionInvalidError)
10
- end
11
-
12
- it "should raise an error if API key is not passed as an option or set on module" do
13
- Lob.api_key = nil # make sure API key is nil
14
- ->{ Lob() }.must_raise(ArgumentError)
5
+ Lob(api_key: "test", api_version: "2014-11-25").must_be_kind_of(Lob::V1::Resource)
15
6
  end
16
7
 
17
8
  it "should *not* raise an error if API key has been on module and not passed as option" do
@@ -26,13 +17,13 @@ describe Lob do
26
17
  it "should allow detailed configuration" do
27
18
  Lob.configure do |config|
28
19
  config.api_key = "test"
29
- config.api_version = "v1"
20
+ config.api_version = "2014-11-24"
30
21
  config.protocol = "https"
31
22
  config.api_host = "api.lob.com"
32
23
  end
33
24
 
34
25
  Lob.api_key.must_equal "test"
35
- Lob.api_version.must_equal "v1"
26
+ Lob.api_version.must_equal "2014-11-24"
36
27
  Lob.protocol.must_equal "https"
37
28
  Lob.api_host.must_equal "api.lob.com"
38
29
  end
@@ -43,11 +34,24 @@ describe Lob do
43
34
  Lob.api_key = "test"
44
35
  Lob.load.wont_be_nil
45
36
 
46
- Lob.api_key = nil # make sure API key is nil
47
- ->{ Lob.load }.must_raise(ArgumentError)
37
+ Lob.load(api_key: "test", api_version: "2014-11-24").must_be_kind_of(Lob::V1::Resource)
38
+ end
48
39
 
49
- ->{Lob.load(api_key: "test", api_version: "test")}.must_raise(Lob::VersionInvalidError)
40
+ it "should handle API errors gracefully" do
41
+ lob = Lob.load(api_key: ENV["LOB_API_KEY"])
42
+ assert_raises Lob::InvalidRequestError do
43
+ VCR.use_cassette('bad_request') do
44
+ lob.objects.create(name: "Test", file: "https://lob.com/test.pdf", bad_param: "bad_value")
45
+ end
46
+ end
47
+ end
50
48
 
51
- Lob.load(api_key: "test", api_version: "v1").must_be_kind_of(Lob::V1::Resource)
49
+ it "should work when no api_version is provided" do
50
+ lob = Lob.load(api_key: ENV["LOB_API_KEY"])
51
+ Lob.api_version = nil
52
+ VCR.use_cassette('no_api_version') do
53
+ lob.addresses.list
54
+ end
55
+ Lob.api_version = "2014-11-24"
52
56
  end
53
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lob
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.7'
4
+ version: '1.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-31 00:00:00.000000000 Z
11
+ date: 2014-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -159,6 +159,7 @@ extra_rdoc_files: []
159
159
  files:
160
160
  - .gitignore
161
161
  - .travis.yml
162
+ - CHANGELOG.md
162
163
  - Gemfile
163
164
  - LICENSE.txt
164
165
  - README.md
@@ -168,7 +169,8 @@ files:
168
169
  - examples/jobs.rb
169
170
  - examples/postcards.rb
170
171
  - lib/lob.rb
171
- - lib/lob/lob_error.rb
172
+ - lib/lob/errors/invalid_request_error.rb
173
+ - lib/lob/errors/lob_error.rb
172
174
  - lib/lob/v1/address.rb
173
175
  - lib/lob/v1/area.rb
174
176
  - lib/lob/v1/bank_account.rb
@@ -183,7 +185,9 @@ files:
183
185
  - lib/lob/v1/service.rb
184
186
  - lib/lob/v1/setting.rb
185
187
  - lib/lob/v1/state.rb
188
+ - lib/lob/version.rb
186
189
  - lob.gemspec
190
+ - spec/lob/errors/lob_error_spec.rb
187
191
  - spec/lob/v1/address_spec.rb
188
192
  - spec/lob/v1/area_spec.rb
189
193
  - spec/lob/v1/bank_account_spec.rb
@@ -220,11 +224,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
224
  version: '0'
221
225
  requirements: []
222
226
  rubyforge_project:
223
- rubygems_version: 2.3.0
227
+ rubygems_version: 2.0.14
224
228
  signing_key:
225
229
  specification_version: 4
226
230
  summary: Ruby wrapper for Lob.com API with ActiveRecord-style syntax
227
231
  test_files:
232
+ - spec/lob/errors/lob_error_spec.rb
228
233
  - spec/lob/v1/address_spec.rb
229
234
  - spec/lob/v1/area_spec.rb
230
235
  - spec/lob/v1/bank_account_spec.rb
data/lib/lob/lob_error.rb DELETED
@@ -1,6 +0,0 @@
1
- module Lob
2
- class Error < StandardError
3
- end
4
- class VersionInvalidError < StandardError
5
- end
6
- end