stone-ruby 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +21 -0
  3. data/.rubocop.yml +28 -0
  4. data/Gemfile +4 -2
  5. data/Gemfile.lock +56 -2
  6. data/Rakefile +5 -3
  7. data/bin/console +4 -3
  8. data/lib/stone-ruby.rb +3 -1
  9. data/lib/stone.rb +7 -2
  10. data/lib/stone/conciliation.rb +3 -1
  11. data/lib/stone/conciliation/client.rb +5 -6
  12. data/lib/stone/conciliation/client/access_authorization.rb +3 -3
  13. data/lib/stone/conciliation/error.rb +2 -0
  14. data/lib/stone/siclos.rb +4 -1
  15. data/lib/stone/siclos/client.rb +40 -39
  16. data/lib/stone/siclos/client/claim_check.rb +8 -8
  17. data/lib/stone/siclos/client/danfe.rb +8 -8
  18. data/lib/stone/siclos/client/establishment.rb +7 -7
  19. data/lib/stone/siclos/client/finance.rb +3 -3
  20. data/lib/stone/siclos/client/pos.rb +10 -10
  21. data/lib/stone/siclos/client/pre_transaction.rb +8 -8
  22. data/lib/stone/siclos/client/recipient.rb +7 -7
  23. data/lib/stone/siclos/client/token.rb +2 -0
  24. data/lib/stone/siclos/client/transaction.rb +7 -7
  25. data/lib/stone/siclos/client/webhook.rb +15 -15
  26. data/lib/stone/siclos/entity.rb +25 -0
  27. data/lib/stone/siclos/entity/address.rb +17 -0
  28. data/lib/stone/siclos/entity/anticipation.rb +13 -0
  29. data/lib/stone/siclos/entity/bank.rb +16 -0
  30. data/lib/stone/siclos/entity/capture_method.rb +14 -0
  31. data/lib/stone/siclos/entity/card_rate.rb +16 -0
  32. data/lib/stone/siclos/entity/contact.rb +13 -0
  33. data/lib/stone/siclos/entity/contact_recipient.rb +11 -0
  34. data/lib/stone/siclos/entity/create_establishment.rb +28 -0
  35. data/lib/stone/siclos/entity/create_establishment_existing.rb +17 -0
  36. data/lib/stone/siclos/entity/create_recipient.rb +24 -0
  37. data/lib/stone/siclos/entity/create_recipient_existing.rb +18 -0
  38. data/lib/stone/siclos/entity/responsible.rb +12 -0
  39. data/lib/stone/siclos/entity/responsible_recipient.rb +14 -0
  40. data/lib/stone/siclos/error.rb +2 -0
  41. data/lib/stone/types.rb +15 -0
  42. data/lib/stone/version.rb +4 -2
  43. data/stone-ruby.gemspec +8 -4
  44. metadata +64 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a23a63fbdc1bb1433367f370c063a0d28cfdc52c
4
- data.tar.gz: 204650e096bde9af4068afde6f655d2195500156
3
+ metadata.gz: a541b337ffb36ae567af10ae71e538c422786d89
4
+ data.tar.gz: fbecf06870b9af48a83caed8a95f604bc49363b4
5
5
  SHA512:
6
- metadata.gz: 3e85a013d4e0c3bac241c7198a7806ad1d92483ecddd079e0e9c74d117566dbd9de6749e72df2ac15428eeb3c8e36d711b35cf5f568b473f850fd3692570b2ff
7
- data.tar.gz: 1fe3e4abb1aaf457a838caf58d89b884cf7be6bc8dd7d38c26039efaf65f2810a981fd6774db9e67fd72839ca219b850191bffea27ee18f6bc2919796441bc6a
6
+ metadata.gz: 825e4759a977d4352adaeda0b88c118197823f33eabe64c6872dcb019d66903fb03b67d3ebf28f4a65a40bce5bee2262bd8ba594faa2a4c32ba2e93d211056d0
7
+ data.tar.gz: f7664fd60f013f7aeba71e548e685cf289959171fb34ec3245eccf1ebce990eaf6a92ba4b02eeaeb501d0573542336aefdbe0f0fb52baa5f5384f2e7a4e32976
data/.editorconfig ADDED
@@ -0,0 +1,21 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+
8
+ [*]
9
+
10
+ # Change these settings to your own preference
11
+ indent_style = space
12
+ indent_size = 2
13
+
14
+ # We recommend you to keep these unchanged
15
+ end_of_line = lf
16
+ charset = utf-8
17
+ trim_trailing_whitespace = true
18
+ insert_final_newline = true
19
+
20
+ [*.md]
21
+ trim_trailing_whitespace = false
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
11
+ Style/HashEachMethods:
12
+ Enabled: true
13
+ Style/HashTransformKeys:
14
+ Enabled: true
15
+ Style/HashTransformValues:
16
+ Enabled: true
17
+ Layout/LineLength:
18
+ Max: 100
19
+ Style/StringLiterals:
20
+ EnforcedStyle: single_quotes
21
+ Style/Documentation:
22
+ Enabled: false
23
+ Style/DocumentationMethod:
24
+ Enabled: false
25
+ Naming/AccessorMethodName:
26
+ Enabled: false
27
+ Style/ClassAndModuleChildren:
28
+ Enabled: false
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in stone-ruby.gemspec
6
8
  gemspec
