finix 0.7 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjIwZTY2OGE1ZjA0OWNhYWEwOGZmOTFkZWM1MjU5MzE0ZTdlNGQ0Yw==
4
+ Zjg0YmY4ZWE5ZDU2MDdlNzc3Mzg4MGM5YTU2YTAxZmFhY2YwZjNjNw==
5
5
  data.tar.gz: !binary |-
6
- YzA3ZmQ1ZGZmMDliMzU5ZTU4NmZlYzllYWU5NzQ3MjZlYjRmZTNmNw==
6
+ ZmM5ODFlMzBlYzZlMWVjZmQwMTVkMGYyY2FjZDU0NDhlYTNjZmVlMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTc4NzJjMWE5Y2JkZjhjMjVlZDI3OTM4MjZjZDVjZDNhMzc3NjdhZGJlZTZl
10
- YzAzOTdjODBiMDdiZmFiZWVmMDc2MGQwYzI3MzlmOGYwMmI4OTBhNDJjMDU2
11
- ZDRhNzA3MmI1YzA2NTBkZDNlNzcyMDlhOGU5NDI1MGZhZjExZjg=
9
+ YjJmNGRlZmFlZDA2NjAxNTM5NWE0MjNhZGE1ZGVjN2Y2ODM2ZTA2NTRiODRh
10
+ YzQ2NWQ0MDBmMTNkYjA1NTYwYTIyN2NiOTVkYjVmOTVkM2FiNmFkMTBlNTFi
11
+ NWVmN2RmYmM2YTViZWI0ZmMyZDQ3NGEyZTYzYTdiZTZlNzNhYjY=
12
12
  data.tar.gz: !binary |-
13
- YzJmZWZiYTExMDg5YTI5OTBhNjA2OGY5MzIzMWRlMGE0YTA5ZGUxYjQ0MjAx
14
- OTA2ZDk0NWJhY2NlMDBhMWIwNmNhOTNiZDkzMWYwZTVlYWUyMWVmYjY1NTc0
15
- NTY1MGViMzViODZhMDhkZGE3ZDM4ZTJhYmM5ZWE1MzUxMGVjZDA=
13
+ YjIzYzhiMDJhZjNlNDE3OGFiZDU1MjFhYzk1Y2JhYTQwZTk5NThiNGU3NzZi
14
+ MDZhMzVhOGFkN2M0NjhkYzg1YjRjYWZjZmU1MDI3ZTk0OTNmN2QxMzRmODg1
15
+ N2IwMjI4MmEzYzMwZmExNWRkNWY2NDFlYmE4ZDBiOWIxNDkyMDc=
data/circle.yml CHANGED
@@ -18,4 +18,13 @@ test:
18
18
  - rvm $RUBY_VERSIONS --verbose do bundle exec rake test
19
19
 
20
20
  post:
21
- - cp -Rf .report/ $CIRCLE_ARTIFACTS
21
+ - cp -Rf .report/ $CIRCLE_ARTIFACTS
22
+
23
+ #deployment:
24
+ # release:
25
+ # tag: /v[0-9]+(\.[0-9]+)*/
26
+ # owner: finix-payments
27
+ # commands:
28
+ # - echo "--\n:rubygems_api_key: ${RUBYGEMS_API_KEY}" > ~/.gem/credentials
29
+ # - gem build *.gemspec
30
+ # - gem push *.gem
data/lib/finix.rb CHANGED
@@ -5,7 +5,7 @@ require 'finix/error'
5
5
  module Finix
6
6
 
7
7
  @client = nil
8
- @config = {:root_url=>'https://localhost/processing'}
8
+ @config = {:root_url => 'https://localhost/processing'}
9
9
  @hypermedia_registry = {}
10
10
 
11
11
  class << self
@@ -30,25 +30,20 @@ module Finix
30
30
  URI.parse(href).path.sub(/\/$/, '').split('/')
31
31
  end
32
32
 
33
- def from_hypermedia_registry(resource_name)
34
- cls = Finix.hypermedia_registry[resource_name]
35
- if cls.nil?
36
- return Finix::UnknownResource
37
- end
38
- cls
33
+ def get_href(cls)
34
+ href = Finix.hypermedia_registry.key(cls)
35
+ href = Finix.hypermedia_registry.key(cls.superclass) if href.nil?
36
+ href
39
37
  end
40
38
 
41
- def from_href(href)
39
+ def from_hypermedia_registry(href, attributes={})
42
40
  split_uri = split_the_href(href)
43
41
  split_uri.reverse!.each do |resource|
44
42
  cls = Finix.hypermedia_registry[resource]
43
+ cls = cls.send :hypermedia_subtype, attributes if not cls.nil? and cls.respond_to?(:hypermedia_subtype)
45
44
  return cls unless cls.nil?
46
45
  end
47
- end
48
-
49
- def is_collection(href)
50
- split_uri = split_the_href(href)
51
- Finix.hypermedia_registry.has_key?(split_uri.last)
46
+ Finix::UnknownResource
52
47
  end
53
48
 
54
49
  def get(*args, &block)
