lob 2.5.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/CHANGELOG.md +9 -0
  4. data/CONTRIBUTING.md +19 -0
  5. data/Gemfile +0 -2
  6. data/README.md +19 -36
  7. data/examples/README.md +14 -6
  8. data/examples/checks.rb +6 -7
  9. data/examples/csv_checks/create_checks.rb +47 -0
  10. data/examples/csv_checks/input.csv +6 -0
  11. data/examples/csv_letters/create_letters.rb +40 -0
  12. data/examples/csv_letters/input.csv +6 -0
  13. data/examples/csv_letters/letter_template.html +33 -0
  14. data/examples/csv_postcards/create_postcards.rb +2 -3
  15. data/examples/letters.rb +4 -5
  16. data/examples/postcards.rb +4 -5
  17. data/examples/verify/verify.rb +3 -4
  18. data/lib/lob.rb +1 -91
  19. data/lib/lob/client.rb +61 -0
  20. data/lib/lob/resources/address.rb +24 -0
  21. data/lib/lob/resources/area.rb +16 -0
  22. data/lib/lob/resources/bank_account.rb +24 -0
  23. data/lib/lob/resources/check.rb +14 -0
  24. data/lib/lob/resources/country.rb +16 -0
  25. data/lib/lob/resources/letter.rb +14 -0
  26. data/lib/lob/resources/postcard.rb +14 -0
  27. data/lib/lob/resources/resource_base.rb +108 -0
  28. data/lib/lob/resources/route.rb +24 -0
  29. data/lib/lob/resources/state.rb +16 -0
  30. data/lib/lob/version.rb +1 -1
  31. data/spec/lob/{v1 → resources}/address_spec.rb +15 -14
  32. data/spec/lob/{v1 → resources}/area_spec.rb +2 -2
  33. data/spec/lob/{v1 → resources}/bank_account_spec.rb +2 -2
  34. data/spec/lob/{v1 → resources}/check_spec.rb +3 -2
  35. data/spec/lob/{v1 → resources}/country_spec.rb +2 -2
  36. data/spec/lob/{v1 → resources}/letter_spec.rb +2 -2
  37. data/spec/lob/{v1 → resources}/postcard_spec.rb +2 -2
  38. data/spec/lob/resources/resource_base_spec.rb +53 -0
  39. data/spec/lob/{v1 → resources}/route_spec.rb +2 -2
  40. data/spec/lob/{v1 → resources}/state_spec.rb +2 -2
  41. data/spec/lob_spec.rb +12 -45
  42. data/spec/spec_helper.rb +2 -0
  43. metadata +86 -89
  44. data/examples/jobs.rb +0 -91
  45. data/lib/lob/v1/address.rb +0 -41
  46. data/lib/lob/v1/area.rb +0 -27
  47. data/lib/lob/v1/bank_account.rb +0 -37
  48. data/lib/lob/v1/check.rb +0 -33
  49. data/lib/lob/v1/country.rb +0 -21
  50. data/lib/lob/v1/job.rb +0 -39
  51. data/lib/lob/v1/letter.rb +0 -33
  52. data/lib/lob/v1/object.rb +0 -33
  53. data/lib/lob/v1/postcard.rb +0 -33
  54. data/lib/lob/v1/resource.rb +0 -69
  55. data/lib/lob/v1/route.rb +0 -27
  56. data/lib/lob/v1/setting.rb +0 -25
  57. data/lib/lob/v1/state.rb +0 -21
  58. data/spec/lob/v1/job_spec.rb +0 -161
  59. data/spec/lob/v1/object_spec.rb +0 -72
  60. data/spec/lob/v1/resource_spec.rb +0 -41
  61. data/spec/lob/v1/setting_spec.rb +0 -21
