Class: OiApi::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty, Advertisers, AutoResponders, Balances, Cards, Charges, DataTransfers, Offers, Reports, Subscriptions, LookupTables
Defined in:
lib/oi_api/client.rb,
lib/oi_api/client/cards.rb,
lib/oi_api/client/offers.rb,
lib/oi_api/client/charges.rb,
lib/oi_api/client/reports.rb,
lib/oi_api/client/balances.rb,
lib/oi_api/client/advertisers.rb,
lib/oi_api/client/subscriptions.rb,
lib/oi_api/client/data_transfers.rb,
lib/oi_api/client/auto_responders.rb

Defined Under Namespace

Modules: Advertisers, AutoResponders, Balances, Cards, Charges, DataTransfers, Offers, Reports, Subscriptions

Constant Summary

Constants included from LookupTables

LookupTables::CATEGORIES, LookupTables::DATA_FIELDS

Instance Method Summary collapse

Methods included from Reports

#reports

Methods included from AutoResponders

#all_auto_responders, #auto_responder, #auto_responders, #create_auto_responder, #update_auto_responder

Methods included from DataTransfers

#create_data_transfer, #data_transfer, #data_transfers, #delete_data_transfer, #update_data_transfer

Methods included from Offers

#create_offer, #offer, #offers, #update_offer

Methods included from Balances

#balance

Methods included from Subscriptions

#create_subscription, #subscription, #subscriptions

Methods included from Charges

#create_charge

Methods included from Cards

#card, #create_card, #update_card

Methods included from Advertisers

#advertiser, #advertisers, #create_advertiser, #delete_advertiser, #update_advertiser

Methods included from LookupTables

category_ids, category_names, data_field_oi_name, data_fields

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/oi_api/client.rb', line 33

def initialize(options = {})
  # Use options passed in, but fall back to config module defaults
  merged_options = OiApi.options.merge(options)

  # Copy the merged values to this client and ignore those
  # not part of our configuration
  OiApi::Configuration::VALID_CONFIG_KEYS.each do |key|
    public_send("#{key}=", merged_options[key])
  end

  if username.nil? || password.nil?
    raise NoCredentialsError, 'you must provide a username and password'
  end

  # set base_uri and format via HTTParty class methods
  self.class.base_uri(api_endpoint)
  self.class.format(format)
end

Instance Method Details

#delete(url, options = {}) ⇒ Object



64
65
66
# File 'lib/oi_api/client.rb', line 64

def delete(url, options = {})
  self.class.delete url, options_with_basic_auth(options)
end

#get(url, options = {}) ⇒ Object



52
53
54
# File 'lib/oi_api/client.rb', line 52

def get(url, options = {})
  self.class.get url, options_with_basic_auth(options)
end

#post(url, options = {}) ⇒ Object



56
57
58
# File 'lib/oi_api/client.rb', line 56

def post(url, options = {})
  self.class.post url, options_with_basic_auth(options)
end

#put(url, options = {}) ⇒ Object



60
61
62
# File 'lib/oi_api/client.rb', line 60

def put(url, options = {})
  self.class.put url, options_with_basic_auth(options)
end