Class: Yelp::V1::Request

Inherits:
Record
  • Object
show all
Defined in:
lib/yelpster/v1/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Request

Returns a new instance of Request



18
19
20
21
22
23
# File 'lib/yelpster/v1/request.rb', line 18

def initialize (params)
  default_params = {
    :response_format => Yelp::ResponseFormat::JSON_TO_RUBY
  }
  super(default_params.merge(params))
end

Instance Attribute Details

#response_formatObject (readonly)

one of the Yelp::ResponseFormat format specifiers detailing the desired format of the search results, defaulting to Yelp::ResponseFormat::JSON_TO_RUBY.



11
12
13
# File 'lib/yelpster/v1/request.rb', line 11

def response_format
  @response_format
end

#yws_idObject (readonly)

the Yelp Web Services ID to be passed with the request for authentication purposes. See www.yelp.com/developers/getting_started/api_access to get your own.



16
17
18
# File 'lib/yelpster/v1/request.rb', line 16

def yws_id
  @yws_id
end

Instance Method Details

#pull_results(url, http_params) ⇒ Object



42
43
44
# File 'lib/yelpster/v1/request.rb', line 42

def pull_results(url, http_params)
  open(url, http_params).read
end

#to_yelp_paramsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/yelpster/v1/request.rb', line 25

def to_yelp_params
  params = {
    :ywsid => yws_id || Yelp::Base.client.yws_id
  }

  # if they specified anything other than a json variant, we
  # need to tell yelp what we're looking for
  case @response_format
  when Yelp::ResponseFormat::PICKLE
    params[:output] = 'pickle'
  when Yelp::ResponseFormat::PHP
    params[:output] = 'php'
  end

  params
end