Class: TRex::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/t_rex/request.rb

Constant Summary collapse

ACCEPTABLE_ENDPOINTS =
%w(
colleges
community
geo
military_bases
nearby_neighborhoods
nearby_colleges
nearby_military_bases )
DEFAULT_LOCATION =
"city=Norcross,region=GA,country=US,lat=33.9411,long=-84.2136,metro=909,msa=9009,zip=30092,areacode=770"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}, headers = {}) ⇒ Request

Returns a new instance of Request.



21
22
23
24
25
26
27
# File 'lib/t_rex/request.rb', line 21

def initialize(params = {}, headers = {})
  @headers = TRex::ParamsHash.new headers
  @params  = TRex::ParamsHash.new params
  @params[:endpoint] ||= 'geo'
  @params[:endpoint] = @params[:endpoint].to_s
  clean_params! if params_includes_endpoint
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



14
15
16
# File 'lib/t_rex/request.rb', line 14

def headers
  @headers
end

#locationObject

Returns the value of attribute location.



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

def location
  @location
end

#paramsObject

Returns the value of attribute params.



14
15
16
# File 'lib/t_rex/request.rb', line 14

def params
  @params
end

#requestObject

Returns the value of attribute request.



14
15
16
# File 'lib/t_rex/request.rb', line 14

def request
  @request
end

#responseObject

Returns the value of attribute response.



14
15
16
# File 'lib/t_rex/request.rb', line 14

def response
  @response
end

Class Method Details

.get(params = {}, headers = {}, &block) ⇒ Object



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

def self.get(params = {}, headers = {}, &block)
  new(params, headers).get(&block)
end

Instance Method Details

#execute(client, &block) ⇒ Object



29
30
31
32
33
# File 'lib/t_rex/request.rb', line 29

def execute(client, &block)
  @response = client.get
  @request = response.request
  block ? yield(response) : response
end

#get(&block) ⇒ Object



35
36
37
# File 'lib/t_rex/request.rb', line 35

def get(&block)
  execute(client, &block)
end

#set_default_location(geo_string = DEFAULT_LOCATION) ⇒ Object



43
44
45
# File 'lib/t_rex/request.rb', line 43

def set_default_location(geo_string = DEFAULT_LOCATION)
  @location = { 'X-Geo-Data' => geo_string }
end