lob 1.2 → 1.3.1

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: bc23512932804b6f7ab2f1e15f2db402fbd51517
4
- data.tar.gz: da3019d42bf5dd557c1fa4369a217fe13792c652
3
+ metadata.gz: 28b1bd25b6896a7a20910ff62e4aecb86cc73877
4
+ data.tar.gz: 6e52736c7c0b7f380bb841d659d3c9372137ef07
5
5
  SHA512:
6
- metadata.gz: 9a2f560d31987b814e11b8e2baa0e592b698547601fe18f723852eca913f8db7b93682f9a309bc482ed2cbe1823c3e4500b700ba8cb4ebce77f48b099126c756
7
- data.tar.gz: 7541054ab21ad31ee44d03baa99f55812023b549d46c5691f9cdc568ce99f0dd724fa0c371cf3ddbe07a6e0894fbab611c573fef82c82c69d6e055d7c3d4cda5
6
+ metadata.gz: e4243be1598476f54d6eda19a384a66da23b258e702d9c39dbb3f164038eda1de726ce195916b1308767385c3a4dd497cf6137af8b594f5b398d223bd6c9eea8
7
+ data.tar.gz: 17e5b1d1118920e1026dac87382c610f5e0ef602bc8412bfda38cdf4b91fcbb9b667f0fd88bc2dfa95b8c95bbb65a6ebe0d50d0dfc26d86098a535353ee21957
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # lob-ruby
2
2
 
3
- [![Build Status](https://travis-ci.org/lob/lob-ruby.png?branch=master)](https://travis-ci.org/lob/lob-ruby)
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)
4
6
 
5
7
  Ruby wrapper for the [Lob.com](http://lob.com) API. This gem gives you an ActiveRecord-style syntax to use the Lob.com API.
6
8
 
@@ -41,7 +43,7 @@ The Ruby interpreter assumes it's not of base-10 and tries to convert it to base
41
43
 
42
44
 
43
45
  # Alternatively, to set the API key for all calls in the future
44
- Lob.api_key = "you-api-key"
46
+ Lob.api_key = "your-api-key"
45
47
  @lob = Lob() # don't forget the paranthesis!
46
48
  ```
47
49
 
@@ -125,6 +127,38 @@ end
125
127
  #### Create jobs
126
128
 
127
129
  ```ruby
130
+
131
+ # Below is an example with inline addresses and object creation
132
+
133
+ @lob.jobs.create(
134
+ name: "Inline Test Job",
135
+ from: {
136
+ name: "Test Address",
137
+ email: "test@test.com",
138
+ address_line1: "123 Test Street",
139
+ address_line2: "Unit 199",
140
+ city: "Mountain View",
141
+ state: "CA",
142
+ country: "US",
143
+ zip: 94085
144
+ },
145
+ to: {
146
+ name: "TestAddress",
147
+ email: "test@test.com",
148
+ address_line1: "123 Test Street",
149
+ address_line2: "Unit 199",
150
+ city: "Mountain View",
151
+ state: "CA",
152
+ country: "US",
153
+ zip: 94085
154
+ },
155
+ objects: {
156
+ name: "Local File Object",
157
+ file: File.new(File.expand_path("<<YOUR PATH>>/letter.pdf", __FILE__)),
158
+ setting_id: 100
159
+ })
160
+
161
+
128
162
  # name, to-address and object are the arguments
129
163
  # to-address can be specified as an address-id
130
164
  @lob.jobs.create(
@@ -134,7 +168,7 @@ end
134
168
  objects: "object-id"
135
169
  )
136
170
 
137
- # to-address can also be specified as address params to create new address
171
+ # mixing inline objects with ids
138
172
  @lob.jobs.create(
139
173
  name: "New Cool Posters",
140
174
  from: {
@@ -145,14 +179,7 @@ end
145
179
  country: "US",
146
180
  zip: 12345
147
181
  },
148
- to: {
149
- name: "ToAddress",
150
- address_line1: "120, 6th Ave",
151
- city: "Boston",
152
- state: "MA",
153
- country: "US",
154
- zip: 12345
155
- },
182
+ to: "to-address-id",
156
183
  objects: "object-id"
157
184
  )
158
185
 
@@ -170,7 +197,7 @@ end
170
197
  }
171
198
  )
172
199
 
173
- # Or add a job with multiple objects
200
+ # Multi Object Jobs (include more than 1 file)
174
201
 