@@ -49,9 +49,7 @@ module Finix
49
49
  attrs = attrs.attributes if attrs.is_a?(Finix::Resource)
50
50
  attrs = Finix::Utils.indifferent_read_access attrs
51
51
  href = @hyperlinks[:self]
52
- if @resource_class.nil?
53
- @resource_class = Finix.from_href(href)
54
- end
52
+ @resource_class = Finix.from_hypermedia_registry href, attrs
55
53
  @resource_class.new(attrs, href).save
56
54
  end
57
55
 
@@ -70,7 +68,10 @@ module Finix
70
68
  if body.has_key? '_embedded'
71
69
  resource_name, resources = body.delete('_embedded').first
72
70
  @resource_class = Finix.from_hypermedia_registry resource_name
73
- @attributes['items'] = resources.map { |item| @resource_class.construct_from_response item }
71
+ @attributes['items'] = resources.map do |attrs|
72
+ cls = Finix.from_hypermedia_registry resource_name, attrs
73
+ cls.construct_from_response attrs
74
+ end
74
75
  @attributes['page'] = body.delete('page')
75
76
  end
76
77
  end
@@ -17,4 +17,5 @@ require 'finix/resources/webhook'
17
17
  require 'finix/resources/verification'
18
18
  require 'finix/resources/dispute'
19
19
  require 'finix/resources/evidence'
20
- require 'finix/resources/refund'
20
+ require 'finix/resources/refund'
21
+ require 'finix/resources/settlement'
@@ -6,7 +6,7 @@ module Finix
6
6
  define_hypermedia_types [:authorizations]
7
7
 
8
8
  def void
9
- self['void_me'] = true
9
+ self.void_me = true
10
10
  self.save
11
11
  end
12
12
 
@@ -6,7 +6,7 @@ module Finix
6
6
 
7
7
  define_hypermedia_types [:identities]
8
8
 
9
- def provision_merchant_on(attrs={})
9
+ def provision_merchant(attrs={})
10
10
  self.merchants.create(attrs)
11
11
  end
12
12
 
@@ -15,13 +15,7 @@ module Finix
15
15
  attrs.identity = self.id
16
16
  attrs = attrs.attributes
17
17
  else
18
- attrs['identity'] = self.id # TODO might be error here
19
- end
20
-
21
- if attrs['type'] == 'PAYMENT_CARD'
22
- self.payment_instruments.resource_class = Finix::PaymentCard
23
- elsif attrs['type'] == 'BANK_ACCOUNT'
24
- self.payment_instruments.resource_class = Finix::BankAccount
18
+ attrs['identity'] = self.id
25
19
  end
26
20
 
27
21
  self.payment_instruments.create(attrs)
@@ -2,6 +2,7 @@ module Finix
2
2
  class Merchant
3
3
  include Finix::Resource
4
4
  include Finix::HypermediaRegistry
5
+ include Finix::Verifiable
5
6
 
6
7
  define_hypermedia_types [:merchants]
7
8
  end
@@ -2,7 +2,22 @@ module Finix
2
2
  class PaymentInstrument
3
3
  include Finix::Resource
4
4
  include Finix::HypermediaRegistry
5
+ include Finix::Verifiable
5
6
 
6
7
  define_hypermedia_types [:payment_instruments]
8
+
9
+ class << self
10
+ def hypermedia_subtype(response)
11
+ unless response.nil?
12
+ type = response['instrument_type'] || response['type']
13
+ if type == 'PAYMENT_CARD'
14
+ return Finix::PaymentCard
15
+ elsif type == 'BANK_ACCOUNT'
16
+ return Finix::BankAccount
17
+ end
18
+ end
19
+ self
20
+ end
21
+ end
7
22
  end
8
23
  end
@@ -38,10 +38,9 @@ module Finix
38
38
  options = options.is_a?(Finix::Resource) ? options.attributes : options
39
39
  @attributes = @attributes.merge options
40
40
  href ||= @hyperlinks[:self]
41
- # href = @attributes.delete('href')
42
41
  method = :post
43
42
  if href.nil?
44
- href = Finix.hypermedia_registry.key(self.class)
43
+ href = Finix.get_href self.class
45
44
  elsif not @attributes[:id].nil?
46
45
  method = :put
47
46
  end
@@ -59,9 +58,7 @@ module Finix
59
58
  def sanitize
60
59
  to_submit = {}
61
60
  @attributes.each do |key, value|
62
- if not value.is_a? Finix::Resource
63
- to_submit[key] = value
64
- end
61
+ to_submit[key] = value unless value.is_a? Finix::Resource
65
62
  end
66
63
  to_submit
67
64
  end
@@ -78,14 +75,11 @@ module Finix
78
75
  fresh = self.class.construct_from_response the_response.body
79
76
  else
80
77
  fresh = self.find(@hyperlinks[:self])
81
- # fresh = self.find(@attributes[:href])
82
78
  end
83
79
  fresh and copy_from fresh
84
80
  self
85
81
  end
86
82
 
87
- # alias refresh load!
88
-
89
83
  def copy_from(other)
90
84
  other.instance_variables.each do |ivar|
91
85
  instance_variable_set ivar, other.instance_variable_get(ivar)
