Class: Lyft::Client::Api::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/lyft/client/api/base.rb

Direct Known Subclasses

Availability, Oauth, Rides, User

Constant Summary collapse

API_VERSION =
ENV['LYFT_API_VERSION'] || 'v1'
ENDPOINTS =
{}
DEFAULT_VALIDATES =
[:access_token]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Base

Returns a new instance of Base.



56
57
58
59
# File 'lib/lyft/client/api/base.rb', line 56

def initialize(configuration)
  @configuration = configuration
  set_debug_output
end

Class Method Details

.path_for(key, args = {}) ⇒ String

Constructs path for endpoint.

Examples:

Get path for product stock changes.

Products.path_for(:stock_changes) # '/products/stock_changes'

Get path for product with sku.

Products.path_for(:product, { sku: '123' })
#=> Converts '/products/{{sku}}' to '/products/123'

Parameters:

  • key (Symbol)

    The key for ENDPOINTS.

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

    A hash which maps values to variables.

Returns:

  • (String)

    The constructed path.



29
30
31
32
33
34
35
36
37
38
# File 'lib/lyft/client/api/base.rb', line 29

def self.path_for(key, args = {})
  # Must call dup because gsub! works with the reference
  # and will change the constant ENDPOINTS which is bad.
  path = self::ENDPOINTS.fetch(key.to_sym).dup
  args.each do |arg_key, value|
    path.gsub!("{{#{arg_key}}}", value.to_s)
  end

  path
end

Instance Method Details

#path_for(key, args = {}) ⇒ String

Resolve path for ENDPOINTS

Examples:

Get path for product stock changes.

client.products.path_for(:stock_changes) # '/products/stock_changes'

Get path for product with sku.

client.products.path_for(:product, { sku: '123' })
#=> Converts '/products/{{sku}}' to '/products/123'

Returns:

  • (String)

    The constructed path.



52
53
54
# File 'lib/lyft/client/api/base.rb', line 52

def path_for(key, args = {})
  self.class.path_for(key, args)
end

#set_debug_outputObject



61
62
63
# File 'lib/lyft/client/api/base.rb', line 61

def set_debug_output
  self.class.default_options[:debug_output] = @configuration.debug_output
end