Class: Yp::Client
- Inherits:
-
Object
- Object
- Yp::Client
- 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
-
#details(listingid) ⇒ Object
e.g.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#search(options = {}) ⇒ Object
e.g.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
16 17 18 |
# File 'lib/yp.rb', line 16 def initialize(={}) @api_key = [:api_key] end |
Instance Method Details
#details(listingid) ⇒ Object
e.g. client.details(“30624356”) api2.yp.com/listings/v1/details?listingid=30624356&key=xxxxxxxxxx
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(={}) response = connection.get do |req| req.url SEARCH_PATH, end JSON.parse(response.body)['searchResult']['searchListings']['searchListing'] end |