data/Gemfile.lock CHANGED
@@ -1,27 +1,67 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stone-ruby (0.0.1)
4
+ stone-ruby (0.1.0)
5
+ activesupport (~> 4.2)
5
6
  dry-configurable (~> 0.8.3)
7
+ dry-struct (~> 0.7)
6
8
  request_store_rails (~> 2.0.0)
7
9
  typhoeus (~> 1.0.2)
8
10
 
9
11
  GEM
10
12
  remote: https://rubygems.org/
11
13
  specs:
14
+ activesupport (4.2.11.3)
15
+ i18n (~> 0.7)
16
+ minitest (~> 5.1)
17
+ thread_safe (~> 0.3, >= 0.3.4)
18
+ tzinfo (~> 1.1)
19
+ ast (2.4.2)
12
20
  concurrent-ruby (1.1.8)
13
21
  diff-lcs (1.3)
14
22
  dry-configurable (0.8.3)
15
23
  concurrent-ruby (~> 1.0)
16
24
  dry-core (~> 0.4, >= 0.4.7)
25
+ dry-container (0.7.2)
26
+ concurrent-ruby (~> 1.0)
27
+ dry-configurable (~> 0.1, >= 0.1.3)
17
28
  dry-core (0.4.9)
18
29
  concurrent-ruby (~> 1.0)
30
+ dry-equalizer (0.2.2)
31
+ dry-inflector (0.1.2)
32
+ dry-logic (0.6.1)
33
+ concurrent-ruby (~> 1.0)
34
+ dry-core (~> 0.2)
35
+ dry-equalizer (~> 0.2)
36
+ dry-struct (0.7.0)
37
+ dry-core (~> 0.4, >= 0.4.3)
38
+ dry-equalizer (~> 0.2)
39
+ dry-types (~> 0.15)
40
+ ice_nine (~> 0.11)
41
+ dry-types (0.15.0)
42
+ concurrent-ruby (~> 1.0)
43
+ dry-container (~> 0.3)
44
+ dry-core (~> 0.4, >= 0.4.4)
45
+ dry-equalizer (~> 0.2, >= 0.2.2)
46
+ dry-inflector (~> 0.1, >= 0.1.2)
47
+ dry-logic (~> 0.5, >= 0.5)
19
48
  ethon (0.12.0)
20
49
  ffi (>= 1.3.0)
21
- ffi (1.14.2)
50
+ ffi (1.15.0)
51
+ i18n (0.9.5)
52
+ concurrent-ruby (~> 1.0)
53
+ ice_nine (0.11.2)
54
+ jaro_winkler (1.5.4)
55
+ minitest (5.14.1)
56
+ parallel (1.19.1)
57
+ parser (3.0.0.0)
58
+ ast (~> 2.4.1)
59
+ rainbow (2.2.2)
60
+ rake
22
61
  rake (10.5.0)
23
62
  request_store_rails (2.0.0)
24
63
  concurrent-ruby (~> 1.0)
64
+ rexml (3.2.4)
25
65
  rspec (3.9.0)
26
66
  rspec-core (~> 3.9.0)
27
67
  rspec-expectations (~> 3.9.0)
@@ -35,8 +75,21 @@ GEM
35
75
  diff-lcs (>= 1.2.0, < 2.0)
36
76
  rspec-support (~> 3.9.0)
37
77
  rspec-support (3.9.3)
78
+ rubocop (0.80.1)
79
+ jaro_winkler (~> 1.5.1)
80
+ parallel (~> 1.10)
81
+ parser (>= 2.7.0.1)
82
+ rainbow (>= 2.2.2, < 4.0)
83
+ rexml
84
+ ruby-progressbar (~> 1.7)
85
+ unicode-display_width (>= 1.4.0, < 1.7)
86
+ ruby-progressbar (1.10.1)
87
+ thread_safe (0.3.6)
38
88
  typhoeus (1.0.2)
