Class: Geoloqi::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/geoloqi/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Instantiate a new Geoloqi::Config object.

Examples:

# Dynamically create a Geoloqi::Config object
geoloqi_config = Geoloqi::Config.new :use_hashie_mash => true, :throw_exceptions => false

# Use geoloqi_config to create new session
geoloqi_session = Geoloqi::Session.new :access_token => 'YOUR ACCESS TOKEN', :config => geoloqi_config

Parameters:

  • opts (defaults to: {})

    A hash of the config settings.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/geoloqi/config.rb', line 80

def initialize(opts={})
  self.use_hashie_mash ||= false
  self.throw_exceptions ||= true
  self.symbolize_names ||= true
  self.use_dynamic_exceptions ||= false

  opts.each {|k,v| send("#{k}=", v)}

  begin
    require 'hashie' if self.use_hashie_mash && !defined?(Hashie::Mash)
  rescue LoadError
    raise Error, "You've requested Hashie::Mash, but the gem is not available. Don't set use_hashie_mash in your config, or install the hashie gem"
  end
end

Instance Attribute Details

#adapterSymbol

Which HTTP adapter to use for Faraday. Defaults to :net_http

Examples:

Geoloqi.config.adapter = :typhoeus

Returns:

  • (Symbol)


29
30
31
# File 'lib/geoloqi/config.rb', line 29

def adapter
  @adapter
end

#api_urlString

Which API URL to use for Geoloqi. You shouldn't need to change this.

Returns:

  • (String)


22
23
24
# File 'lib/geoloqi/config.rb', line 22

def api_url
  @api_url
end

#client_idString

OAuth2 Client ID for the application. Retrieve from the Geoloqi Developers Site.

Examples:

Geoloqi.config.client_id = 'YOUR APPLICATION CLIENT ID'

Returns:

  • (String)


8
9
10
# File 'lib/geoloqi/config.rb', line 8

def client_id
  @client_id
end

#client_secretString

OAuth2 Client Secret for the application. Retrieve from the Geoloqi Developers Site.

Returns:

  • (String)


12
13
14
# File 'lib/geoloqi/config.rb', line 12

def client_secret
  @client_secret
end

#loggerIO

Provide a logger. This can be any object that responds to print and puts (anything that inherits IO).

Examples:

Geoloqi.config.logger = STDOUT

Returns:

  • (IO)


36
37
38
# File 'lib/geoloqi/config.rb', line 36

def logger
  @logger
end

#redirect_uriString

OAuth2 Redirect URI. This is the location the user will be redirected to after authorization from the Geoloqi OAuth2 server. If this is not provided, the user will be redirected to the URI configured at the Geoloqi Developers Site.

Returns:

  • (String)


17
18
19
# File 'lib/geoloqi/config.rb', line 17

def redirect_uri
  @redirect_uri
end

#symbolize_namesBoolean

Use symbols for keys in Hash response. Defaults to true.

Examples:

Geoloqi.config.symbolize_names = true

Returns:

  • (Boolean)


67
68
69
# File 'lib/geoloqi/config.rb', line 67

def symbolize_names
  @symbolize_names
end

#throw_exceptionsBoolean

Throw Geoloqi::ApiError exception on API errors. Defaults to true. If set to false, you will need to check for the error key in responses.

Examples:

Geoloqi.config.throw_exceptions = false

Returns:

  • (Boolean)


55
56
57
# File 'lib/geoloqi/config.rb', line 55

def throw_exceptions
  @throw_exceptions
end

#use_dynamic_exceptionsBoolean

Use dynamic error class names, which inherit from Geoloqi::ApiError. This may be deprecated in a future release.

Returns:

  • (Boolean)


60
61
62
# File 'lib/geoloqi/config.rb', line 60

def use_dynamic_exceptions
  @use_dynamic_exceptions
end

#use_hashie_mashBoolean

Use Hashie::Mash for return objects, which provides dot-style data retrieval.

Examples:

Geoloqi.config.use_hashie_mash = true

 # Get profile and retrieve data via Hashie::Mash dot notation
 result = Geoloqi.get 'YOUR ACCESS TOKEN', 'account/profile'
 result.name # => "Your Name"

Returns:

  • (Boolean)

See Also:



48
49
50
# File 'lib/geoloqi/config.rb', line 48

def use_hashie_mash
  @use_hashie_mash
end

Instance Method Details

#client_id?Boolean

Check if the OAuth2 Client ID exists.

Returns:

  • (Boolean)


97
98
99
# File 'lib/geoloqi/config.rb', line 97

def client_id?
  !client_id.nil? && !client_id.empty?
end

#client_secret?Boolean

Check if OAuth2 Client Secret exists.

Returns:

  • (Boolean)


103
104
105
# File 'lib/geoloqi/config.rb', line 103

def client_secret?
  !client_secret.nil? && !client_secret.empty?
end