airvisual_api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99cb795e5895323f25820f36add9b3062e9a6743640990748577d69e22e831e6
4
- data.tar.gz: c5d9f6ad94f00bb8a792f477a517b8bf7fa1e3c2acdfc38c24ed5aeafd5f92b7
3
+ metadata.gz: e074bae36cd7cde2a2c4452d8d8f17f43d24a5df32db0014356e33527fcbc728
4
+ data.tar.gz: 2797272c6cdff75d079f39d9a752f4f1d35a80f21178fd4fcdbd6134c800fd27
5
5
  SHA512:
6
- metadata.gz: fb9c75b057e4cdb898e06fcd9719efabe42c4f71b45a2278ccdba53a0c97cb3ff7d5ff2a7f8b828438de151328427a1aa2101b8cdda201c2b7124bec1209b237
7
- data.tar.gz: 384008d2e42b04397f970e98f493e6177dad22a11997d708ba9ea94dcf2c7f77c713ed8efcb98e9a5b4b53fb470f2208d9ce867679a853c30c3963023730b550
6
+ metadata.gz: d771ef49fcabd86e3a6a51018966c7ff308b1f43126c2aec8770484fe17c5f8c766b0609a7201c345be65b8b1a777cf36af2e33582fbeeca7d9998f9a7f91b37
7
+ data.tar.gz: bee3e204bc9ad8a3c11fcfe2034521ee11531512c69ee2ef55b042f919ed10fcb9130f0bce26afe022529830b5bf627562374f1db79bcc86174c4cc1b1fb98ab
@@ -6,6 +6,12 @@ module AirVisualApi
6
6
  # some of the key names. I can't stand abbreviation
7
7
  # and jargon.
8
8
 
9
+ # Have to actually set the IP or we'll get the
10
+ # server's IP as a result.
11
+ def nearest_city_by_ip(ip:)
12
+ client.get(url: '/nearest_city', headers: { 'x-forwarded-for' => ip })
13
+ end
14
+
9
15
  def nearest_city_by_gps(latitude:, longitude:)
10
16
  # coercing to float to ensure proper formatting
11
17
  # this should probably be a little smarter with some
@@ -3,22 +3,27 @@ require 'httparty'
3
3
  module AirVisualApi
4
4
  class Client
5
5
  BASE_URI = 'http://api.airvisual.com/v2'
6
+ DEFAULT_HEADERS = {
7
+ 'Accept' => 'application/json',
8
+ 'Content-Type' => 'application/json'
9
+ }.freeze
6
10
 
7
11
  def initialize(api_key: ENV['AIRVISUAL_API_KEY'])
8
12
  # defaults to env variable but can be specified
9
13
  @api_key = api_key
10
14
  end
11
15
 
12
- def get(url:)
13
- HTTParty.get(BASE_URI + url + key_param)
16
+ def get(url:, headers: {})
17
+ HTTParty.get(BASE_URI + url + key_param(url), headers: headers.merge(DEFAULT_HEADERS))
14
18
  end
15
19
 
16
20
  private
17
21
 
18
22
  attr_reader :api_key
19
23
 
20
- def key_param
21
- "&key=#{api_key}"
24
+ def key_param(url)
25
+ return "&key=#{api_key}" if url.include?('?')
26
+ "?key=#{api_key}"
22
27
  end
23
28
  end
24
29
  end
@@ -1,3 +1,3 @@
1
1
  module AirVisualApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airvisual_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joey Ferguson