ebanx 0.1.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6199e3f2a9c361e756af0826fca2bbc2a48f11b
4
- data.tar.gz: 95dfdfde61a1d96da9e15187cb17d3f05be0c051
3
+ metadata.gz: 457ce2e7ec65501d6a9cc5aa6751220dd02e8525
4
+ data.tar.gz: a3133d9e22217d01ef0bc35071dbc2cf309b366d
5
5
  SHA512:
6
- metadata.gz: 65245844edf359c97ae313f59ab19eff89959f4e28b46fd4ad972f063f2bf630b7d36cf42a261fb743bf5852e24dd5f2ffab2dffa1f1ce97c15ca61a5ba0cc51
7
- data.tar.gz: f16ca6ad24dc33081e58c12f4f143270745cb2903ac27e8acf947da9962eaff9e4ba02acc87044828b76699e9407d50ac2ec100e6fbf72268e393447b75187e7
6
+ metadata.gz: 46e1c94cd33109f050d628bca2b9deaba68852016cc2c13b8612022d335d116f853241753eb5817d4c000384b67e85259105300bdc9c90219117394294389548
7
+ data.tar.gz: d3cc2e19b0427d1291fe327229313b760da40416d62df5365acdff0ee35007862ed42f45aafb408b71175475e81dd8f4aeae2cf33b922664262d0bd49cf990b5
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1
7
+ - 2.2
8
+ - jruby-19mode
data/CONTRIBUTORS CHANGED
@@ -1 +1,2 @@
1
+ Ariel Patschiki <arielpts@me.com>
1
2
  Gustavo Henrique Mascarenhas Machado <guhemama@gmail.com>
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
- # Ebanx
1
+ # EBANX Ruby gem [![Build Status](https://travis-ci.org/ebanx-integration/ebanx-ruby.svg?branch=master)](https://travis-ci.org/ebanx-integration/ebanx-ruby) [![Code Climate](https://codeclimate.com/github/ebanx-integration/ebanx-ruby/badges/gpa.svg)](https://codeclimate.com/github/ebanx-integration/ebanx-ruby) [![Test Coverage](https://codeclimate.com/github/ebanx-integration/ebanx-ruby/badges/coverage.svg)](https://codeclimate.com/github/ebanx-integration/ebanx-ruby/coverage)
2
+ Gem to communicate with EBANX.
2
3
 
3
- TODO: Write a gem description
4
+ Documentation: https://developers.ebanx.com/
4
5
 
5
6
  ## Installation
6
7
 
7
- Add this line to your application's Gemfile:
8
+ Add this line to your application's Gemfile, and bundle it:
8
9
 
9
- gem 'ebanx'
10
-
11
- And then execute:
12
-
13
- $ bundle
10
+ ```
11
+ gem 'ebanx'
12
+ $ bundle
13
+ ```
14
14
 
15
15
  Or install it yourself as:
16
16
 
@@ -18,7 +18,40 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ #### Create a new Boleto using Direct API
22
+ ```ruby
23
+ response = ebanx.do_direct {
24
+ operation: 'request',
25
+ mode: 'full',
26
+ payment: {
27
+ name: 'João da Silva',
28
+ email: 'joao@mailinator.com',
29
+ currency_code: 'USD',
30
+ amount_total: 100.50,
31
+ merchant_payment_code: Random.rand(10000000000),
32
+ payment_type_code: 'boleto',
33
+ person_type: 'personal',
34
+ document: '13326724691',
35
+ birth_date: '01/01/1980',
36
+ zipcode: '70000-000',
37
+ address: 'Rua Brasil',
38
+ street_number: '1',
39
+ city: 'Brasília',
40
+ state: 'DF',
41
+ country: 'br',
42
+ phone_number: '6130001111',
43
+ due_date: (Time.now + 86400).strftime('%d/%m/%Y')
44
+ }
45
+ }
46
+
47
+ ```
48
+
49
+ ## Automated Tests
50
+ We use minitest for testing this Gem.
51
+
52
+ ```
53
+ rake test
54
+ ```
22
55
 
