Module: Charger

Defined in:
lib/charger.rb,
lib/charger/event.rb,
lib/charger/price.rb,
lib/charger/client.rb,
lib/charger/product.rb,
lib/charger/request.rb,
lib/charger/version.rb,
lib/charger/customer.rb,
lib/charger/resource.rb,
lib/charger/component.rb,
lib/charger/exception.rb,
lib/charger/line_item.rb,
lib/charger/statement.rb,
lib/charger/credit_card.rb,
lib/charger/transaction.rb,
lib/charger/subscription.rb,
lib/charger/configuration.rb,
lib/charger/product_family.rb,
lib/charger/component/on_off.rb,
lib/charger/line_item/on_off.rb,
lib/charger/component/metered.rb,
lib/charger/line_item/metered.rb,
lib/charger/component/quantity_based.rb,
lib/charger/line_item/quantity_based.rb

Defined Under Namespace

Modules: Request, Resource Classes: Client, Component, Configuration, CreditCard, Customer, Event, Exception, LineItem, Price, Product, ProductFamily, Statement, Subscription, Transaction

Constant Summary collapse

VERSION =
"0.2.0"
@@configurations =

The hash of configurations

{}
@@current =

The current client

nil

Class Method Summary collapse

Class Method Details

.clearvoid

This method returns an undefined value.

Clears all configurations



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

def self.clear
  @@configurations = Hash.new
  @@current = nil
end

.clientCharger::Client

Returns:



74
75
76
77
78
# File 'lib/charger.rb', line 74

def self.client
  @@current.client
rescue
  nil
end

.configurationsObject



80
81
82
# File 'lib/charger.rb', line 80

def self.configurations
  @@configurations
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Charger)

    the object that the method was called on



38
39
40
# File 'lib/charger.rb', line 38

def configure
  yield self
end

.currentObject



84
85
86
# File 'lib/charger.rb', line 84

def self.current
  @@current
end

.site=(params = {}) ⇒ void

This method returns an undefined value.

Add a configuration to Charger

Parameters:

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


47
48
49
50
51
52
# File 'lib/charger.rb', line 47

def self.site= params={}
  return unless params[:subdomain] || params[:api_key]
  config = Configuration.new(params)
  @@configurations[config.subdomain] = config
  @@current = config
end

.switch(subdomain) ⇒ Boolean

Switches between configurations. Useful if you want to connect to multiple chargify accounts at once.

Returns:

  • (Boolean)


58
59
60
61
62
63
# File 'lib/charger.rb', line 58

def self.switch subdomain
  @@current = @@configurations[subdomain]
  true
rescue
  false
end