Module: Finix

Defined in:
lib/finix.rb,
lib/finix/utils.rb,
lib/finix/client.rb,
lib/finix/errors.rb,
lib/finix/version.rb,
lib/finix/pagination.rb,
lib/finix/hal_resource.rb,
lib/finix/resources/user.rb,
lib/finix/resources/error.rb,
lib/finix/resources/token.rb,
lib/finix/indifferent_hash.rb,
lib/finix/resources/refund.rb,
lib/finix/resources/dispute.rb,
lib/finix/resources/webhook.rb,
lib/finix/resources/evidence.rb,
lib/finix/resources/identity.rb,
lib/finix/resources/merchant.rb,
lib/finix/resources/resource.rb,
lib/finix/resources/transfer.rb,
lib/finix/resources/processor.rb,
lib/finix/resources/hypermedia.rb,
lib/finix/resources/settlement.rb,
lib/finix/resources/verifiable.rb,
lib/finix/resources/application.rb,
lib/finix/resources/fee_profile.rb,
lib/finix/resources/bank_account.rb,
lib/finix/resources/payment_card.rb,
lib/finix/resources/risk_profile.rb,
lib/finix/resources/verification.rb,
lib/finix/resources/authorization.rb,
lib/finix/resources/merchant_profile.rb,
lib/finix/resources/unknown_resource.rb,
lib/finix/resources/payment_instrument.rb

Defined Under Namespace

Modules: HalResource, HypermediaRegistry, Resource, Utils, Verifiable Classes: Application, Authorization, BadRequest, BankAccount, Client, Dispute, Error, Errors, Evidence, FeeProfile, Forbidden, Identity, IndifferentHash, InternalServerError, Merchant, MerchantProfile, MethodNotAllowed, NotFound, Pagination, PaymentCard, PaymentInstrument, PaymentRequired, Processor, Refund, RiskProfile, Settlement, Token, Transfer, Unauthorized, UnknownResource, UnprocessableEntity, User, Verification, Webhook

Constant Summary collapse

VERSION =
'1.0.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.clientObject

Returns the value of attribute client.



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

def client
  @client
end

.configObject

Returns the value of attribute config.



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

def config
  @config
end

.errors_registryObject

Returns the value of attribute errors_registry.



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

def errors_registry
  @errors_registry
end

.hypermedia_registryObject

Returns the value of attribute hypermedia_registry.



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

def hypermedia_registry
  @hypermedia_registry
end

Class Method Details

.configure(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/finix.rb', line 29

def configure(options={})
  unless options[:root_url].nil?
    @config = {}
  end

  @config = @config.merge(options)
  @config[:user] = @config[:user].strip unless @config[:user].nil?
  @config[:password] = @config[:password].strip unless @config[:password].nil?

  @client = Client.new @config
end

.find_resource_cls(resource, attributes = {}) ⇒ Object



67
68
69
70
71
72
# File 'lib/finix.rb', line 67

def find_resource_cls(resource, attributes={})
  cls = hypermedia_registry[resource]
  # cls = hypermedia_registry["__stub__#{resource}"] if cls.nil?
  cls = cls.send :hypermedia_subtype, attributes if not cls.nil? and cls.respond_to?(:hypermedia_subtype)
  cls
end

.from_hypermedia_registry(href, attributes = {}) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/finix.rb', line 58

def from_hypermedia_registry(href, attributes={})
  split_uri = split_the_href(href)
  split_uri.reverse!.each do |resource|
    cls = find_resource_cls(resource, attributes)
    return cls unless cls.nil?
  end
  Finix::Utils.eval_class self, UnknownResource
end

.get(*args, &block) ⇒ Object



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

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

.get_href(cls) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/finix.rb', line 45

def get_href(cls)
  href = (not cls.nil? and not cls.hypermedia_types.nil?) ? cls.hypermedia_types.last : hypermedia_registry.key(cls)

  sps = cls
  while href.nil?
    sps = sps.superclass
    break if sps.nil?
    clss = Finix::Utils.eval_class cls, sps
    href = hypermedia_registry.key(clss)
  end
  href
end

.post(*args, &block) ⇒ Object



78
79
80
# File 'lib/finix.rb', line 78

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

.put(*args, &block) ⇒ Object



82
83
84
# File 'lib/finix.rb', line 82

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

.split_the_href(href) ⇒ Object



41
42
43
# File 'lib/finix.rb', line 41

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