class IqairAirvisual::Client
Attributes
TODO: Air quality guidelines TODO: Units breakdown TODO: Return codes api-docs.iqair.com/?version=latest Below are a few example of return codes you may get. This list is not exhaustive. success: returned when JSON file was generated successfully. call_limit_reached: returned when minute/monthly limit is reached. api_key_expired: returned when API key is expired. incorrect_api_key: returned when using wrong API key. ip_location_failed: returned when service is unable to locate IP address of request. no_nearest_station: returned when there is no nearest station within specified radius. feature_not_available: returned when call requests a feature that is not available in chosen subscription plan. too_many_requests: returned when more than 10 calls per second are made.
TODO: Air quality guidelines TODO: Units breakdown TODO: Return codes api-docs.iqair.com/?version=latest Below are a few example of return codes you may get. This list is not exhaustive. success: returned when JSON file was generated successfully. call_limit_reached: returned when minute/monthly limit is reached. api_key_expired: returned when API key is expired. incorrect_api_key: returned when using wrong API key. ip_location_failed: returned when service is unable to locate IP address of request. no_nearest_station: returned when there is no nearest station within specified radius. feature_not_available: returned when call requests a feature that is not available in chosen subscription plan. too_many_requests: returned when more than 10 calls per second are made.
TODO: Air quality guidelines TODO: Units breakdown TODO: Return codes api-docs.iqair.com/?version=latest Below are a few example of return codes you may get. This list is not exhaustive. success: returned when JSON file was generated successfully. call_limit_reached: returned when minute/monthly limit is reached. api_key_expired: returned when API key is expired. incorrect_api_key: returned when using wrong API key. ip_location_failed: returned when service is unable to locate IP address of request. no_nearest_station: returned when there is no nearest station within specified radius. feature_not_available: returned when call requests a feature that is not available in chosen subscription plan. too_many_requests: returned when more than 10 calls per second are made.
TODO: Air quality guidelines TODO: Units breakdown TODO: Return codes api-docs.iqair.com/?version=latest Below are a few example of return codes you may get. This list is not exhaustive. success: returned when JSON file was generated successfully. call_limit_reached: returned when minute/monthly limit is reached. api_key_expired: returned when API key is expired. incorrect_api_key: returned when using wrong API key. ip_location_failed: returned when service is unable to locate IP address of request. no_nearest_station: returned when there is no nearest station within specified radius. feature_not_available: returned when call requests a feature that is not available in chosen subscription plan. too_many_requests: returned when more than 10 calls per second are made.
TODO: Air quality guidelines TODO: Units breakdown TODO: Return codes api-docs.iqair.com/?version=latest Below are a few example of return codes you may get. This list is not exhaustive. success: returned when JSON file was generated successfully. call_limit_reached: returned when minute/monthly limit is reached. api_key_expired: returned when API key is expired. incorrect_api_key: returned when using wrong API key. ip_location_failed: returned when service is unable to locate IP address of request. no_nearest_station: returned when there is no nearest station within specified radius. feature_not_available: returned when call requests a feature that is not available in chosen subscription plan. too_many_requests: returned when more than 10 calls per second are made.
Public Class Methods
This is the version of the API docs this client was built off-of
# File lib/iqair_airvisual/client.rb, line 38 def self.api_version 'v2 2021-04-18' end
# File lib/iqair_airvisual/client.rb, line 33 def self.compatible_api_version 'v2' end
# File lib/iqair_airvisual/client.rb, line 27 def initialize(api_key:, base_path: BASE_PATH, port: 80) @api_key = api_key @base_path = base_path @port = port end
Private Instance Methods
# File lib/iqair_airvisual/client.rb, line 84 def body_is_missing?(response) response.body.nil? || response.body.empty? end
# File lib/iqair_airvisual/client.rb, line 80 def body_is_present?(response) !body_is_missing?(response) end
# File lib/iqair_airvisual/client.rb, line 130 def construct_base_path(path, params) constructed_path = "#{base_path}/#{path}" if params == {} constructed_path else "#{constructed_path}?#{process_params(params)}" end end
# File lib/iqair_airvisual/client.rb, line 70 def construct_metadata(response, start_time, end_time) total_time = end_time - start_time { 'start_time' => start_time, 'end_time' => end_time, 'total_time' => total_time } end
# File lib/iqair_airvisual/client.rb, line 62 def construct_response_object(response, path, start_time, end_time) { 'body' => parse_body(response, path), 'headers' => response.headers, 'metadata' => construct_metadata(response, start_time, end_time) } end
# File lib/iqair_airvisual/client.rb, line 126 def get_micro_second_time (Time.now.to_f * 1000000).to_i end
# File lib/iqair_airvisual/client.rb, line 88 def parse_body(response, path) parsed_response = JSON.parse(response.body) # Purposely not using HTTParty if parsed_response.dig(path.to_s) parsed_response.dig(path.to_s) else parsed_response end rescue JSON::ParserError => _e response.body end
# File lib/iqair_airvisual/client.rb, line 140 def process_params(params) params.keys.map { |key| "#{key}=#{params[key]}" }.join('&') end