payment-manager-client 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +19 -0
- data/Guardfile +3 -3
- data/Rakefile +3 -3
- data/bin/console +4 -3
- data/circle.yml +4 -0
- data/lib/payment/manager/client.rb +12 -9
- data/lib/payment/manager/client/version.rb +2 -1
- data/lib/payment/manager/config.rb +1 -0
- data/lib/payment/manager/plan.rb +27 -0
- data/lib/payment/manager/plan_parser.rb +32 -0
- data/lib/payment/manager/request.rb +6 -1
- data/payment-manager-client.gemspec +14 -13
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ede71b85212fd3e76e0880867dbd6c70f494d643
|
4
|
+
data.tar.gz: a471d110719216e159667c48e0dc78d0301cc9f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4da633760b58715646b68350a3abeabe9546438b4d5e947d8a98b1611b8ef56d62e6954288558acd9638e9a44b34c38656aaff47980eade52b3e8b8db92101de
|
7
|
+
data.tar.gz: 1f1010ddefa3f59c0db4f526c266528de94e38096d1da4c64760cf659136b3187ac68ddc4fe6e31d46167c4a8d0f9d23350f0cedf12da8bda9ee31c13adcd8cc
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This is the configuration used to check the rubocop source code.
|
2
|
+
# Check out: https://github.com/bbatsov/rubocop
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.3
|
5
|
+
|
6
|
+
Include:
|
7
|
+
- '**/config.ru'
|
8
|
+
Exclude:
|
9
|
+
- 'vendor/**/*'
|
10
|
+
- 'db/**/*'
|
11
|
+
- 'db/schema.rb'
|
12
|
+
Metrics/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Style/Documentation:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/BlockLength:
|
19
|
+
ExcludedMethods: ['describe', 'context']
|
data/Guardfile
CHANGED
@@ -24,8 +24,8 @@
|
|
24
24
|
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
25
|
# * 'just' rspec: 'rspec'
|
26
26
|
|
27
|
-
guard :rspec, cmd:
|
28
|
-
require
|
27
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
28
|
+
require 'guard/rspec/dsl'
|
29
29
|
dsl = Guard::RSpec::Dsl.new(self)
|
30
30
|
|
31
31
|
# Feel free to open issues for suggestions and improvements
|
@@ -65,6 +65,6 @@ guard :rspec, cmd: "bundle exec rspec" do
|
|
65
65
|
# Turnip features and steps
|
66
66
|
watch(%r{^spec/acceptance/(.+)\.feature$})
|
67
67
|
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
68
|
-
Dir[File.join("**/#{m[1]}.feature")][0] ||
|
68
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
|
69
69
|
end
|
70
70
|
end
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require
|
4
|
-
require
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'payment/manager/client'
|
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 "payment/manager/client"
|
|
10
11
|
# require "pry"
|
11
12
|
# Pry.start
|
12
13
|
|
13
|
-
require
|
14
|
+
require 'irb'
|
14
15
|
IRB.start
|
data/circle.yml
ADDED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'payment/manager/client/version'
|
3
|
+
require 'payment/manager/request'
|
4
|
+
require 'payment/manager/config'
|
5
|
+
require 'payment/manager/plan_parser'
|
6
|
+
require 'payment/manager/plan'
|
7
|
+
require 'json'
|
5
8
|
|
6
9
|
module Payment
|
7
10
|
module Manager
|
@@ -21,22 +24,22 @@ module Payment
|
|
21
24
|
plan_id: plan_id,
|
22
25
|
resource_id: resource_id
|
23
26
|
}
|
24
|
-
response =
|
27
|
+
response = Payment::Manager::Request.get_from_api('/api/checkout', params)
|
25
28
|
JSON.parse(response.body)['url']
|
26
29
|
end
|
27
30
|
|
28
31
|
def plans
|
29
32
|
params = {
|
30
33
|
client_id: config.client_id,
|
31
|
-
client_secret: config.client_secret
|
34
|
+
client_secret: config.client_secret
|
32
35
|
}
|
33
36
|
|
34
|
-
response =
|
35
|
-
|
37
|
+
response = Payment::Manager::Request.get_from_api('/api/plans', params)
|
38
|
+
PlanParser.new(response.body).plans
|
36
39
|
end
|
37
40
|
|
38
41
|
def valid_token?(token)
|
39
|
-
response =
|
42
|
+
response = Payment::Manager::Request.get_from_api("/api/tokens/validate/#{config.client_id}/#{token}", {})
|
40
43
|
JSON.parse(response.body)['valid']
|
41
44
|
end
|
42
45
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Payment
|
3
|
+
module Manager
|
4
|
+
class Plan
|
5
|
+
attr_accessor :id
|
6
|
+
attr_accessor :name
|
7
|
+
attr_accessor :description
|
8
|
+
attr_accessor :price
|
9
|
+
attr_accessor :installments
|
10
|
+
attr_accessor :duration_in_months
|
11
|
+
attr_accessor :details
|
12
|
+
|
13
|
+
def initialize(args = nil)
|
14
|
+
args&.each do |k, v|
|
15
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def eql?(other)
|
20
|
+
id == other.id &&
|
21
|
+
name == other.name &&
|
22
|
+
description == other.description &&
|
23
|
+
price == other.price
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Payment
|
3
|
+
module Manager
|
4
|
+
class PlanParser
|
5
|
+
def initialize(body)
|
6
|
+
@json = JSON.parse(body)
|
7
|
+
end
|
8
|
+
|
9
|
+
def plans
|
10
|
+
@json.collect do |json|
|
11
|
+
Payment::Manager::Plan.new(
|
12
|
+
plan(json)
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def plan(json)
|
20
|
+
{
|
21
|
+
id: json['id'],
|
22
|
+
name: json['name'],
|
23
|
+
description: json['description'],
|
24
|
+
price: json['price'],
|
25
|
+
installments: json['installments'],
|
26
|
+
duration_in_months: json['duration_in_months'],
|
27
|
+
details: json['details']
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -2,6 +2,12 @@
|
|
2
2
|
module Payment
|
3
3
|
module Manager
|
4
4
|
module Request
|
5
|
+
def self.get_from_api(path, params)
|
6
|
+
api_url = Payment::Manager::Config.api_url
|
7
|
+
final_url = api_url + path
|
8
|
+
get(final_url, params)
|
9
|
+
end
|
10
|
+
|
5
11
|
def self.get(url, params)
|
6
12
|
uri = URI(url)
|
7
13
|
uri.query = URI.encode_www_form(params)
|
@@ -16,4 +22,3 @@ module Payment
|
|
16
22
|
end
|
17
23
|
end
|
18
24
|
end
|
19
|
-
|
@@ -4,10 +4,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'payment/manager/client/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'payment-manager-client'
|
8
8
|
spec.version = Payment::Manager::Client::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Kaio Magalhães']
|
10
|
+
spec.email = ['me@kaiomagalhaes.com']
|
11
11
|
|
12
12
|
spec.summary = 'a gem to handle the requests to the payment api'
|
13
13
|
spec.homepage = 'https://github.com/4devmonkeys'
|
@@ -16,16 +16,17 @@ Gem::Specification.new do |spec|
|
|
16
16
|
# delete this section to allow pushing this gem to any host.
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
-
spec.bindir =
|
19
|
+
spec.bindir = 'exe'
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
spec.add_development_dependency 'pry'
|
27
|
+
spec.add_development_dependency 'guard-rspec'
|
28
|
+
spec.add_development_dependency 'dotenv'
|
29
|
+
spec.add_development_dependency 'webmock'
|
30
|
+
spec.add_development_dependency 'vcr'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
31
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payment-manager-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kaio Magalhães
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description:
|
126
140
|
email:
|
127
141
|
- me@kaiomagalhaes.com
|
@@ -132,6 +146,7 @@ files:
|
|
132
146
|
- ".env"
|
133
147
|
- ".gitignore"
|
134
148
|
- ".rspec"
|
149
|
+
- ".rubocop.yml"
|
135
150
|
- ".travis.yml"
|
136
151
|
- CODE_OF_CONDUCT.md
|
137
152
|
- Gemfile
|
@@ -140,9 +155,12 @@ files:
|
|
140
155
|
- Rakefile
|
141
156
|
- bin/console
|
142
157
|
- bin/setup
|
158
|
+
- circle.yml
|
143
159
|
- lib/payment/manager/client.rb
|
144
160
|
- lib/payment/manager/client/version.rb
|
145
161
|
- lib/payment/manager/config.rb
|
162
|
+
- lib/payment/manager/plan.rb
|
163
|
+
- lib/payment/manager/plan_parser.rb
|
146
164
|
- lib/payment/manager/request.rb
|
147
165
|
- payment-manager-client.gemspec
|
148
166
|
homepage: https://github.com/4devmonkeys
|