lob 1.3.1 → 1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28b1bd25b6896a7a20910ff62e4aecb86cc73877
4
- data.tar.gz: 6e52736c7c0b7f380bb841d659d3c9372137ef07
3
+ metadata.gz: 73c25870f258cf39d0d433b254712629a7ca7e91
4
+ data.tar.gz: 6c7b1d259b1e8d8ee8f48398ac03290608d567a7
5
5
  SHA512:
6
- metadata.gz: e4243be1598476f54d6eda19a384a66da23b258e702d9c39dbb3f164038eda1de726ce195916b1308767385c3a4dd497cf6137af8b594f5b398d223bd6c9eea8
7
- data.tar.gz: 17e5b1d1118920e1026dac87382c610f5e0ef602bc8412bfda38cdf4b91fcbb9b667f0fd88bc2dfa95b8c95bbb65a6ebe0d50d0dfc26d86098a535353ee21957
6
+ metadata.gz: 08df0587f62aa357c84323426dbc3cb81906be0c56a888fd5c283222ef29734373ac775e27722911525669554476545bd028ede36fa313c1dfee2c5258522151
7
+ data.tar.gz: 97597db31774db70091e0dc49f2a6e71ab1a9ce28545e4c34a715094b4aa97dfed4252b9f91721ca7ae92ac95777b117f1085cb594f994c1e8871387b1f56e2f
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # lob-ruby
2
2
 
