Module: Balanced

Defined in:
lib/balanced.rb,
lib/balanced/error.rb,
lib/balanced/pager.rb,
lib/balanced/utils.rb,
lib/balanced/client.rb,
lib/balanced/version.rb,
lib/balanced/resources/card.rb,
lib/balanced/resources/debit.rb,
lib/balanced/resources/event.rb,
lib/balanced/resources/order.rb,
lib/balanced/resources/credit.rb,
lib/balanced/resources/refund.rb,
lib/balanced/resources/account.rb,
lib/balanced/resources/api_key.rb,
lib/balanced/resources/dispute.rb,
lib/balanced/resources/callback.rb,
lib/balanced/resources/customer.rb,
lib/balanced/resources/resource.rb,
lib/balanced/resources/reversal.rb,
lib/balanced/resources/transfer.rb,
lib/balanced/resources/card_hold.rb,
lib/balanced/resources/hypermedia.rb,
lib/balanced/resources/settlement.rb,
lib/balanced/resources/marketplace.rb,
lib/balanced/resources/bank_account.rb,
lib/balanced/resources/funding_instrument.rb

Defined Under Namespace

Modules: HypermediaRegistry, Resource, Utils Classes: Account, ApiKey, BadGateway, BadRequest, BankAccount, BankAccountVerification, BankAccountVerificationFailure, Callback, Card, CardHold, Client, Conflict, Credit, Customer, Debit, DebitableFundingInstrument, Dispute, Error, Event, EventCallback, Forbidden, FundingInstrument, FundingInstrumentNotCreditable, FundingInstrumentVerificationError, GatewayTimeout, Gone, InternalServerError, Log, Marketplace, MethodNotAllowed, MoreInformationRequired, NotFound, NotImplemented, Order, Pager, PaymentRequired, Refund, Reversal, ServiceUnavailable, Settlement, StandardError, Transfer, UnassociatedCardError, Unauthorized

Constant Summary collapse

VERSION =
'1.2.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clientObject

Returns the value of attribute client.



22
23
24
# File 'lib/balanced.rb', line 22

def client
  @client
end

.configObject

Returns the value of attribute config.



23
24
25
# File 'lib/balanced.rb', line 23

def config
  @config
end

.hypermedia_registryObject

Returns the value of attribute hypermedia_registry.



24
25
26
# File 'lib/balanced.rb', line 24

def hypermedia_registry
  @hypermedia_registry
end

Class Method Details

.configure(api_key = nil, options = {}) ⇒ Object



26
27
28
29
# File 'lib/balanced.rb', line 26

def configure(api_key=nil, options={})
  @config = @config.merge(options)
  @client = Balanced::Client.new(api_key, @config)
end

.from_href(href) ⇒ Object



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

def from_href(href)
  split_uri = split_the_href(href)
  split_uri.reverse!.each do |resource|
    cls = Balanced.hypermedia_registry[resource]
    return cls unless cls.nil?
  end
end

.from_hypermedia_registry(resource_name) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/balanced.rb', line 39

def from_hypermedia_registry(resource_name)
  cls = Balanced.hypermedia_registry[resource_name]
  if cls.nil?
    raise 'OH SHIT'
  end
  cls
end

.get(*args, &block) ⇒ Object



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

def get(*args, &block)
  self.client.get *args
end

.is_collection(href) ⇒ Object



55
56
57
58
# File 'lib/balanced.rb', line 55

def is_collection(href)
  split_uri = split_the_href(href)
  Balanced.hypermedia_registry.has_key?(split_uri.last)
end

.is_configured_with_api_key?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/balanced.rb', line 31

def is_configured_with_api_key?
  !@client.api_key.nil?
end

.post(*args, &block) ⇒ Object



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

def post(*args, &block)
  self.client.post *args
end

.put(*args, &block) ⇒ Object



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

def put(*args, &block)
  self.client.put *args
end

.split_the_href(href) ⇒ Object



35
36
37
# File 'lib/balanced.rb', line 35

def split_the_href(href)
  URI.parse(href).path.sub(/\/$/, '').split('/')
end

.unstore(*args, &block) ⇒ Object Also known as: delete



72
73
74
# File 'lib/balanced.rb', line 72

def unstore(*args, &block)
  self.client.unstore *args
end