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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c399d0336423ed9916451406bd1611b57185734e
4
- data.tar.gz: 516b3250021a7874bf2179ba3068b7aa70812772
3
+ metadata.gz: ede71b85212fd3e76e0880867dbd6c70f494d643
4
+ data.tar.gz: a471d110719216e159667c48e0dc78d0301cc9f7
5
5
  SHA512:
6
- metadata.gz: 602b3bb4fd2a79892f3059fd4e077b4ce31a53da936a072d7820ffd88b932eba14ea937e247e8466ee3651889060cecfe411063a733fb91550215699c193f602
7
- data.tar.gz: d7a0019d5381b16c81c676a60994ab281d7e7e4adcc7fbcbe047d044da107f16e25b741a94373e2eb1aaf950353f4484939fb4bb2cd9c326ef4324619f5d319b
6
+ metadata.gz: 4da633760b58715646b68350a3abeabe9546438b4d5e947d8a98b1611b8ef56d62e6954288558acd9638e9a44b34c38656aaff47980eade52b3e8b8db92101de
7
+ data.tar.gz: 1f1010ddefa3f59c0db4f526c266528de94e38096d1da4c64760cf659136b3187ac68ddc4fe6e31d46167c4a8d0f9d23350f0cedf12da8bda9ee31c13adcd8cc
@@ -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: "bundle exec rspec" do
28
- require "guard/rspec/dsl"
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] || "spec/acceptance"
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
69
69
  end
70
70
  end
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "payment/manager/client"
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 "irb"
14
+ require 'irb'
14
15
  IRB.start
@@ -0,0 +1,4 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.3.3
4
+
@@ -1,7 +1,10 @@
1
- require "payment/manager/client/version"
2
- require "payment/manager/request"
3
- require "payment/manager/config"
4
- require "json"
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 = Payment::Manager::Request.get(config.api_url + '/api/checkout', params)
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 = Payment::Manager::Request.get(config.api_url + '/api/plans', params)
35
- JSON.parse(response.body)
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 = Payment::Manager::Request.get(config.api_url + "/api/tokens/validate/#{config.client_id}/#{token}", {})
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
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
1
2
  module Payment
2
3
  module Manager
3
4
  module Client
4
- VERSION = "0.2.0"
5
+ VERSION = '0.3.0'
5
6
  end
6
7
  end
7
8
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Payment
2
3
  module Manager
3
4
  module Config
@@ -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 = "payment-manager-client"
7
+ spec.name = 'payment-manager-client'
8
8
  spec.version = Payment::Manager::Client::VERSION
9
- spec.authors = ["Kaio Magalhães"]
10
- spec.email = ["me@kaiomagalhaes.com"]
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 = "exe"
19
+ spec.bindir = 'exe'
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
22
22
 
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"
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.2.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: 2016-12-16 00:00:00.000000000 Z
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