Lob.com - a great web app for the custom postcards/letters sending, but one problem - official gem has very limited features implementation. For example Templates endpoint and other things.
Btw you can use - my fork with tiny patch for the templates support.
Start using this gem - super simple, for example - little service, which takes clien list and params:
class LobService
def self.call(clients, params)
lob_client = Lob::Client.new(api_key: ENV['LOB_API_KEY'])
front_html = File.open(File.join(Rails.root, 'public', 'postcards', 'postcard_front.html')).read
back_html = File.open(File.join(Rails.root, 'public', 'postcards', 'postcard_back.html')).read
clients.each do |client|
result = lob_client.postcards.create(
description: 'API TEST',
to: {
name: client.name,
address_line1: client.address_line1,
address_line2: client.address_line2,
address_city: client.address_city,
address_state: client.address_state,
address_zip: client.address_zip,
address_country: client.address_country,
},
from: {
name: 'Api User',
address_line1: '185 Berry Street',
address_city: 'San Francisco',
address_state: 'CA',
address_zip: '94117',
address_country: "US",
},
size: '6x11',
front: front_html,
back: back_html,
)
end
end
end
And we got output JSON:
{
"id": "psc_14c1b66f31264c34",
"description": "API TEST",
"metadata": {},
"to": {
"id": "adr_d3489cd64c791ab5",
"description": null,
"name": "HARRY ZHANG",
"company": null,
"phone": null,
"email": null,
"address_line1": "185 BERRY ST STE 6100",
"address_line2": "",
"address_city": "SAN FRANCISCO",
"address_state": "CA",
"address_zip": "94107-1741",
"address_country": "UNITED STATES",
"metadata": {},
"date_created": "2017-09-05T17:47:53.767Z",
"date_modified": "2017-09-05T17:47:53.767Z",
"deleted": true,
"object": "address"
},
"from": {
"id": "adr_b8fb5acf3a2b55db",
"description": null,
"name": "LEORE AVIDAR",
"company": null,
"phone": null,
"email": null,
"address_line1": "185 BERRY ST STE 6100",
"address_line2": "",
"address_city": "SAN FRANCISCO",
"address_state": "CA",
"address_zip": "94107-1741",
"address_country": "UNITED STATES",
"metadata": {},
"date_created": "2017-09-05T17:47:53.767Z",
"date_modified": "2017-09-05T17:47:53.767Z",
"deleted": true,
"object": "address"
},
"url": "https://s3-us-west-2.amazonaws.com/assets.lob.com/psc_14c1b66f31264c34.pdf?AWSAccessKeyId=AKIAJVT3IPSNH662QU6A&Expires=1449430428&Signature=j%2FTzUuHJkrlbAJZGNpCm3xfxgmE%3D",
"front_template_id": null,
"back_template_id": null,
"front_template_version_id": null,
"back_template_version_id": null,
"carrier": "USPS",
"tracking_events": [],
"thumbnails": [
{
"small": "https://s3-us-west-2.amazonaws.com/assets.lob.com/psc_14c1b66f31264c34_thumb_small_1.png?AWSAccessKeyId=AKIAJVT3IPSNH662QU6A&Expires=1449430428&Signature=j%2FTzUuHJkrlbAJZGNpCm3xfxgmE%3D",
"medium": "https://s3-us-west-2.amazonaws.com/assets.lob.com/psc_14c1b66f31264c34_thumb_medium_1.png?AWSAccessKeyId=AKIAJVT3IPSNH662QU6A&Expires=1449430428&Signature=j%2FTzUuHJkrlbAJZGNpCm3xfxgmE%3D",
"large": "https://s3-us-west-2.amazonaws.com/assets.lob.com/psc_14c1b66f31264c34_thumb_large_1.png?AWSAccessKeyId=AKIAJVT3IPSNH662QU6A&Expires=1449430428&Signature=j%2FTzUuHJkrlbAJZGNpCm3xfxgmE%3D"
},
{
"small": "https://s3-us-west-2.amazonaws.com/assets.lob.com/psc_14c1b66f31264c34_thumb_small_2.png?AWSAccessKeyId=AKIAJVT3IPSNH662QU6A&Expires=1449430428&Signature=j%2FTzUuHJkrlbAJZGNpCm3xfxgmE%3D",
"medium": "https://s3-us-west-2.amazonaws.com/assets.lob.com/psc_14c1b66f31264c34_thumb_medium_2.png?AWSAccessKeyId=AKIAJVT3IPSNH662QU6A&Expires=1449430428&Signature=j%2FTzUuHJkrlbAJZGNpCm3xfxgmE%3D",
"large": "https://s3-us-west-2.amazonaws.com/assets.lob.com/psc_14c1b66f31264c34_thumb_large_2.png?AWSAccessKeyId=AKIAJVT3IPSNH662QU6A&Expires=1449430428&Signature=j%2FTzUuHJkrlbAJZGNpCm3xfxgmE%3D"
}
],
"size": "4x6",
"mail_type": "usps_first_class",
"expected_delivery_date": "2017-09-12",
"date_created": "2017-09-05T17:47:53.967Z",
"date_modified": "2017-09-05T17:47:53.967Z",
"send_date": "2017-09-05T17:47:53.967Z",
"object": "postcard"
}
That’s it, you have created your first Postcard via Lob.com!