lob 4.2.0 → 5.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,7 +19,7 @@ module Lob
19
19
  query: query
20
20
  }
21
21
 
22
- submit request
22
+ submit(request)
23
23
  end
24
24
 
25
25
  def find(resource_id)
@@ -28,7 +28,7 @@ module Lob
28
28
  url: resource_url(resource_id)
29
29
  }
30
30
 
31
- submit request
31
+ submit(request)
32
32
  end
33
33
 
34
34
  def create(body={}, headers={}, query={})
@@ -40,7 +40,7 @@ module Lob
40
40
  query: query
41
41
  }
42
42
 
43
- submit request
43
+ submit(request)
44
44
  end
45
45
 
46
46
  def destroy(resource_id)
@@ -49,7 +49,7 @@ module Lob
49
49
  url: resource_url(resource_id)
50
50
  }
51
51
 
52
- submit request
52
+ submit(request)
53
53
  end
54
54
 
55
55
  private
@@ -71,11 +71,14 @@ module Lob
71
71
  if query != {}
72
72
  url = "#{url}?#{build_nested_query(query)}"
73
73
  end
74
-
74
+
75
75
  begin
76
76
  if method == :get || method == :delete
77
77
  response = RestClient.send(method, url, headers)
78
78
  else
79
+ if body[:merge_variables] and body[:merge_variables].class == Hash
80
+ body[:merge_variables] = body[:merge_variables].to_json()
81
+ end
79
82
  response = RestClient.send(method, url, body, headers)
80
83
  end
81
84
 
@@ -0,0 +1,26 @@
1
+ require "lob/resources/resource_base"
2
+
3
+ module Lob
4
+ module Resources
5
+ class USAutocompletions < Lob::Resources::ResourceBase
6
+
7
+ undef_method :list, :find, :create, :destroy
8
+
9
+ def initialize(config)
10
+ super(config)
11
+ @endpoint = "us_autocompletions"
12
+ end
13
+
14
+ def autocomplete(body={})
15
+ request = {
16
+ method: :post,
17
+ url: endpoint_url,
18
+ body: body
19
+ }
20
+
21
+ submit request
22
+ end
23
+
24
+ end
25
+ end
26
+ end
data/lib/lob/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lob
2
- VERSION = "4.2.0"
2
+ VERSION = "5.1.2"
3
3
  end
data/lob.gemspec CHANGED
@@ -18,14 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "rest-client", ">= 1.8", "< 3.0"
21
+ spec.add_dependency "rest-client", ">= 2.0.1", "< 3.0"
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake", "~> 10.4.2"
23
+ spec.add_development_dependency "rake", "~> 12.3.3"
25
24
  spec.add_development_dependency "minitest", "~> 5.6.1"
26
25
  spec.add_development_dependency "webmock", "~> 1.2"
27
- spec.add_development_dependency "travis-lint", "~> 2.0.0"
28
- spec.add_development_dependency "coveralls", "~> 0.8.1"
29
- spec.add_development_dependency "simplecov", "~> 0.10.0"
30
- spec.add_development_dependency "pry", "~> 0.10.0"
26
+ spec.add_development_dependency "coveralls", "~> 0.8.13"
27
+ spec.add_development_dependency "simplecov", "~> 0.11.0"
31
28
  end
@@ -50,6 +50,27 @@ describe Lob::Resources::Check do
50
50
 
51
51
  result["amount"].to_s.must_equal("2000.12")
52
52
  end
53
+
54
+ it "should create a check with a merge variable conditional" do
55
+ new_address = subject.addresses.create @sample_address_params
56
+
57
+ new_bank_account = subject.bank_accounts.create(@sample_bank_account_params)
58
+
59
+ subject.bank_accounts.verify(new_bank_account["id"], amounts: [1, 2])
60
+
61
+ result = subject.checks.create(
62
+ bank_account: new_bank_account["id"],
63
+ to: new_address["id"],
64
+ from: new_address["id"],
65
+ amount: "2000.12",
66
+ attachment: "<html>{{#is_awesome}}You are awesome!{{/is_awesome}}</html>",
67
+ merge_variables: {
68
+ is_awesome: false
69
+ }
70
+ )
71
+
72
+ result["merge_variables"]["is_awesome"].must_equal(false)
73
+ end
53
74
  end
