Class: Yelp::V2::Request

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

Direct Known Subclasses

Business::Request::Id, Search::Request::Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Request

Returns a new instance of Request


20
21
22
23
24
25
# File 'lib/yelpster/v2/request.rb', line 20

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

Instance Attribute Details

#consumer_keyObject (readonly)

For backwards compatibility


15
16
17
# File 'lib/yelpster/v2/request.rb', line 15

def consumer_key
  @consumer_key
end

#consumer_secretObject (readonly)

Returns the value of attribute consumer_secret


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

def consumer_secret
  @consumer_secret
end

#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.


10
11
12
# File 'lib/yelpster/v2/request.rb', line 10

def response_format
  @response_format
end

#tokenObject (readonly)

Returns the value of attribute token


17
18
19
# File 'lib/yelpster/v2/request.rb', line 17

def token
  @token
end

#token_secretObject (readonly)

Returns the value of attribute token_secret


18
19
20
# File 'lib/yelpster/v2/request.rb', line 18

def token_secret
  @token_secret
end

Instance Method Details

#pull_results(url, _) ⇒ Object


42
43
44
45
46
# File 'lib/yelpster/v2/request.rb', line 42

def pull_results(url, _)
  consumer = OAuth::Consumer.new(consumer_key, consumer_secret, {:site => "http://api.yelp.com"})
  access_token = OAuth::AccessToken.new(consumer, token, token_secret)
  access_token.get(url).body
end

#to_yelp_paramsObject


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

def to_yelp_params
  params = {}

  # 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