Class: TRex::Request
- Inherits:
-
Object
- Object
- TRex::Request
- 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
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#location ⇒ Object
Returns the value of attribute location.
-
#params ⇒ Object
Returns the value of attribute params.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(client, &block) ⇒ Object
- #get(&block) ⇒ Object
-
#initialize(params = {}, headers = {}) ⇒ Request
constructor
A new instance of Request.
- #set_default_location(geo_string = DEFAULT_LOCATION) ⇒ Object
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
#headers ⇒ Object
Returns the value of attribute headers.
14 15 16 |
# File 'lib/t_rex/request.rb', line 14 def headers @headers end |
#location ⇒ Object
Returns the value of attribute location.
15 16 17 |
# File 'lib/t_rex/request.rb', line 15 def location @location end |
#params ⇒ Object
Returns the value of attribute params.
14 15 16 |
# File 'lib/t_rex/request.rb', line 14 def params @params end |
#request ⇒ Object
Returns the value of attribute request.
14 15 16 |
# File 'lib/t_rex/request.rb', line 14 def request @request end |
#response ⇒ Object
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 |