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/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/marketplace.rb,
lib/balanced/resources/bank_account.rb,
lib/balanced/resources/funding_instrument.rb

Defined Under Namespace

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

Constant Summary collapse

VERSION =
'1.0.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clientObject

Returns the value of attribute client.



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

def client
  @client
end

.configObject

Returns the value of attribute config.



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

def config
  @config
end

.hypermedia_registryObject

Returns the value of attribute hypermedia_registry.



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

def hypermedia_registry
  @hypermedia_registry
end

Class Method Details

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



28
29
30
31
# File 'lib/balanced.rb', line 28

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

.from_href(href) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/balanced.rb', line 49

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



41
42
43
44
45
46
47
# File 'lib/balanced.rb', line 41

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



62
63
64
# File 'lib/balanced.rb', line 62

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

.is_collection(href) ⇒ Object



57
58
59
60
# File 'lib/balanced.rb', line 57

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)


33
34
35
# File 'lib/balanced.rb', line 33

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

.post(*args, &block) ⇒ Object



66
67
68
# File 'lib/balanced.rb', line 66

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

.put(*args, &block) ⇒ Object



70
71
72
# File 'lib/balanced.rb', line 70

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

.split_the_href(href) ⇒ Object



37
38
39
# File 'lib/balanced.rb', line 37

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

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



74
75
76
# File 'lib/balanced.rb', line 74

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