fondy 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef61421423338fe035dd21c3caf23c6fa17eceb5
4
- data.tar.gz: 48d29cc0c1f0c20d953eaa60f2d4b3f43a68aa70
3
+ metadata.gz: a9df4598dab25bd0bcd77d4a2416abe2a2ac0b3b
4
+ data.tar.gz: 6d966ddfe92439ac1d4d534de7864754307bc4af
5
5
  SHA512:
6
- metadata.gz: aaaa9f468e1f928bc551d1e847e2e55fc65cc569e5f4c2ae2b87e248eece0d2a5158dc4006179e08cdc4c406faccb1106de27d5ca0e1f852ff83a10bc19c6c61
7
- data.tar.gz: a95f7facba55c64d1ded788424fe3a0fa0678fcd3db0023c1322ab692a15cdd17ba3890e738ff4ce29f57e477dcac75004b16b03bef7548ed7f1c8c8c1fb15ef
6
+ metadata.gz: 0d342a92161f05c2aa5f150e72a21c8a441329e1ee0e32240103f49626ee354e7f5477a47443a8922dfd19bab7200efedcdc861aee438e18ae027061ed49ce52
7
+ data.tar.gz: 27bf1e76c71ea98216c77d29509bd27ef0c6420f03ba0aac9f3fe483cc3ce24a3e146d777bcd21dcc5dc4eda3599eb34e3909da7b65b9ff4a98b40011eb6e499
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.2
2
+ TargetRubyVersion: 2.3
3
3
  DisplayCopNames: true
4
4
  DisplayStyleGuide: true
5
5
  Exclude:
@@ -29,3 +29,7 @@ Style/MultilineMethodCallIndentation:
29
29
  Style/EmptyLines:
30
30
  Exclude:
31
31
  - 'spec/**/*'
32
+
33
+ Metrics/BlockLength:
34
+ Exclude:
35
+ - 'spec/**/*'
@@ -2,5 +2,5 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.2.3
5
- - 2.3.1
5
+ - 2.3.5
6
6
  before_install: gem install bundler -v 1.12.5
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  source 'https://rubygems.org'
2
3
 
3
4
  # Specify your gem's dependencies in fondy.gemspec
data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'bundler/gem_tasks'
2
3
  require 'rspec/core/rake_task'
3
4
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'fondy'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'json'
2
3
  require 'faraday'
3
4
 
@@ -5,7 +6,9 @@ require 'fondy/version'
5
6
  require 'fondy/errors'
6
7
  require 'fondy/client'
7
8
  require 'fondy/request'
9
+ require 'fondy/base_response'
8
10
  require 'fondy/response'
11
+ require 'fondy/transaction_list_response'
9
12
  require 'fondy/signature'
10
13
 
11
14
  module Fondy
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module Fondy
3
+ class BaseResponse
4
+ def initialize(http_response)
5
+ @http_response = http_response
6
+ end
7
+
8
+ def success?
9
+ raise NotImplementedError
10
+ end
11
+
12
+ def error?
13
+ !success?
14
+ end
15
+
16
+ def error_code
17
+ raise NotImplementedError
18
+ end
19
+
20
+ def error_message
21
+ raise NotImplementedError
22
+ end
23
+
24
+ private
25
+
26
+ def response
27
+ @response ||= json_body[:response] || raise(Fondy::Error, 'Invalid response')
28
+ end
29
+
30
+ def json_body
31
+ @json_body ||=
32
+ begin
33
+ JSON.parse(@http_response.body, symbolize_names: true)
34
+ rescue
35
+ raise Fondy::InvalidResponseError, 'Invalid response'
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Fondy
2
3
  class Client
3
4
  attr_reader :merchant_id, :password
@@ -48,12 +49,25 @@ module Fondy
48
49
  send_request(:post, '/api/reverse/order_id', params)
49
50
  end
50
51
 
