Class: Yp::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yp.rb

Overview

Yp::Client.new(api_key: “YOUR_API_KEY”)

Constant Summary collapse

API_URL =
"http://api2.yp.com"
SEARCH_PATH =
"listings/v1/search"
DETAILS_PATH =
"listings/v1/details"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



16
17
18
# File 'lib/yp.rb', line 16

def initialize(options={})
  @api_key = options[:api_key]
end

Instance Method Details

#details(listingid) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/yp.rb', line 32

def details(listingid)
  response = connection.get do |req|
    req.url DETAILS_PATH, {listingid: listingid}
  end

  JSON.parse(response.body)['listingsDetailsResult']['listingsDetails']['listingDetail'][0]
end

#search(options = {}) ⇒ Object

e.g. client.search(searchloc: “94109”, term: “kayak”) api2.yp.com/listings/v1/search



22
23
24
25
26
27
28
# File 'lib/yp.rb', line 22

def search(options={})
  response = connection.get do |req|
    req.url SEARCH_PATH, options
  end

  JSON.parse(response.body)['searchResult']['searchListings']['searchListing']
end