175
202
  @lob.jobs.create(
176
203
  name: "New Cool Posters",
@@ -186,6 +213,8 @@ end
186
213
  objects: ["object-id", "another-object-id"]
187
214
  )
188
215
 
216
+
217
+
189
218
  ```
190
219
 
191
220
  #### List jobs
@@ -210,11 +239,11 @@ end
210
239
  #### Create objects
211
240
 
212
241
  ```ruby
213
- # You can create by passing the name, file url and setting ID
242
+ # You can create an onject by passing the name, file url and setting ID, quantity is defaulted to 1
214
243
  @lob.objects.create(
215
244
  name: "Your fantistic object",
216
- file: "http://test.com/file.pdf",
217
- setting_id: "some-setting-id"
245
+ file: "https://www.lob.com/test.pdf",
246
+ setting_id: "201"
218
247
  )
219
248
 
220
249
  # You can also pass the quantity as an option
@@ -262,20 +291,38 @@ end
262
291
 
263
292
  ### Postcards
264
293
 
265
- #### Creating post cards
294
+ #### Creating postcards
266
295
 
267
296
  You'll have to specify either the `message` option or the `back` option.
268
297
 
269
298
  ```ruby
270
- # accepts the name, address-id to send to and options
299
+
300
+
301
+ # create postcard with complete customization
271
302
  @lob.postcards.create(
272
303
  name: "John Joe",
273
- to: "to-address-id",
274
- message: "Hey buddy. Waiting to hear your stories",
275
- front: File.new("/path/to/file.pdf")
304
+ to: {
305
+ name: "ToAddress",
306
+ address_line1: "120, 6th Ave",
307
+ city: "Boston",
308
+ state: "MA",
309
+ country: "US",
310
+ zip: 12345
311
+ },
312
+ from: {
313
+ name: "FromAddress",
314
+ address_line1: "120, 6th Ave",
315
+ city: "Boston",
316
+ state: "MA",
317
+ country: "US",
318
+ zip: 12345
319
+ }
320
+ front: "https://www.lob.com/postcardback.pdf",
321
+ back: File.new("/path/to/file.pdf")
276
322
  )
277
323
 
278
- # create using address params, front, back and from address
324
+ # create postcard with templated back
325
+
279
326
  @lob.postcards.create(
280
327
  name: "John Joe",
281
328
  to: {
@@ -286,9 +333,6 @@ You'll have to specify either the `message` option or the `back` option.
286
333
  country: "US",
287
334
  zip: 12345
288
335
  },
289
- message: "Hey buddy. Waiting to hear your stories",
290
- front: "https://www.lob.com/postcardback.pdf",
291
- back: File.new("/path/to/file.pdf"),
292
336
  from: {
293
337
  name: "FromAddress",
294
338
  address_line1: "120, 6th Ave",
@@ -297,6 +341,16 @@ You'll have to specify either the `message` option or the `back` option.
297
341
  country: "US",
298
342
  zip: 12345
299
343
  }
344
+ front: "https://www.lob.com/postcardback.pdf",
345
+ message: "Hey Buddy, Thanks for Visiting"
346
+ )
347
+
348
+ # sending a new postcard with stored address id
349
+ @lob.postcards.create(
350
+ name: "John Joe",
351
+ to: "to-address-id",
352
+ message: "Hey buddy. Waiting to hear your stories",
353
+ front: File.new("/path/to/file.pdf")
300
354
  )
301
355
  ```
302
356
 
@@ -427,8 +481,9 @@ You can also configure, TravisCI for your fork of the repository and it'll run t
427
481
  2. Create your feature branch (`git checkout -b my-new-feature`)
428
482
  3. Commit your changes (`git commit -am 'Add some feature'`)
429
483
  4. Push to the branch (`git push origin my-new-feature`)
430
- 5. Make sure the tests pass and add tests if required
431
- 6. Create new Pull Request
484
+ 5. Make sure the tests pass
485
+ 6. Open up coverage/index.html in your browser and add tests if required
486
+ 7. Create new Pull Request
432
487
 
433
488
  ## Credits
434
489
 
data/lib/lob.rb CHANGED
@@ -41,10 +41,10 @@ module Lob
41
41
  def self.submit(method, url, parameters={})
42
42
  parameters = {:params => parameters} if method == :get
43
43
  JSON(RestClient.send(method, url, parameters))
44
+ # :nocov:
44
45
  rescue => e
45
- error_message = nil
46
- raise e unless e.respond_to? :http_body
47
46
  begin
47
+ # Parse the error to raise a nice Lob::Error
48
48
  json = JSON(e.http_body)
