class TheCity::Client

Attributes

access_token[W]
app_id[W]
app_secret[W]
oauth_token=[W]
subdomain[W]
version[W]

Public Class Methods

new(options={}) { |self| ... } click to toggle source

Initializes a new Client object

@param options [Hash] @return [TheCity::API::Client]

# File lib/the_city/client.rb, line 13
def initialize(options={})
  for key, value in options
    send(:"#{key}=", value)
  end
  yield self if block_given?
end

Public Instance Methods

access_token() click to toggle source

@return [String]

# File lib/the_city/client.rb, line 48
def access_token
  if instance_variable_defined?(:@access_token)
    @access_token
  else
    ENV['THECITY_ACCESS_TOKEN']
  end
end
Also aliased as: oauth_token
api_version()
Alias for: version
app_id() click to toggle source

@return [String]

# File lib/the_city/client.rb, line 30
def app_id
  if instance_variable_defined?(:@app_id)
    @app_id
  else
    ENV['THECITY_APP_ID']
  end
end
app_secret() click to toggle source

@return [String]

# File lib/the_city/client.rb, line 39
def app_secret
  if instance_variable_defined?(:@app_secret)
    @app_secret
  else
    ENV['THECITY_APP_SECRET']
  end
end
credentials() click to toggle source

@return [Hash]

# File lib/the_city/client.rb, line 70
def credentials
  {
    :app_id     => app_id,
    :app_secret => app_secret,
    :token      => access_token,
  }
end
credentials?() click to toggle source

@return [Boolean]

# File lib/the_city/client.rb, line 79
def credentials?
  credentials.values.all?
end
oauth_token()
Alias for: access_token
subdomain() click to toggle source

@return [String]

# File lib/the_city/client.rb, line 21
def subdomain
  if instance_variable_defined?(:@subdomain)
    @subdomain
  else
    ENV['THECITY_SUBDOMAIN']
  end
end
version() click to toggle source

@return [String]

# File lib/the_city/client.rb, line 58
def version
  if instance_variable_defined?(:@version)
    @api_version || "1"
  elsif ENV['THECITY_API_VERSION']
    ENV['THECITY_API_VERSION']
  else
    "1"
  end
end
Also aliased as: api_version

Private Instance Methods

validate_credentials!() click to toggle source

Ensures that all credentials set during configuration are of a valid type. Valid types are String and Symbol.

# File lib/the_city/client.rb, line 87
def validate_credentials!
  for credential, value in credentials
    raise(Error::ConfigurationError, "Invalid #{credential} specified: #{value.inspect} must be a string or symbol.") unless value.is_a?(String) || value.is_a?(Symbol)
  end
end