54
75
 
55
76
 
@@ -0,0 +1,50 @@
1
+ require "spec_helper"
2
+
3
+ describe Lob::Resources::Group do
4
+
5
+ before :each do
6
+ @sample_params = {
7
+ description: "Unsubscribe group",
8
+ metadata: {
9
+ test: 'stuff'
10
+ }
11
+ }
12
+ end
13
+
14
+ subject { Lob::Client.new(api_key: API_KEY) }
15
+
16
+ describe "list" do
17
+ it "should list groups" do
18
+ assert subject.groups.list["object"] == "list"
19
+ end
20
+ end
21
+
22
+
23
+ describe "create" do
24
+ it "should create a group" do
25
+ result = subject.groups.create @sample_params
26
+
27
+ result["description"].must_equal(@sample_params[:description])
28
+ end
29
+ end
30
+
31
+
32
+ describe "find" do
33
+ it "should find a group" do
34
+ new_group = subject.groups.create @sample_params
35
+
36
+ find_result = subject.groups.find(new_group["id"])
37
+ find_result["description"].must_equal(@sample_params[:description])
38
+ end
39
+ end
40
+
41
+
42
+ describe "destroy" do
43
+ it "should delete a group" do
44
+ new_group = subject.groups.create @sample_params
45
+
46
+ delete_result = subject.groups.destroy(new_group["id"])
47
+ assert_equal(new_group["id"], delete_result["id"])
48
+ end
49
+ end
50
+ end
@@ -15,13 +15,10 @@ describe Lob::Resources::IntlVerifications do
15
15
  subject { Lob::Client.new(api_key: API_KEY) }
16
16
 
17
17
  describe "verify" do
18
- it "should return a 403 in test mode" do
19
- begin
20
- subject.intl_verifications.verify @sample_params
21
- rescue Lob::InvalidRequestError => e
22
- assert e.http_status == 403
23
- assert e._response.headers.include?(:content_type)
24
- end
18
+ it "should verify an international address" do
19
+ result = subject.intl_verifications.verify @sample_params
20
+
21
+ result["recipient"].must_equal("TEST KEYS DO NOT VERIFY ADDRESSES")
25
22
  end
26
23
  end
27
24
 
@@ -31,7 +31,7 @@ describe Lob::Resources::Letter do
31
31
  new_letter = subject.letters.create(
32
32
  description: "TestLetter",
33
33
  color: true,
34
- file: "https://s3-us-west-2.amazonaws.com/lob-assets/letter-goblue.pdf",
34
+ file: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/us_letter_1pg.pdf",
35
35
  to: new_address["id"],
36
36
  from: @sample_address_params
37
37
  )
@@ -52,6 +52,26 @@ describe Lob::Resources::Letter do
52
52
 
53
53
  new_letter["description"].must_equal("TestLetter")
54
54
  end
55
+
56
+ it "should create a letter with a merge variable object" do
57
+ new_address = subject.addresses.create @sample_address_params
58
+
59
+ new_letter = subject.letters.create(
60
+ description: "TestLetter",
61
+ color: true,
62
+ file: "<html>{{data.name}}</html>",
63
+ to: new_address["id"],
64
+ from: @sample_address_params,
65
+ merge_variables: {
66
+ data: {
67
+ name: "Kobe"
68
+ }
69
+ }
70
+ )
71
+
72
+ new_letter["description"].must_equal("TestLetter")
73
+ new_letter["merge_variables"]["data"]["name"].must_equal("Kobe")
74
+ end
55
75
  end
56
76
 
57
77
 
@@ -62,13 +82,13 @@ describe Lob::Resources::Letter do
62
82
  new_letter = subject.letters.create(
63
83
  description: "TestLetter",
64
84
  color: true,
65
- file: "https://s3-us-west-2.amazonaws.com/lob-assets/letter-goblue.pdf",
85
+ file: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/us_letter_1pg.pdf",
66
86
  to: new_address["id"],
67
87
  from: new_address["id"]
68
88
  )
