lob 1.0.2
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 +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +315 -0
- data/Rakefile +27 -0
- data/lib/lob/lob_error.rb +4 -0
- data/lib/lob/v1/address.rb +42 -0
- data/lib/lob/v1/job.rb +40 -0
- data/lib/lob/v1/object.rb +34 -0
- data/lib/lob/v1/packaging.rb +21 -0
- data/lib/lob/v1/postcard.rb +39 -0
- data/lib/lob/v1/resource.rb +63 -0
- data/lib/lob/v1/service.rb +21 -0
- data/lib/lob/v1/setting.rb +25 -0
- data/lib/lob/version.rb +3 -0
- data/lib/lob.rb +68 -0
- data/lob.gemspec +27 -0
- data/spec/lob/v1/address_spec.rb +79 -0
- data/spec/lob/v1/job_spec.rb +117 -0
- data/spec/lob/v1/object_spec.rb +93 -0
- data/spec/lob/v1/packaging_spec.rb +16 -0
- data/spec/lob/v1/postcard_spec.rb +128 -0
- data/spec/lob/v1/resource_spec.rb +50 -0
- data/spec/lob/v1/service_spec.rb +16 -0
- data/spec/lob/v1/setting_spec.rb +29 -0
- data/spec/lob_spec.rb +34 -0
- data/spec/spec_helper.rb +16 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 30db6f13b99ec0741402870415497e121b65aae5
|
4
|
+
data.tar.gz: 09cd39be27af5bc020f3da55fc05c1cf80328b69
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 62d35cd4ce46eb893300f006d25e9efdeeb090a14fe5afe2bea8e4a22316a888519c668a1cb84edf6fe199f7167d50466d312934233473410ed0b5906e49b28f
|
7
|
+
data.tar.gz: 3db7ed010961fdb7279c82829a1cb88e155b99c0dac30b2c736be59d357dc851860ba0a3053e52f67b943a33049c7547c63ef89aa8ba1cbafb590c93d224ac4b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Lob.com
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,315 @@
|
|
1
|
+
# lob-ruby
|
2
|
+
|
3
|
+
Ruby wrapper for the [Lob.com](http://lob.com) API. This gem gives you an ActiveRecord-style syntax to use the Lob.com API.
|
4
|
+
|
5
|
+
Supports Ruby 1.9.3 and greater.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's `Gemfile`:
|
10
|
+
|
11
|
+
gem 'lob'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install lob
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The library uses an ActiveRecord-style interface. You'll feel right at home.
|
24
|
+
You'll need a Lob.com API key. It's free and you can get yours [here](https://www.lob.com/account).
|
25
|
+
|
26
|
+
For optional parameters and other details, refer the docs here - <https://lob.com/docs>
|
27
|
+
|
28
|
+
### Initialization and configuration
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# To initialize a Lob object
|
32
|
+
@lob = Lob(api_key: "your-api-key")
|
33
|
+
|
34
|
+
|
35
|
+
# Alternatively, to set the API key for all calls in the future
|
36
|
+
Lob.api_key = "you-api-key"
|
37
|
+
@lob = Lob() # don't forget the paranthesis!
|
38
|
+
```
|
39
|
+
|
40
|
+
#### Or if you want some detailed configuration
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
Lob.configure do |config|
|
44
|
+
config.api_key = "your-api-key" # get your own at http://lob.com :)
|
45
|
+
config.api_version = "v1" # default version
|
46
|
+
config.protocol = "https" # default protocol
|
47
|
+
config.api_host = "api.lob.com" # ofcourse it's Lob
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
### Addresses
|
52
|
+
|
53
|
+
#### To create an address
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# name, address, city, state, country and zip are required parameters
|
57
|
+
@lob.addresses.create(
|
58
|
+
name: "John Doe",
|
59
|
+
address_line1: "104, Printing Boulevard",
|
60
|
+
city: "Boston",
|
61
|
+
state: "MA",
|
62
|
+
country: "USA"
|
63
|
+
zip: 12345
|
64
|
+
)
|
65
|
+
|
66
|
+
# You can also pass address_line2
|
67
|
+
@lob.addresses.create(
|
68
|
+
name: "John Doe",
|
69
|
+
email: "test@test.com", # see you can also pass other optional parameters?
|
70
|
+
address_line1: "104, Printing Boulevard",
|
71
|
+
address_line2: "Sunset Town",
|
72
|
+
city: "Boston",
|
73
|
+
state: "MA",
|
74
|
+
country: "USA"
|
75
|
+
zip: 12345
|
76
|
+
)
|
77
|
+
```
|
78
|
+
|
79
|
+
#### List addresses
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
# returns an array of addresses
|
83
|
+
@lob.addresses.list
|
84
|
+
|
85
|
+
#you can also pass count and offset
|
86
|
+
@lob.addresses.list(count: 10, offset: 3)
|
87
|
+
```
|
88
|
+
|
89
|
+
#### Find a specific address
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
# returns the address with the corresponding ID
|
93
|
+
@lob.addresses.find("some-address-id")
|
94
|
+
```
|
95
|
+
|
96
|
+
#### Deletes a specific address
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
# deletes the address with the corresponding ID
|
100
|
+
@lob.addresses.destroy("some-address-id")
|
101
|
+
```
|
102
|
+
|
103
|
+
### Address verification
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
# verifies and returns an address with more details
|
107
|
+
@lob.addresses.verify(
|
108
|
+
address_line1: "220 WILLIAM T MORRISSEY BLVD",
|
109
|
+
city: "Boston",
|
110
|
+
state: "MA",
|
111
|
+
zip: 02125
|
112
|
+
)
|
113
|
+
```
|
114
|
+
|
115
|
+
### Jobs
|
116
|
+
|
117
|
+
#### Create jobs
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
# name, to-address and object are the arguments
|
121
|
+
# to-address can be specified as an address-id
|
122
|
+
@lob.jobs.create("New Cool Posters", "to-address-id", "object-id")
|
123
|
+
|
124
|
+
# to-address can also be specified as address params to create new address
|
125
|
+
@lob.jobs.create(
|
126
|
+
"New Cool Posters",
|
127
|
+
{name: "ToAddress", address_line1: "120, 6th Ave", city: "Boston", country: "USA", zip: 12345},
|
128
|
+
"object-id"
|
129
|
+
)
|
130
|
+
|
131
|
+
# You can also pass new object params for the object
|
132
|
+
# and other options like packaging_id an setting_id
|
133
|
+
@lob.jobs.create(
|
134
|
+
"New Cool Posters",
|
135
|
+
"to-address-id",
|
136
|
+
"object-id",
|
137
|
+
{
|
138
|
+
name: "Your fantistic object",
|
139
|
+
file: "http://test.com/file.pdf",
|
140
|
+
setting_id: "some-setting-id"
|
141
|
+
}
|
142
|
+
)
|
143
|
+
```
|
144
|
+
|
145
|
+
#### List jobs
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
# returns an array of jobs
|
149
|
+
@lob.jobs.list
|
150
|
+
|
151
|
+
#you can also pass count and offset
|
152
|
+
@lob.jobs.list(count: 10, offset: 3)
|
153
|
+
```
|
154
|
+
|
155
|
+
#### Find a specific job
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
# returns the job with the corresponding ID
|
159
|
+
@lob.jobs.find("some-job-id")
|
160
|
+
```
|
161
|
+
|
162
|
+
### Objects
|
163
|
+
|
164
|
+
#### Create objects
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
# You can create by passing the name, file url and setting ID
|
168
|
+
@lob.objects.create(
|
169
|
+
"Your fantistic object",
|
170
|
+
"http://test.com/file.pdf",
|
171
|
+
"some-setting-id"
|
172
|
+
)
|
173
|
+
|
174
|
+
# You can also pass the quantity as an option
|
175
|
+
# Or pass a file for upload instead of a url
|
176
|
+
@lob.objects.create(
|
177
|
+
"Your fantistic object",
|
178
|
+
File.new("/path/to/file.pdf"),
|
179
|
+
"some-setting-id",
|
180
|
+
quantity: 12
|
181
|
+
)
|
182
|
+
```
|
183
|
+
|
184
|
+
#### List objects
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
# returns an array of objects
|
188
|
+
@lob.objects.list
|
189
|
+
|
190
|
+
#you can also pass count and offset
|
191
|
+
@lob.objects.list(count: 10, offset: 3)
|
192
|
+
```
|
193
|
+
|
194
|
+
#### Find a specific object
|
195
|
+
|
196
|
+
```ruby
|
197
|
+
# returns the object with the corresponding ID
|
198
|
+
@lob.objects.find("some-object-id")
|
199
|
+
```
|
200
|
+
|
201
|
+
#### Delete a specific object
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
# deletes the object with the corresponding ID
|
205
|
+
@lob.objects.destroy("some-object-id")
|
206
|
+
```
|
207
|
+
|
208
|
+
### Packagings
|
209
|
+
|
210
|
+
#### List packagings
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
# returns a list of packagings
|
214
|
+
@lob.packagings.list
|
215
|
+
```
|
216
|
+
|
217
|
+
### Postcards
|
218
|
+
|
219
|
+
#### Creating post cards
|
220
|
+
|
221
|
+
You'll have to specify either the `message` option or the `back` option.
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
# accepts the name, address-id to send to and options
|
225
|
+
@lob.postcards.create(
|
226
|
+
"John Joe",
|
227
|
+
"to-address-id",
|
228
|
+
message: front: File.read("/path/to/file.pdf")
|
229
|
+
)
|
230
|
+
|
231
|
+
# create using address params, front, back and from address
|
232
|
+
@lob.postcards.create(
|
233
|
+
"John Joe",
|
234
|
+
{name: "ToAddress", address_line1: "120, 6th Ave", city: "Boston", country: "USA", zip: 12345},
|
235
|
+
message: "Hey buddy. Waiting to hear your stories",
|
236
|
+
front: "http://test.com/file.pdf",
|
237
|
+
back: File.read("/path/to/file.pdf"),
|
238
|
+
from: {name: "FromAddress", address_line1: "120, 6th Ave", city: "Boston", country: "USA", zip: 12345},
|
239
|
+
)
|
240
|
+
```
|
241
|
+
|
242
|
+
#### List postcards
|
243
|
+
|
244
|
+
```ruby
|
245
|
+
@lob.postcards.list
|
246
|
+
|
247
|
+
#you can also pass count and offset
|
248
|
+
@lob.postcards.list(count: 10, offset: 3)
|
249
|
+
```
|
250
|
+
|
251
|
+
#### Find a postcard
|
252
|
+
|
253
|
+
```ruby
|
254
|
+
@lob.postcards.find "post-card-id"
|
255
|
+
```
|
256
|
+
|
257
|
+
### Services
|
258
|
+
|
259
|
+
#### List services
|
260
|
+
|
261
|
+
```ruby
|
262
|
+
# returns a list of services
|
263
|
+
@lob.services.list
|
264
|
+
```
|
265
|
+
|
266
|
+
### Settings
|
267
|
+
|
268
|
+
#### List settings
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
# returns a list of settings
|
272
|
+
@lob.settings.list
|
273
|
+
```
|
274
|
+
|
275
|
+
## Developing
|
276
|
+
|
277
|
+
Make sure you have Ruby 2.0 installed. Copy and paste the following commands in your projects directory.
|
278
|
+
|
279
|
+
git clone https://github.com/lob/lob-ruby.git
|
280
|
+
cd lob
|
281
|
+
bundle install
|
282
|
+
|
283
|
+
You are powered up and ready to roll ~!
|
284
|
+
|
285
|
+
## Running the test-suite
|
286
|
+
|
287
|
+
To run the tests, download the required sample files by running the following command:
|
288
|
+
|
289
|
+
bundle exec rake dev:setup
|
290
|
+
|
291
|
+
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).
|
292
|
+
|
293
|
+
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.
|
294
|
+
|
295
|
+
Here's how you can run the tests:
|
296
|
+
|
297
|
+
LOB_API_KEY=your_test_api_key bundle exec rake test
|
298
|
+
|
299
|
+
|
300
|
+
## Contributing
|
301
|
+
|
302
|
+
1. Fork it
|
303
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
304
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
305
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
306
|
+
5. Make sure the tests pass and add tests if required
|
307
|
+
6. Create new Pull Request
|
308
|
+
|
309
|
+
## Credits
|
310
|
+
|
311
|
+
* [Akash Manohar J](http://github.com/HashNuke)
|
312
|
+
|
313
|
+
Copyright © 2013 Lob.com
|
314
|
+
|
315
|
+
Released under the MIT License, which can be found in the repository in `LICENSE.txt`.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.libs.push "lib", "spec"
|
7
|
+
t.test_files = FileList['spec/**/*_spec.rb']
|
8
|
+
t.verbose = true
|
9
|
+
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://www.lob.com/postcardfront.pdf", name: "postcardfront.pdf"},
|
19
|
+
{url: "https://www.lob.com/postcardback.pdf", name: "postcardback.pdf"},
|
20
|
+
{url: "https://www.lob.com/goblue.pdf", name: "goblue.pdf"}
|
21
|
+
]
|
22
|
+
files.each do |f|
|
23
|
+
system "wget #{f[:url]} -O spec/samples/#{f[:name]}"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Lob
|
2
|
+
module V1
|
3
|
+
class Address
|
4
|
+
|
5
|
+
def initialize(resource)
|
6
|
+
@resource = resource
|
7
|
+
end
|
8
|
+
|
9
|
+
def verify(options={})
|
10
|
+
params = @resource.format_address_params(options, false)
|
11
|
+
Lob.submit(:post, address_verify_url, params)
|
12
|
+
end
|
13
|
+
|
14
|
+
def list(options={})
|
15
|
+
Lob.submit(:get, address_url, options)["data"] || []
|
16
|
+
end
|
17
|
+
|
18
|
+
def find(address_id)
|
19
|
+
Lob.submit :get, address_url(address_id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(options = {})
|
23
|
+
Lob.submit :post, address_url, @resource.format_address_params(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def destroy(address_id)
|
27
|
+
Lob.submit :delete, address_url(address_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def address_url(address_id = nil)
|
33
|
+
@resource.construct_url("addresses", address_id)
|
34
|
+
end
|
35
|
+
|
36
|
+
def address_verify_url
|
37
|
+
@resource.construct_url("verify")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/lob/v1/job.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Lob
|
2
|
+
module V1
|
3
|
+
class Job
|
4
|
+
|
5
|
+
def initialize(resource)
|
6
|
+
@resource = resource
|
7
|
+
end
|
8
|
+
|
9
|
+
def list(options={})
|
10
|
+
Lob.submit(:get, job_url, options)["data"] || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(job_id)
|
14
|
+
Lob.submit :get, job_url(job_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(name, to, object1, options = {})
|
18
|
+
options = { name: name, to: to, object1: object1 }.merge(options)
|
19
|
+
|
20
|
+
if options[:to] && !options[:to].is_a?(String)
|
21
|
+
options[:to] = @resource.format_address_params(options[:to])
|
22
|
+
end
|
23
|
+
|
24
|
+
if options[:from] && !options[:from].is_a?(String)
|
25
|
+
options[:from] = @resource.format_address_params(options[:from])
|
26
|
+
end
|
27
|
+
|
28
|
+
Lob.submit :post, job_url, options
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def job_url(job_id = nil)
|
35
|
+
@resource.construct_url("jobs", job_id)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Lob
|
2
|
+
module V1
|
3
|
+
class Object
|
4
|
+
|
5
|
+
def initialize(resource)
|
6
|
+
@resource = resource
|
7
|
+
end
|
8
|
+
|
9
|
+
def list(options={})
|
10
|
+
Lob.submit(:get, object_url, options)["data"] || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(lob_object_id)
|
14
|
+
Lob.submit :get, object_url(lob_object_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(name, file, setting_id, options = {})
|
18
|
+
options = { name: name, file: file, setting_id: setting_id }.merge(options)
|
19
|
+
Lob.submit :post, object_url, options
|
20
|
+
end
|
21
|
+
|
22
|
+
def destroy(lob_object_id)
|
23
|
+
Lob.submit :delete, object_url(lob_object_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def object_url(lob_object_id = nil)
|
29
|
+
@resource.construct_url("objects", lob_object_id)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Lob
|
2
|
+
module V1
|
3
|
+
class Packaging
|
4
|
+
|
5
|
+
def initialize(resource)
|
6
|
+
@resource = resource
|
7
|
+
end
|
8
|
+
|
9
|
+
def list(options={})
|
10
|
+
Lob.submit(:get, packaging_url, options)["data"] || []
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def packaging_url
|
16
|
+
@resource.construct_url("packagings")
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Lob
|
2
|
+
module V1
|
3
|
+
class Postcard
|
4
|
+
|
5
|
+
def initialize(resource)
|
6
|
+
@resource = resource
|
7
|
+
end
|
8
|
+
|
9
|
+
def list(options={})
|
10
|
+
Lob.submit(:get, postcard_url, options)["data"] || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(postcard_id)
|
14
|
+
Lob.submit :get, postcard_url(postcard_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create(name, to, options = {})
|
18
|
+
options = { name: name, to: to }.merge(options)
|
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
|
+
Lob.submit :post, postcard_url, options
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def postcard_url(postcard_id = nil)
|
34
|
+
@resource.construct_url("postcards", postcard_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Lob
|
2
|
+
module V1
|
3
|
+
class Resource
|
4
|
+
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def addresses
|
12
|
+
Lob::V1::Address.new(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def jobs
|
16
|
+
Lob::V1::Job.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def objects
|
20
|
+
Lob::V1::Object.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def packagings
|
24
|
+
Lob::V1::Packaging.new(self)
|
25
|
+
end
|
26
|
+
|
27
|
+
def postcards
|
28
|
+
Lob::V1::Postcard.new(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def services
|
32
|
+
Lob::V1::Service.new(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def settings
|
36
|
+
Lob::V1::Setting.new(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
def base_url
|
40
|
+
"#{@options[:protocol]}://#{@options[:api_key]}:@#{@options[:api_host]}/v1"
|
41
|
+
end
|
42
|
+
|
43
|
+
def construct_url(resource_type, resource_id=nil)
|
44
|
+
"#{base_url}/#{resource_type}#{'/' + resource_id if resource_id}"
|
45
|
+
end
|
46
|
+
|
47
|
+
#NOTE to format address param names into API-compatible ones
|
48
|
+
def format_address_params(params, check_required_options=true)
|
49
|
+
if check_required_options
|
50
|
+
Lob.require_options(params, :name, :address_line1, :city, :state, :zip, :country)
|
51
|
+
end
|
52
|
+
|
53
|
+
[:city, :state, :zip, :country].each do |option|
|
54
|
+
params["address_#{option}".to_sym] = params[option] if params[option]
|
55
|
+
params.delete(option)
|
56
|
+
end
|
57
|
+
|
58
|
+
params
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Lob
|
2
|
+
module V1
|
3
|
+
class Service
|
4
|
+
|
5
|
+
def initialize(resource)
|
6
|
+
@resource = resource
|
7
|
+
end
|
8
|
+
|
9
|
+
def list(options={})
|
10
|
+
Lob.submit(:get, service_url, options)["data"] || []
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def service_url
|
16
|
+
@resource.construct_url("services")
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Lob
|
2
|
+
module V1
|
3
|
+
class Setting
|
4
|
+
|
5
|
+
def initialize(resource)
|
6
|
+
@resource = resource
|
7
|
+
end
|
8
|
+
|
9
|
+
def list(options={})
|
10
|
+
Lob.submit(:get, setting_url, options)["data"] || []
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(setting_id)
|
14
|
+
Lob.submit :get, setting_url(setting_id)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def setting_url(setting_id = nil)
|
20
|
+
@resource.construct_url("settings", setting_id)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/lob/version.rb
ADDED