39
89
  ethon (>= 0.9.0)
90
+ tzinfo (1.2.7)
91
+ thread_safe (~> 0.1)
92
+ unicode-display_width (1.6.1)
40
93
 
41
94
  PLATFORMS
42
95
  ruby
@@ -45,6 +98,7 @@ DEPENDENCIES
45
98
  bundler (~> 1.17)
46
99
  rake (~> 10.0)
47
100
  rspec (~> 3.0)
101
+ rubocop (= 0.80.1)
48
102
  stone-ruby!
49
103
 
50
104
  BUNDLED WITH
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "stone/payments"
4
+ require 'bundler/setup'
5
+ require 'stone/payments'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "stone/payments"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
data/lib/stone-ruby.rb CHANGED
@@ -1 +1,3 @@
1
- require 'stone'
1
+ # frozen_string_literal: true
2
+
3
+ require 'stone'
data/lib/stone.rb CHANGED
@@ -1,10 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry-configurable'
4
+ require 'dry-struct'
2
5
  require 'typhoeus'
3
6
  require 'stone/version'
7
+ require 'stone/types'
8
+ require 'active_support'
4
9
 
5
10
  module Stone
6
11
  extend Dry::Configurable
7
12
 
13
+ autoload :Types, 'stone/types'
8
14
  autoload :Siclos, 'stone/siclos'
9
15
  autoload :Conciliation, 'stone/conciliation'
10
16
 
@@ -24,7 +30,6 @@ module Stone
24
30
  end
25
31
 
26
32
  def self.configure
27
- yield self.config
33
+ yield config
28
34
  end
29
-
30
35
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Stone
2
4
  module Conciliation
3
5
  autoload :Client, 'stone/conciliation/client'
4
6
  autoload :Error, 'stone/conciliation/error'
5
7
  end
6
- end
8
+ end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Stone::Siclos
2
4
  module Client
3
-
4
-
5
5
  class Response
6
6
  def initialize(code, data)
7
7
  @code = code
@@ -17,6 +17,7 @@ module Stone::Siclos
17
17
  end
18
18
 
19
19
  private
20
+
20
21
  def raise_exception
21
22
  return unless Stone.config.siclos.use_exception
22
23
 
@@ -25,7 +26,6 @@ module Stone::Siclos
25
26
  end
26
27
 
27
28
  class Base
28
-
29
29
  def initialize
30
30
  @token = Stone.config.siclos.api_key
31
31
  end
@@ -44,8 +44,8 @@ module Stone::Siclos
44
44
  body: data ? data.to_json : nil,
45
45
  params: params,
46
46
  headers: {
47
- :'Content-Type'=> 'application/json',
48
- :Authorization => "Bearer #{@token}"
47
+ 'Content-Type': 'application/json',
48
+ Authorization: "Bearer #{@token}"
49
49
  }
50
50
  ).run
51
51
  Response.new(response.response_code, response.response_body)
@@ -53,7 +53,6 @@ module Stone::Siclos
53
53
  end
54
54
 
55
55
  class << self
56
-
57
56
  end
58
57
  end
59
58
  end
@@ -1,7 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Stone::Conciliation::Client
2
4
  class AccessAuthorization
3
- def self.call(stone_code)
4
-
5
- end
5
+ def self.call(stone_code); end
6
6
  end
7
7
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Stone::Conciliation
2
4
  class Error < StandardError
3
5
  class TokenError < Error; end
data/lib/stone/siclos.rb CHANGED
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Stone
2
4
  module Siclos
3
5
  autoload :Client, 'stone/siclos/client'
6
+ autoload :Entity, 'stone/siclos/entity'
4
7
  autoload :Error, 'stone/siclos/error'
5
8
  end
6
- end
9
+ end
@@ -1,8 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Stone::Siclos
2
4
  module Client
3
-
4
- TOKEN_KEY = :siclos_token
5
-
6
5
  autoload :Token, 'stone/siclos/client/token'
7
6
  autoload :Establishment, 'stone/siclos/client/establishment'
8
7
  autoload :Recipient, 'stone/siclos/client/recipient'
@@ -15,19 +14,21 @@ module Stone::Siclos
15
14
  autoload :Webhook, 'stone/siclos/client/webhook'
16
15
 
17
16
  class Response
17
+ attr_reader :data
18
+ attr_reader :code
19
+
18
20
  def initialize(code, data)
19
21
  @code = code
20
22
  @data = JSON.parse(data, symbolize_names: true)
21
23
  raise_exception unless @data[:success]
22
24
  end