69
89
 
70
90
  result = subject.letters.find(new_letter["id"])
71
- assert /#{new_letter["description"]}/ =~ result.to_s
91
+ assert %r{#{new_letter["description"]}} =~ result.to_s
72
92
  end
73
93
  end
74
94
 
@@ -80,7 +100,7 @@ describe Lob::Resources::Letter do
80
100
  new_letter = subject.letters.create(
81
101
  description: "TestLetter",
82
102
  color: true,
83
- file: "https://s3-us-west-2.amazonaws.com/lob-assets/letter-goblue.pdf",
103
+ file: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/us_letter_1pg.pdf",
84
104
  to: new_address["id"],
85
105
  from: new_address["id"]
86
106
  )
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ describe Lob::Resources::GroupsMember do
4
+
5
+ before :each do
6
+ @sample_group_params = {
7
+ description: "Unsubscribe group",
8
+ metadata: {
9
+ test: 'stuff'
10
+ }
11
+ }
12
+ @sample_member_params = {
13
+ recipient: {
14
+ name: 'Sophie',
15
+ address_line1: '185 Berry St',
16
+ address_line2: '6100',
17
+ address_city: 'San Francisco',
18
+ address_state: 'CA',
19
+ address_zip: '94107'
20
+ },
21
+ description: "Some Member",
22
+ metadata: {
23
+ test: 'stuff'
24
+ }
25
+ }
26
+ @new_group = subject.groups.create @sample_group_params
27
+ end
28
+
29
+ subject { Lob::Client.new(api_key: API_KEY) }
30
+
31
+ describe "list" do
32
+ it "should list members in a group" do
33
+ assert subject.groups_members.list(@new_group["id"])["object"] == "list"
34
+ end
35
+ end
36
+
37
+
38
+ describe "create" do
39
+ it "should create a member" do
40
+ result = subject.groups_members.create(@new_group["id"], @sample_member_params)
41
+
42
+ result["description"].must_equal(@sample_member_params[:description])
43
+ end
44
+ end
45
+
46
+
47
+ describe "find" do
48
+ it "should find a member" do
49
+ new_member = subject.groups_members.create(@new_group["id"], @sample_member_params)
50
+
51
+ find_result = subject.groups_members.find(@new_group["id"], new_member["id"])
52
+ find_result["description"].must_equal(@sample_member_params[:description])
53
+ end
54
+ end
55
+
56
+
57
+ describe "destroy" do
58
+ it "should delete a member" do
59
+ new_member = subject.groups_members.create(@new_group["id"], @sample_member_params)
60
+
61
+ delete_result = subject.groups_members.destroy(@new_group["id"], new_member["id"])
62
+ assert_equal(new_member["id"], delete_result["id"])
63
+ end
64
+ end
65
+ end
@@ -37,7 +37,7 @@ describe Lob::Resources::Postcard do
37
37
  description: @sample_postcard_params[:description],
38
38
  to: new_address["id"],
39
39
  back: @sample_postcard_params[:back],
40
- front: "https://lob.com/postcardfront.pdf"
40
+ front: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/pc_4x6_front.pdf"
41
41
  )
42
42
 
43
43
  result["description"].must_equal(@sample_postcard_params[:description])
@@ -48,7 +48,7 @@ describe Lob::Resources::Postcard do
48
48
  description: @sample_postcard_params[:description],
49
49
  to: @sample_address_params,
50
50
  back: @sample_postcard_params[:back],
51
- front: "https://lob.com/postcardfront.pdf"
51
+ front: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/pc_4x6_front.pdf"
52
52
  )
53
53
 
54
54
  result["description"].must_equal(@sample_postcard_params[:description])
@@ -62,7 +62,7 @@ describe Lob::Resources::Postcard do
62
62
  to: new_address["id"],
63
63
  from: @sample_address_params,
64
64
  back: @sample_postcard_params[:back],
65
- front: "https://lob.com/postcardfront.pdf"
65
+ front: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/pc_4x6_front.pdf"
66
66
  )
67
67
 
68
68
  result["description"].must_equal(@sample_postcard_params[:description])
@@ -74,8 +74,8 @@ describe Lob::Resources::Postcard do
74
74
  result = subject.postcards.create(
75
75
  description: @sample_postcard_params[:description],
76
76
  to: new_address["id"],
77
- front: "https://lob.com/postcardfront.pdf",
78
- back: "https://lob.com/postcardback.pdf"
77
+ front: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/pc_4x6_front.pdf",
78
+ back: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/pc_4x6_back.pdf"
79
79
  )
80
80
 
81
81
  result["description"].must_equal(@sample_postcard_params[:description])
@@ -95,6 +95,31 @@ describe Lob::Resources::Postcard do
95
95
  result["description"].must_equal(@sample_postcard_params[:description])
96
96
  end
97
97
 
98
+ it "should create a postcard with a merge variable list" do
99
+ new_address = subject.addresses.create @sample_address_params
100
+ merge_variables = {
101
+ list: [
102
+ {
103
+ name: "Larissa"
104
+ },
105
+ {
106
+ name: "Larry"
107
+ }
108
+ ]
109
+ }
110
+
111
+ result = subject.postcards.create(
112
+ description: @sample_postcard_params[:description],
113
+ to: new_address["id"],
114
+ back: "<html>{{#list}} {{name}} {{/list}}</html>",
115
+ front: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/pc_4x6_front.pdf",
116
+ merge_variables: merge_variables
117
+ )
118
+
119
+ result["description"].must_equal(@sample_postcard_params[:description])
120
+ result["merge_variables"]["list"][0]["name"].must_equal("Larissa")
121
+ result["merge_variables"]["list"][1]["name"].must_equal("Larry")
122
+ end
98
123
  end
99
124
 
100
125
 
@@ -2,22 +2,14 @@ require "spec_helper"
2
2
 
3
3
  describe Lob::Resources::ResourceBase do
4
4
 
5
- before :each do
6
- @api_key = API_KEY
7
- end
8
-
9
- subject { Lob::Client.new(api_key: @api_key) }
5
+ subject { Lob::Client.new(api_key: API_KEY) }
10
6
 
11
7
  describe "when Lob is initialized" do
12
8
  it "should have API key in config" do
13
- subject.config[:api_key].must_equal @api_key
9
+ subject.config[:api_key].must_equal API_KEY
14
10
  end
15
11
  end
16
12
 
17
- it "should return areas resource" do
18
- subject.areas.must_be_kind_of(Lob::Resources::Area)
19
- end
20
-
21
13
  it "should return addresses resource" do
22
14
  subject.addresses.must_be_kind_of(Lob::Resources::Address)
23
15
  end
@@ -38,10 +30,6 @@ describe Lob::Resources::ResourceBase do
38
30
  subject.postcards.must_be_kind_of(Lob::Resources::Postcard)
39
31
  end
40
32
 
41
- it "should return routes resource" do
42
- subject.routes.must_be_kind_of(Lob::Resources::Route)
43
- end
44
-
45
33
  it "should accept an idempotency_key" do
46
34
  sample_address_params = {
47
35
  name: "TestAddress",
@@ -67,7 +55,7 @@ describe Lob::Resources::ResourceBase do
67
55
  description: sample_postcard_params[:description],
68
56
  to: new_address["id"],
69
57
  back: sample_postcard_params[:back],
70
- front: "https://lob.com/postcardfront.pdf"
58
+ front: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/pc_4x6_front.pdf"
71
59
  }, {
72
60
  "Idempotency-Key" => idempotency_key
73
61
  })
@@ -76,7 +64,7 @@ describe Lob::Resources::ResourceBase do
76
64
  description: sample_postcard_params[:description],
77
65
  to: new_address["id"],
78
66
  back: sample_postcard_params[:back],
79
- front: "https://lob.com/postcardfront.pdf"
67
+ front: "https://s3-us-west-2.amazonaws.com/public.lob.com/assets/pc_4x6_front.pdf"
80
68
  }, {
81
69
  "Idempotency-Key" => idempotency_key
82
70
  })