23
56
  ## Contributing
24
57
 
@@ -26,4 +59,4 @@ TODO: Write usage instructions here
26
59
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
60
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
61
  4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
62
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.pattern = "test/**/*_test.rb"
9
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 1.0.0
data/ebanx.gemspec CHANGED
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "codeclimate-test-reporter"
23
24
 
24
- spec.add_dependency('rest-client', '~> 1.5')
25
- end
25
+ spec.add_dependency 'rest-client', '~> 1.7.3'
26
+ spec.add_dependency 'json'
27
+ end
data/lib/ebanx.rb CHANGED
@@ -2,35 +2,41 @@ require 'rest-client'
2
2
  require 'json'
3
3
 
4
4
  require_relative 'ebanx/version'
5
+ require_relative 'ebanx/response'
5
6
  require_relative 'ebanx/command/command'
6
7
  require_relative 'ebanx/command/cancel'
7
8
  require_relative 'ebanx/command/capture'
9
+ require_relative 'ebanx/command/direct'
8
10
  require_relative 'ebanx/command/exchange'
9
- require_relative 'ebanx/command/print_html'
11
+ require_relative 'ebanx/command/print'
10
12
  require_relative 'ebanx/command/query'
11
13
  require_relative 'ebanx/command/refund'
12
14
  require_relative 'ebanx/command/refund_or_cancel'
13
15
  require_relative 'ebanx/command/request'
14
-
16
+ require_relative 'ebanx/command/token'
17
+ require_relative 'ebanx/command/zipcode'
15
18
 
16
19
  module Ebanx
17
20
  @test_mode = false
18
21
 
19
22
  class << self
20
- attr_accessor :integration_key, :test_mode
23
+ attr_accessor :integration_key, :test_mode, :parse_response
21
24
  end
22
25
 
23
26
  def self.base_uri
24
27
  if @test_mode
25
- 'https://www.ebanx.com/test/ws/'
28
+ 'https://sandbox.ebanx.com/ws/'
26
29
  else
27
30
  'https://www.ebanx.com/pay/ws/'
28
31
  end
29
32
  end
30
33
 
34
+ protected
31
35
  def self.run_command(method, params)
32
36
  klass = get_command_class method
33
37
 
38
+ raise ArgumentError if !params[0] || params[0].length == 0
39
+
34
40
  params = params[0].merge! integration_key: @integration_key
35
41
  command = klass.new params
36
42
 
@@ -41,8 +47,13 @@ module Ebanx
41
47
 
42
48
  def self.request(command)
43
49
  uri = Ebanx::base_uri + command.request_action
44
- result = RestClient.send command.request_method, uri, params: command.params, content_type: command.response_type
45
- JSON.parse result
50
+
51
+ case command.request_method
52
+ when :post then response = RestClient.post uri, command.params, content_type: command.response_type
53
+ when :get then response = RestClient.get uri, params: command.params
54
+ end
55
+
56
+ Ebanx::Response.new response, command.response_type
46
57
  end
47
58
 
48
59
  def self.method_missing(method, *args, &block)
@@ -1,12 +1,23 @@
1
1
  module Ebanx
2
2
  module Command
3
3
  class Command
4
- attr_accessor :params, :request_method, :request_action, :response_type
4
+ @request_body = false
5
+
6
+ attr_accessor :params, :request_method, :request_action, :response_type, :request_body
5
7
 
6
8
  def valid?
7
9
  validate
8
10
  end
9
11
 
12
+ def params
13
+ # Wraps parameters into request_body
14
+ if @request_body
15
+ { request_body: @params.to_json }
16
+ else
17
+ @params
18
+ end
19
+ end
20
+
10
21
  protected
11
22
  def validate
12
23
  raise NotImplementedError