49
49
 
50
50
  if json.has_key? 'errors'
@@ -54,10 +54,13 @@ module Lob
54
54
  else
55
55
  error_message = "Unknown error: #{json}"
56
56
  end
57
- rescue => e
57
+
58
+ raise Lob::Error.new(error_message)
59
+ rescue
60
+ # If error parsing failed re-raise the original error
58
61
  raise e
59
62
  end
60
- raise Lob::Error.new(error_message)
63
+ # :nocov:
61
64
  end
62
65
 
63
66
  end
@@ -44,10 +44,6 @@ module Lob
44
44
  Lob::V1::Check.new(self)
45
45
  end
46
46
 
47
- def cheques
48
- Lob::V1::Check.new(self)
49
- end
50
-
51
47
  def bank_accounts
52
48
  Lob::V1::BankAccount.new(self)
53
49
  end
data/lob.gemspec CHANGED
@@ -5,9 +5,9 @@ $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.2"
9
- spec.authors = ["Akash Manohar J"]
10
- spec.email = ["akash@akash.im"]
8
+ spec.version = "1.3.1"
9
+ spec.authors = ["Lob"]
10
+ spec.email = ["support@lob.com"]
11
11
  spec.description = %q{Lob API Ruby wrapper}
12
12
  spec.summary = %q{Ruby wrapper for Lob.com API with ActiveRecord-style syntax}
13
13
  spec.homepage = "https://github.com/lob/lob-ruby"
@@ -21,8 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency "rest-client", ">= 0"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "webmock", '~> 1.2'
26
- spec.add_development_dependency "travis-lint"
27
- spec.add_development_dependency "vcr"
24
+ spec.add_development_dependency "rake", "~> 10.3.2"
25
+ spec.add_development_dependency "webmock", "~> 1.2"
26
+ spec.add_development_dependency "travis-lint", "~> 2.0.0"
27
+ spec.add_development_dependency "vcr", "~> 2.9.2"
28
+ spec.add_development_dependency "coveralls", "~> 0.7.0"
29
+ spec.add_development_dependency "simplecov", "~> 0.7.1"
30
+ spec.add_development_dependency "pry", "~> 0.10.0"
28
31
  end
@@ -1,17 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lob::V1::Address do
4
- let(:sample_params2) {
5
- {
6
- name: "Russell Smith",
7
- email: "test@test.com",
8
- address_line1: "673 Brannan",
9
- city: "San Francisco",
10
- state: "CA",
11
- country: "US",
12
- zip: 94107
13
- }
14
- }
15
4
 
16
5
  let(:sample_params) {
17
6
  {
@@ -28,20 +17,6 @@ describe Lob::V1::Address do
28
17
  subject { Lob(api_key: ENV["LOB_API_KEY"], api_version: "v1") }
29
18
 
30
19
  describe "verify" do
31
- it "should verify an address" do
32
- assert_raises(Lob::Error) do
33
- VCR.use_cassette('verify_address2') do
34
- result = subject.addresses.verify(
35
- address_line1: sample_params2[:address_line1],
36
- city: sample_params2[:city],
37
- state: sample_params2[:state],
38
- zip: sample_params2[:zip]
39
- )
40
-
41
- result["address"]["address_country"].must_equal("United States")
42
- end
43
- end
44
- end
45
20
 
46
21
  it "should verify an address" do
47
22
  VCR.use_cassette('verify_address') do
@@ -52,7 +27,7 @@ describe Lob::V1::Address do
52
27
  zip: sample_params[:zip]
53
28
  )
54
29
 
55
- result["address"]["address_country"].must_equal("United States")
30
+ result["address"]["address_country"].must_equal("US")
56
31
  end
57
32
  end
58
33
  end
@@ -98,7 +73,7 @@ describe Lob::V1::Address do
98
73
  new_address = subject.addresses.create sample_params
99
74
 
100
75
  delete_result = subject.addresses.destroy(new_address["id"])
101
- assert /has been deleted/ =~ delete_result["message"]
76
+ assert_equal(new_address["id"], delete_result["id"])
102
77
  end
103
78
  end
104
79
  end
@@ -198,7 +198,7 @@ describe Lob::V1::Job do
198
198
  objects: new_object["id"]
199
199
  )
200
200
 
201
- result = subject.jobs.find(new_job["id"])
201
+ result = subject.jobs.find(new_job["id"])
202
202
  result["name"].must_equal(@sample_job_params[:name])