52
+ def transaction_list(order_id:)
53
+ send_request(
54
+ :post,
55
+ '/api/transaction_list',
56
+ {
57
+ merchant_id: merchant_id,
58
+ order_id: order_id,
59
+ },
60
+ verify_signature: false,
61
+ response_class: TransactionListResponse,
62
+ )
63
+ end
64
+
51
65
  private
52
66
 
53
- def send_request(method, url, params, verify_signature: true)
67
+ def send_request(method, url, params, verify_signature: true, response_class: Response)
54
68
  params[:signature] = Signature.build(params: params, password: password)
55
69
  http_response = Request.call(method, url, params)
56
- response = Response.new(http_response)
70
+ response = response_class.new(http_response)
57
71
 
58
72
  if verify_signature && response.success?
59
73
  Signature.verify(params: response.to_h, password: password)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Fondy
2
3
  class Error < StandardError
3
4
  end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  module Fondy
2
3
  class Request
3
- API_HOST = 'https://api.fondy.eu'.freeze
4
+ API_HOST = 'https://api.fondy.eu'
4
5
 
5
6
  def self.call(*args)
6
7
  new(*args).call
@@ -1,9 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  module Fondy
2
- class Response
3
- def initialize(http_response)
4
- @http_response = http_response
5
- end
6
-
3
+ class Response < BaseResponse
7
4
  def to_h
8
5
  response
9
6
  end
@@ -12,10 +9,6 @@ module Fondy
12
9
  response[:response_status] == 'success'
13
10
  end
14
11
 
15
- def error?
16
- !success?
17
- end
18
-
19
12
  def error_code
20
13
  response[:error_code]
21
14
  end
@@ -31,20 +24,5 @@ module Fondy
31
24
  def respond_to_missing?(method, *_args)
32
25
  response.key?(method)
33
26
  end
34
-
35
- private
36
-
37
- def response
38
- @response ||= json_body[:response] || raise(Fondy::Error, 'Invalid response')
39
- end
40
-
41
- def json_body
42
- @json_body ||=
43
- begin
44
- JSON.parse(@http_response.body, symbolize_names: true)
45
- rescue
46
- raise Fondy::InvalidResponseError, 'Invalid response'
47
- end
48
- end
49
27
  end
50
28
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Fondy
2
3
  class Signature
3
4
  def self.build(*args)
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module Fondy
3
+ class TransactionListResponse < BaseResponse
4
+ def transactions
5
+ success? ? response : []
6
+ end
7
+
8
+ def success?
9
+ response.is_a?(Array)
10
+ end
11
+
12
+ def error_code
13
+ response[:error_code] if response.is_a?(Hash)
14
+ end
15
+
16
+ def error_message
17
+ response[:error_message] if response.is_a?(Hash)
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Fondy
2
- VERSION = '0.1.3'.freeze
3
+ VERSION = '0.1.4'
3
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fondy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Khrebtov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-08 00:00:00.000000000 Z
11
+ date: 2019-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -113,11 +113,13 @@ files:
113
113
  - bin/setup
114
114
  - fondy.gemspec
115
115
  - lib/fondy.rb
116
+ - lib/fondy/base_response.rb
116
117
  - lib/fondy/client.rb
117
118
  - lib/fondy/errors.rb
118
119
  - lib/fondy/request.rb
119
120
  - lib/fondy/response.rb
120
121
  - lib/fondy/signature.rb
122
+ - lib/fondy/transaction_list_response.rb
121
123
  - lib/fondy/version.rb
122
124
  homepage: https://github.com/busfor/fondy
123
125
  licenses:
@@ -139,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
141
  version: '0'
140
142
  requirements: []
141
143
  rubyforge_project:
142
- rubygems_version: 2.4.8
144
+ rubygems_version: 2.5.2.1
143
145
  signing_key:
144
146
  specification_version: 4
145
147
  summary: Ruby wrapper for Fondy API