Class: Lyft::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/lyft/client.rb,
lib/lyft/client/api/base.rb,
lib/lyft/client/api/user.rb,
lib/lyft/client/api/oauth.rb,
lib/lyft/client/api/rides.rb,
lib/lyft/client/configuration.rb,
lib/lyft/client/mashed_parser.rb,
lib/lyft/client/api/availability.rb

Overview

Client for making Lyft api requests

Defined Under Namespace

Modules: Api Classes: Configuration, MashedParser

Constant Summary collapse

@@namespaces =

Keep track of what we are namespacing.

[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Client

The initializer

Parameters:

  • args (Hash) (defaults to: {})

Options Hash (args):

  • :client_id (String)
  • :client_secret (String)
  • :debug_output (Boolean)


68
69
70
71
# File 'lib/lyft/client.rb', line 68

def initialize(args = {})
  @configuration = Lyft::Client::Configuration.new args
  @@config = @configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



11
12
13
# File 'lib/lyft/client.rb', line 11

def configuration
  @configuration
end

Class Method Details

.create_instance(klass) ⇒ Object

Dynamically creates an attr_reader for each client space and sets it to the initalized values



29
30
31
32
33
34
# File 'lib/lyft/client.rb', line 29

def self.create_instance(klass)
  reader = klass.to_s.split('::').last.underscore
  @@namespaces << reader

  define_method(reader.to_sym) { klass.new @@config }
end

.namespace(name) ⇒ Object

Defines a method to access class instance.

Examples:

Create a namespace for availability

namespace :availability #=> Lyft::Client::Availability.new


19
20
21
22
23
# File 'lib/lyft/client.rb', line 19

def self.namespace(name)
  converted = name.to_s.split('_').map(&:capitalize).join
  klass = Lyft::Client::Api.const_get(converted)
  create_instance(klass)
end

Instance Method Details

#availabilityObject

Class to handle availability api calls.

Returns:

  • Lyft::Client::Api::Availability



46
# File 'lib/lyft/client.rb', line 46

namespace :availability

#oauthObject

Class to handle availability api calls.

Returns:

  • Lyft::Client::Api::Oauth



40
# File 'lib/lyft/client.rb', line 40

namespace :oauth

#ridesObject

Class to handle availability api calls.

Returns:

  • Lyft::Client::Api::Rides



52
# File 'lib/lyft/client.rb', line 52

namespace :rides

#userObject

Class to handle availability api calls.

Returns:

  • Lyft::Client::Api::User



58
# File 'lib/lyft/client.rb', line 58

namespace :user