Class: OpenWeatherClient::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/open_weather_client/configuration.rb

Overview

Configuratin of OpenWeatherClient

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize a new Configuration with the default settings



28
29
30
31
32
33
34
35
36
# File 'lib/open_weather_client/configuration.rb', line 28

def initialize
  @api_version = :v25
  @caching = OpenWeatherClient::Caching.new
  @lang = 'de'
  @max_memory_entries = 10_000
  @units = 'metric'
  @url = 'https://api.openweathermap.org/data'
  @user_agent = "Open Weather Client/#{OpenWeatherClient::VERSION}"
end

Instance Attribute Details

#api_versionObject

String

Used api version. One of :v25, :v30. Default :v25



8
9
10
# File 'lib/open_weather_client/configuration.rb', line 8

def api_version
  @api_version
end

#appidObject

String

API key to access OpenWeatherMap



10
11
12
# File 'lib/open_weather_client/configuration.rb', line 10

def appid
  @appid
end

#cachingObject

Caching method. One of :none, :memory



12
13
14
# File 'lib/open_weather_client/configuration.rb', line 12

def caching
  @caching
end

#langObject

String

Requested language of the result



14
15
16
# File 'lib/open_weather_client/configuration.rb', line 14

def lang
  @lang
end

#max_memory_entriesObject

Integer

Maximum allowed number of entries when using caching method :memory



16
17
18
# File 'lib/open_weather_client/configuration.rb', line 16

def max_memory_entries
  @max_memory_entries
end

#spatial_quantizationObject

Proc

Quantization of latitude and longitude



18
19
20
# File 'lib/open_weather_client/configuration.rb', line 18

def spatial_quantization
  @spatial_quantization
end

#unitsObject

String

Requested units of the result



20
21
22
# File 'lib/open_weather_client/configuration.rb', line 20

def units
  @units
end

#urlObject

String

Base URL of the requests to OpenWeatherMap



22
23
24
# File 'lib/open_weather_client/configuration.rb', line 22

def url
  @url
end

#user_agentObject

String

User-Agent of the requests made to OpenWeatherMap



24
25
26
# File 'lib/open_weather_client/configuration.rb', line 24

def user_agent
  @user_agent
end

Instance Method Details

#load_from_rails_credentialsObject

Load appid from Rails credentials

Load the appid from Rails credentials using the top-level key ‘open_weather_client’

Raises:

  • (RuntimeError)

    if not using Rails



52
53
54
55
56
57
# File 'lib/open_weather_client/configuration.rb', line 52

def load_from_rails_credentials
  raise 'This method is only available in Ruby on Rails.' unless defined? Rails

  settings = Rails.application.credentials.open_weather_client!
  self.appid = settings[:appid]
end