This guide illustrates differences between Lob’s the legacy versions of this SDK and the new current version.
In this guide we compare how v5.*.*
and >= v6.0.0
implement the following method pattern.
- CREATE
- LIST
- GET
- DELETE
- VERIFY (BANK ACCOUNTS)
- UPDATE
Similar to the legacy version, the new lob-ruby SDK is available through gem
:
$ gem install lob
require 'lob'
config = Lob::Configuration.default
config.username = ENV['LOB_API_TEST_KEY']
You then instantiate the specific resource API that you need access to as follows:
api = Lob::ApiClient.new(config)
addressApi = AddressesApi.new(@api)
The new SDK version abstracts the request/response interaction out of the calling code such that you create the resource and pass it to the corresponding API in a begin/rescue such that any non-success is an ApiException
that must be handled.
Here is a sample of the legacy lob-ruby CREATE function:
@lob.addresses.create(
description: 'Harry - Office',
name: 'Harry Zhang',
company: 'Lob',
email: '[email protected]',
phone: '5555555555',
address_line1: '210 King St',
address_line2: '# 6100',
address_city: 'San Francisco',
address_state: 'CA',
address_country: 'US',
address_zip: '94107'
)
Here is a sample of the updated CREATE method
addressEditable = AddressEditable.new({
name: 'Thing T. Thing',
address_line1: '1313 CEMETERY LN',
address_city: 'WESTFIELD',
address_state: 'NJ',
address_zip: '07000',
})
begin
response = @addressApi.create(addressEditable)
rescue => e
puts 'An error of has occcured, message is #{e.message}'
end
Here is a sample of the legacy lob-ruby LIST method:
@lob.addresses.list(limit: 2)
Here is a sample of the updated LIST method:
begin
response = @addressApi.list()
rescue => e
puts 'An error of has occcured, message is #{e.message}'
end
Here is a sample of the legacy lob-ruby GET method:
@lob.addresses.find('adr_xxx')
Here is a sample of the updated GET method:
begin
response = @addressApi.get('adr_xxx')
rescue => e
puts 'An error of has occcured, message is #{e.message}'
end
Here is a sample of the legacy lob-ruby DELETE method:
@lob.addresses.destroy('adr_xxx')
Here is a sample of the updated DELETE method:
begin
response = @addressApi.delete('adr_xxx')
rescue => e
puts 'An error of has occcured, message is #{e.message}'
end
Here is a sample of the legacy lob-ruby BANK ACCOUNT VERIFY method:
@lob.bank_accounts.verify('bank_xxx', amounts: [25, 63])
Here is a sample of the updated BANK ACCOUNT VERIFY method:
bankVerify = BankAccountVerify.new({ 'amounts': [11, 35] })
begin
response = @bankAccountApi.verify('bank_xxx', bankVerify)
rescue => e
puts 'An error of has occcured, message is #{e.message}'
end
Here is a sample of the legacy lob-ruby UPDATE method:
This feature was not supported by the legacy library.
Here is a sample of the updated UPDATE method:
updatableTemplate = TemplateUpdate.new({
description: 'Updated template for Ruby Integration Test'
})
begin
updatedTemplate = @templateApi.update('tmpl_xxxx', updatableTemplate)
rescue => e
puts 'An error of has occcured, message is #{e.message}'
end