lob 1.9.1 → 2.5.0
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 +4 -4
- data/.gitignore +0 -2
- data/.travis.yml +3 -6
- data/CHANGELOG.md +46 -0
- data/README.md +125 -596
- data/Rakefile +0 -19
- data/examples/README.md +27 -0
- data/examples/checks.rb +22 -23
- data/examples/csv_postcards/create_postcards.rb +46 -0
- data/examples/csv_postcards/input.csv +7 -0
- data/examples/csv_postcards/postcard_back.html +38 -0
- data/examples/csv_postcards/postcard_front.html +25 -0
- data/examples/jobs.rb +65 -21
- data/examples/letters.rb +73 -0
- data/examples/postcards.rb +64 -12
- data/examples/verify/input.txt +7 -0
- data/examples/verify/verify.rb +38 -0
- data/lib/lob/errors/lob_error.rb +9 -6
- data/lib/lob/v1/address.rb +3 -4
- data/lib/lob/v1/area.rb +1 -1
- data/lib/lob/v1/bank_account.rb +5 -9
- data/lib/lob/v1/check.rb +1 -5
- data/lib/lob/v1/country.rb +1 -1
- data/lib/lob/v1/job.rb +1 -9
- data/lib/lob/v1/letter.rb +29 -0
- data/lib/lob/v1/object.rb +1 -1
- data/lib/lob/v1/postcard.rb +1 -9
- data/lib/lob/v1/resource.rb +4 -24
- data/lib/lob/v1/route.rb +9 -1
- data/lib/lob/v1/setting.rb +1 -1
- data/lib/lob/v1/state.rb +1 -1
- data/lib/lob/version.rb +1 -1
- data/lib/lob.rb +37 -16
- data/lob.gemspec +5 -7
- data/spec/lob/errors/lob_error_spec.rb +4 -2
- data/spec/lob/v1/address_spec.rb +24 -34
- data/spec/lob/v1/area_spec.rb +16 -38
- data/spec/lob/v1/bank_account_spec.rb +25 -79
- data/spec/lob/v1/check_spec.rb +38 -65
- data/spec/lob/v1/country_spec.rb +2 -4
- data/spec/lob/v1/job_spec.rb +116 -162
- data/spec/lob/v1/letter_spec.rb +75 -0
- data/spec/lob/v1/object_spec.rb +32 -50
- data/spec/lob/v1/postcard_spec.rb +66 -90
- data/spec/lob/v1/resource_spec.rb +0 -9
- data/spec/lob/v1/route_spec.rb +28 -6
- data/spec/lob/v1/setting_spec.rb +4 -12
- data/spec/lob/v1/state_spec.rb +2 -4
- data/spec/lob_spec.rb +25 -6
- data/spec/samples/8.5x11.pdf +0 -0
- data/spec/samples/postcardback.pdf +2288 -1
- data/spec/samples/postcardfront.pdf +1550 -0
- data/spec/spec_helper.rb +0 -6
- metadata +58 -62
- data/examples/create_pdf.rb +0 -25
- data/lib/lob/v1/packaging.rb +0 -21
- data/lib/lob/v1/service.rb +0 -21
- data/spec/lob/v1/packaging_spec.rb +0 -16
- data/spec/lob/v1/service_spec.rb +0 -16
data/README.md
CHANGED
|
@@ -1,25 +1,43 @@
|
|
|
1
1
|
# lob-ruby
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.org/lob/lob-ruby)
|
|
4
|
+
[](http://badge.fury.io/rb/lob)
|
|
5
|
+
[](https://gemnasium.com/lob/lob-ruby)
|
|
6
|
+
[](https://coveralls.io/r/lob/lob-ruby?branch=master)
|
|
7
|
+
[](https://rubygems.org/gems/lob)
|
|
4
8
|
|
|
5
|
-
[
|
|
6
|
-
|
|
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.
|
|
9
|
+
Ruby wrapper for the [Lob.com](http://lob.com) API. See the full Lob.com [API Documentation](https://lob.com/docs/ruby). For best results, be sure that you're using [the latest version](https://lob.com/docs/ruby#version) of the Lob API and the latest version of the ruby wrapper. This gem gives you an ActiveRecord-style syntax to use the Lob.com API.
|
|
8
10
|
|
|
9
11
|
Supports Ruby 1.9.3 and greater.
|
|
10
12
|
|
|
11
13
|
## Table of Contents
|
|
12
14
|
|
|
13
|
-
- [
|
|
14
|
-
- [
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [Testing](#testing)
|
|
15
|
+
- [Getting Started](#getting-started)
|
|
16
|
+
- [Registration](#registration)
|
|
17
|
+
- [Installation](#installation)
|
|
18
|
+
- [Usage](#usage)
|
|
19
|
+
- [Examples](#examples)
|
|
20
|
+
- [API Documentation](#api-documentation)
|
|
20
21
|
- [Contributing](#contributing)
|
|
22
|
+
- [Testing](#testing)
|
|
23
|
+
|
|
24
|
+
## Getting Started
|
|
25
|
+
|
|
26
|
+
Here's a general overview of the Lob services available, click through to read more.
|
|
27
|
+
|
|
28
|
+
- [Postcards API](https://lob.com/services/postcards)
|
|
29
|
+
- [Letters API](https://lob.com/services/letters)
|
|
30
|
+
- [Checks API](https://lob.com/services/checks)
|
|
31
|
+
- [Area Mail API](https://lob.com/services/area)
|
|
32
|
+
- [Address Verification API](https://lob.com/verification/address)
|
|
21
33
|
|
|
22
|
-
|
|
34
|
+
### Registration
|
|
35
|
+
|
|
36
|
+
First, you will need to first create an account at [Lob.com](https://dashboard.lob.com/#/register) and obtain your Test and Live API Keys.
|
|
37
|
+
|
|
38
|
+
Once you have created an account, you can access your API Keys from the [Settings Panel](https://dashboard.lob.com/#/settings).
|
|
39
|
+
|
|
40
|
+
### Installation
|
|
23
41
|
|
|
24
42
|
Add this line to your application's `Gemfile`:
|
|
25
43
|
|
|
@@ -33,40 +51,13 @@ Or manually install it yourself:
|
|
|
33
51
|
|
|
34
52
|
$ gem install lob
|
|
35
53
|
|
|
36
|
-
|
|
54
|
+
### Usage
|
|
37
55
|
|
|
38
56
|
The library uses an ActiveRecord-style interface. You'll feel right at home.
|
|
39
|
-
You'll need a Lob.com API key. It's free and you can get yours [here](https://dashboard.lob.com/settings).
|
|
40
57
|
|
|
41
58
|
For optional parameters and other details, refer to the docs [here](https://lob.com/docs/ruby).
|
|
42
59
|
|
|
43
|
-
####
|
|
44
|
-
|
|
45
|
-
When using zip codes with zero-prefixes, always quote them. For example when specifying `02125`, pass it as a string `"02125"`, instead of an integer.
|
|
46
|
-
|
|
47
|
-
The Ruby interpreter assumes it's not of base-10 and tries to convert it to base-10 number. So that might result in an entirely different zip-code than intended.
|
|
48
|
-
|
|
49
|
-
## Supported Image Types
|
|
50
|
-
|
|
51
|
-
The Lob.com API supports the following image types:
|
|
52
|
-
|
|
53
|
-
- PDF
|
|
54
|
-
- PNG
|
|
55
|
-
- JPEG
|
|
56
|
-
|
|
57
|
-
For more information on prepping images please see the [Lob documentation](https://lob.com/docs/ruby#prepping).
|
|
58
|
-
|
|
59
|
-
#### Creating a PDF
|
|
60
|
-
|
|
61
|
-
If you need to generate your own PDF programmatically we recommend using [prawn](https://github.com/prawnpdf/prawn). There is an example provided in the examples folder [here](examples/create_pdf.rb).
|
|
62
|
-
|
|
63
|
-
## HTML Support
|
|
64
|
-
|
|
65
|
-
The Lob.com API also supports HTML strings in leiu of a file of the above type. See below for examples of submitting with HTML strings.
|
|
66
|
-
|
|
67
|
-
For templates and more information regarding HTML, please see the [Lob documentation](https://lob.com/docs/ruby#html-fonts).
|
|
68
|
-
|
|
69
|
-
## Initialization and Configuration
|
|
60
|
+
#### Initialization and Configuration
|
|
70
61
|
|
|
71
62
|
```ruby
|
|
72
63
|
# To initialize a Lob object
|
|
@@ -86,555 +77,103 @@ Lob.configure do |config|
|
|
|
86
77
|
end
|
|
87
78
|
```
|
|
88
79
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
- [Simple Print Service](#simple-print-service)
|
|
92
|
-
- [lob.jobs](#lobjobs)
|
|
93
|
-
- [lob.jobs.create](#lobjobscreate)
|
|
94
|
-
- [lob.jobs.list](#lobjobslist)
|
|
95
|
-
- [lob.jobs.find](#lobjobsfind)
|
|
96
|
-
- [lob.addresses](#lobaddresses)
|
|
97
|
-
- [lob.addresses.create](#lobaddressescreate)
|
|
98
|
-
- [lob.addresses.list](#lobaddresseslist)
|
|
99
|
-
- [lob.addresses.find](#lobaddressesfind)
|
|
100
|
-
- [lob.addresses.destroy](#lobaddressesdestroy)
|
|
101
|
-
- [lob.addresses.verify](#lobaddressesverify)
|
|
102
|
-
- [lob.objects](#lobobjects)
|
|
103
|
-
- [lob.objects.create](#lobobjectscreate)
|
|
104
|
-
- [lob.objects.list](#lobobjectslist)
|
|
105
|
-
- [lob.objects.find](#lobobjectsfind)
|
|
106
|
-
- [lob.objects.destroy](#lobobjectsdestroy)
|
|
107
|
-
- [lob.settings](#lobsettings)
|
|
108
|
-
- [lob.settings.list](#lobsettingslist)
|
|
109
|
-
- [lob.settings.find](#lobsettingsfind)
|
|
110
|
-
- [lob.services](#lobservices)
|
|
111
|
-
- [lob.services.list](#lobserviceslist)
|
|
112
|
-
- [Simple Postcard Service](#simple-postcard-service)
|
|
113
|
-
- [lob.postcards](#lobpostcards)
|
|
114
|
-
- [lob.postcards.create](#lobpostcardscreate)
|
|
115
|
-
- [lob.postcards.list](#lobpostcardslist)
|
|
116
|
-
- [lob.postcards.find](#lobpostcardsfind)
|
|
117
|
-
- [Simple Check Service](#simple-check-service)
|
|
118
|
-
- [lob.checks](#lobchecks)
|
|
119
|
-
- [lob.checks.create](#lobcheckscreate)
|
|
120
|
-
- [lob.checks.list](#lobcheckslist)
|
|
121
|
-
- [lob.checks.find](#lobchecksfind)
|
|
122
|
-
- [lob.bank_accounts](#lobbank_accounts)
|
|
123
|
-
- [lob.bank_accounts.create](#lobbank_accountscreate)
|
|
124
|
-
- [lob.bank_accounts.list](#lobbank_accountslist)
|
|
125
|
-
- [lob.bank_accounts.find](#lobbank_accountsfind)
|
|
126
|
-
- [Simple Area Mail](#simple-area-mail)
|
|
127
|
-
- [lob.areas](#lobareas)
|
|
128
|
-
- [lob.areas.create](#lobareascreate)
|
|
129
|
-
- [lob.areas.list](#lobareaslist)
|
|
130
|
-
- [lob.areas.find](#lobareasfind)
|
|
131
|
-
- [lob.routes](#lobroutes)
|
|
132
|
-
- [lob.routes.find](#lobroutesfind)
|
|
133
|
-
- [Resources](#lobresources)
|
|
134
|
-
- [lob.countries](#lobcountries)
|
|
135
|
-
- [lob.countries.list](#lobcountrieslist)
|
|
136
|
-
- [lob.states](#lobstates)
|
|
137
|
-
- [lob.states.list](#lobstateslist)
|
|
138
|
-
|
|
139
|
-
## Simple Print Service
|
|
140
|
-
|
|
141
|
-
### lob.jobs
|
|
142
|
-
|
|
143
|
-
#### lob.jobs.create
|
|
144
|
-
|
|
145
|
-
```ruby
|
|
146
|
-
|
|
147
|
-
# Below is an example with inline addresses and object creation
|
|
148
|
-
|
|
149
|
-
@lob.jobs.create(
|
|
150
|
-
name: "Inline Test Job",
|
|
151
|
-
from: {
|
|
152
|
-
name: "Test Address",
|
|
153
|
-
email: "test@test.com",
|
|
154
|
-
address_line1: "123 Test Street",
|
|
155
|
-
address_line2: "Unit 199",
|
|
156
|
-
city: "Mountain View",
|
|
157
|
-
state: "CA",
|
|
158
|
-
country: "US",
|
|
159
|
-
zip: 94085
|
|
160
|
-
},
|
|
161
|
-
to: {
|
|
162
|
-
name: "TestAddress",
|
|
163
|
-
email: "test@test.com",
|
|
164
|
-
address_line1: "123 Test Street",
|
|
165
|
-
address_line2: "Unit 199",
|
|
166
|
-
city: "Mountain View",
|
|
167
|
-
state: "CA",
|
|
168
|
-
country: "US",
|
|
169
|
-
zip: 94085
|
|
170
|
-
},
|
|
171
|
-
objects: {
|
|
172
|
-
name: "Local File Object",
|
|
173
|
-
file: File.new("/path/to/file.pdf"),
|
|
174
|
-
setting: 100
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
# name, to-address and object are the arguments
|
|
179
|
-
# to-address can be specified as an address-id
|
|
180
|
-
@lob.jobs.create(
|
|
181
|
-
name: "New Cool Posters",
|
|
182
|
-
from: "from-address-id",
|
|
183
|
-
to: "to-address-id",
|
|
184
|
-
objects: "object-id"
|
|
185
|
-
)
|
|
186
|
-
|
|
187
|
-
# mixing inline objects with ids
|
|
188
|
-
@lob.jobs.create(
|
|
189
|
-
name: "New Cool Posters",
|
|
190
|
-
from: {
|
|
191
|
-
name: "FromAddress",
|
|
192
|
-
address_line1: "120, 6th Ave",
|
|
193
|
-
city: "Boston",
|
|
194
|
-
state: "MA",
|
|
195
|
-
country: "US",
|
|
196
|
-
zip: 12345
|
|
197
|
-
},
|
|
198
|
-
to: "to-address-id",
|
|
199
|
-
objects: "object-id"
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
# You can also pass new object params for the object
|
|
203
|
-
# and other options like setting
|
|
204
|
-
@lob.jobs.create(
|
|
205
|
-
name: "New Cool Posters",
|
|
206
|
-
from: "from-address-id",
|
|
207
|
-
to: "to-address-id",
|
|
208
|
-
objects: "object-id",
|
|
209
|
-
{
|
|
210
|
-
name: "Your fantistic object",
|
|
211
|
-
file: "http://test.com/file.pdf",
|
|
212
|
-
setting: "some-setting"
|
|
213
|
-
}
|
|
214
|
-
)
|
|
215
|
-
|
|
216
|
-
# Multi Object Jobs (include more than 1 file)
|
|
217
|
-
|
|
218
|
-
@lob.jobs.create(
|
|
219
|
-
name: "New Cool Posters",
|
|
220
|
-
from: "from-address-id",
|
|
221
|
-
to: {
|
|
222
|
-
name: "ToAddress",
|
|
223
|
-
address_line1: "120, 6th Ave",
|
|
224
|
-
city: "Boston",
|
|
225
|
-
state: "MA",
|
|
226
|
-
country: "US",
|
|
227
|
-
zip: 12345
|
|
228
|
-
},
|
|
229
|
-
objects: ["object-id", "another-object-id"]
|
|
230
|
-
)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
#### lob.jobs.list
|
|
237
|
-
|
|
238
|
-
```ruby
|
|
239
|
-
# returns an array of jobs
|
|
240
|
-
@lob.jobs.list
|
|
241
|
-
|
|
242
|
-
#you can also pass count and offset
|
|
243
|
-
@lob.jobs.list(count: 10, offset: 3)
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
#### lob.jobs.find
|
|
247
|
-
|
|
248
|
-
```ruby
|
|
249
|
-
# returns the job with the corresponding ID
|
|
250
|
-
@lob.jobs.find("some-job-id")
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
### lob.addresses
|
|
254
|
-
|
|
255
|
-
#### lob.addresses.create
|
|
256
|
-
|
|
257
|
-
```ruby
|
|
258
|
-
# name, address, city, state, country and zip are required parameters
|
|
259
|
-
@lob.addresses.create(
|
|
260
|
-
name: "John Doe",
|
|
261
|
-
email: "test@test.com", # optional
|
|
262
|
-
address_line1: "104, Printing Boulevard",
|
|
263
|
-
address_line2: "Sunset Town", # optional
|
|
264
|
-
city: "Boston",
|
|
265
|
-
state: "MA",
|
|
266
|
-
country: "US",
|
|
267
|
-
zip: 12345
|
|
268
|
-
)
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
#### lob.addresses.list
|
|
272
|
-
|
|
273
|
-
```ruby
|
|
274
|
-
# returns an array of addresses
|
|
275
|
-
@lob.addresses.list
|
|
276
|
-
|
|
277
|
-
#you can also pass count and offset
|
|
278
|
-
@lob.addresses.list(count: 10, offset: 3)
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
#### lob.addresses.find
|
|
282
|
-
|
|
283
|
-
```ruby
|
|
284
|
-
# returns the address with the corresponding ID
|
|
285
|
-
@lob.addresses.find("some-address-id")
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
#### lob.addresses.destroy
|
|
289
|
-
|
|
290
|
-
```ruby
|
|
291
|
-
# deletes the address with the corresponding ID
|
|
292
|
-
@lob.addresses.destroy("some-address-id")
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
#### lob.addresses.verify
|
|
296
|
-
|
|
297
|
-
```ruby
|
|
298
|
-
# verifies and returns an address with more details
|
|
299
|
-
@lob.addresses.verify(
|
|
300
|
-
address_line1: "220 WILLIAM T MORRISSEY BLVD",
|
|
301
|
-
city: "Boston",
|
|
302
|
-
state: "MA",
|
|
303
|
-
zip: "02125"
|
|
304
|
-
)
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### lob.objects
|
|
308
|
-
|
|
309
|
-
#### lob.objects.create
|
|
310
|
-
|
|
311
|
-
```ruby
|
|
312
|
-
# You can create an object by passing the name, file url and setting ID, quantity is defaulted to 1
|
|
313
|
-
@lob.objects.create(
|
|
314
|
-
name: "Your fantastic object",
|
|
315
|
-
file: "https://s3-us-west-2.amazonaws.com/lob-assets/test.pdf",
|
|
316
|
-
setting: "201"
|
|
317
|
-
)
|
|
318
|
-
|
|
319
|
-
# You can also pass the quantity as an option
|
|
320
|
-
# Or pass a file for upload instead of a url
|
|
321
|
-
@lob.objects.create(
|
|
322
|
-
name: "Your fantastic object",
|
|
323
|
-
file: File.new("/path/to/file.pdf"),
|
|
324
|
-
setting: "some-setting",
|
|
325
|
-
quantity: 12
|
|
326
|
-
)
|
|
327
|
-
|
|
328
|
-
# You can also pass an HTML string instead of a file
|
|
329
|
-
@lob.objects.create(
|
|
330
|
-
name: "Your fantastic object",
|
|
331
|
-
file: "<html style='margin: 130px; font-size: 50;'>HTML here</html>",
|
|
332
|
-
setting: "some-setting"
|
|
333
|
-
)
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
#### lob.objects.list
|
|
337
|
-
|
|
338
|
-
```ruby
|
|
339
|
-
# returns an array of objects
|
|
340
|
-
@lob.objects.list
|
|
341
|
-
|
|
342
|
-
#you can also pass count and offset
|
|
343
|
-
@lob.objects.list(count: 10, offset: 3)
|
|
344
|
-
```
|
|
345
|
-
|
|
346
|
-
#### lob.objects.find
|
|
347
|
-
|
|
348
|
-
```ruby
|
|
349
|
-
# returns the object with the corresponding ID
|
|
350
|
-
@lob.objects.find("some-object-id")
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
#### lob.objects.destroy
|
|
354
|
-
|
|
355
|
-
```ruby
|
|
356
|
-
# deletes the object with the corresponding ID
|
|
357
|
-
@lob.objects.destroy("some-object-id")
|
|
358
|
-
```
|
|
359
|
-
|
|
360
|
-
### lob.settings
|
|
361
|
-
|
|
362
|
-
#### lob.settings.list
|
|
363
|
-
```ruby
|
|
364
|
-
# returns an array of settings
|
|
365
|
-
@lob.settings.list
|
|
366
|
-
```
|
|
367
|
-
|
|
368
|
-
#### lob.settings.find
|
|
369
|
-
```ruby
|
|
370
|
-
# returns a setting object
|
|
371
|
-
@lob.settings.find("setting")
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
### lob.services
|
|
375
|
-
|
|
376
|
-
#### lob.services.list
|
|
377
|
-
|
|
378
|
-
```ruby
|
|
379
|
-
# returns a list of services
|
|
380
|
-
@lob.services.list
|
|
381
|
-
```
|
|
382
|
-
|
|
383
|
-
## Simple Postcard Service
|
|
384
|
-
|
|
385
|
-
### lob.postcards
|
|
386
|
-
|
|
387
|
-
#### lob.postcards.create
|
|
388
|
-
|
|
389
|
-
You'll have to specify either the `message` option or the `back` option.
|
|
390
|
-
|
|
391
|
-
```ruby
|
|
392
|
-
|
|
393
|
-
# create postcard with message
|
|
394
|
-
|
|
395
|
-
@lob.postcards.create(
|
|
396
|
-
name: "John Joe",
|
|
397
|
-
to: {
|
|
398
|
-
name: "ToAddress",
|
|
399
|
-
address_line1: "120, 6th Ave",
|
|
400
|
-
city: "Boston",
|
|
401
|
-
state: "MA",
|
|
402
|
-
country: "US",
|
|
403
|
-
zip: 12345
|
|
404
|
-
},
|
|
405
|
-
from: {
|
|
406
|
-
name: "FromAddress",
|
|
407
|
-
address_line1: "120, 6th Ave",
|
|
408
|
-
city: "Boston",
|
|
409
|
-
state: "MA",
|
|
410
|
-
country: "US",
|
|
411
|
-
zip: 12345
|
|
412
|
-
},
|
|
413
|
-
front: "https://lob.com/postcardfront.pdf",
|
|
414
|
-
message: "Hey Buddy, Thanks for Visiting",
|
|
415
|
-
full_bleed: 1
|
|
416
|
-
)
|
|
417
|
-
|
|
418
|
-
# create postcard with your own back, adhering to lob's template
|
|
419
|
-
@lob.postcards.create(
|
|
420
|
-
name: "John Joe",
|
|
421
|
-
to: {
|
|
422
|
-
name: "ToAddress",
|
|
423
|
-
address_line1: "120, 6th Ave",
|
|
424
|
-
city: "Boston",
|
|
425
|
-
state: "MA",
|
|
426
|
-
country: "US",
|
|
427
|
-
zip: 12345
|
|
428
|
-
},
|
|
429
|
-
from: {
|
|
430
|
-
name: "FromAddress",
|
|
431
|
-
address_line1: "120, 6th Ave",
|
|
432
|
-
city: "Boston",
|
|
433
|
-
state: "MA",
|
|
434
|
-
country: "US",
|
|
435
|
-
zip: 12345
|
|
436
|
-
},
|
|
437
|
-
front: "https://lob.com/postcardfront.pdf",
|
|
438
|
-
back: File.new("/path/to/file.pdf"),
|
|
439
|
-
full_bleed: 1,
|
|
440
|
-
template: 1
|
|
441
|
-
)
|
|
442
|
-
|
|
443
|
-
# create postcard with HTML string & a stored address id
|
|
444
|
-
@lob.postcards.create(
|
|
445
|
-
name: "John Joe",
|
|
446
|
-
to: "to-address-id",
|
|
447
|
-
front: "<html style='margin: 130px; font-size: 50;'>HTML here</html>",
|
|
448
|
-
message: "Hey buddy. Waiting to hear your stories."
|
|
449
|
-
)
|
|
450
|
-
```
|
|
451
|
-
|
|
452
|
-
#### lob.postcards.list
|
|
453
|
-
|
|
454
|
-
```ruby
|
|
455
|
-
@lob.postcards.list
|
|
456
|
-
|
|
457
|
-
#you can also pass count and offset
|
|
458
|
-
@lob.postcards.list(count: 10, offset: 3)
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
#### lob.postcards.find
|
|
462
|
-
|
|
463
|
-
```ruby
|
|
464
|
-
@lob.postcards.find("post-card-id")
|
|
465
|
-
```
|
|
466
|
-
|
|
467
|
-
## Simple Check Service
|
|
468
|
-
|
|
469
|
-
### lob.checks
|
|
470
|
-
|
|
471
|
-
#### lob.checks.create
|
|
472
|
-
|
|
473
|
-
```ruby
|
|
474
|
-
# For the "to" address, you can pass params
|
|
475
|
-
# Transfer $5000 to a bank account.
|
|
476
|
-
@lob.checks.create(
|
|
477
|
-
bank_account: "bank-account-id",
|
|
478
|
-
to: {
|
|
479
|
-
name: "FromAddress",
|
|
480
|
-
address_line1: "120, 6th Ave",
|
|
481
|
-
city: "Boston",
|
|
482
|
-
state: "MA",
|
|
483
|
-
country: "US",
|
|
484
|
-
zip: 12345
|
|
485
|
-
},
|
|
486
|
-
amount: 5000,
|
|
487
|
-
logo: "https://s3-us-west-2.amazonaws.com/lob-assets/lob_check_logo.png" # optional
|
|
488
|
-
)
|
|
489
|
-
|
|
490
|
-
# or an address ID
|
|
491
|
-
@lob.checks.create(
|
|
492
|
-
bank_account: "bank-account-id",
|
|
493
|
-
to: "to-address-ID",
|
|
494
|
-
amount: 5000,
|
|
495
|
-
logo: "https://s3-us-west-2.amazonaws.com/lob-assets/lob_check_logo.png" # optional
|
|
496
|
-
)
|
|
497
|
-
|
|
498
|
-
# You can also specify an optional 4th argument, with other options.
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
#### lob.checks.list
|
|
502
|
-
|
|
503
|
-
```ruby
|
|
504
|
-
@lob.checks.list
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
#### lob.checks.find
|
|
508
|
-
|
|
509
|
-
```ruby
|
|
510
|
-
@lob.checks.find("check-id")
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
### lob.bank_accounts
|
|
514
|
-
|
|
515
|
-
#### lob.bank_accounts.create
|
|
516
|
-
|
|
517
|
-
```ruby
|
|
518
|
-
bank_address =
|
|
519
|
-
|
|
520
|
-
account_address =
|
|
521
|
-
|
|
522
|
-
# Pass address params or address IDs
|
|
523
|
-
# The 5th argument is the options argument and is optional
|
|
524
|
-
@lob.bank_accounts.create(
|
|
525
|
-
routing_number: "routing_number",
|
|
526
|
-
account_number: "account_number",
|
|
527
|
-
signatory: "John Doe",
|
|
528
|
-
bank_address: {
|
|
529
|
-
name: "ToAddress",
|
|
530
|
-
address_line1: "120 6th Ave",
|
|
531
|
-
city: "Boston",
|
|
532
|
-
country: "US",
|
|
533
|
-
zip: 12345
|
|
534
|
-
},
|
|
535
|
-
account_address: {
|
|
536
|
-
name: "ToAddress",
|
|
537
|
-
address_line1: "120 6th Ave",
|
|
538
|
-
city: "Boston",
|
|
539
|
-
country: "US",
|
|
540
|
-
zip: 12345
|
|
541
|
-
}
|
|
542
|
-
)
|
|
543
|
-
```
|
|
544
|
-
|
|
545
|
-
#### lob.bank_accounts.list
|
|
546
|
-
|
|
547
|
-
```ruby
|
|
548
|
-
# returns a list of accounts
|
|
549
|
-
@lob.bank_accounts.list
|
|
550
|
-
```
|
|
551
|
-
|
|
552
|
-
#### lob.bank_accounts.find
|
|
553
|
-
|
|
554
|
-
```ruby
|
|
555
|
-
@lob.bank_accounts.find("bank-account-id")
|
|
556
|
-
```
|
|
557
|
-
|
|
558
|
-
## Simple Area Mail
|
|
559
|
-
|
|
560
|
-
### lob.areas
|
|
561
|
-
|
|
562
|
-
#### lob.areas.create
|
|
563
|
-
|
|
564
|
-
You'll have to specify front, back, and either zip_codes or routes
|
|
80
|
+
#### Caution: Pass zero-prefixed zip codes as strings
|
|
565
81
|
|
|
566
|
-
|
|
567
|
-
# create an area request with remote files & with routes
|
|
568
|
-
@lob.areas.create(
|
|
569
|
-
name: "My Area",
|
|
570
|
-
front: "https://s3-us-west-2.amazonaws.com/lob-assets/areafront.pdf",
|
|
571
|
-
back: "https://s3-us-west-2.amazonaws.com/lob-assets/areaback.pdf",
|
|
572
|
-
routes: ["94158-C001", "94107-C031"],
|
|
573
|
-
target_type: "all",
|
|
574
|
-
full_bleed: "1"
|
|
575
|
-
)
|
|
576
|
-
|
|
577
|
-
# create an area request with HTML & with zip codes
|
|
578
|
-
@lob.areas.create(
|
|
579
|
-
name: "My Area",
|
|
580
|
-
front: "<html style='margin: 130px; font-size: 50;'>HTML here</html>",
|
|
581
|
-
back: "<html style='margin: 130px; font-size: 50;'>HTML here</html>",
|
|
582
|
-
zip_codes: ["95678", "94158"],
|
|
583
|
-
target_type: "all",
|
|
584
|
-
full_bleed: "1"
|
|
585
|
-
)
|
|
586
|
-
```
|
|
82
|
+
When using zip codes with zero-prefixes, always quote them. For example when specifying `02125`, pass it as a string `"02125"`, instead of an integer.
|
|
587
83
|
|
|
588
|
-
|
|
84
|
+
The Ruby interpreter assumes it's not of base-10 and tries to convert it to base-10 number. So that might result in an entirely different zip-code than intended.
|
|
589
85
|
|
|
590
|
-
####
|
|
591
|
-
```ruby
|
|
592
|
-
@lob.areas.list
|
|
86
|
+
#### Accessing Response Headers
|
|
593
87
|
|
|
594
|
-
|
|
595
|
-
@lob.areas.list(count: 10, offset: 3)
|
|
596
|
-
```
|
|
88
|
+
You can access response headers via a hidden `headers` method on the response hash.
|
|
597
89
|
|
|
598
|
-
#### lob.areas.find
|
|
599
90
|
```ruby
|
|
600
|
-
@lob.
|
|
601
|
-
```
|
|
602
|
-
|
|
603
|
-
### lob.routes
|
|
91
|
+
addresses = @lob.addresses.list
|
|
604
92
|
|
|
605
|
-
|
|
93
|
+
addresses._response.headers[:content_type]
|
|
94
|
+
# => "application/json; charset=utf-8"
|
|
606
95
|
|
|
607
|
-
|
|
96
|
+
addresses._response.headers[:rate_limit_window]
|
|
97
|
+
# => "60"
|
|
608
98
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
zip_codes: ["95678, 94158"]
|
|
612
|
-
)
|
|
99
|
+
addresses._response.headers[:rate_limit_remaining]
|
|
100
|
+
# => "1234"
|
|
613
101
|
```
|
|
614
102
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
## Resources
|
|
618
|
-
|
|
619
|
-
### lob.countries
|
|
620
|
-
|
|
621
|
-
#### lob.countries.list
|
|
103
|
+
You can also access headers from `Lob::InvalidRequestError`s.
|
|
622
104
|
|
|
623
105
|
```ruby
|
|
624
|
-
|
|
625
|
-
@lob.
|
|
106
|
+
begin
|
|
107
|
+
@lob.objects.create(name: "Test", file: "https://lob.com/test.pdf", bad_param: "bad_value")
|
|
108
|
+
rescue Lob::InvalidRequestError => e
|
|
109
|
+
e._response.headers[:content_type]
|
|
110
|
+
# => "application/json; charset=utf-8"
|
|
111
|
+
end
|
|
626
112
|
```
|
|
627
113
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
114
|
+
## Examples
|
|
115
|
+
|
|
116
|
+
We've provided various examples for you to try out [here](https://github.com/lob/lob-ruby/tree/master/examples).
|
|
117
|
+
|
|
118
|
+
There are simple scripts to demonstrate how to create all the core Lob products (checks, letters, postcards, jobs etc.), as well as more complex examples that utilize other libraries and external files:
|
|
119
|
+
|
|
120
|
+
- [Creating Dynamic Postcards with HTML and Data](https://github.com/lob/lob-ruby/tree/master/examples/csv_postcards)
|
|
121
|
+
|
|
122
|
+
## API Documentation
|
|
123
|
+
|
|
124
|
+
- [Introduction](https://lob.com/docs/ruby#introduction)
|
|
125
|
+
- [Versioning](https://lob.com/docs/ruby#version)
|
|
126
|
+
- [Errors](https://lob.com/docs/ruby#errors)
|
|
127
|
+
- [Rate Limiting](https://lob.com/docs/ruby#rate-limits)
|
|
128
|
+
- [Metadata](https://lob.com/docs/ruby#metadata)
|
|
129
|
+
- **Addresses**
|
|
130
|
+
- [Address Book](https://lob.com/docs/ruby#addresses)
|
|
131
|
+
- [Create an Address](https://lob.com/docs/ruby#addresses_create)
|
|
132
|
+
- [Retrieve an Address](https://lob.com/docs/ruby#addresses_retrieve)
|
|
133
|
+
- [Delete an Address](https://lob.com/docs/ruby#addresses_delete)
|
|
134
|
+
- [List all Addresses](https://lob.com/docs/ruby#addresses_list)
|
|
135
|
+
- [Address Verification API](https://lob.com/docs/ruby#verify)
|
|
136
|
+
- [Verify an Address](https://lob.com/docs/ruby#verify_create)
|
|
137
|
+
- **Postcards API**
|
|
138
|
+
- [Postcards](https://lob.com/docs/ruby#postcards)
|
|
139
|
+
- [Create a Postcard](https://lob.com/docs/ruby#postcards_create)
|
|
140
|
+
- [Retrieve a Postcard](https://lob.com/docs/ruby#postcards_retrieve)
|
|
141
|
+
- [List all Postcards](https://lob.com/docs/ruby#postcards_list)
|
|
142
|
+
- **Letters API**
|
|
143
|
+
- [Letters](https://lob.com/docs/ruby#letters)
|
|
144
|
+
- [Create a Letter](https://lob.com/docs/ruby#letters_create)
|
|
145
|
+
- [Retrieve a Letter](https://lob.com/docs/ruby#letters_retrieve)
|
|
146
|
+
- [List all Letters](https://lob.com/docs/ruby#letters_list)
|
|
147
|
+
- **Checks API**
|
|
148
|
+
- [Checks](https://lob.com/docs/ruby#checks)
|
|
149
|
+
- [Create a Check](https://lob.com/docs/ruby#checks_create)
|
|
150
|
+
- [Retrieve a Check](https://lob.com/docs/ruby#checks_retrieve)
|
|
151
|
+
- [List all Checks](https://lob.com/docs/ruby#checks_list)
|
|
152
|
+
- [Bank Accounts](https://lob.com/docs/ruby#bank-accounts)
|
|
153
|
+
- [Create a Bank Account](https://lob.com/docs/ruby#bankaccounts_create)
|
|
154
|
+
- [Retrieve a Bank Account](https://lob.com/docs/ruby#bankaccounts_retrieve)
|
|
155
|
+
- [Delete a Bank Account](https://lob.com/docs/ruby#bankaccounts_delete)
|
|
156
|
+
- [Verify a Bank Account](https://lob.com/docs/ruby#bankaccounts_verify)
|
|
157
|
+
- [List all Bank Accounts](https://lob.com/docs/ruby#bankaccounts_list)
|
|
158
|
+
- **Area Mail API**
|
|
159
|
+
- [Areas](https://lob.com/docs/ruby#areas)
|
|
160
|
+
- [Create an Area Mailing](https://lob.com/docs/ruby#areas_create)
|
|
161
|
+
- [Retrieve an Area Mailing](https://lob.com/docs/ruby#areas_retrieve)
|
|
162
|
+
- [List all Area Mailings](https://lob.com/docs/ruby#areas_list)
|
|
163
|
+
- [Routes](https://lob.com/docs/ruby#routes)
|
|
164
|
+
- [Retrieve a Zip Code](https://lob.com/docs/ruby#routes_retrieve)
|
|
165
|
+
- [List all Zip Codes](https://lob.com/docs/ruby#routes_list)
|
|
166
|
+
- **Resources**
|
|
167
|
+
- [Countries](https://lob.com/docs/ruby#countries)
|
|
168
|
+
- [List all Countries](https://lob.com/docs/ruby#countries_list)
|
|
169
|
+
- [States](https://lob.com/docs/ruby#states)
|
|
170
|
+
- [List all States](https://lob.com/docs/ruby#states_list)
|
|
171
|
+
- **Appendix**
|
|
172
|
+
- [API Changelog](https://lob.com/docs/ruby#changelog)
|
|
173
|
+
- [HTML Examples](https://lob.com/docs/ruby#html-examples)
|
|
174
|
+
- [Image Prepping](https://lob.com/docs/ruby#prepping)
|
|
631
175
|
|
|
632
|
-
|
|
633
|
-
# returns a list of states
|
|
634
|
-
@lob.states.list
|
|
635
|
-
```
|
|
636
|
-
|
|
637
|
-
## Developing
|
|
176
|
+
## Contributing
|
|
638
177
|
|
|
639
178
|
Make sure you have Ruby 2.0 installed. Copy and paste the following commands in your projects directory.
|
|
640
179
|
|
|
@@ -642,15 +181,19 @@ Make sure you have Ruby 2.0 installed. Copy and paste the following commands in
|
|
|
642
181
|
cd lob-ruby
|
|
643
182
|
bundle install
|
|
644
183
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
## Testing
|
|
184
|
+
### Contributing Instructions
|
|
648
185
|
|
|
649
|
-
|
|
186
|
+
1. Fork it
|
|
187
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
188
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
189
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
190
|
+
5. Make sure the tests pass
|
|
191
|
+
6. Open up coverage/index.html in your browser and add tests if required
|
|
192
|
+
7. Create new Pull Request
|
|
650
193
|
|
|
651
|
-
|
|
194
|
+
## Testing
|
|
652
195
|
|
|
653
|
-
Tests are written using MiniTest, a testing library that comes with Ruby stdlib.
|
|
196
|
+
Tests are written using MiniTest, a testing library that comes with Ruby stdlib.
|
|
654
197
|
|
|
655
198
|
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.
|
|
656
199
|
|
|
@@ -658,25 +201,11 @@ Here's how you can run the tests:
|
|
|
658
201
|
|
|
659
202
|
LOB_API_KEY=your_test_api_key bundle exec rake test
|
|
660
203
|
|
|
661
|
-
|
|
662
|
-
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`.
|
|
663
|
-
|
|
664
204
|
You can also configure, TravisCI for your fork of the repository and it'll run the tests for you, when you push.
|
|
665
205
|
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
1. Fork it
|
|
669
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
670
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
671
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
|
672
|
-
5. Make sure the tests pass
|
|
673
|
-
6. Open up coverage/index.html in your browser and add tests if required
|
|
674
|
-
7. Create new Pull Request
|
|
675
|
-
|
|
676
|
-
## Credits
|
|
677
|
-
|
|
678
|
-
* [Akash Manohar J](http://github.com/HashNuke)
|
|
206
|
+
=======================
|
|
679
207
|
|
|
680
208
|
Copyright © 2013 Lob.com
|
|
681
209
|
|
|
682
210
|
Released under the MIT License, which can be found in the repository in `LICENSE.txt`.
|
|
211
|
+
|