Class: GoogleAPI
- Inherits:
-
Object
- Object
- GoogleAPI
- Defined in:
- lib/civic_info.rb
Instance Method Summary collapse
- #get(call_string) ⇒ Object
-
#initialize(api_key, service_name) ⇒ GoogleAPI
constructor
A new instance of GoogleAPI.
- #post(call_string, body) ⇒ Object
Constructor Details
#initialize(api_key, service_name) ⇒ GoogleAPI
Returns a new instance of GoogleAPI.
7 8 9 10 11 |
# File 'lib/civic_info.rb', line 7 def initialize(api_key, service_name) @api_key = ENV['GOOGLE_API_KEY'] @service_url = "https://www.googleapis.com#{service_name}" @conn = Faraday.new(:url => @service_url) end |
Instance Method Details
#get(call_string) ⇒ Object
13 14 15 |
# File 'lib/civic_info.rb', line 13 def get(call_string) JSON.parse(@conn.get("#{call_string}?key=#{@api_key}").body).with_indifferent_access end |
#post(call_string, body) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/civic_info.rb', line 17 def post(call_string, body) response = @conn.post do |conn| conn.url "#{call_string}?key=#{@api_key}" conn.headers['Content-Type'] = 'application/json' conn.body = body.to_json end JSON.parse(response.body).with_indifferent_access end |