ruby-trustedsearch

trustedSEARCH Ruby Gem

Full Documentation: http://developers.trustedsearch.org

Ruby Gems: https://rubygems.org/gems/trustedsearch

Requirements

Ruby 1.9 or above.

Installation

Add this line to your application's Gemfile:

gem 'trustedsearch'

And then execute:

$ bundle

Or install it yourself as:

$ gem install trustedsearch

Once you have your credentials you can manually run rake tasks to access the the api, or you can integrate direction.

Usage

The gem is designed to support all existing and future TRUSTEDSearch API's resources.

To start using the gem, you need to be given your sandbox and production public & private keys.

API Examples

Include the required libs & set your public and private keys


require "trustedsearch"

TrustedSearch.public_key = "PUBLIC_KEY"
TrustedSearch.private_key = "PRIVATE_KEY"
TrustedSearch.environment = "production"  #default is 'sandbox'

Get All Business for all users locations

See the API documentation for a list of parameters for each API resource.

api = TrustedSearch::V1.new
puts api.getBusinessUpdate().data.to_s

Get Business Updates for single location

See the API documentation for a list of parameters for each API resource.

api = TrustedSearch::V1.new
puts api.getBusinessUpdate(534f95e8-1de1-558f-885c-3962f22c9a28).data.to_s

Get Business Updates since epoch 1380611103

See the API documentation for a list of parameters for each API resource.

api = TrustedSearch::V1.new
puts api.getBusinessUpdateSince(1380611103).data.to_s

Submit New Business Listings

See the API documentation for a list of parameters for each API resource.

business_data = [
    {
        :externalId => 'ABC123',
        :order => {
            :onBehalfOf => 'Sample Partner',
            :packages => [
                9,10
            ]
        },
        :contact => {
            :firstName => "Albert",
            :lastName => "Einstein",
            :email => "[email protected]",
            :phone => "5555555555"
        },
        :business => {
            :name => "Albert's Relativity Lane",
            :street => "123 Cherry Tree Lane",
            :city => "Santa Barbara",
            :state => "CA",
            :postalCode => "93041",
            :phoneTollFree =>"(800) 555-5555",
            :website => "http://www.relativitylane.com",
            :email => "[email protected]",
        }
    },
    {
        :externalId => 'ABC456',
        :order => {
            :onBehalfOf => 'Sample Partner',
            :packages => [
                9,10
            ]
        },
        :contact => {
            :firstName => "Albert",
            :lastName => "Einstein",
            :email => "[email protected]",
            :phone => "4444444444"
        },
        :business => {
            :name => "Albert's Relativity Lane",
            :street => "456 Cherry Tree Lane",
            :city => "Santa Barbara",
            :state => "CA",
            :postalCode => "93041",
            :phoneTollFree =>"(800) 555-5555",
            :website => "http://www.relativitylane.com/mc2",
            :email => "[email protected]",
        }
    }
]

api = TrustedSearch::V1.new
response = api.postBusiness(business_data)

# # Ex: v1/directory-listings/:uuid
uuid = response.data[0]["uuid"]

Testing

Testing / Simulating a change in a business listing


uuid = '534f95e8-1de1-558f-885c-3962f22c9a28'
api = TrustedSearch::V1.new
response = api.putTestFulfillment(uuid)


Error Handling

Exceptions are thrown when there is an api issue.


since = ( args.since.nil? ? nil : args.since)
api = TrustedSearch::V1.new
begin
    puts api.getBusinessUpdate(uuid, since).data.to_s
rescue Exception => e
    puts "Message: " + e.message
    puts "Body:"
    puts e.body
    puts "Code: " + e.code.to_s

end

Output: (Body is formatted for readability.)


Message: Bummer, we couldn't save this record. You might have to fix a few things first and try again.
Body:
{   
    "status"=>"error", 
    "code"=>409, 
    "message"=>"Bummer, we couldn't save this record. You might have to fix a few things first and try again.", 
    "error"=>"ModelSaveFailedException", 
    "debug"=>"Model was unable to save, check validation errors.", 
    "validations"=>{"uuid"=>["The uuid field is required."], 
    "business_name"=>["The business name field is required."]}, 
    "data"=>[]
}
Code: 409

Rake Examples

Get all udpates in your account

rake v1:updates[YourPublicKey,YourPrivateKey]

Get update for location 534f95e8-1de1-558f-885c-3962f22c9a28

rake v1:updates[YourPublicKey,YourPrivateKey,534f95e8-1de1-558f-885c-3962f22c9a28]

Get update since 1380611103

rake v1:updates_since[YourPublicKey,YourPrivateKey,1380611103]

Submit a new location using JSON data in file relative path "examples/body.json"

rake v1:submit[YourPublicKey,YourPrivateKey,"examples/body.json"]

SANDBOX ONLY: Test the fulfilment process for development & testing purposes

rake v1:test_fulfillment[YourPublicKey,YourPrivateKey,534f95e8-1de1-558f-885c-3962f22c9a28]