3
- [![Build Status](https://travis-ci.org/lob/lob-ruby.svg?branch=master)](https://travis-ci.org/lob/lob-ruby) [![Gem Version](https://badge.fury.io/rb/lob.svg)](http://badge.fury.io/rb/lob) [![Dependency Status](https://gemnasium.com/lob/lob-ruby.svg)](https://gemnasium.com/lob/lob-ruby)
4
-
5
- [![Coverage Status](https://img.shields.io/coveralls/lob/lob-ruby.svg)](https://coveralls.io/r/lob/lob-ruby?branch=master)
3
+ [![Build Status](https://travis-ci.org/lob/lob-ruby.svg?branch=master)](https://travis-ci.org/lob/lob-ruby) [![Gem Version](https://badge.fury.io/rb/lob.svg)](http://badge.fury.io/rb/lob) [![Dependency Status](https://gemnasium.com/lob/lob-ruby.svg)](https://gemnasium.com/lob/lob-ruby) [![Coverage Status](https://img.shields.io/coveralls/lob/lob-ruby.svg)](https://coveralls.io/r/lob/lob-ruby?branch=master) ![](http://ruby-gem-downloads-badge.herokuapp.com/lob?color=green)
6
4
 
7
5
  Ruby wrapper for the [Lob.com](http://lob.com) API. This gem gives you an ActiveRecord-style syntax to use the Lob.com API.
8
6
 
@@ -41,12 +39,22 @@ The Ruby interpreter assumes it's not of base-10 and tries to convert it to base
41
39
  # To initialize a Lob object
42
40
  @lob = Lob(api_key: "your-api-key")
43
41
 
44
-
45
42
  # Alternatively, to set the API key for all calls in the future
46
43
  Lob.api_key = "your-api-key"
47
44
  @lob = Lob() # don't forget the paranthesis!
48
45
  ```
49
46
 
47
+ ### Alternatively, you can use initialize and configure like this
48
+
49
+ ```ruby
50
+ # To initialize a Lob object
51
+ @lob = Lob.load(api_key: "your-api-key")
52
+
53
+ # Alternatively, to set the API key for all calls in the future
54
+ Lob.api_key = "your-api-key"
55
+ @lob = Lob.load
56
+ ```
57
+
50
58
  #### Or if you want some detailed configuration
51
59
 
52
60
  ```ruby
@@ -369,6 +377,64 @@ You'll have to specify either the `message` option or the `back` option.
369
377
  @lob.postcards.find("post-card-id")
370
378
  ```
371
379
 
380
+ ### Simple Area Mail
381
+
382
+ #### Create areas
383
+
384
+ You'll have to specify front, back, and either zip_codes or routes
385
+
386
+ ```ruby
387
+ # create an area request with routes
388
+ @lob.area.create(
389
+ name: "My Area",
390
+ front: "https://www.lob.com/areafront.pdf",
391
+ back: "https://www.lob.com/areaback.pdf",
392
+ routes: ["94158-C001", "94107-C031"],
393
+ target_type: "all",
394
+ full_blled = "1"
395
+ )
396
+
397
+ # create an area request with zip_codes
398
+ @lob.area.create(
399
+ name: "My Area",
400
+ front: "https://www.lob.com/areafront.pdf",
401
+ back: "https://www.lob.com/areaback.pdf",
402
+ zip_codes: ["95678", "94158"],
403
+ target_type: "all",
404
+ full_blled = "1"
405
+ )
406
+ ```
407
+
408
+ zip_codes and routes can be a string or an array of strings
409
+
410
+ #### List areas
411
+ ```ruby
412
+ @lob.areas.list
413
+
414
+ # you can also pass count and offset
415
+ @lob.areas.list(count: 10, offset: 3)
416
+ ```
417
+
418
+
419
+ #### Find an area
420
+ ```ruby
421
+ @lob.areas.find("area_id")
422
+ ```
423
+
424
+ ### Routes
425
+
426
+ You'll have to specify zip_codes
427
+
428
+ #### Find routes
429
+
430
+ ```ruby
431
+ @lob.routes.find(
432
+ zip_codes: ["95678, 94158"]
433
+ )
434
+ ```
435
+
436
+ zip_codes can be a string or an array of strings
437
+
372
438
  ### Services
373
439
 
374
440
  #### List services
data/lib/lob.rb CHANGED
@@ -1,18 +1,9 @@
1
1
  require "rest-client"
2
2
  require "json"
3
-
4
3
  require "lob/lob_error"
5
- require "lob/v1/resource"
6
- require "lob/v1/address"
7
- require "lob/v1/job"
8
- require "lob/v1/object"
9
- require "lob/v1/packaging"
10
- require "lob/v1/postcard"
11
- require "lob/v1/service"
12
- require "lob/v1/setting"
13
- require "lob/v1/country"
14
- require "lob/v1/check"
15
- require "lob/v1/bank_account"
4
+
5
+ # Dynamically require files
6
+ Dir[File.join(File.dirname(__FILE__), 'lob', 'v*', '*.rb')].each {|file| require file }
16
7
 
17
8
  module Lob
18
9
 
@@ -30,7 +21,6 @@ module Lob
30
21
  alias :config :configure
31
22
  end
32
23
 
33
-
34
24
  def self.require_options(options, *keys)
35
25
  keys.each do |key|
36
26
  raise ArgumentError.new(":#{key} is required") unless options.key?(key)
@@ -63,6 +53,9 @@ module Lob
63
53
  # :nocov:
64
54
  end
65
55
 
56
+ def self.load(options={})
57
+ Lob(options)
58
+ end
66
59
  end
67
60
 
68
61
 
@@ -72,10 +65,13 @@ def Lob(options={})
72
65
  options[:api_version] ||= Lob.api_version || "v1"
73
66
  options[:api_key] ||= Lob.api_key
74
67
 
75
- unless options[:api_key]
68
+ if options[:api_key].nil?
76
69
  raise ArgumentError.new(":api_key is a required argument to initialize Lob")
77
70
  end
78
71
 
79
- #TODO check if the version exists first
80
- Lob.const_get("#{options[:api_version].capitalize}").const_get("Resource").new(options)
72
+ if Dir[File.join(File.dirname(__FILE__), 'lob', options[:api_version])].empty?
73
+ raise Lob::VersionInvalidError.new("api version #{options[:api_version]} doesn't exist")
74
+ end
75
+
76
+ Lob.const_get(options[:api_version].capitalize).const_get("Resource").new(options)
81
77
  end
@@ -1,4 +1,6 @@
1
1
  module Lob
2
2
  class Error < StandardError
3
3
  end
4
+ class VersionInvalidError < StandardError
5
+ end
4
6
  end
@@ -0,0 +1,27 @@
1
+ module Lob
2
+ module V1
3
+ class Area
4
+ def initialize(resource)
5
+ @resource = resource
6
+ end
7
+
8
+ def list(options = {})
9
+ Lob.submit(:get, area_url, options)["data"] || []
10
+ end
11
+
12
+ def find(lob_object_id)
13
+ Lob.submit :get, area_url(lob_object_id)
14
+ end
15
+
16
+ def create(options = {})
17
+ Lob.submit :post, area_url, options
18
+ end
19
+
20
+ private
21
+
22
+ def area_url(area_id = nil)
23
+ @resource.construct_url("areas", area_id)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -6,7 +6,7 @@ module Lob
6
6
  @resource = resource
7
7
  end
8
8
 
9
- def list(options={})
9
+ def list(options = {})
10
10
  Lob.submit(:get, object_url, options)["data"] || []
11
11
  end
12
12
 
@@ -8,6 +8,10 @@ module Lob
8
8
  @options = options
9
9
  end
10
10
 
11
+ def areas
12
+ Lob::V1::Area.new(self)
13
+ end
14
+
11
15
  def addresses
12
16
  Lob::V1::Address.new(self)
13
17
  end
@@ -28,6 +32,10 @@ module Lob
28
32
  Lob::V1::Postcard.new(self)
29
33
  end
30
34
 
35
+ def routes
36
+ Lob::V1::Route.new(self)
37
+ end
38
+
31
39
  def services
32
40
  Lob::V1::Service.new(self)
33
41
  end
@@ -0,0 +1,19 @@
1
+ module Lob
2
+ module V1
3
+ class Route
4
+ def initialize(resource)
5
+ @resource = resource
6
+ end
7
+
8
+ def list(options = {})
9
+ Lob.submit(:get, route_url, options)["data"] || []
10
+ end
11
+
12
+ private
13
+
14
+ def route_url(route_id = nil)
15
+ @resource.construct_url("routes", route_id)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "lob"
8
- spec.version = "1.3.1"
8
+ spec.version = "1.4"
9
9
  spec.authors = ["Lob"]
10
10
  spec.email = ["support@lob.com"]
11
11
  spec.description = %q{Lob API Ruby wrapper}
@@ -0,0 +1,92 @@
1
+ require "spec_helper"
2
+
3
+ describe Lob::V1::Area do
4
+ before :each do
5
+ @sample_area_params = {
6
+ front: "https://www.lob.com/areafront.pdf",
7
+ back: "https://www.lob.com/areaback.pdf",
8
+ routes: ["94158-C001", "94107-C031"],
9
+ }
10
+ end
11
+
12
+ subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
13
+
14
+ describe "list" do
15
+ it "should list areas" do
16
+ VCR.use_cassette('list_areas') do
17
+ @sample_area_params[:name] = "Test Area"
18
+ new_area = subject.areas.create @sample_area_params
19
+
20
+ list_result = subject.areas.list
21
+
22
+ assert /#{new_area["name"]}/ =~ list_result.to_s
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "create" do
28
+ it "should create an area object" do
29
+ VCR.use_cassette('create_area_object') do
30
+ result = subject.areas.create @sample_area_params
31
+
32
+ result["object"].must_equal("area")
33
+ end
34
+ end
35
+
36
+ it "should create an area object with optionals params" do
37
+ VCR.use_cassette('create_area_object_with_optional_params') do
38
+ @sample_area_params[:name] = "123456789"
39
+ @sample_area_params[:target_type] = "all"
40
+ @sample_area_params[:full_bleed] = "1"
41
+
42
+ result = subject.areas.create @sample_area_params
43
+
44
+ result["name"].must_equal @sample_area_params[:name]
45
+ result["target_type"].must_equal @sample_area_params[:target_type]
46
+ # TODO this should be added when Lob API is updated
47
+ # result["full_bleed"].must_equal(@sample_area_params[:full_bleed])
48
+ end
49
+ end
50
+
51
+ it "should create an area object with a single route" do
52
+ VCR.use_cassette('create_area_object_with_single_route') do
53
+ @sample_area_params[:routes] = "94158-C001"
54
+ result = subject.areas.create @sample_area_params
55
+
56
+ result["object"].must_equal("area")
57
+ end
58
+ end
59
+
60
+ it "should create an area object with zip_codes" do
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"
74
+ result = subject.areas.create @sample_area_params
75
+
76
+ result["object"].must_equal("area")
77
+ end
78
+ end
79
+ end
80
+
81
+ describe "find" do
82
+ it "should find an area" do
83
+ VCR.use_cassette('find_area') do
84
+ @sample_area_params[:name] = "Test Area"
85
+ new_area = subject.areas.create @sample_area_params
86
+
87
+ result = subject.areas.find new_area["id"]
88
+ result["name"].must_equal @sample_area_params[:name]
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe Lob::V1::Route do
4
+ subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
5
+
6
+ describe "list" do
7
+ it "should list routes" do
8
+ VCR.use_cassette("list_routes") do
9
+ routes = subject.routes.list(
10
+ zip_codes: "94158"
11
+ )
12
+
13
+ routes[0]["zip_code"].must_equal("94158")
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,19 +1,12 @@
1
1
  require "spec_helper"
2
2
 
3
- module Lob
4
- module Test
5
- class Resource
6
- attr_accessor :options
7
- def initialize(options)
8
- @options = options
9
- end
10
- end
3
+ describe Lob do
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)
11
6
  end
12
- end
13
7
 
14
- describe Lob do
15
- it "should return the resource object for the specified version" do
16
- Lob(api_key: "test", api_version: "test").must_be_kind_of(Lob::Test::Resource)
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)
17
10
  end
18
11
 
19
12
  it "should raise an error if API key is not passed as an option or set on module" do
@@ -43,4 +36,18 @@ describe Lob do
43
36
  Lob.protocol.must_equal "https"
44
37
  Lob.api_host.must_equal "api.lob.com"
45
38
  end
39
+
40
+ it "should work with Lob.load" do
41
+ Lob.load(api_key: "test").options[:api_key].must_equal "test"
42
+
43
+ Lob.api_key = "test"
44
+ Lob.load.wont_be_nil
45
+
46
+ Lob.api_key = nil # make sure API key is nil
47
+ ->{ Lob.load }.must_raise(ArgumentError)
48
+
49
+ ->{Lob.load(api_key: "test", api_version: "test")}.must_raise(Lob::VersionInvalidError)
50
+
51
+ Lob.load(api_key: "test", api_version: "v1").must_be_kind_of(Lob::V1::Resource)
52
+ end
46
53
  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.3.1
4
+ version: '1.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-24 00:00:00.000000000 Z
11
+ date: 2014-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -152,6 +152,7 @@ files:
152
152
  - lib/lob.rb
153
153
  - lib/lob/lob_error.rb
154
154
  - lib/lob/v1/address.rb
155
+ - lib/lob/v1/area.rb
155
156
  - lib/lob/v1/bank_account.rb
156
157
  - lib/lob/v1/check.rb
157
158
  - lib/lob/v1/country.rb
@@ -160,10 +161,12 @@ files:
160
161
  - lib/lob/v1/packaging.rb
161
162
  - lib/lob/v1/postcard.rb
162
163
  - lib/lob/v1/resource.rb
164
+ - lib/lob/v1/route.rb
163
165
  - lib/lob/v1/service.rb
164
166
  - lib/lob/v1/setting.rb
165
167
  - lob.gemspec
166
168
  - spec/lob/v1/address_spec.rb
169
+ - spec/lob/v1/area_spec.rb
167
170
  - spec/lob/v1/bank_account_spec.rb
168
171
  - spec/lob/v1/check_spec.rb
169
172
  - spec/lob/v1/country_spec.rb
@@ -172,6 +175,7 @@ files:
172
175
  - spec/lob/v1/packaging_spec.rb
173
176
  - spec/lob/v1/postcard_spec.rb
174
177
  - spec/lob/v1/resource_spec.rb
178
+ - spec/lob/v1/route_spec.rb
175
179
  - spec/lob/v1/service_spec.rb
176
180
  - spec/lob/v1/setting_spec.rb
177
181
  - spec/lob_spec.rb
@@ -202,6 +206,7 @@ specification_version: 4
202
206
  summary: Ruby wrapper for Lob.com API with ActiveRecord-style syntax
203
207
  test_files:
204
208
  - spec/lob/v1/address_spec.rb
209
+ - spec/lob/v1/area_spec.rb
205
210
  - spec/lob/v1/bank_account_spec.rb
206
211
  - spec/lob/v1/check_spec.rb
207
212
  - spec/lob/v1/country_spec.rb
@@ -210,6 +215,7 @@ test_files:
210
215
  - spec/lob/v1/packaging_spec.rb
211
216
  - spec/lob/v1/postcard_spec.rb
212
217
  - spec/lob/v1/resource_spec.rb
218
+ - spec/lob/v1/route_spec.rb
213
219
  - spec/lob/v1/service_spec.rb
214
220
  - spec/lob/v1/setting_spec.rb
215
221
  - spec/lob_spec.rb