Class: Maju::Client
Instance Attribute Summary collapse
-
#lang ⇒ Object
Returns the value of attribute lang.
-
#token ⇒ Object
Returns the value of attribute token.
-
#unit ⇒ Object
Returns the value of attribute unit.
Instance Method Summary collapse
- #current(params) ⇒ Object
- #forecast(params) ⇒ Object
- #geocode(params) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
Methods included from Helpers
#api_url_base, #api_url_current, #api_url_forecast, #api_url_geocode, #check_metric, #headers, #json, #parsed_params
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 |
# File 'lib/maju/maju.rb', line 11 def initialize() @token = [:api_token] @lang = [:lang] ? [:lang] : 'en' @unit = check_metric([:unit].to_s) Maju::Errors.api_token_blank if !@token || @token.empty? end |
Instance Attribute Details
#lang ⇒ Object
Returns the value of attribute lang.
9 10 11 |
# File 'lib/maju/maju.rb', line 9 def lang @lang end |
#token ⇒ Object
Returns the value of attribute token.
9 10 11 |
# File 'lib/maju/maju.rb', line 9 def token @token end |
#unit ⇒ Object
Returns the value of attribute unit.
9 10 11 |
# File 'lib/maju/maju.rb', line 9 def unit @unit end |
Instance Method Details
#current(params) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/maju/maju.rb', line 19 def current(params) Maju::Errors.city_geocode_blank if params[:city].nil? && params[:lat].nil? url = api_url_current(params) response = RestClient.get(url, headers) json(response) end |
#forecast(params) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/maju/maju.rb', line 28 def forecast(params) Maju::Errors.city_geocode_blank if params[:city].nil? && params[:lat].nil? url = api_url_forecast(params) response = RestClient.get(url, headers) json(response) end |
#geocode(params) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/maju/maju.rb', line 37 def geocode(params) Maju::Errors.city_name_blank if params[:city].nil? or params[:city].to_s.empty? url = api_url_geocode(params) response = RestClient.get(url, headers) json(response).count > 1 ? json(response) : json(response).first end |