@@ -0,0 +1,19 @@
1
+ module Ebanx
2
+ module Command
3
+ class Direct < Command
4
+ def initialize(params)
5
+ @params = params
6
+ @request_method = :post
7
+ @request_action = 'direct'
8
+ @response_type = :json
9
+ @request_body = true
10
+ end
11
+
12
+ def validate
13
+ validate_presence :operation
14
+ validate_presence :mode
15
+ validate_presence :payment
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,10 +1,10 @@
1
1
  module Ebanx
2
2
  module Command
3
- class PrintHtml < Command
3
+ class Print < Command
4
4
  def initialize(params)
5
5
  @params = params
6
6
  @request_method = :get
7
- @request_action = 'boleto/printHTML'
7
+ @request_action = 'print'
8
8
  @response_type = 'text/html'
9
9
  end
10
10
 
@@ -0,0 +1,21 @@
1
+ module Ebanx
2
+ module Command
3
+ class Zipcode < Command
4
+ def initialize(params)
5
+ @params = params
6
+ @request_method = :post
7
+ @request_action = 'token'
8
+ @response_type = :json
9
+ end
10
+
11
+ def validate
12
+ validate_presence :currency_code
13
+ validate_presence :amount
14
+ validate_presence :merchant_payment_code
15
+ validate_presence :name
16
+ validate_presence :email
17
+ validate_presence :payment_type_code
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ module Ebanx
2
+ module Command
3
+ class Zipcode < Command
4
+ def initialize(params)
5
+ @params = params
6
+ @request_method = :get
7
+ @request_action = 'zipcode'
8
+ @response_type = :json
9
+ end
10
+
11
+ def validate
12
+ validate_presence :zipcode
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Ebanx
2
+ class Response
3
+ attr_accessor :http_code, :raw_response, :response
4
+
5
+ def initialize(response, response_type)
6
+ @http_code = response.code
7
+ @raw_response = response.to_str
8
+ @response = response.to_str
9
+
10
+ @response = JSON.parse @response if response_type == :json
11
+ end
12
+ end
13
+ end
data/lib/ebanx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ebanx
2
- VERSION = '0.1.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -0,0 +1,7 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe Ebanx::Command::Cancel do
4
+ it "can't run without arguments" do
5
+ lambda { ebanx.do_cancel }.must_raise ArgumentError
6
+ end
7
+ end
@@ -0,0 +1,38 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe Ebanx::Command::Direct do
4
+ before do
5
+ @params = {
6
+ operation: 'request',
7
+ mode: 'full',
8
+ payment: {
9
+ name: 'João da Silva',
10
+ email: 'joao@mailinator.com',
11
+ currency_code: 'BRL',
12
+ amount_total: 100.50,
13
+ merchant_payment_code: Random.rand(10000000000),
14
+ payment_type_code: 'boleto',
15
+ document: '13326724691',
16
+ birth_date: '01/01/1980',
17
+ zipcode: '70000-000',
18
+ address: 'Rua Brasil',
19
+ street_number: '1',
20
+ city: 'Brasília',
21
+ state: 'DF',
22
+ country: 'br',
23
+ phone_number: '6130001111',
24
+ due_date: (Time.now + 86400).strftime('%d/%m/%Y')
25
+ }
26
+ }
27
+ end
28
+
29
+ it "can't run without arguments" do
30
+ lambda { ebanx.do_direct }.must_raise ArgumentError
31
+ end
32
+
33
+ it "performs a successful request" do
34
+ response = ebanx.do_direct @params
35
+ response.http_code.must_equal 200
36
+ response.response['status'].must_equal 'SUCCESS'
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe Ebanx::Command::Request do
4
+ before do
5
+ @params = {
6
+ name: 'João da Silva',
7
+ email: 'joao@mailinator.com',
8
+ currency_code: 'BRL',
9
+ amount: 100.00,
10
+ merchant_payment_code: Random.rand(10000000000),
11
+ payment_type_code: 'boleto',
12
+ }
13
+ end
14
+
15
+ it "can't run without arguments" do
16
+ lambda { ebanx.do_request }.must_raise ArgumentError
17
+ end
18
+
19
+ it "performs a successful request" do
20
+ response = ebanx.do_request @params
21
+ response.http_code.must_equal 200
22
+ response.response['status'].must_equal 'SUCCESS'
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe Ebanx::Command::Zipcode do
4
+ before do
5
+ @params = {
6
+ zipcode: '80230010'
7
+ }
8
+ end
9
+
10
+ it "can't run without arguments" do
11
+ lambda { ebanx.do_zipcode }.must_raise ArgumentError
12
+ end
13
+
14
+ # Evil integration test
15
+ it "performs a successful request" do
16
+ response = ebanx.do_zipcode @params
17
+ response.http_code.must_equal 200
18
+ response.response['status'].must_equal 'SUCCESS'
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ end
5
+
6
+ require 'ebanx'
7
+ require 'minitest/autorun'
8
+ require 'minitest/spec'
9
+ require 'minitest/pride'
10
+
11
+ class MiniTest::Spec
12
+ def ebanx
13
+ Ebanx.tap do |e|
14
+ e.integration_key = ENV.fetch('INTEGRATION_KEY')
15
+ e.test_mode = true
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -1,57 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebanx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gustavo Henrique Mascarenhas Machado
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2015-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rest-client
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ~>
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '1.5'
61
+ version: 1.7.3
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ~>
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '1.5'
68
+ version: 1.7.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: EBANX is the market leader in e-commerce payment solutions for International
56
84
  Merchants selling online to Brazil
