Class: Yelp::V1::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Request

Returns a new instance of Request.



24
25
26
27
28
29
30
# File 'lib/yelped/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

#compress_responseObject (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/yelped/v1/request.rb', line 10

def compress_response
  @compress_response
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.



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

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.



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

def yws_id
  @yws_id
end

Instance Method Details

#pull_results(url, http_params) ⇒ Object



49
50
51
52
# File 'lib/yelped/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

#to_yelp_paramsObject



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

def to_yelp_params
  params = {
	:ywsid => 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