23
- attr_reader :data
24
- attr_reader :code
25
25
 
26
26
  def success?
27
27
  @data[:success]
28
28
  end
29
29
 
30
30
  private
31
+
31
32
  def raise_exception
32
33
  return unless Stone.config.siclos.use_exception
33
34
 
@@ -36,9 +37,8 @@ module Stone::Siclos
36
37
  end
37
38
 
38
39
  class Base
39
-
40
- def initialize(_token = Stone.config.siclos.api_key)
41
- @token = RequestLocals.store[TOKEN_KEY] || _token
40
+ def initialize(token = Stone.config.siclos.api_key)
41
+ @token = token
42
42
  end
43
43
 
44
44
  def parse_endpoint(path)
@@ -48,81 +48,82 @@ module Stone::Siclos
48
48
  URI.join(endpoint, path)
49
49
  end
50
50
 
51
+ def remove_blank_values(data)
52
+ object = data.respond_to?(:attributes) ? data.attributes : data
53
+ object.each_with_object({}) do |(k, v), new_hash|
54
+ unless v.blank? && v != false
55
+ if v.respond_to?(:attributes)
56
+ new_hash[k] = remove_blank_values(v.attributes)
57
+ next
58
+ end
59
+
60
+ new_hash[k] = v.is_a?(Hash) ? remove_blank_values(v) : v
61
+ end
62
+ end
63
+ end
64
+
51
65
  def request(method, path, data = nil, params = nil)
52
66
  response = Typhoeus::Request.new(
53
67
  parse_endpoint(path),
54
68
  method: method,
55
- body: data ? data.to_json : nil,
69
+ body: data ? remove_blank_values(data).to_json : nil,
56
70
  params: params,
57
- headers: {
58
- :'Content-Type'=> 'application/json',
59
- :Authorization => "Bearer #{@token}"
60
- }
71
+ headers: { 'Content-Type': 'application/json', Authorization: "Bearer #{@token}" }
61
72
  ).run
62
73
  Response.new(response.response_code, response.response_body)
63
74
  end
64
75
  end
65
76
 
66
77
  class << self
78
+ attr_reader :authentication_token
79
+
67
80
  def token
68
81
  @token ||= Token.new
69
82
  end
70
83
 
71
84
  def establishment
72
- @establishment ||= Establishment.new
85
+ @establishment ||= Establishment.new(@authentication_token)
73
86
  end
74
87
 
75
88
  def recipient
76
- @recipient ||= Recipient.new
89
+ @recipient ||= Recipient.new(@authentication_token)
77
90
  end
78
91
 
79
92
  def pos
80
- @pos ||= Pos.new
93
+ @pos ||= Pos.new(@authentication_token)
81
94
  end
82
95
 
83
96
  def pre_transaction
84
- @pre_transaction ||= PreTransaction.new
97
+ @pre_transaction ||= PreTransaction.new(@authentication_token)
85
98
  end
86
99
 
87
100
  def transaction
88
- @transaction ||= Transaction.new
101
+ @transaction ||= Transaction.new(@authentication_token)
89
102
  end
90
103
 
91
104
  def finance
92
- @finance ||= Finance.new
105
+ @finance ||= Finance.new(@authentication_token)
93
106
  end
94
107
 
95
108
  def danfe
96
- @danfe ||= Danfe.new
109
+ @danfe ||= Danfe.new(@authentication_token)
97
110
  end
98
111
 
99
112
  def claim_check
100
- @claim_check ||= ClaimCheck.new
113
+ @claim_check ||= ClaimCheck.new(@authentication_token)
101
114
  end
102
115
 
103
116
  def webhook
104
- @webhook ||= Webhook.new
117
+ @webhook ||= Webhook.new(@authentication_token)
105
118
  end
106
119
 
107
120
  def with_token
108
- clear_token
109
- authentication_token = token.token
110
-
111
- if authentication_token.success?
112
- RequestLocals.store[TOKEN_KEY] = authentication_token.data[:token]
113
- result = yield(self)
114
- result
115
- else
116
- raise Stone::Siclos::Error::TokenError, authentication_token.data[:msg]
117
- end
118
- ensure
119
- clear_token
120
- end
121
-
122
- private
121
+ token_result = token.token
122
+ raise Stone::Siclos::Error::TokenError, token_result.data[:msg] unless token_result.success?
123
123
 
124
- def clear_token
125
- RequestLocals.store[TOKEN_KEY] = nil
124
+ @authentication_token = token_result.data[:token]
125
+ result = yield(self)
126
+ result
126
127
  end
127
128
  end
128
129
  end