57
85
  email:
@@ -60,7 +88,8 @@ executables: []
60
88
  extensions: []
61
89
  extra_rdoc_files: []
62
90
  files:
63
- - .gitignore
91
+ - ".gitignore"
92
+ - ".travis.yml"
64
93
  - CONTRIBUTORS
65
94
  - Gemfile
66
95
  - LICENSE.txt
@@ -72,13 +101,22 @@ files:
72
101
  - lib/ebanx/command/cancel.rb
73
102
  - lib/ebanx/command/capture.rb
74
103
  - lib/ebanx/command/command.rb
104
+ - lib/ebanx/command/direct.rb
75
105
  - lib/ebanx/command/exchange.rb
76
- - lib/ebanx/command/print_html.rb
106
+ - lib/ebanx/command/print.rb
77
107
  - lib/ebanx/command/query.rb
78
108
  - lib/ebanx/command/refund.rb
79
109
  - lib/ebanx/command/refund_or_cancel.rb
80
110
  - lib/ebanx/command/request.rb
111
+ - lib/ebanx/command/token.rb
112
+ - lib/ebanx/command/zipcode.rb
113
+ - lib/ebanx/response.rb
81
114
  - lib/ebanx/version.rb
115
+ - test/ebanx/cancel_command_test.rb
116
+ - test/ebanx/direct_command_test.rb
117
+ - test/ebanx/request_command_test.rb
118
+ - test/ebanx/zipcode_command_test.rb
119
+ - test/test_helper.rb
82
120
  homepage: https://www.ebanx.com
83
121
  licenses:
84
122
  - BSD
@@ -89,18 +127,23 @@ require_paths:
89
127
  - lib
90
128
  required_ruby_version: !ruby/object:Gem::Requirement
91
129
  requirements:
92
- - - '>='
130
+ - - ">="
93
131
  - !ruby/object:Gem::Version
94
132
  version: '0'
95
133
  required_rubygems_version: !ruby/object:Gem::Requirement
96
134
  requirements:
97
- - - '>='
135
+ - - ">="
98
136
  - !ruby/object:Gem::Version
99
137
  version: '0'
100
138
  requirements: []
101
139
  rubyforge_project:
102
- rubygems_version: 2.1.11
140
+ rubygems_version: 2.4.6
103
141
  signing_key:
104
142
  specification_version: 4
105
143
  summary: Ruby bindings for the EBANX API
106
- test_files: []
144
+ test_files:
145
+ - test/ebanx/cancel_command_test.rb
146
+ - test/ebanx/direct_command_test.rb
147
+ - test/ebanx/request_command_test.rb
148
+ - test/ebanx/zipcode_command_test.rb
149
+ - test/test_helper.rb