Class: Maju::Client

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/maju/maju.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
	@token   = options[:api_token]
	@lang = options[:lang] ? options[:lang] : 'en'
	@unit   = check_metric(options[:unit].to_s)

  Maju::Errors.api_token_blank if !@token || @token.empty?
end

Instance Attribute Details

#langObject

Returns the value of attribute lang.



9
10
11
# File 'lib/maju/maju.rb', line 9

def lang
  @lang
end

#tokenObject

Returns the value of attribute token.



9
10
11
# File 'lib/maju/maju.rb', line 9

def token
  @token
end

#unitObject

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