data/lib/lob/v1/route.rb DELETED
@@ -1,27 +0,0 @@
1
- module Lob
2
- module V1
3
- class Route
4
- def initialize(resource)
5
- @resource = resource
6
- end
7
-
8
- def find(route)
9
- Lob.submit :get, route_url(route)
10
- end
11
-
12
- def list(options = {})
13
- if options.is_a?(String)
14
- Lob.submit(:get, route_url(options))
15
- else
16
- Lob.submit(:get, route_url, options)
17
- end
18
- end
19
-
20
- private
21
-
22
- def route_url(route_id = nil)
23
- @resource.construct_url("routes", route_id)
24
- end
25
- end
26
- end
27
- end
@@ -1,25 +0,0 @@
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)
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/v1/state.rb DELETED
@@ -1,21 +0,0 @@
1
- module Lob
2
- module V1
3
- class State
4
-
5
- def initialize(resource)
6
- @resource = resource
7
- end
8
-
9
- def list(options={})
10
- Lob.submit(:get, state_url, options)
11
- end
12
-
13
- private
14
-
15
- def state_url
16
- @resource.construct_url("states")
17
- end
18
-
19
- end
20
- end
21
- end
@@ -1,161 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Lob::V1::Job do
4
-
5
- before :each do
6
- @sample_address_params = {
7
- name: "TestAddress",
8
- email: "test@test.com",
9
- address_line1: "123 Test Street",
10
- address_line2: "Unit 199",
11
- address_city: "Mountain View",
12
- address_state: "CA",
13
- address_country: "US",
14
- address_zip: 94085
15
- }
16
-
17
- @sample_job_params = { description: "TestJob" }
18
- @sample_object_params = { description: "TestObject" }
19
- @test_setting_id = 201
20
- end
21
-
22
- subject { Lob(api_key: ENV["LOB_API_KEY"]) }
23
-
24
- describe "list" do
25
- it "should list jobs" do
26
- assert subject.jobs.list["object"] == "list"
27
- end
28
- end
29
-
30
- describe "create" do
31
- it "should create a job with address_id" do
32
- new_address = subject.addresses.create @sample_address_params
33
-
34
- settings_list = subject.settings.list
35
- new_object = subject.objects.create(
36
- description: @sample_object_params[:description],
37
- file: "https://lob.com/postcardfront.pdf",
38
- setting: @test_setting_id
39
- )
40
-
41
- result = subject.jobs.create(
42
- description: @sample_job_params[:description],
43
- from: new_address["id"],
44
- to: new_address["id"],
45
- objects: new_object["id"]
46
- )
47
- result["description"].must_equal(@sample_job_params[:description])
48
- end
49
-
50
- it "should be able to create multiple jobs" do
51
- new_address = subject.addresses.create @sample_address_params
52
-
53
- settings_list = subject.settings.list
54
-
55
- new_object_params = {
56
- description: @sample_object_params[:description],
57
- file: "https://lob.com/postcardfront.pdf",
58
- setting: 500
59
- }
60
-
61
- another_object_params = {
62
- description: "Another #{@sample_object_params[:description]}",
63
- file: "https://lob.com/postcardfront.pdf",
64
- setting: 500
65
- }
66
-
67
- result = subject.jobs.create(
68
- description: @sample_job_params[:description],
69
- from: new_address["id"],
70
- to: new_address["id"],
71
- objects: [new_object_params, another_object_params]
72
- )
73
-
74
- result["description"].must_equal(@sample_job_params[:description])
75
- end
76
-
77
- it "should be able to create jobs from a mix of remote and local files" do
78
- new_address = subject.addresses.create @sample_address_params
79
-
80
- new_object_params = {
81
- description: @sample_object_params[:description],
82
- file: File.new(File.expand_path("../../../samples/postcardfront.pdf", __FILE__)),
83
- setting: 500
84
- }
85
-
86
- another_object_params = {
87
- description: "Another #{@sample_object_params[:description]}",
88
- file: "https://lob.com/postcardfront.pdf",
89
- setting: 500
90
- }
91
-
92
- result = subject.jobs.create(
93
- description: @sample_job_params[:description],
94
- from: new_address["id"],
95
- to: new_address["id"],
96
- objects: [new_object_params, another_object_params]
97
- )
98
-
99
- result["description"].must_equal(@sample_job_params[:description])
100
- end
101
-
102
- it "should create a job with address params" do
103
- settings_list = subject.settings.list
104
- new_object = subject.objects.create(
105
- description: @sample_object_params[:description],
106
- file: "https://lob.com/postcardfront.pdf",
107
- setting: @test_setting_id
108
- )
109
-
110
- result = subject.jobs.create(
111
- description: @sample_job_params[:description],
112
- from: @sample_address_params,
113
- to: @sample_address_params,
114
- objects: new_object["id"]
115
- )
116
- result["description"].must_equal(@sample_job_params[:description])
117
- end
118
-
119
- it "should create a job with object params" do
120
- new_address = subject.addresses.create @sample_address_params
121
- settings_list = subject.settings.list
122
- new_object_params = {
123
- description: @sample_object_params[:description],
124
- file: "https://lob.com/postcardfront.pdf",
125
- setting: @test_setting_id
126
- }
127
-
128
- result = subject.jobs.create(
129
- description: @sample_job_params[:description],
130
- from: new_address["id"],
131
- to: new_address["id"],
132
- objects: new_object_params
133
- )
134
- result["description"].must_equal(@sample_job_params[:description])
135
- end
136
- end
137
-
138
- describe "find" do
139
- it "should find a job" do
140
- new_address = subject.addresses.create @sample_address_params
141
-
142
- settings_list = subject.settings.list
143
- new_object = subject.objects.create(
144
- description: @sample_object_params[:description],
145
- file: "https://lob.com/postcardfront.pdf",
146
- setting: @test_setting_id
147
- )
148
-
149
- new_job = subject.jobs.create(
150
- description: @sample_job_params[:description],
151
- from: new_address["id"],
152
- to: new_address["id"],
153
- objects: new_object["id"]
154
- )
155
-
156
- result = subject.jobs.find(new_job["id"])
157
- result["description"].must_equal(@sample_job_params[:description])
158
- end
159
- end
160
-
161
- end
@@ -1,72 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Lob::V1::Object do
4
-
5
- before :each do
6
- @sample_params = {
7
- description: "TestObject",
8
- }
9
- @test_setting_id = 201
10
- end
11
-
12
- subject { Lob(api_key: ENV["LOB_API_KEY"]) }
13
-
14
- describe "list" do
15
- it "should list objects" do
16
- assert subject.objects.list["object"] == "list"
17
- end
18
- end
19
-
20
- describe "create" do
21
- it "should create an object with file url" do
22
- settings_list = subject.settings.list
23
- result = subject.objects.create(
24
- description: @sample_params[:description],
25
- file: "https://lob.com/postcardfront.pdf",
26
- setting: @test_setting_id
27
- )
28
-
29
- result["description"].must_equal(@sample_params[:description])
30
- end
31
-
32
- it "should create an object with file" do
33
- settings_list = subject.settings.list
34
- result = subject.objects.create(
35
- description: @sample_params[:description],
36
- file: File.new(File.expand_path("../../../samples/postcardfront.pdf", __FILE__), "rb"),
37
- setting: @test_setting_id
38
- )
39
-
40
- result["description"].must_equal(@sample_params[:description])
41
- end
42
- end
43
-
44
- describe "find" do
45
- it "should find an object" do
46
- settings_list = subject.settings.list
47
- new_object = subject.objects.create(
48
- description: @sample_params[:description],
49
- file: "https://lob.com/postcardfront.pdf",
50
- setting: @test_setting_id
51
- )
52
-
53
- find_result = subject.objects.find(new_object["id"])
54
- find_result["description"].must_equal(@sample_params[:description])
55
- end
56
- end
57
-
58
- describe "destroy" do
59
- it "should delete an object" do
60
- settings_list = subject.settings.list
61
- new_object = subject.objects.create(
62
- description: @sample_params[:description],
63
- file: "https://lob.com/postcardfront.pdf",
64
- setting: @test_setting_id
65
- )
66
-
67
- delete_result = subject.objects.destroy(new_object["id"])
68
- assert_equal(new_object["id"], delete_result["id"])
69
- end
70
- end
71
-
72
- end
@@ -1,41 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Lob::V1::Resource do
4
-
5
- before :each do
6
- @api_key = "test"
7
- end
8
-
9
- subject { Lob(api_key: @api_key) }
10
-
11
- describe "when Lob is initialized" do
12
- it "should receive and contain default options when Lob is initialized" do
13
- subject.options[:protocol].must_equal "https"
14
- subject.options[:api_host].must_equal "api.lob.com"
15
- end
16
-
17
- it "should have API key in options" do
18
- subject.options[:api_key].must_equal @api_key
19
- end
20
- end
21
-
22
- it "should return addresses resource" do
23
- subject.addresses.must_be_kind_of(Lob::V1::Address)
24
- end
25
-
26
- it "should return jobs resource" do
27
- subject.jobs.must_be_kind_of(Lob::V1::Job)
28
- end
29
-
30
- it "should return objects resource" do
31
- subject.objects.must_be_kind_of(Lob::V1::Object)
32
- end
33
-
34
- it "should return postcards resource" do
35
- subject.postcards.must_be_kind_of(Lob::V1::Postcard)
36
- end
37
-
38
- it "should return settings resource" do
39
- subject.settings.must_be_kind_of(Lob::V1::Setting)
40
- end
41
- end
@@ -1,21 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Lob::V1::Setting do
4
-
5
- subject { Lob(api_key: ENV["LOB_API_KEY"]) }
6
-
7
- describe "list" do
8
- it "should list settings" do
9
- assert subject.settings.list["object"] == "list"
10
- end
11
- end
12
-
13
-
14
- describe "find" do
15
- it "should find a setting" do
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"])
19
- end
20
- end
21
- end