Class: TRex::Metasaurus
- Inherits:
-
Object
- Object
- TRex::Metasaurus
- Includes:
- HTTParty
- Defined in:
- lib/t_rex/metasaurus.rb
Class Attribute Summary collapse
-
.metasaurus_path ⇒ Object
Hooks for rspec testing to clear memoization.
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#params ⇒ Object
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #debug ⇒ Object
- #endpoint ⇒ Object
- #get ⇒ Object
-
#initialize(params = {}, headers = {}) ⇒ Metasaurus
constructor
A new instance of Metasaurus.
- #scrub_params ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(params = {}, headers = {}) ⇒ Metasaurus
Returns a new instance of Metasaurus.
19 20 21 22 |
# File 'lib/t_rex/metasaurus.rb', line 19 def initialize(params = {}, headers = {}) @params, @headers = params, headers scrub_params end |
Class Attribute Details
.metasaurus_path ⇒ Object
Hooks for rspec testing to clear memoization
11 12 13 |
# File 'lib/t_rex/metasaurus.rb', line 11 def @metasaurus_path end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
7 8 9 |
# File 'lib/t_rex/metasaurus.rb', line 7 def headers @headers end |
#params ⇒ Object
Returns the value of attribute params.
7 8 9 |
# File 'lib/t_rex/metasaurus.rb', line 7 def params @params end |
Class Method Details
.metasaurus_url ⇒ Object
14 15 16 17 |
# File 'lib/t_rex/metasaurus.rb', line 14 def self. @metasaurus_path ||= TRex.configuration. || raise(TRexConfigurationError, 'No URL defined for Metasaurus') end |
Instance Method Details
#debug ⇒ Object
24 25 26 |
# File 'lib/t_rex/metasaurus.rb', line 24 def debug TRex.configuration. end |
#endpoint ⇒ Object
28 29 30 |
# File 'lib/t_rex/metasaurus.rb', line 28 def endpoint @endpoint ||= (self.params.delete('endpoint') || 'geo') end |
#get ⇒ Object
32 33 34 35 |
# File 'lib/t_rex/metasaurus.rb', line 32 def get = {query: params, headers: headers} self.class.get url, end |
#scrub_params ⇒ Object
37 38 39 40 41 |
# File 'lib/t_rex/metasaurus.rb', line 37 def scrub_params if params[:zip].to_s =~ /(\d{5})[-\w]?/ self.params[:zip] = $1 end end |
#url ⇒ Object
43 44 45 |
# File 'lib/t_rex/metasaurus.rb', line 43 def url "#{self.class.}/#{endpoint}" end |