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
|
@@ -8,14 +8,14 @@ describe Lob::V1::Postcard do
|
|
|
8
8
|
email: "test@test.com",
|
|
9
9
|
address_line1: "123 Test Street",
|
|
10
10
|
address_line2: "Unit 199",
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
address_city: "Mountain View",
|
|
12
|
+
address_state: "CA",
|
|
13
|
+
address_country: "US",
|
|
14
|
+
address_zip: 94085
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
@sample_postcard_params = {
|
|
18
|
-
|
|
18
|
+
description: "TestPostcard",
|
|
19
19
|
message: "Sample postcard message"
|
|
20
20
|
}
|
|
21
21
|
end
|
|
@@ -24,97 +24,75 @@ describe Lob::V1::Postcard do
|
|
|
24
24
|
|
|
25
25
|
describe "list" do
|
|
26
26
|
it "should list postcards" do
|
|
27
|
-
|
|
28
|
-
new_address = subject.addresses.create @sample_address_params
|
|
29
|
-
|
|
30
|
-
new_postcard = subject.postcards.create(
|
|
31
|
-
name: @sample_postcard_params[:name],
|
|
32
|
-
to: new_address["id"],
|
|
33
|
-
front: File.new(File.expand_path("../../../samples/postcardfront.pdf", __FILE__)),
|
|
34
|
-
back: File.new(File.expand_path("../../../samples/postcardback.pdf", __FILE__))
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
list_result = subject.postcards.list
|
|
38
|
-
assert /#{new_postcard["name"]}/ =~ list_result.to_s
|
|
39
|
-
end
|
|
27
|
+
assert subject.postcards.list({ include: ['total_count'] })["object"] == "list"
|
|
40
28
|
end
|
|
41
29
|
end
|
|
42
30
|
|
|
43
31
|
|
|
44
32
|
describe "create" do
|
|
45
33
|
it "should create a postcard with address_id" do
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
result["name"].must_equal(@sample_postcard_params[:name])
|
|
57
|
-
end
|
|
34
|
+
new_address = subject.addresses.create @sample_address_params
|
|
35
|
+
|
|
36
|
+
result = subject.postcards.create(
|
|
37
|
+
name: @sample_postcard_params[:name],
|
|
38
|
+
to: new_address["id"],
|
|
39
|
+
message: @sample_postcard_params[:message],
|
|
40
|
+
front: "https://lob.com/postcardfront.pdf",
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
result["name"].must_equal(@sample_postcard_params[:name])
|
|
58
44
|
end
|
|
59
45
|
|
|
60
46
|
it "should create a postcard with to address params" do
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
result["name"].must_equal(@sample_postcard_params[:name])
|
|
70
|
-
end
|
|
47
|
+
result = subject.postcards.create(
|
|
48
|
+
name: @sample_postcard_params[:name],
|
|
49
|
+
to: @sample_address_params,
|
|
50
|
+
message: @sample_postcard_params[:message],
|
|
51
|
+
front: "https://lob.com/postcardfront.pdf"
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
result["name"].must_equal(@sample_postcard_params[:name])
|
|
71
55
|
end
|
|
72
56
|
|
|
73
57
|
it "should create a postcard with from address params" do
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
result["name"].must_equal(@sample_postcard_params[:name])
|
|
86
|
-
end
|
|
58
|
+
new_address = subject.addresses.create @sample_address_params
|
|
59
|
+
|
|
60
|
+
result = subject.postcards.create(
|
|
61
|
+
name: @sample_postcard_params[:name],
|
|
62
|
+
to: new_address["id"],
|
|
63
|
+
from: @sample_address_params,
|
|
64
|
+
message: @sample_postcard_params[:message],
|
|
65
|
+
front: "https://lob.com/postcardfront.pdf"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
result["name"].must_equal(@sample_postcard_params[:name])
|
|
87
69
|
end
|
|
88
70
|
|
|
89
71
|
it "should create a postcard with front and back as urls" do
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
result["name"].must_equal(@sample_postcard_params[:name])
|
|
101
|
-
end
|
|
72
|
+
new_address = subject.addresses.create @sample_address_params
|
|
73
|
+
|
|
74
|
+
result = subject.postcards.create(
|
|
75
|
+
name: @sample_postcard_params[:name],
|
|
76
|
+
to: new_address["id"],
|
|
77
|
+
front: "https://lob.com/postcardfront.pdf",
|
|
78
|
+
back: "https://lob.com/postcardback.pdf"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
result["name"].must_equal(@sample_postcard_params[:name])
|
|
102
82
|
end
|
|
103
83
|
|
|
104
84
|
|
|
105
85
|
it "should create a postcard with front and back as PDFs" do
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
result["name"].must_equal(@sample_postcard_params[:name])
|
|
117
|
-
end
|
|
86
|
+
new_address = subject.addresses.create @sample_address_params
|
|
87
|
+
|
|
88
|
+
result = subject.postcards.create(
|
|
89
|
+
name: @sample_postcard_params[:name],
|
|
90
|
+
to: new_address["id"],
|
|
91
|
+
front: File.new(File.expand_path("../../../samples/postcardfront.pdf", __FILE__)),
|
|
92
|
+
back: File.new(File.expand_path("../../../samples/postcardback.pdf", __FILE__))
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
result["name"].must_equal(@sample_postcard_params[:name])
|
|
118
96
|
end
|
|
119
97
|
|
|
120
98
|
end
|
|
@@ -122,19 +100,17 @@ describe Lob::V1::Postcard do
|
|
|
122
100
|
|
|
123
101
|
describe "find" do
|
|
124
102
|
it "should find a postcard" do
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
result["name"].must_equal(@sample_postcard_params[:name])
|
|
137
|
-
end
|
|
103
|
+
new_address = subject.addresses.create @sample_address_params
|
|
104
|
+
|
|
105
|
+
new_postcard = subject.postcards.create(
|
|
106
|
+
name: @sample_postcard_params[:name],
|
|
107
|
+
to: new_address["id"],
|
|
108
|
+
front: File.new(File.expand_path("../../../samples/postcardfront.pdf", __FILE__)),
|
|
109
|
+
back: File.new(File.expand_path("../../../samples/postcardback.pdf", __FILE__))
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
result = subject.postcards.find(new_postcard["id"])
|
|
113
|
+
result["name"].must_equal(@sample_postcard_params[:name])
|
|
138
114
|
end
|
|
139
115
|
end
|
|
140
116
|
|
|
@@ -19,7 +19,6 @@ describe Lob::V1::Resource do
|
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
|
|
23
22
|
it "should return addresses resource" do
|
|
24
23
|
subject.addresses.must_be_kind_of(Lob::V1::Address)
|
|
25
24
|
end
|
|
@@ -32,18 +31,10 @@ describe Lob::V1::Resource do
|
|
|
32
31
|
subject.objects.must_be_kind_of(Lob::V1::Object)
|
|
33
32
|
end
|
|
34
33
|
|
|
35
|
-
it "should return packagings resource" do
|
|
36
|
-
subject.packagings.must_be_kind_of(Lob::V1::Packaging)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
34
|
it "should return postcards resource" do
|
|
40
35
|
subject.postcards.must_be_kind_of(Lob::V1::Postcard)
|
|
41
36
|
end
|
|
42
37
|
|
|
43
|
-
it "should return services resource" do
|
|
44
|
-
subject.services.must_be_kind_of(Lob::V1::Service)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
38
|
it "should return settings resource" do
|
|
48
39
|
subject.settings.must_be_kind_of(Lob::V1::Setting)
|
|
49
40
|
end
|
data/spec/lob/v1/route_spec.rb
CHANGED
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
describe Lob::V1::Route do
|
|
4
|
+
|
|
4
5
|
subject { Lob(api_key: ENV["LOB_API_KEY"]) }
|
|
5
6
|
|
|
7
|
+
describe "find" do
|
|
8
|
+
|
|
9
|
+
it "should fetch a route" do
|
|
10
|
+
zip_code = "94158"
|
|
11
|
+
routes = subject.routes.find(zip_code)
|
|
12
|
+
routes["zip_code"].must_equal(zip_code)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
6
17
|
describe "list" do
|
|
18
|
+
|
|
7
19
|
it "should list routes" do
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
zip_code = "94158"
|
|
21
|
+
routes = subject.routes.list(zip_codes: zip_code)
|
|
22
|
+
routes["data"][0]["zip_code"].must_equal(zip_code)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "should accept a single ZIP code as input" do
|
|
26
|
+
zip_code = "94158"
|
|
27
|
+
routes = subject.routes.list(zip_code)
|
|
28
|
+
routes["zip_code"].must_equal(zip_code)
|
|
29
|
+
end
|
|
12
30
|
|
|
13
|
-
|
|
14
|
-
|
|
31
|
+
it "should list routes given multiple zip codes" do
|
|
32
|
+
zip_codes = ["94107", "94158"]
|
|
33
|
+
routes = subject.routes.list(zip_codes: zip_codes)
|
|
34
|
+
routes["data"][0]["zip_code"].must_equal(zip_codes[0])
|
|
15
35
|
end
|
|
36
|
+
|
|
16
37
|
end
|
|
38
|
+
|
|
17
39
|
end
|
data/spec/lob/v1/setting_spec.rb
CHANGED
|
@@ -6,24 +6,16 @@ describe Lob::V1::Setting do
|
|
|
6
6
|
|
|
7
7
|
describe "list" do
|
|
8
8
|
it "should list settings" do
|
|
9
|
-
|
|
10
|
-
result = subject.settings.list
|
|
11
|
-
result.length.must_be :>, 0
|
|
12
|
-
/Document/ =~ result.to_s
|
|
13
|
-
/Poster/ =~ result.to_s
|
|
14
|
-
/Card/ =~ result.to_s
|
|
15
|
-
end
|
|
9
|
+
assert subject.settings.list["object"] == "list"
|
|
16
10
|
end
|
|
17
11
|
end
|
|
18
12
|
|
|
19
13
|
|
|
20
14
|
describe "find" do
|
|
21
15
|
it "should find a setting" do
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
result["description"].must_equal(list_result.first["description"])
|
|
26
|
-
end
|
|
16
|
+
list_result = subject.settings.list["data"]
|
|
17
|
+
result = subject.settings.find(list_result.first["id"])
|
|
18
|
+
result["description"].must_equal(list_result.first["description"])
|
|
27
19
|
end
|
|
28
20
|
end
|
|
29
21
|
end
|
data/spec/lob/v1/state_spec.rb
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
require "spec_helper"
|
|
2
2
|
|
|
3
3
|
describe Lob::V1::State do
|
|
4
|
+
|
|
4
5
|
subject { Lob(api_key: ENV["LOB_API_KEY"]) }
|
|
5
6
|
|
|
6
7
|
describe "list" do
|
|
7
8
|
it "should list states" do
|
|
8
|
-
|
|
9
|
-
result = subject.states.list
|
|
10
|
-
result.length.must_be :>, 0
|
|
11
|
-
end
|
|
9
|
+
assert subject.states.list["object"] == "list"
|
|
12
10
|
end
|
|
13
11
|
end
|
|
14
12
|
end
|
data/spec/lob_spec.rb
CHANGED
|
@@ -3,6 +3,7 @@ require "spec_helper"
|
|
|
3
3
|
describe Lob do
|
|
4
4
|
|
|
5
5
|
after do
|
|
6
|
+
Lob.api_key = nil
|
|
6
7
|
Lob.api_version = nil
|
|
7
8
|
end
|
|
8
9
|
|
|
@@ -19,6 +20,12 @@ describe Lob do
|
|
|
19
20
|
Lob(api_key: "test").options[:api_key].must_equal "test"
|
|
20
21
|
end
|
|
21
22
|
|
|
23
|
+
it "should raise an error if no API key is supplied" do
|
|
24
|
+
assert_raises ArgumentError do
|
|
25
|
+
Lob()
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
22
29
|
it "should allow detailed configuration" do
|
|
23
30
|
Lob.configure do |config|
|
|
24
31
|
config.api_key = "test"
|
|
@@ -45,18 +52,30 @@ describe Lob do
|
|
|
45
52
|
it "should handle API errors gracefully" do
|
|
46
53
|
lob = Lob.load(api_key: ENV["LOB_API_KEY"])
|
|
47
54
|
assert_raises Lob::InvalidRequestError do
|
|
48
|
-
|
|
49
|
-
lob.objects.create(name: "Test", file: "https://lob.com/test.pdf", bad_param: "bad_value")
|
|
50
|
-
end
|
|
55
|
+
lob.objects.create(name: "Test", file: "https://lob.com/test.pdf", bad_param: "bad_value")
|
|
51
56
|
end
|
|
52
57
|
end
|
|
53
58
|
|
|
54
59
|
it "should work when no api_version is provided" do
|
|
55
60
|
lob = Lob.load(api_key: ENV["LOB_API_KEY"])
|
|
56
61
|
Lob.api_version = nil
|
|
57
|
-
|
|
58
|
-
lob.addresses.list
|
|
59
|
-
end
|
|
62
|
+
lob.addresses.list
|
|
60
63
|
Lob.api_version = "2014-11-24"
|
|
61
64
|
end
|
|
65
|
+
|
|
66
|
+
it "should include the raw response" do
|
|
67
|
+
lob = Lob.load(api_key: ENV["LOB_API_KEY"])
|
|
68
|
+
result = lob.addresses.list
|
|
69
|
+
assert result._response.headers.include?(:content_type)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
it "should include response headers for errors" do
|
|
73
|
+
lob = Lob.load(api_key: ENV["LOB_API_KEY"])
|
|
74
|
+
begin
|
|
75
|
+
lob.objects.create(name: "Test", file: "https://lob.com/test.pdf", bad_param: "bad_value")
|
|
76
|
+
rescue Lob::InvalidRequestError => e
|
|
77
|
+
assert e._response.headers.include?(:content_type)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
62
81
|
end
|
|
Binary file
|