@@ -96,6 +90,11 @@ module Finix
96
90
  "#{self.class.name.split('::').last || ''} #{@attributes}"
97
91
  end
98
92
 
93
+ def inspect
94
+ insp = super.inspect
95
+ "#{insp.split('::').last || ''}"
96
+ end
97
+
99
98
  def self.included(base)
100
99
  base.extend ClassMethods
101
100
  end
@@ -132,6 +131,7 @@ module Finix
132
131
  end
133
132
 
134
133
  alias find fetch
134
+ alias retrieve fetch
135
135
  end
136
136
 
137
137
  end
@@ -1,12 +1,9 @@
1
1
  module Finix
2
2
  module Verifiable
3
- def verify_on(attrs={})
3
+ def verify(attrs={})
4
4
  attrs = attrs.attributes if attrs.is_a?(Finix::Resource)
5
- unless self.verifications.nil?
6
- self.verifications.create(attrs)
7
- else
8
- raise NotImplementedError.new 'not found `verifications` rel'
9
- end
5
+ return self.verifications.create(attrs) unless self.verifications.nil?
6
+ raise NotImplementedError.new 'not found `verifications` rel'
10
7
  end
11
8
  end
12
9
  end
data/lib/finix/utils.rb CHANGED
@@ -1,45 +1,10 @@
1
1
  module Finix
2
-
3
2
  module Utils
4
3
 
5
4
  def callable(callable_or_not)
6
5
  callable_or_not.respond_to?(:call) ? callable_or_not : lambda { callable_or_not }
7
6
  end
8
7
 
9
- def camelize(underscored_word)
10
- underscored_word.to_s.gsub(/(?:^|_)(.)/) { $1.upcase }
11
- end
12
-
13
- def classify(table_name)
14
- camelize singularize(table_name.to_s.sub(/.*\./, ''))
15
- end
16
-
17
- def demodulize(class_name_in_module)
18
- class_name_in_module.to_s.sub(/^.*::/, '')
19
- end
20
-
21
- def pluralize(word)
22
- word.to_s.sub(/([^s])$/, '\1s')
23
- end
24
-
25
- def singularize(word)
26
- word.to_s.sub(/s$/, '').sub(/ie$/, 'y')
27
- end
28
-
29
- def underscore(camel_cased_word)
30
- word = camel_cased_word.to_s.dup
31
- word.gsub!(/::/, '/')
32
- word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
33
- word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
34
- word.tr! '-', '_'
35
- word.downcase!
36
- word
37
- end
38
-
39
- # def extract_href_from_object(object)
40
- # object.respond_to?(:href) ? object.href : object
41
- # end
42
-
43
8
  def indifferent_read_access(base = {})
44
9
  indifferent = Hash.new do |hash, key|
45
10
  hash[key.to_s] if key.is_a? Symbol
@@ -69,40 +34,6 @@ module Finix
69
34
  indifferent
70
35
  end
71
36
 
72
- # def stringify_keys!(hash)
73
- # hash.keys.each do |key|
74
- # stringify_keys! hash[key] if hash[key].is_a? Hash
75
- # hash[key.to_s] = hash.delete key if key.is_a? Symbol
76
- # end
77
- # end
78
-
79
- # Validate all keys in a hash match *valid keys, raising ArgumentError on a mismatch.
80
- # Note that keys are NOT treated indifferently, meaning if you use strings for keys but assert symbols
81
- # as keys, this will fail.
82
- #
83
- # ==== Examples
84
- # { :name => "Rob", :years => "28" }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key(s): years"
85
- # { :name => "Rob", :age => "28" }.assert_valid_keys("name", "age") # => raises "ArgumentError: Unknown key(s): name, age"
86
- # { :name => "Rob", :age => "28" }.assert_valid_keys(:name, :age) # => passes, raises nothing
87
- # def assert_valid_keys(hash, *valid_keys)
88
- # unknown_keys = hash.keys - [valid_keys].flatten
89
- # raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(', ')}") unless unknown_keys.empty?
90
- # end
91
-
92
- # http://pablomanrubia.com/2011/03/extending-ruby-to-validate-required-keys-in-a-hash-table/
93
- #def assert_required_keys(hash, params)
94
- # params[:required] ||= []
95
- # params[:optional] ||= []
96
- # assert_valid_keys(hash, params[:required] + params[:optional])
97
- # pending_keys = params[:required] - hash.keys
98
- # raise(ArgumentError, "Required key(s) not present: #{pending_keys.join(', ')}") unless pending_keys.empty?
99
- #end
100
-
101
- # def assert_required_keys(hash, params)
102
- # params[:required] ||= []
103
- # pending_keys = params[:required] - hash.keys
104
- # raise(ArgumentError, "Required key(s) not present: #{pending_keys.join(', ')}") unless pending_keys.empty?
105
- # end
106
37
  extend self
107
38
  end
108
39
  end
data/lib/finix/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Finix
2
- VERSION = '0.7'
2
+ VERSION = '0.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: finix
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - finix-payments
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-08 00:00:00.000000000 Z
11
+ date: 2016-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday