lob 5.2.0 → 5.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'lob'
3
+ require 'pp'
4
+
5
+ # initialize Lob object
6
+ lob = Lob::Client.new(api_key: 'YOUR_API_KEY')
7
+
8
+ # HTML to send to the server
9
+ html = %{
10
+ <html>
11
+ <head>
12
+ <title>Lob.com Sample 4x6 Postcard Front</title>
13
+ <style>
14
+ *, *:before, *:after {
15
+ -webkit-box-sizing: border-box;
16
+ -moz-box-sizing: border-box;
17
+ box-sizing: border-box;
18
+ }
19
+
20
+ @font-face {
21
+ font-family: 'Loved by the King';
22
+ font-style: normal;
23
+ font-weight: 400;
24
+ src: url('https://s3-us-west-2.amazonaws.com/public.lob.com/fonts/lovedByTheKing/LovedbytheKing.ttf') format('truetype');
25
+ }
26
+
27
+ body {
28
+ width: 6.25in;
29
+ height: 4.25in;
30
+ margin: 0;
31
+ padding: 0;
32
+ /* If using an image, the background image should have dimensions of 1875x1275 pixels. */
33
+ background-image: url('https://s3-us-west-2.amazonaws.com/public.lob.com/assets/beach.jpg');
34
+ background-size: 6.25in 4.25in;
35
+ background-repeat: no-repeat;
36
+ }
37
+
38
+ .text {
39
+ margin: 50px;
40
+ width: 400px;
41
+ font-family: 'Loved by the King';
42
+ font-size: 50px;
43
+ font-weight: 700;
44
+ color: white;
45
+ text-shadow: 3px 3px black;
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <h1 class="text">Hello {{name}}!</h1>
52
+ <p class="text">Join us for the {{event}}!</p>
53
+ </body>
54
+
55
+ </html>
56
+ }
57
+
58
+ # create a to address
59
+ to_address = lob.addresses.create(
60
+ name: "ToAddress",
61
+ address_line1: "370 Water St",
62
+ address_city: "Summerside",
63
+ address_state: "Prince Edward Island",
64
+ address_country: "CA",
65
+ address_zip: "C1N 1C4"
66
+ )
67
+
68
+ # create a from address
69
+ from_address = lob.addresses.create(
70
+ name: "FromAddress",
71
+ address_line1: "120 6th Ave",
72
+ address_city: "Boston",
73
+ address_state: "MA",
74
+ address_country: "US",
75
+ address_zip: 12345
76
+ )
77
+
78
+ # send a postcard
79
+ pp lob.postcards.create(
80
+ description: "Beach Postcard",
81
+ to: to_address["id"],
82
+ from: from_address["id"],
83
+ metadata: { campaign: "Summer 2015 Beach" },
84
+ merge_variables: { name: "Albert", event: "Summer 2015 Beach-athon" },
85
+ front: html,
86
+ back: "<h1>Please RSVP as soon as possible to reserve your lounge chair.</h1>"
87
+ )
@@ -0,0 +1,87 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'lob.rb'
3
+ require 'pp'
4
+
5
+ # initialize Lob object
6
+ lob = Lob::Client.new(api_key: 'YOUR_API_KEY')
7
+
8
+ # HTML to send to the server
9
+ html = %{
10
+ <html>
11
+ <head>
12
+ <title>Lob.com Sample 4x6 Postcard Front</title>
13
+ <style>
14
+ *, *:before, *:after {
15
+ -webkit-box-sizing: border-box;
16
+ -moz-box-sizing: border-box;
17
+ box-sizing: border-box;
18
+ }
19
+
20
+ @font-face {
21
+ font-family: 'Loved by the King';
22
+ font-style: normal;
23
+ font-weight: 400;
24
+ src: url('https://s3-us-west-2.amazonaws.com/public.lob.com/fonts/lovedByTheKing/LovedbytheKing.ttf') format('truetype');
25
+ }
26
+
27
+ body {
28
+ width: 6.25in;
29
+ height: 4.25in;
30
+ margin: 0;
31
+ padding: 0;
32
+ /* If using an image, the background image should have dimensions of 1875x1275 pixels. */
33
+ background-image: url('https://s3-us-west-2.amazonaws.com/public.lob.com/assets/beach.jpg');
34
+ background-size: 6.25in 4.25in;
35
+ background-repeat: no-repeat;
36
+ }
37
+
38
+ .text {
39
+ margin: 50px;
40
+ width: 400px;
41
+ font-family: 'Loved by the King';
42
+ font-size: 50px;
43
+ font-weight: 700;
44
+ color: white;
45
+ text-shadow: 3px 3px black;
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <h1 class="text">Hello {{name}}!</h1>
52
+ <p class="text">Join us for the {{event}}!</p>
53
+ </body>
54
+
55
+ </html>
56
+ }
57
+
58
+ # create a to address
59
+ to_address = lob.addresses.create(
60
+ name: "ToAddress",
61
+ address_line1: "120 6th Ave",
62
+ address_city: "Boston",
63
+ address_state: "MA",
64
+ address_country: "US",
65
+ address_zip: 12345
66
+ )
67
+
68
+ # create a from address
69
+ from_address = lob.addresses.create(
70
+ name: "FromAddress",
71
+ address_line1: "120 6th Ave",
72
+ address_city: "Boston",
73
+ address_state: "MA",
74
+ address_country: "US",
75
+ address_zip: 12345
76
+ )
77
+
78
+ # send a postcard
79
+ pp lob.postcards.create(
80
+ description: "Beach Postcard",
81
+ to: to_address["id"],
82
+ from: from_address["id"],
83
+ metadata: { campaign: "Summer 2015 Beach" },
84
+ merge_variables: { name: "Albert", event: "Summer 2015 Beach-athon" },
85
+ front: 'https://s3-us-west-2.amazonaws.com/public.lob.com/assets/templates/4x6_pc_template.pdf',
86
+ back: 'https://s3-us-west-2.amazonaws.com/public.lob.com/assets/templates/4x6_pc_template.pdf'
87
+ )
@@ -0,0 +1,97 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'lob.rb'
3
+ require 'pp'
4
+ require 'date'
5
+
6
+ # initialize Lob object
7
+ lob = Lob::Client.new(api_key: 'YOUR_API_KEY')
8
+
9
+ # HTML to send to the server
10
+ html = %{
11
+ <html>
12
+ <head>
13
+ <title>Lob.com Sample 4x6 Postcard Front</title>
14
+ <style>
15
+ *, *:before, *:after {
16
+ -webkit-box-sizing: border-box;
17
+ -moz-box-sizing: border-box;
18
+ box-sizing: border-box;
19
+ }
20
+
21
+ @font-face {
22
+ font-family: 'Loved by the King';
23
+ font-style: normal;
24
+ font-weight: 400;
25
+ src: url('https://s3-us-west-2.amazonaws.com/public.lob.com/fonts/lovedByTheKing/LovedbytheKing.ttf') format('truetype');
26
+ }
27
+
28
+ body {
29
+ width: 6.25in;
30
+ height: 4.25in;
31
+ margin: 0;
32
+ padding: 0;
33
+ /* If using an image, the background image should have dimensions of 1875x1275 pixels. */
34
+ background-image: url('https://s3-us-west-2.amazonaws.com/public.lob.com/assets/beach.jpg');
35
+ background-size: 6.25in 4.25in;
36
+ background-repeat: no-repeat;
37
+ }
38
+
39
+ .text {
40
+ margin: 50px;
41
+ width: 400px;
42
+ font-family: 'Loved by the King';
43
+ font-size: 50px;
44
+ font-weight: 700;
45
+ color: white;
46
+ text-shadow: 3px 3px black;
47
+ }
48
+ </style>
49
+ </head>
50
+
51
+ <body>
52
+ <h1 class="text">Hello {{name}}!</h1>
53
+ <p class="text">Join us for the {{event}}!</p>
54
+ </body>
55
+
56
+ </html>
57
+ }
58
+
59
+ # create a to address
60
+ to_address = lob.addresses.create(
61
+ name: "ToAddress",
62
+ address_line1: "120 6th Ave",
63
+ address_city: "Boston",
64
+ address_state: "MA",
65
+ address_country: "US",
66
+ address_zip: 12345
67
+ )
68
+
69
+ # create a from address
70
+ from_address = lob.addresses.create(
71
+ name: "FromAddress",
72
+ address_line1: "120 6th Ave",
73
+ address_city: "Boston",
74
+ address_state: "MA",
75
+ address_country: "US",
76
+ address_zip: 12345
77
+ )
78
+
79
+ def get_date()
80
+ time = Time.new
81
+ if time.month == 12
82
+ return "#{time.year + 1}-01-#{time.day}"
83
+ else
84
+ return "#{time.year}-#{time.month + 1}-#{time.day}"
85
+ end
86
+ end
87
+
88
+ pp lob.postcards.create(
89
+ description: "Beach Postcard",
90
+ to: to_address["id"],
91
+ from: from_address["id"],
92
+ metadata: { campaign: "Summer 2015 Beach" },
93
+ merge_variables: { name: "Albert", event: "Summer 2015 Beach-athon" },
94
+ front: html,
95
+ back: "<h1>Please RSVP as soon as possible to reserve your lounge chair.</h1>",
96
+ send_date: get_date()
97
+ )
@@ -0,0 +1,98 @@
1
+ $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
+ require 'lob.rb'
3
+ require 'pp'
4
+
5
+ # initialize Lob object
6
+ # this key is publicly available in the legacy docs, so it's hardcoded
7
+ # since the templates are associated with this dummy account
8
+ # you can replace this key with your own, and the IDs below with any
9
+ # saved templates you have
10
+ lob = Lob::Client.new(api_key: 'test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc')
11
+
12
+ # HTML to send to the server
13
+ html = %{
14
+ <html>
15
+ <head>
16
+ <title>Lob.com Sample 4x6 Postcard Front</title>
17
+ <style>
18
+ *, *:before, *:after {
19
+ -webkit-box-sizing: border-box;
20
+ -moz-box-sizing: border-box;
21
+ box-sizing: border-box;
22
+ }
23
+
24
+ @font-face {
25
+ font-family: 'Loved by the King';
26
+ font-style: normal;
27
+ font-weight: 400;
28
+ src: url('https://s3-us-west-2.amazonaws.com/public.lob.com/fonts/lovedByTheKing/LovedbytheKing.ttf') format('truetype');
29
+ }
30
+
31
+ body {
32
+ width: 6.25in;
33
+ height: 4.25in;
34
+ margin: 0;
35
+ padding: 0;
36
+ /* If using an image, the background image should have dimensions of 1875x1275 pixels. */
37
+ background-image: url('https://s3-us-west-2.amazonaws.com/public.lob.com/assets/beach.jpg');
38
+ background-size: 6.25in 4.25in;
39
+ background-repeat: no-repeat;
40
+ }
41
+
42
+ .text {
43
+ margin: 50px;
44
+ width: 400px;
45
+ font-family: 'Loved by the King';
46
+ font-size: 50px;
47
+ font-weight: 700;
48
+ color: white;
49
+ text-shadow: 3px 3px black;
50
+ }
51
+ </style>
52
+ </head>
53
+
54
+ <body>
55
+ <h1 class="text">Hello {{name}}!</h1>
56
+ <p class="text">Join us for the {{event}}!</p>
57
+ </body>
58
+
59
+ </html>
60
+ }
61
+
62
+ # create a to address
63
+ to_address = lob.addresses.create(
64
+ {
65
+ "name": "ToAddress",
66
+ "address_line1": "120 6th Ave",
67
+ "address_city": "Boston",
68
+ "address_state": "MA",
69
+ "address_country": "US",
70
+ "address_zip": 12345
71
+ }
72
+ )
73
+
74
+ # create a from address
75
+ from_address = lob.addresses.create(
76
+ {
77
+ "name": "FromAddress",
78
+ "address_line1": "120 6th Ave",
79
+ "address_city": "Boston",
80
+ "address_state": "MA",
81
+ "address_country": "US",
82
+ "address_zip": 12345
83
+ }
84
+ )
85
+
86
+ # send a postcard
87
+ pp lob.postcards.create(
88
+ {
89
+ "description": "Beach Postcard",
90
+ "to": to_address["id"],
91
+ "from": from_address["id"],
92
+ "metadata": { campaign: "Summer 2015 Beach" },
93
+ "merge_variables": { name: "Albert", event: "Summer 2015 Beach-athon" },
94
+ # you can replace these template IDs
95
+ "front": 'tmpl_b846a20859ae11a',
96
+ "back": 'tmpl_01b0d396a10c268'
97
+ }
98
+ )
@@ -1,8 +1,9 @@
1
1
  $:.unshift File.expand_path("../lib", File.dirname(__FILE__))
2
2
  require 'lob'
3
+ require 'pp'
3
4
 
4
5
  # initialize Lob object
5
- lob = Lob::Client.new(api_key: 'YOUR_API_KEY_HERE')
6
+ lob = Lob::Client.new(api_key: 'YOUR_API_KEY')
6
7
 
7
8
  # create a to address
8
9
  to_address = lob.addresses.create(
@@ -26,7 +27,7 @@ from_address = lob.addresses.create(
26
27
 
27
28
 
28
29
  # send a self mailer
29
- puts lob.self_mailers.create(
30
+ pp lob.self_mailers.create(
30
31
  description: "Beach Postcard",
31
32
  to: to_address["id"],
32
33
  from: from_address["id"],
data/lib/lob/client.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "lob/resources/address"
2
2
  require "lob/resources/bank_account"
3
+ require "lob/resources/bulk_intl_verifications"
4
+ require "lob/resources/bulk_us_verifications"
3
5
  require "lob/resources/check"
4
6
  require "lob/resources/group"
5
7
  require "lob/resources/groups_member"
@@ -8,6 +10,7 @@ require "lob/resources/letter"
8
10
  require "lob/resources/postcard"
9
11
  require "lob/resources/self_mailer"
10
12
  require "lob/resources/us_autocompletions"
13
+ require "lob/resources/us_reverse_geocode_lookups"
11
14
  require "lob/resources/us_verifications"
12
15
  require "lob/resources/us_zip_lookups"
13
16
 
@@ -32,6 +35,14 @@ module Lob
32
35
  Lob::Resources::BankAccount.new(config)
33
36
  end
34
37
 
38
+ def bulk_intl_verifications
39
+ Lob::Resources::BulkIntlVerifications.new(config)
40
+ end
41
+
42
+ def bulk_us_verifications
43
+ Lob::Resources::BulkUSVerifications.new(config)
44
+ end
45
+
35
46
  def checks
36
47
  Lob::Resources::Check.new(config)
37
48
  end
@@ -64,6 +75,10 @@ module Lob
64
75
  Lob::Resources::USAutocompletions.new(config)
65
76
  end
66
77
 
78
+ def us_reverse_geocode_lookups
79
+ Lob::Resources::USReverseGeocodeLookups.new(config)
80
+ end
81
+
67
82
  def us_verifications
68
83
  Lob::Resources::USVerifications.new(config)
69
84
  end
@@ -0,0 +1,26 @@
1
+ require "lob/resources/resource_base"
2
+
3
+ module Lob
4
+ module Resources
5
+ class BulkIntlVerifications < Lob::Resources::ResourceBase
6
+
7
+ undef_method :list, :find, :create, :destroy
8
+
9
+ def initialize(config)
10
+ super(config)
11
+ @endpoint = "bulk/intl_verifications"
12
+ end
13
+
14
+ def verify(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
@@ -0,0 +1,27 @@
1
+ require "lob/resources/resource_base"
2
+
3
+ module Lob
4
+ module Resources
5
+ class BulkUSVerifications < Lob::Resources::ResourceBase
6
+
7
+ undef_method :list, :find, :create, :destroy
8
+
9
+ def initialize(config)
10
+ super(config)
11
+ @endpoint = "bulk/us_verifications"
12
+ end
13
+
14
+ def verify(body={}, query={})
15
+ request = {
16
+ method: :post,
17
+ url: endpoint_url,
18
+ body: body,
19
+ query: query
20
+ }
21
+
22
+ submit request
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require "lob/resources/resource_base"
2
+
3
+ module Lob
4
+ module Resources
5
+ class USReverseGeocodeLookups < Lob::Resources::ResourceBase
6
+
7
+ undef_method :list, :find, :create, :destroy
8
+
9
+ def initialize(config)
10
+ super(config)
11
+ @endpoint = "us_reverse_geocode_lookups"
12
+ end
13
+
14
+ def lookup(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 = "5.2.0"
2
+ VERSION = "5.4.2"
3
3
  end
data/lob.gemspec CHANGED
@@ -23,6 +23,8 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake", "~> 12.3.3"
24
24
  spec.add_development_dependency "minitest", "~> 5.6.1"
25
25
  spec.add_development_dependency "webmock", "~> 1.2"
26
- spec.add_development_dependency "coveralls", "~> 0.8.13"
27
- spec.add_development_dependency "simplecov", "~> 0.11.0"
26
+ spec.add_development_dependency "coveralls_reborn", "~> 0.23.1"
27
+ spec.add_development_dependency "simplecov", "~> 0.21.0"
28
+ spec.add_development_dependency "json", "~> 2.3.1"
29
+ spec.add_development_dependency "uri", "~> 0.10.1"
28
30
  end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe Lob::Resources::BulkIntlVerifications do
4
+
5
+ before :each do
6
+ @sample_params = {
7
+ addresses: [
8
+ {
9
+ primary_line: "123 Test St",
10
+ city: "HEARST",
11
+ state: "ONTARIO",
12
+ postal_code: "P0L1N0",
13
+ country: "CA"
14
+ }
15
+ ]
16
+ }
17
+ end
18
+
19
+ subject { Lob::Client.new(api_key: API_KEY) }
20
+
21
+ describe "verify" do
22
+ it "should verify an international address" do
23
+ result = subject.bulk_intl_verifications.verify @sample_params
24
+ addresses = result["addresses"]
25
+ address = addresses.first
26
+ address["recipient"].must_equal("TEST KEYS DO NOT VERIFY ADDRESSES")
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+ describe Lob::Resources::BulkUSVerifications do
4
+
5
+ before :each do
6
+ @sample_params = {
7
+ addresses: [
8
+ {
9
+ recipient: "LOB.COM",
10
+ primary_line: "185 BERRY ST STE 6600",
11
+ city: "SAN FRANCISCO",
12
+ state: "CA",
13
+ zip_code: "94107"
14
+ }
15
+ ]
16
+ }
17
+ end
18
+
19
+ subject { Lob::Client.new(api_key: API_KEY) }
20
+
21
+ describe "verify" do
22
+ it "should verify a US address" do
23
+ result = subject.bulk_us_verifications.verify @sample_params
24
+ addresses = result["addresses"]
25
+ address = addresses.first
26
+ address["recipient"].must_equal("TEST KEYS DO NOT VERIFY ADDRESSES")
27
+ end
28
+
29
+ it "should allow 'case' in query params" do
30
+ result = subject.bulk_us_verifications.verify @sample_params, {case: "proper"}
31
+ addresses = result["addresses"]
32
+ address = addresses.first
33
+ address["recipient"].must_equal("Test Keys Do Not Verify Addresses")
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ describe Lob::Resources::USReverseGeocodeLookups do
4
+
5
+ before :each do
6
+ @sample_params = {
7
+ latitude: 37.777456,
8
+ longitude: -122.393039
9
+ }
10
+ end
11
+
12
+ subject { Lob::Client.new(api_key: API_KEY) }
13
+
14
+ describe "lookup" do
15
+ it "should reverse geocode a valid US location" do
16
+ result = subject.us_reverse_geocode_lookups.lookup @sample_params
17
+ puts result["addresses"][0]["components"]["zip_code"].class
18
+ result["addresses"].length.must_equal(5)
19
+ end
20
+ end
21
+
22
+ end