class Instamojo::API

Constants

WHITELISTED_API_PARAMS

Attributes

client[R]

Public Class Methods

new(api_key = nil, auth_token = nil, endpoint = nil, options = {}, &block) click to toggle source
# File lib/API/api.rb, line 15
def initialize(api_key = nil, auth_token = nil, endpoint = nil, options = {}, &block)
  options = find_params(api_key, auth_token, endpoint, options, block)

  options.select { |k, _| WHITELISTED_API_PARAMS.include? k.to_sym }.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Private Class Methods

whitelist_parameters() click to toggle source
# File lib/API/api.rb, line 5
def whitelist_parameters
  API::WHITELISTED_API_PARAMS.each { |x| attr_reader x }
end

Public Instance Methods

to_s() click to toggle source
# File lib/API/api.rb, line 27
def to_s
  @endpoint ? sprintf("Instamojo API(key: %s, endpoint: %s)", @api_key, @endpoint): sprintf("Instamojo API(key: %s)", @api_key)
end

Private Instance Methods

find_params(api_key, auth_token, endpoint, options, block) click to toggle source
# File lib/API/api.rb, line 33
def find_params(api_key, auth_token, endpoint, options, block)
  params = if api_key.is_a? Hash
    api_key
  elsif api_key
    { api_key: api_key, auth_token: auth_token }
  elsif block
    struct = OpenStruct.new
    block.call(struct) && struct.marshal_dump
  else options
  end
  params.merge!(endpoint: endpoint) if endpoint
  params
end