203
203
  end
204
204
  end
@@ -86,7 +86,7 @@ describe Lob::V1::Object do
86
86
  )
87
87
 
88
88
  delete_result = subject.objects.destroy(new_object["id"])
89
- assert /has been deleted/ =~ delete_result["message"]
89
+ assert_equal(new_object["id"], delete_result["id"])
90
90
  end
91
91
  end
92
92
  end
@@ -14,7 +14,7 @@ describe Lob::V1::Postcard do
14
14
  zip: 94085
15
15
  }
16
16
 
17
- @sample_postcard_params = {
17
+ @sample_postcard_params = {
18
18
  name: "TestPostcard",
19
19
  message: "Sample postcard message"
20
20
  }
@@ -57,10 +57,8 @@ describe Lob::V1::Postcard do
57
57
  end
58
58
  end
59
59
 
60
-
61
- it "should create a postcard with address params" do
62
- VCR.use_cassette('create_postcard_with_address_params') do
63
-
60
+ it "should create a postcard with to address params" do
61
+ VCR.use_cassette('create_postcard_with_to_address_params') do
64
62
  result = subject.postcards.create(
65
63
  name: @sample_postcard_params[:name],
66
64
  to: @sample_address_params,
@@ -72,6 +70,21 @@ describe Lob::V1::Postcard do
72
70
  end
73
71
  end
74
72
 
73
+ it "should create a postcard with from address params" do
74
+ VCR.use_cassette('create_postcard_with_from_address_params') do
75
+ new_address = subject.addresses.create @sample_address_params
76
+
77
+ result = subject.postcards.create(
78
+ name: @sample_postcard_params[:name],
79
+ to: new_address["id"],
80
+ from: @sample_address_params,
81
+ message: @sample_postcard_params[:message],
82
+ front: "https://www.lob.com/postcardfront.pdf"
83
+ )
84
+
85
+ result["name"].must_equal(@sample_postcard_params[:name])
86
+ end
87
+ end
75
88
 
76
89
  it "should create a postcard with front and back as urls" do
77
90
  VCR.use_cassette('create_postcard_with_front_and_back_urls') do
data/spec/lob_spec.rb CHANGED
@@ -11,9 +11,7 @@ module Lob
11
11
  end
12
12
  end
13
13
 
14
-
15
14
  describe Lob do
16
-
17
15
  it "should return the resource object for the specified version" do
18
16
  Lob(api_key: "test", api_version: "test").must_be_kind_of(Lob::Test::Resource)
19
17
  end
@@ -31,4 +29,18 @@ describe Lob do
31
29
  it "should pass the API key to the resource for the version" do
32
30
  Lob(api_key: "test").options[:api_key].must_equal "test"
33
31
  end
32
+
33
+ it "should allow detailed configuration" do
34
+ Lob.configure do |config|
35
+ config.api_key = "test"
36
+ config.api_version = "v1"
37
+ config.protocol = "https"
38
+ config.api_host = "api.lob.com"
39
+ end
40
+
41
+ Lob.api_key.must_equal "test"
42
+ Lob.api_version.must_equal "v1"
43
+ Lob.protocol.must_equal "https"
44
+ Lob.api_host.must_equal "api.lob.com"
45
+ end
34
46
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,14 @@
1
1
  $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
2
 
3
+ require "simplecov"
4
+ require "coveralls"
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ SimpleCov.start
11
+
3
12
  require "lob"
4
13
  require "minitest/spec"
5
14
  require "minitest/pride"
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.2'
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
- - Akash Manohar J
7
+ - Lob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-14 00:00:00.000000000 Z
11
+ date: 2014-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 10.3.2
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 10.3.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: webmock
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,33 +70,75 @@ dependencies:
70
70
  name: travis-lint
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 2.0.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 2.0.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: vcr
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 2.9.2
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 2.9.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.7.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.7.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.7.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: 0.7.1
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.10.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 0.10.0
97
139
  description: Lob API Ruby wrapper
98
140
  email:
99
- - akash@akash.im
141
+ - support@lob.com
100
142
  executables: []
101
143
  extensions: []
102
144
  extra_rdoc_files: []
@@ -154,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
196
  version: '0'
155
197
  requirements: []
156
198
  rubyforge_project:
157
- rubygems_version: 2.0.2
199
+ rubygems_version: 2.3.0
158
200
  signing_key:
159
201
  specification_version: 4
160
202
  summary: Ruby wrapper for Lob.com API with ActiveRecord-style syntax