paggi 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3040c05c193b4100f974efac33a9eb66357fae76
4
+ data.tar.gz: 9656bb3aa89c0bb4a063e974c3de42b5983c8e82
5
+ SHA512:
6
+ metadata.gz: 982a957150e8a65d6721eecc0fc47baebc1072939f54d6ec2cbc2cc34eb70fac2ac0f77e6ec7f7ec8751daf62d1bf53683103a7c9a639d1c70b42f76b2609a3a
7
+ data.tar.gz: c84388d82a44af76fcb39b76b54b1f7e1563d3e668830eb5def3f861b4f03ef3bfd9fd3a6c73434824bcdb73ce6f173c401e8c028d28f6c27ab32da71aabc1b9
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ kiik-*.gem
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ paggi (0.1.0)
5
+ httparty (>= 0.13.7)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.0.2)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ addressable (2.5.0)
16
+ public_suffix (~> 2.0, >= 2.0.2)
17
+ concurrent-ruby (1.0.5)
18
+ crack (0.4.3)
19
+ safe_yaml (~> 1.0.0)
20
+ hashdiff (0.3.2)
21
+ httparty (0.14.0)
22
+ multi_xml (>= 0.5.2)
23
+ i18n (0.8.1)
24
+ metaclass (0.0.4)
25
+ minitest (5.10.1)
26
+ mocha (0.14.0)
27
+ metaclass (~> 0.0.1)
28
+ multi_xml (0.6.0)
29
+ power_assert (1.0.1)
30
+ public_suffix (2.0.5)
31
+ rake (10.5.0)
32
+ safe_yaml (1.0.4)
33
+ shoulda (3.5.0)
34
+ shoulda-context (~> 1.0, >= 1.0.1)
35
+ shoulda-matchers (>= 1.4.1, < 3.0)
36
+ shoulda-context (1.2.2)
37
+ shoulda-matchers (2.8.0)
38
+ activesupport (>= 3.0.0)
39
+ test-unit (3.2.3)
40
+ power_assert
41
+ thread_safe (0.3.6)
42
+ tzinfo (1.2.2)
43
+ thread_safe (~> 0.1)
44
+ webmock (1.24.6)
45
+ addressable (>= 2.3.6)
46
+ crack (>= 0.3.2)
47
+ hashdiff
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ mocha (~> 0.13)
54
+ paggi!
55
+ rake (~> 10.4)
56
+ shoulda (~> 3.5)
57
+ test-unit (~> 3.1)
58
+ webmock (~> 1.21)
59
+
60
+ BUNDLED WITH
61
+ 1.14.6
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Paggi Ruby
2
+ [![Build Status](https://semaphoreci.com/api/v1/kiik-payment/paggi_ruby/branches/master/badge.svg)](https://semaphoreci.com/kiik-payment/paggi_ruby)
3
+
4
+
5
+ Gem for bindings with Paggi API
6
+
7
+ Requirements
8
+ --------------
9
+ * ruby >= 2.2.3
10
+ * httpaty >= 0.13.7
11
+
12
+ Installation
13
+ --------------
14
+ ### Gem
15
+ `gem install paggi`
16
+
17
+ ### Bundle
18
+ ```ruby
19
+ source 'https://rubygems.org'
20
+ gem 'paggi'
21
+ ```
22
+
23
+ Tasks
24
+ -----
25
+ ### Configuration
26
+
27
+ #### Rails Apps
28
+
29
+ In order to generate config files, run:
30
+
31
+ ```
32
+ rails g paggi:install
33
+ ```
34
+
35
+ This command will create two files: `config/initializers/paggi.rb` and
36
+ `config/paggi.yml`, containing the default settings for the app to run.
37
+
38
+ #### Non-Rails Apps
39
+
40
+ It is recommended to create a YAML configuration file and a Ruby initializer file. The initializer must be required inside the main application ruby file.
41
+
42
+ ```yaml
43
+ # paggi.yml
44
+ development:
45
+ api_key: payos_test
46
+ host: http://localhost:8800
47
+ version: '0.3'
48
+ staging:
49
+ api_key: B31DCE74-E768-43ED-86DA-85501612548F
50
+ host: https://demo.kiik.com
51
+ version: '0.3'
52
+ production:
53
+ api_key: B31DCE74-E768-43ED-86DA-85501612548F
54
+ host: https://api.kiik.com
55
+ version: '0.3'
56
+ ```
57
+
58
+ ```ruby
59
+ # paggi.rb
60
+ KIIK_ENV = ENV['KIIK_ENV'] || 'development'
61
+ KIIK_CONFIG = YAML.load_file('./kiik.yml')[KIIK_ENV]
62
+
63
+ Kiik.setup do |config|
64
+ config.host = KIIK_CONFIG['host']
65
+ config.api_key = KIIK_CONFIG['api_key']
66
+ config.version = KIIK_CONFIG['version']
67
+ end
68
+ ```
69
+
70
+ *Important:* Don't forget to change `api_key` to your key.
71
+
72
+ ### Usage
73
+
74
+ ```ruby
75
+ #Create customer
76
+ customer = Kiik::Customer.create({name: "User name", email: "user@email.com"})
77
+ ```
78
+
79
+ ### Production
80
+
81
+ For production env, don't forget to set `PAGGI_ENV` to `production`, that way, our gem will read the `paggi.yml` file correctly.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+
3
+ task :default => [:test]
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.pattern = './test/**/*_test.rb'
7
+ end
@@ -0,0 +1,19 @@
1
+ module Paggi
2
+ module Generators
3
+ # Configuration files generator
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ desc 'Copy paggi.yml file to the application config directory.'
6
+
7
+ def self.source_root
8
+ @source_root ||= File.expand_path(
9
+ File.join(File.dirname(__FILE__), 'templates')
10
+ )
11
+ end
12
+
13
+ def copy_config_file
14
+ template 'config/paggi.yml'
15
+ template 'config/initializers/paggi.rb'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ PAGGI_ENV = ENV['PAGGI_ENV'] || ENV['RAILS_ENV'] || 'development'
2
+ PAGGI_CONFIG = YAML.load_file("#{Rails.root}/config/kiik.yml")[PAGGI_ENV]
3
+
4
+ Paggi.setup do |config|
5
+ config.host = PAGGI_CONFIG['host']
6
+ config.api_key = PAGGI_CONFIG['api_key']
7
+ config.version = PAGGI_CONFIG['version']
8
+ end
@@ -0,0 +1,14 @@
1
+ development:
2
+ api_key: #APIKEY
3
+ host: https://online.paggi.com
4
+ version: 'v4demo'
5
+
6
+ staging:
7
+ api_key: #APIKEY
8
+ host: https://staging-online.paggi.com
9
+ version: 'v4'
10
+
11
+ production:
12
+ api_key: #APIKEY
13
+ host: https://online.paggi.com
14
+ version: 'v4'
data/lib/paggi/card.rb ADDED
@@ -0,0 +1,20 @@
1
+ module Paggi
2
+ class Card < Resource
3
+ include Paggi::Rest::Create
4
+ include Paggi::Rest::Update
5
+
6
+ attr_accessor :customer_id, :name, :number, :month, :year, :cvc, :card_alias, :cvc_check, :default
7
+
8
+ class << self
9
+
10
+ def check!(params)
11
+ update!(params)
12
+ end
13
+
14
+ def check(params)
15
+ update(params)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ module Paggi
2
+ class Charge < Resource
3
+ include Paggi::Rest::Create
4
+
5
+ attr_accessor :customer, :amount, :receipt_email, :destination,
6
+ :description, :statement_descriptor, :status, :intermediaries, :expected_compensation
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module Paggi
2
+ # Configuration data holder
3
+ class Configuration
4
+ attr_accessor :host, :api_key, :version
5
+ end
6
+ end
@@ -0,0 +1,25 @@
1
+ module Paggi
2
+ class Customer < Resource
3
+ include Paggi::Rest::Create
4
+ include Paggi::Rest::Update
5
+
6
+ attr_accessor :phone, :name, :document, :email, :metadata, :description, :cards
7
+
8
+ def initialize(attributes = {})
9
+ super(attributes)
10
+ @cards = @cards.nil? ? [] : @cards.map{ |card| Card.new(card) }
11
+ end
12
+
13
+ def to_json
14
+ super.merge!(super([
15
+ :phone,
16
+ :name,
17
+ :document,
18
+ :email,
19
+ :metadata,
20
+ :description,
21
+ :cards
22
+ ]))
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module Paggi
2
+ class PaggiError < StandardError
3
+ attr_accessor :errors
4
+ def initialize(body = nil)
5
+ @errors = body.nil? || body['errors'].nil? ? [] : body['errors'].map{ |error| symbolize_keys(error) }
6
+ end
7
+
8
+ def to_s
9
+ @errors.map{ |e| e[:param].nil? ? e[:message] : "#{e[:param]}: #{e[:message]}" }.join(', ')
10
+ end
11
+
12
+ private
13
+
14
+ def symbolize_keys(hash)
15
+ Hash[hash.map{|(k,v)| [k.to_sym,v]}]
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Paggi
2
+ class Paginated
3
+ attr_accessor :result, :total, :errors
4
+ end
5
+ end
@@ -0,0 +1,48 @@
1
+ module Paggi
2
+ class Payment < Resource
3
+ include Paggi::Rest::GetAll
4
+
5
+ attr_accessor :status, :expected_compensation, :compensated_at, :amount, :amount_raw, :total
6
+
7
+ class << self
8
+ def consolidated(customer = nil, start_date = nil, end_date = nil)
9
+ url = customer.nil? ? '' : "#{customer}/"
10
+ url += 'consolidated'
11
+ params = []
12
+ params << "start_date=#{start_date.strftime('%Y-%m-%d %H:%M:%S')}" if start_date
13
+ params << "end_date=#{end_date.strftime('%Y-%m-%d %H:%M:%S')}" if end_date
14
+ url += "?#{params.join('&')}" if params.length
15
+ result = request(url, {}, :GET, {})
16
+ raise result if result.kind_of? StandardError
17
+ result.total
18
+ end
19
+
20
+ def all(params = {})
21
+ url = params[:customer].nil? ? '' : "#{params[:customer]}/"
22
+ parameters = []
23
+ parameters << "start_date=#{params[:start_date].to_s(:db)}" if params[:start_date]
24
+ parameters << "end_date=#{params[:end_date].to_s(:db)}" if params[:end_date]
25
+ parameters << "page=#{params[:page]}" if params[:page]
26
+ parameters << "page_size=#{params[:page_size]}" if params[:page_size]
27
+ url += "?#{parameters.join('&')}" if parameters.length
28
+ result = request(url, {}, :GET, {})
29
+ raise result if result.kind_of? StandardError
30
+ result
31
+ end
32
+ end
33
+
34
+ def initialize(attributes = {})
35
+ super(attributes)
36
+ end
37
+
38
+ def to_json
39
+ super.merge!(super([
40
+ :status,
41
+ :expected_compensation,
42
+ :compensated_at,
43
+ :amount,
44
+ :amount_raw,
45
+ ]))
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,82 @@
1
+ module Paggi
2
+ class Resource
3
+ include HTTParty
4
+
5
+ attr_accessor :id, :created, :errors
6
+
7
+ class << self
8
+
9
+ def class_name
10
+ self.name.split('::')[-1]
11
+ end
12
+
13
+ def url
14
+ "#{Paggi.configuration.host}api/#{Paggi.configuration.version}/#{Paggi::Util.underscore(class_name)}s"
15
+ end
16
+
17
+ def opts(headers={})
18
+ {
19
+ basic_auth: {username: Paggi.configuration.api_key, password: ''},
20
+ headers: headers.merge({"Content-Type" => 'application/json'})
21
+ }
22
+ end
23
+
24
+ def build(data, error = nil)
25
+ if data['result'] && data['total']
26
+ instance = Paggi::Paginated.new()
27
+ instance.result = data['result'].map { |element| self.new(element) }
28
+ instance.total = data['total']
29
+ else
30
+ instance = self.new(data)
31
+ end
32
+ instance.errors = error.errors unless error.nil?
33
+ instance
34
+ end
35
+
36
+ def request(path=nil, params={}, method=:GET, header={})
37
+ options = opts(header).merge(body: JSON.generate(params))
38
+ url_abs = path.nil? ? url : "#{url}/#{path}"
39
+
40
+ response = case method
41
+ when :GET
42
+ get(url_abs, options)
43
+ when :POST
44
+ post(url_abs, options)
45
+ when :PUT
46
+ put(url_abs, options)
47
+ else
48
+ raise StandardError.new("Method #{method} not implemented")
49
+ end
50
+
51
+ case response.code
52
+ when 200, 402
53
+ build(JSON.parse(response.body))
54
+ when 422, 404
55
+ result = JSON.parse(response.body)
56
+ PaggiError.new(result)
57
+ else
58
+ raise StandardError.new(response.message)
59
+ end
60
+ end
61
+
62
+ end
63
+
64
+ def initialize(attributes = {})
65
+ attributes.each{ |name, value| self.instance_variable_set("@#{name}", value) }
66
+ self.errors = []
67
+ end
68
+
69
+ def valid?
70
+ self.errors.empty?
71
+ end
72
+
73
+ def to_json(attrs = [:id, :created])
74
+ result = {}
75
+ attrs.each{ |attr|
76
+ value = self.instance_variable_get("@#{attr}")
77
+ result[attr] = value unless value.nil? or value.empty?
78
+ }
79
+ result
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,46 @@
1
+ module Paggi
2
+ module Rest
3
+ module Create
4
+ class << self
5
+
6
+ def included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ end
11
+
12
+ def create
13
+ result = self.class.create(self.to_json)
14
+ raise result if result.instance_of? StandardError
15
+
16
+ if result.instance_of? PaggiError
17
+ self.errors = result.errors
18
+ return false
19
+ end
20
+
21
+ initialize(result.to_json)
22
+ true
23
+ end
24
+
25
+ module ClassMethods
26
+
27
+ def create!(params={}, header={})
28
+ begin
29
+ create(params, header)
30
+ rescue PaggiError => e
31
+ build(params, e)
32
+ rescue StandardError => e
33
+ e
34
+ end
35
+ end
36
+
37
+ def create(params={}, header={})
38
+ result = request(nil, params, :POST, header)
39
+ raise result if result.kind_of? StandardError
40
+ result
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ module Paggi
2
+ module Rest
3
+ module GetAll
4
+ class << self
5
+
6
+ def included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ end
11
+ def get_all
12
+ result = self.class.get_all(self.to_json)
13
+ raise result if result.instance_of? StandardError
14
+
15
+ if result.instance_of? PaggiError
16
+ self.errors = result.errors
17
+ return false
18
+ end
19
+
20
+ initialize(result.to_json)
21
+ true
22
+ end
23
+
24
+ module ClassMethods
25
+
26
+ def get_all!(params={}, header={})
27
+ begin
28
+ get_all(params, header)
29
+ rescue PaggiError => e
30
+ build(params, e)
31
+ rescue StandardError => e
32
+ e
33
+ end
34
+ end
35
+
36
+ def get_all(params={}, header={})
37
+
38
+ result = request(nil, params, :GET, header)
39
+
40
+ raise result if result.kind_of? StandardError
41
+ result
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ module Paggi
2
+ module Rest
3
+ module Update
4
+ class << self
5
+
6
+ def included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ end
11
+
12
+ def update
13
+ result = self.class.update(self.to_json)
14
+ raise result if result.instance_of? StandardError
15
+
16
+ if result.instance_of? PaggiError
17
+ self.errors = result.errors
18
+ return false
19
+ end
20
+
21
+ initialize(result.to_json)
22
+ true
23
+ end
24
+
25
+ module ClassMethods
26
+
27
+ def update!(params={id: 0}, header={})
28
+ begin
29
+ update(params, header)
30
+ rescue PaggiError => e
31
+ build(params, e)
32
+ rescue StandardError => e
33
+ raise e
34
+ end
35
+ end
36
+
37
+ def update(params={id: 0}, header={})
38
+ result = request(params[:id], params, :PUT, header)
39
+ raise result if result.kind_of? StandardError
40
+ result
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
data/lib/paggi/util.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Paggi
2
+ module Util
3
+ class << self
4
+ def underscore(camel_cased_word)
5
+ camel_cased_word.
6
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
7
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
8
+ tr('-', '_').
9
+ gsub(/\s/, '_').
10
+ gsub(/__+/, '_').
11
+ downcase
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/paggi.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'yaml'
2
+ require 'httparty'
3
+
4
+ require 'paggi/rest/create'
5
+ require 'paggi/rest/update'
6
+ require 'paggi/rest/get_all'
7
+ require 'paggi/util'
8
+ require 'paggi/resource'
9
+ require 'paggi/card'
10
+ require 'paggi/customer'
11
+ require 'paggi/charge'
12
+ require 'paggi/payment'
13
+ require 'paggi/error'
14
+ require 'paggi/paginated'
15
+ require 'paggi/configuration'
16
+
17
+ module Paggi
18
+ class << self
19
+ attr_accessor :configuration
20
+
21
+ def setup
22
+ self.configuration ||= Paggi::Configuration.new
23
+ yield configuration
24
+ end
25
+ end
26
+ end
data/paggi.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'paggi'
5
+ s.version = '0.1.0'
6
+ s.summary = 'Integrate Paggi with your Ruby app'
7
+ s.description = 'Paggi\'s official gem that helps you to integrate with our services. See https://docs.paggi.com for details.'
8
+ s.authors = ['Esdras Eduardo', 'Flávio Vieira']
9
+ s.email = ['esdras.rosa@paggi.com', 'flavio.mv@paggi.com']
10
+ s.homepage = 'http://docs.paggi.com'
11
+ s.license = 'MIT'
12
+
13
+ s.add_development_dependency('mocha', '~> 0.13')
14
+ s.add_development_dependency('shoulda', '~> 3.5')
15
+ s.add_development_dependency('test-unit', '~> 3.1')
16
+ s.add_development_dependency('rake', '~> 10.4')
17
+ s.add_development_dependency('webmock', '~> 1.21')
18
+ s.add_dependency('httparty', '>= 0.13.7')
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- test/*`.split("\n")
22
+ s.require_paths = ['lib']
23
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Paggi
4
+ class CardTest < Test::Unit::TestCase
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Paggi
4
+ class ChargeTest < Test::Unit::TestCase
5
+ end
6
+ end
@@ -0,0 +1,72 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Paggi
4
+ class CustomerTest < Test::Unit::TestCase
5
+
6
+ should "raise exception for create empty customer" do
7
+ respond = {errors: [{type:"invalid_request_error", param:"name", message:"Param name is required"}]}
8
+ post({}, respond, 422)
9
+ assert_raise PaggiError do
10
+ Paggi::Customer.create
11
+ end
12
+ end
13
+
14
+ should "return invalid customer for create! empty customer" do
15
+ respond = {errors: [{type:"invalid_request_error", param:"name", message:"Param name is required"}]}
16
+ post({}, respond, 422)
17
+ customer = Paggi::Customer.create!
18
+ assert !customer.valid?
19
+ end
20
+
21
+ should "return a new customer for create" do
22
+ customer_data = {name:"Customer test", email:"customer@email.com", phone: "11223344", document:"11122233345"}
23
+ post(customer_data, customer_data)
24
+ customer = Paggi::Customer.create customer_data
25
+ assert customer.valid?
26
+ assert customer.cards.empty?
27
+ end
28
+
29
+ should "return a new customer with card for create with card" do
30
+ card_data = {name:"Card Name", number:"1234567890", month:12, year:17}
31
+ customer_data = {name:"Customer test", email:"customer@email.com", phone: "11223344", document:"11122233345", card:card_data}
32
+ respond = {name:"Customer test", email:"customer@email.com", phone: "11223344", document:"11122233345", cards:[card_data]}
33
+ post(customer_data, respond)
34
+ customer = Paggi::Customer.create customer_data
35
+ assert customer.valid?
36
+ assert customer.cards.first.name == card_data[:name]
37
+ end
38
+
39
+ should "return customer for create using instance" do
40
+ customer_data = {name:"Customer test", email:"customer@email.com", phone: "11223344", document:"11122233345"}
41
+ post(customer_data)
42
+ customer = Paggi::Customer.new customer_data
43
+ customer.create
44
+ assert customer.valid?
45
+ end
46
+
47
+ should "raise exception for update with customer doesn't exists, code 404" do
48
+ error = {errors: [{type:"invalid_request_error", message:"Customer doesn't exists"}]}
49
+ put(0, {}, error, 422)
50
+ assert_raise PaggiError do
51
+ Paggi::Customer.update
52
+ end
53
+ end
54
+
55
+ should "return invalid customer for update! empty customer" do
56
+ error = {errors: [{type:"invalid_request_error", message:"Customer doesn't exists"}]}
57
+ put(0, {}, error, 422)
58
+ customer = Paggi::Customer.update!
59
+ assert !customer.valid?
60
+ assert_equal customer.errors.first[:message], "Customer doesn't exists"
61
+ end
62
+
63
+ should "return customer updated" do
64
+ customer_data = {id: 1, name:"New name", email:"customer@email.com", phone: "11223344", document:"11122233345"}
65
+ customer_send = {id: 1, name:"New name"}
66
+ put(customer_data[:id], customer_send, customer_data)
67
+ customer = Paggi::Customer.update! customer_send
68
+ assert_equal customer.name, customer_data[:name]
69
+ assert_equal customer.email, customer_data[:email]
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Paggi
4
+ class ResourceTest < Test::Unit::TestCase
5
+
6
+ should "" do
7
+ respond = {errors: [{type:"invalid_request_error", param:"name", message:"Param name is required"}]}
8
+ post({}, respond, 422)
9
+ assert_raise PaggiError do
10
+ Paggi::Customer.create
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'paggi'
2
+ require 'test/unit'
3
+ require 'mocha/setup'
4
+ require 'shoulda'
5
+ require 'webmock/test_unit'
6
+ require File.expand_path('../test_mock.rb', __FILE__)
7
+
8
+ class Test::Unit::TestCase
9
+ include Mocha
10
+ include Paggi::TestMock
11
+
12
+ setup do
13
+ Paggi.setup do |config|
14
+ config.api_key = '123'
15
+ config.version = 'v4demo'
16
+ config.host = 'http://online.paggi.com/'
17
+ end
18
+ end
19
+ end
data/test/test_mock.rb ADDED
@@ -0,0 +1,28 @@
1
+ module Paggi
2
+ module TestMock
3
+ def request(url, params = {}, method = :any)
4
+ host = Paggi.configuration.host.gsub(%r{^https:\/\/}, '')
5
+ .gsub(%r{^http:\/\/}, '')
6
+ version = Paggi.configuration.version
7
+ headers = {
8
+ content_type: 'application/json'
9
+ }
10
+ uri = Paggi.configuration.api_key + ":@#{host}api/#{version}/#{url}"
11
+ stub_request(method, uri)
12
+ .with(headers: headers)
13
+ .with(body: params)
14
+ end
15
+
16
+ def post(request = {}, respond = nil, code = 200)
17
+ respond = request.clone if respond.nil?
18
+ request('customers', request, :post)
19
+ .to_return(status: code, body: JSON.generate(respond), headers: {})
20
+ end
21
+
22
+ def put(id = 0, request = {}, respond = nil, code = 200)
23
+ respond = request.clone if respond.nil?
24
+ request("customers/#{id}", request, :put)
25
+ .to_return(status: code, body: JSON.generate(respond), headers: {})
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paggi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Esdras Eduardo
8
+ - Flávio Vieira
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mocha
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.13'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.13'
28
+ - !ruby/object:Gem::Dependency
29
+ name: shoulda
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.5'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.5'
42
+ - !ruby/object:Gem::Dependency
43
+ name: test-unit
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.1'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '10.4'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '10.4'
70
+ - !ruby/object:Gem::Dependency
71
+ name: webmock
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.21'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.21'
84
+ - !ruby/object:Gem::Dependency
85
+ name: httparty
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 0.13.7
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 0.13.7
98
+ description: Paggi's official gem that helps you to integrate with our services. See
99
+ https://docs.paggi.com for details.
100
+ email:
101
+ - esdras.rosa@paggi.com
102
+ - flavio.mv@paggi.com
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - README.md
111
+ - Rakefile
112
+ - lib/generators/paggi/install/install_generator.rb
113
+ - lib/generators/paggi/install/templates/config/initializers/paggi.rb
114
+ - lib/generators/paggi/install/templates/config/paggi.yml
115
+ - lib/paggi.rb
116
+ - lib/paggi/card.rb
117
+ - lib/paggi/charge.rb
118
+ - lib/paggi/configuration.rb
119
+ - lib/paggi/customer.rb
120
+ - lib/paggi/error.rb
121
+ - lib/paggi/paginated.rb
122
+ - lib/paggi/payment.rb
123
+ - lib/paggi/resource.rb
124
+ - lib/paggi/rest/create.rb
125
+ - lib/paggi/rest/get_all.rb
126
+ - lib/paggi/rest/update.rb
127
+ - lib/paggi/util.rb
128
+ - paggi.gemspec
129
+ - test/paggi/card_test.rb
130
+ - test/paggi/charge_test.rb
131
+ - test/paggi/customer_test.rb
132
+ - test/paggi/resource_test.rb
133
+ - test/test_helper.rb
134
+ - test/test_mock.rb
135
+ homepage: http://docs.paggi.com
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.6.8
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Integrate Paggi with your Ruby app
159
+ test_files:
160
+ - test/paggi/card_test.rb
161
+ - test/paggi/charge_test.rb
162
+ - test/paggi/customer_test.rb
163
+ - test/paggi/resource_test.rb
164
+ - test/test_helper.rb
165
+ - test/test_mock.rb