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

- (Request) initialize(params)



24
25
26
27
28
29
30
# File 'lib/yelpster/v1/request.rb', line 24

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

Instance Attribute Details

- (Object) compress_response (readonly) Also known as: compress_response?

specifies whether the response content should be transmitted over the wire compressed, defaulting to true.



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

def compress_response
  @compress_response
end

- (Object) response_format (readonly)

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



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

def response_format
  @response_format
end

- (Object) yws_id (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.



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

def yws_id
  @yws_id
end

Instance Method Details

- (Object) pull_results(url, http_params)



49
50
51
52
# File 'lib/yelpster/v1/request.rb', line 49

def pull_results (url, http_params)
  source = open(url, http_params)
  content = (compress_response?) ? Zlib::GzipReader.new(source).read : source.read
end

- (Object) to_yelp_params



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/yelpster/v1/request.rb', line 32

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