cobrato-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7445bf90a38a9e43604303f380415e75443215ab
4
+ data.tar.gz: 050b8d7ec56df419a7082a7b628fcc29936e69c3
5
+ SHA512:
6
+ metadata.gz: 63e60f05dd8ce7b184fcc26f9707285f481c23daff1499a4c756a1368c0f2c965ca3a80bfae850dbd574d570324292111d999f05833969ba44b236b1e9d5a65a
7
+ data.tar.gz: 1c73c868c884ab61bb3aa3969b3137da4a534e9761bd7365c31f4931f3799a4c3e69efcd89952062c4f16ee6f94b34baeaf0cbb24835411eeca02a7bd48cd54b
data/.gitignore ADDED
@@ -0,0 +1,37 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ .ruby-version
32
+ .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+
37
+ .envrc
data/.hound.yml ADDED
@@ -0,0 +1,11 @@
1
+ AsciiComments:
2
+ Description: 'Use only ascii symbols in comments.'
3
+ Enabled: false
4
+
5
+ LineLength:
6
+ Description: 'Limit lines to 120 characters.'
7
+ Enabled: true
8
+ Max: 120
9
+
10
+ SpaceAroundEqualsInParameterDefault:
11
+ EnforcedStyle: no_space
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.6
5
+ - 2.2.2
6
+ env:
7
+ global:
8
+ # CODECLIMATE_REPO_TOKEN
9
+ - secure: "tIIFBoB2Ftm8tyi0g34YxMgutCtLvdf5D/ifxzyILEujEirw/auxfok1GFC4pT4Adh1GWh7jkBF34DDYU2eIdz7K5c7EwskrsqQO5ZFJzuey25977tzZGUJcoauFterCxaRYwUrSMYF05JcHeaULIGqQKQZS3cl67OaFyyD4Dveees3w6kQGVODIdSyi1eU6w2cpIOFiOApyUWnqC45JQQHUEP+Eg1cbw16W3+ywsgakoYd/b81+vj7kPUTET2ADvv2jwzgCt9ejX/unrON0JOW2g+QE+VbqzDT6cSoLfTKxFVzPCsutNx2nZ1wHahhilHXqs5nW+FJTOTSt+fmNidRcr+WrgG2jarOZcMAvtuf6OnfLopL1SB8taE67YCwHE/2nX1myALx+LVtOOqV+ohE++WMDzMx+P0Hop3EAtewzg5IvBEJ2nDEVGv3cLYE3Y+IzTi4ccN9ReUlUae+DZCvpun7iElh+YAChMVeCZPg2h4dLAbDXrhZW5HbWoX1S34FjcvY5pwpSkm+QyOAKcHWInplv3HqQiqm8aLuFX+DSRi2sJxIvl0dXF15GVeNfoFdgf38ug1Seg4e93K1jgt+6UWEcRbawxb9DUNEo0B3YgdXcWtC/lZJRrJjWZLDb+PPOUKM7pkV3jjmfOQ/Oa3PU52E9JKlJaNlgq0gbesA="
10
+ script:
11
+ - bundle exec rake --trace spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cobrato-client-ruby.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,86 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cobrato-client (0.1.0)
5
+ multi_json (~> 1.11.1)
6
+ typhoeus (~> 0.7.2)
7
+ virtus (~> 1.0.5)
8
+ wisper (~> 1.6)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ axiom-types (0.1.1)
14
+ descendants_tracker (~> 0.0.4)
15
+ ice_nine (~> 0.11.0)
16
+ thread_safe (~> 0.3, >= 0.3.1)
17
+ byebug (4.0.5)
18
+ columnize (= 0.9.0)
19
+ codeclimate-test-reporter (0.4.7)
20
+ simplecov (>= 0.7.1, < 1.0.0)
21
+ coderay (1.1.0)
22
+ coercible (1.0.0)
23
+ descendants_tracker (~> 0.0.1)
24
+ columnize (0.9.0)
25
+ descendants_tracker (0.0.4)
26
+ thread_safe (~> 0.3, >= 0.3.1)
27
+ diff-lcs (1.2.5)
28
+ docile (1.1.5)
29
+ equalizer (0.0.11)
30
+ ethon (0.7.4)
31
+ ffi (>= 1.3.0)
32
+ ffi (1.9.10)
33
+ ice_nine (0.11.1)
34
+ json (1.8.3)
35
+ method_source (0.8.2)
36
+ multi_json (1.11.1)
37
+ pry (0.10.1)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.8.1)
40
+ slop (~> 3.4)
41
+ pry-byebug (3.1.0)
42
+ byebug (~> 4.0)
43
+ pry (~> 0.10)
44
+ rake (10.4.2)
45
+ rspec (3.3.0)
46
+ rspec-core (~> 3.3.0)
47
+ rspec-expectations (~> 3.3.0)
48
+ rspec-mocks (~> 3.3.0)
49
+ rspec-core (3.3.1)
50
+ rspec-support (~> 3.3.0)
51
+ rspec-expectations (3.3.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.3.0)
54
+ rspec-mocks (3.3.1)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.3.0)
57
+ rspec-support (3.3.0)
58
+ simplecov (0.10.0)
59
+ docile (~> 1.1.0)
60
+ json (~> 1.8)
61
+ simplecov-html (~> 0.10.0)
62
+ simplecov-html (0.10.0)
63
+ slop (3.6.0)
64
+ thread_safe (0.3.5)
65
+ typhoeus (0.7.2)
66
+ ethon (>= 0.7.4)
67
+ vcr (2.9.3)
68
+ virtus (1.0.5)
69
+ axiom-types (~> 0.1)
70
+ coercible (~> 1.0)
71
+ descendants_tracker (~> 0.0, >= 0.0.3)
72
+ equalizer (~> 0.0, >= 0.0.9)
73
+ wisper (1.6.0)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ bundler (~> 1.9)
80
+ cobrato-client!
81
+ codeclimate-test-reporter (~> 0.4)
82
+ pry-byebug (~> 3.1)
83
+ rake (~> 10.0)
84
+ rspec (~> 3.3)
85
+ simplecov (~> 0.10)
86
+ vcr (~> 2.9)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Myfreecomm
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # Cobrato Client
2
+
3
+ This is the official Ruby client for the [Cobrato](https://app.cobrato.com) API.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/cobrato-client.png)](https://rubygems.org/gems/cobrato-client)
6
+ [![Build Status](https://api.travis-ci.org/myfreecomm/cobrato-client-ruby.svg?branch=master)](https://travis-ci.org/myfreecomm/cobrato-client-ruby)
7
+ [![Test Coverage](https://codeclimate.com/github/myfreecomm/cobrato-client-ruby/badges/coverage.svg)](https://codeclimate.com/github/myfreecomm/cobrato-client-ruby/coverage)
8
+ [![Code Climate Grade](https://codeclimate.com/github/myfreecomm/cobrato-client-ruby/badges/gpa.svg)](https://codeclimate.com/github/myfreecomm/cobrato-client-ruby)
9
+ [![Inline docs](http://inch-ci.org/github/myfreecomm/cobrato-client-ruby.svg?branch=master)](http://inch-ci.org/github/myfreecomm/cobrato-client-ruby)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'cobrato-client'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install cobrato-client
26
+
27
+ ## Configuration
28
+
29
+ ##### Use Cobrato.configure to setup your environment:
30
+
31
+ ```ruby
32
+ require "cobrato"
33
+
34
+ Cobrato.configure do |config|
35
+ config.url = "https://sandbox.cobrato.com/api/v1" # defaults to "https://app.cobrato.com.br/api/v1"
36
+ config.user_agent = 'My App v1.0' # optional, but you should pass a custom user-agent identifying your app
37
+ end
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ ##### Given your token, create an instance of Cobrato::Client, as below:
43
+
44
+ ```ruby
45
+ client = Cobrato.client("YOUR_TOKEN_HERE")
46
+ ```
47
+
48
+ ##### Now you have acess to every API endpoint:
49
+
50
+ * [Payees API](http://myfreecomm.github.io/cobrato/api/v1/payees/index.html#index)
51
+ * [Bank Accounts API](http://myfreecomm.github.io/cobrato/api/v1/bank_accounts/index.html#index)
52
+ * [Charge Accounts API](http://myfreecomm.github.io/cobrato/api/v1/charge_accounts/index.html#index)
53
+ * [Charges API](http://myfreecomm.github.io/cobrato/api/v1/charges/index.html#index)
54
+ * [Webhooks API](http://myfreecomm.github.io/cobrato/api/v1/webhooks/index.html#index)
55
+
56
+ ## Endpoints
57
+
58
+ #### [Payees](http://myfreecomm.github.io/cobrato/api/v1/payees/index.html#index)
59
+
60
+ | HTTP method | Endpoint | Client method |
61
+ | ----------- | ---------------------------------------------------------------------------------------- | --------------------- |
62
+ | POST | [api/v1/payees](http://myfreecomm.github.io/cobrato/api/v1/payees/index.html#create) | client.payees.create |
63
+ | GET | [api/v1/payees](http://myfreecomm.github.io/cobrato/api/v1/payees/index.html#list) | client.payees.list |
64
+ | GET | [api/v1/payees/:id](http://myfreecomm.github.io/cobrato/api/v1/payees/index.html#show) | client.payees.show |
65
+ | PUT | [api/v1/payees/:id](http://myfreecomm.github.io/cobrato/api/v1/payees/index.html#update) | client.payees.update |
66
+ | DELETE | [api/v1/payees/:id](http://myfreecomm.github.io/cobrato/api/v1/payees/index.html#delete) | client.payees.destroy |
67
+
68
+ #### [Bank Accounts](http://myfreecomm.github.io/cobrato/api/v1/bank_accounts/index.html#index)
69
+
70
+ | HTTP method | Endpoint | Client method |
71
+ | ----------- | --------------------------------------------------------------------------------------------------------------------------- | ----------------------------------- |
72
+ | POST | [api/v1/bank_accounts](http://myfreecomm.github.io/cobrato/api/v1/bank_accounts/index.html#create) | client.bank_accounts.create |
73
+ | GET | [api/v1/bank_accounts](http://myfreecomm.github.io/cobrato/api/v1/bank_accounts/index.html#list) | client.bank_accounts.list |
74
+ | GET | [api/v1/bank_accounts/:id](http://myfreecomm.github.io/cobrato/api/v1/bank_accounts/index.html#show) | client.bank_accounts.show |
75
+ | PUT | [api/v1/bank_accounts/:id](http://myfreecomm.github.io/cobrato/api/v1/bank_accounts/index.html#update) | client.bank_accounts.update |
76
+ | DELETE | [api/v1/bank_accounts/:id](http://myfreecomm.github.io/cobrato/api/v1/bank_accounts/index.html#delete) | client.bank_accounts.destroy |
77
+ | GET | [api/v1/bank_accounts/portfolio_codes](http://myfreecomm.github.io/cobrato/api/v1/bank_accounts/index.html#portfolio_codes) | client.bank_accounts.portfolio_codes |
78
+
79
+ #### [Charge Accounts](http://myfreecomm.github.io/cobrato/api/v1/charge_accounts/index.html#index)
80
+
81
+ | HTTP method | Endpoint | Client method |
82
+ | ----------- | ---------------------------------------------------------------------------------------------------------- | ------------------------------ |
83
+ | POST | [api/v1/charge_accounts](http://myfreecomm.github.io/cobrato/api/v1/charge_accounts/index.html#create) | client.charge_accounts.create |
84
+ | GET | [api/v1/charge_accounts](http://myfreecomm.github.io/cobrato/api/v1/charge_accounts/index.html#list) | client.charge_accounts.list |
85
+ | GET | [api/v1/charge_accounts/:id](http://myfreecomm.github.io/cobrato/api/v1/charge_accounts/index.html#show) | client.charge_accounts.show |
86
+ | PUT | [api/v1/charge_accounts/:id](http://myfreecomm.github.io/cobrato/api/v1/charge_accounts/index.html#update) | client.charge_accounts.update |
87
+ | DELETE | [api/v1/charge_accounts/:id](http://myfreecomm.github.io/cobrato/api/v1/charge_accounts/index.html#delete) | client.charge_accounts.destroy |
88
+
89
+ #### [Charges](http://myfreecomm.github.io/cobrato/api/v1/charges/index.html#index)
90
+
91
+ | HTTP method | Endpoint | Client method |
92
+ | ----------- | ----------------------------------------------------------------------------------------------------------------- | ----------------------------- |
93
+ | POST | [api/v1/charges](http://myfreecomm.github.io/cobrato/api/v1/charges/index.html#create) | client.charges.create |
94
+ | GET | [api/v1/charges](http://myfreecomm.github.io/cobrato/api/v1/charges/index.html#list) | client.charges.list |
95
+ | GET | [api/v1/charges/:id](http://myfreecomm.github.io/cobrato/api/v1/charges/index.html#show) | client.charges.show |
96
+ | PUT | [api/v1/charges/:id](http://myfreecomm.github.io/cobrato/api/v1/charges/index.html#update) | client.charges.update |
97
+ | DELETE | [api/v1/charges/:id](http://myfreecomm.github.io/cobrato/api/v1/charges/index.html#delete) | client.charges.destroy |
98
+ | POST | [api/v1/charges/:id/receive](http://myfreecomm.github.io/cobrato/api/v1/charges/index.html#receive) | client.charges.receive |
99
+ | POST | [api/v1/charges/:id/undo_receive](http://myfreecomm.github.io/cobrato/api/v1/charges/index.html#undo_receive) | client.charges.undo_receive |
100
+ | POST | [api/v1/charges/:id/deliver_billet](http://myfreecomm.github.io/cobrato/api/v1/charges/index.html#deliver_billet) | client.charges.deliver_billet |
101
+
102
+ #### [Webhooks](http://myfreecomm.github.io/cobrato/api/v1/webhooks/index.html#index)
103
+
104
+ | HTTP method | Endpoint | Client method |
105
+ | ----------- | --------------------------------------------------------------------------------------------- | ----------------------- |
106
+ | POST | [api/v1/webhooks](http://myfreecomm.github.io/cobrato//api/v1/webhooks/index.html#create) | client.webhooks.create |
107
+ | GET | [api/v1/webhooks](http://myfreecomm.github.io/cobrato//api/v1/webhooks/index.html#list) | client.webhooks.list |
108
+ | GET | [api/v1/webhooks/:id](http://myfreecomm.github.io/cobrato//api/v1/webhooks/index.html#show) | client.webhooks.show |
109
+ | PUT | [api/v1/webhooks/:id](http://myfreecomm.github.io/cobrato//api/v1/webhooks/index.html#update) | client.webhooks.update |
110
+ | DELETE | [api/v1/webhooks/:id](http://myfreecomm.github.io/cobrato//api/v1/webhooks/index.html#delete) | client.webhooks.destroy |
111
+
112
+ #### [Webhooks](#todo)
113
+
114
+ | HTTP method | Endpoint | Client method |
115
+ | ----------- | ------------------- | ----------------------- |
116
+ | POST | [api/v1/webhooks](#todo) | client.webhooks.create |
117
+ | GET | [api/v1/webhooks](#todo) | client.webhooks.list |
118
+ | GET | [api/v1/webhooks/:id](#todo) | client.webhooks.show |
119
+ | PUT | [api/v1/webhooks/:id](#todo) | client.webhooks.update |
120
+ | DELETE | [api/v1/webhooks/:id](#todo) | client.webhooks.destroy |
121
+
122
+ ## Callbacks
123
+
124
+ All actions that change data triggers an event that you can subscribe to. This event allow you to extend the logic executed when you call a client method.
125
+
126
+ #### Subscribing to an event
127
+
128
+ All you have to do is create a class that responds to a method `#call` with two arguments:
129
+
130
+ ```ruby
131
+ class MyListener
132
+ def call(result, args)
133
+ end
134
+ end
135
+ ```
136
+
137
+ **Where:**
138
+
139
+ * `result` is the return of a client method
140
+ * `args` is an array of arguments passed to the client method you called
141
+
142
+ Now you have a listener, you can subscribe to an event:
143
+
144
+ ```ruby
145
+ Cobrato.subscribe("cobrato.payees.destroy", MyListener.new)
146
+ ```
147
+
148
+ **Example:**
149
+
150
+ When you call `client.payees.destroy(1)`, an event `cobrato.payees.destroy` will be triggered. Your listener method `#call` will receive:
151
+
152
+ * `result` would be `true or false` - depending on what `client.payees.destroy(1)` returned
153
+ * `args` would be `[1]` - an array with the arguments passed to the client method
154
+
155
+ #### Available hooks
156
+
157
+ * payees
158
+ - cobrato.payees.create
159
+ - cobrato.payees.destroy
160
+ * bank_accounts
161
+ - cobrato.bank_accounts.create
162
+ - cobrato.bank_accounts.destroy
163
+ * charge_accounts
164
+ - cobrato.charge_accounts.create
165
+ - cobrato.charge_accounts.destroy
166
+ * charges
167
+ - cobrato.charges.create
168
+ - cobrato.charges.destroy
169
+ - cobrato.charges.receive
170
+ - cobrato.charges.undo_receive
171
+ * webhooks
172
+ - cobrato.webhooks.create
173
+ - cobrato.webhooks.destroy
174
+
175
+ ## Contributing
176
+
177
+ 1. Fork it ( https://github.com/[my-github-username]/cobrato-client-ruby/fork )
178
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
179
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
180
+ 4. Push to the branch (`git push origin my-new-feature`)
181
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task default: :spec
7
+ rescue LoadError
8
+ # no rspec available
9
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cobrato"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cobrato/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cobrato-client"
8
+ spec.version = Cobrato::VERSION
9
+ spec.authors = ["Marcio Ricardo Santos, Rodrigo Tassinari de Oliveira"]
10
+ spec.email = ["mrsantos.caxias@gmail.com", "rodrigo@pittlandia.net"]
11
+
12
+ spec.summary = %q{This is the official Ruby client for the Cobrato API.}
13
+ spec.description = %q{This is the official Ruby client for the Cobrato API. See https://app.cobrato.com for more information.}
14
+ spec.homepage = "https://github.com/myfreecomm/cobrato-client-ruby/"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "typhoeus", "~> 0.7.2"
30
+ spec.add_dependency "multi_json", "~> 1.11.1"
31
+ spec.add_dependency "virtus", "~> 1.0.5"
32
+ spec.add_dependency "wisper", "~> 1.6"
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.9"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency 'vcr', '~> 2.9'
37
+ spec.add_development_dependency 'pry-byebug', '~> 3.1'
38
+ spec.add_development_dependency 'rspec', '~> 3.3'
39
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
40
+ spec.add_development_dependency 'simplecov', '~> 0.10'
41
+ end
data/lib/cobrato.rb ADDED
@@ -0,0 +1,40 @@
1
+ require "typhoeus"
2
+ require "multi_json"
3
+ require "wisper"
4
+
5
+ require "cobrato/version"
6
+ require "cobrato/configuration"
7
+ require "cobrato/client"
8
+ require "cobrato/http"
9
+
10
+ require "cobrato/entities/base"
11
+ require "cobrato/entities/payee"
12
+ require "cobrato/entities/bank_account"
13
+ require "cobrato/entities/charge_account"
14
+ require "cobrato/entities/charge"
15
+ require "cobrato/entities/webhook"
16
+
17
+ require "cobrato/resources/base"
18
+ require "cobrato/resources/payee"
19
+ require "cobrato/resources/bank_account"
20
+ require "cobrato/resources/charge_account"
21
+ require "cobrato/resources/charge"
22
+ require "cobrato/resources/webhook"
23
+
24
+ module Cobrato
25
+ def self.configuration
26
+ @configuration ||= Configuration.new
27
+ end
28
+
29
+ def self.configure
30
+ yield(configuration) if block_given?
31
+ end
32
+
33
+ def self.client(token)
34
+ Client.new(token)
35
+ end
36
+
37
+ def self.subscribe(event, callback)
38
+ Wisper.subscribe(callback, on: event, with: :call)
39
+ end
40
+ end
@@ -0,0 +1,38 @@
1
+ module Cobrato
2
+ class Client
3
+ attr_reader :http
4
+
5
+ def initialize(token)
6
+ @http = Http.new(token)
7
+ end
8
+
9
+ def authenticated?
10
+ http.get("") do |response|
11
+ response.code == 200
12
+ end
13
+ rescue RequestError => e
14
+ raise e unless e.code == 401
15
+ false
16
+ end
17
+
18
+ def payees
19
+ Resources::Payee.new(http)
20
+ end
21
+
22
+ def bank_accounts
23
+ Resources::BankAccount.new(http)
24
+ end
25
+
26
+ def charge_accounts
27
+ Resources::ChargeAccount.new(http)
28
+ end
29
+
30
+ def charges
31
+ Resources::Charge.new(http)
32
+ end
33
+
34
+ def webhooks
35
+ Resources::Webhook.new(http)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,12 @@
1
+ require "base64"
2
+
3
+ module Cobrato
4
+ class Configuration
5
+ attr_accessor :url, :user_agent
6
+
7
+ def initialize
8
+ @url = "https://app.cobrato.com.br/api/v1"
9
+ @user_agent = "Cobrato Ruby Client v#{Cobrato::VERSION}"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module Cobrato
2
+ module Entities
3
+ class BankAccount < Base
4
+ attribute :id, Integer
5
+ attribute :payee_id, Integer
6
+ attribute :bank_code, String
7
+ attribute :agency, String
8
+ attribute :agency_digit, String
9
+ attribute :account, String
10
+ attribute :account_digit, String
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require "virtus"
2
+
3
+ module Cobrato
4
+ module Entities
5
+ class Base
6
+ include Virtus.model
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ module Cobrato
2
+ module Entities
3
+ class Charge < Base
4
+ attribute :id, Integer
5
+ attribute :charge_account_id, Integer
6
+ attribute :due_date, Date
7
+ attribute :processing_date, Date
8
+ attribute :document_kind, String
9
+ attribute :document_date, Date
10
+ attribute :document_number, String
11
+ attribute :custom_our_number, Boolean
12
+ attribute :our_number, String
13
+ attribute :our_number_digit, String
14
+ attribute :total_amount, Decimal
15
+ attribute :instructions, String
16
+ attribute :demonstrative, String
17
+ attribute :payer_emails, String
18
+ attribute :received, Boolean
19
+ attribute :received_amount, Decimal
20
+ attribute :received_at, Date
21
+ attribute :processing_date, Date
22
+ attribute :for_homologation, Boolean
23
+ attribute :billet, String
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module Cobrato
2
+ module Entities
3
+ class ChargeAccount < Base
4
+ attribute :id, Integer
5
+ attribute :bank_account_id, Integer
6
+ attribute :portfolio_code, String
7
+ attribute :agreement_code, String
8
+ attribute :agreement_code_digit, String
9
+ attribute :name, String
10
+ attribute :initial_number, Integer
11
+ attribute :current_number, Integer
12
+ attribute :end_number, Integer
13
+ attribute :status, String
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module Cobrato
2
+ module Entities
3
+ class Payee < Base
4
+ attribute :id, Integer
5
+ attribute :national_identifier_type, String
6
+ attribute :national_identifier, String
7
+ attribute :name, String
8
+ attribute :zipcode, String
9
+ attribute :city, String
10
+ attribute :state, String
11
+ attribute :neighbourhood, String
12
+ attribute :number, String
13
+ attribute :complement, String
14
+ attribute :street, String
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Cobrato
2
+ module Entities
3
+ class Webhook < Base
4
+ attribute :id, Integer
5
+ attribute :description, String
6
+ attribute :url, String
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Cobrato
2
+ class Exception < StandardError
3
+ attr_accessor :code, :body
4
+
5
+ def initialize(args = {})
6
+ super(args[:message])
7
+ @code = args[:code]
8
+ @body = args[:body]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ require "cobrato/request"
2
+ require "cobrato/response"
3
+
4
+ module Cobrato
5
+ class Http
6
+ attr_reader :token
7
+
8
+ def initialize(token)
9
+ @token = token
10
+ end
11
+
12
+ %w[get post delete put patch].each do |m|
13
+ define_method(m) do |path, options = {}, &block|
14
+ send_request(m.to_sym, path, options, &block)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def send_request(method, path, options, &block)
21
+ request = Request.new(options.merge!({
22
+ method: method,
23
+ token: token,
24
+ url: "#{Cobrato.configuration.url}#{path}",
25
+ user_agent: Cobrato.configuration.user_agent
26
+ }))
27
+ response = Response.new(request.run)
28
+ response.resolve!(&block)
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,51 @@
1
+ module Cobrato
2
+ class Request
3
+ attr_reader :args
4
+
5
+ def initialize(args)
6
+ @args = args
7
+ end
8
+
9
+ def run
10
+ request.run
11
+ request.response
12
+ end
13
+
14
+ private
15
+ def request
16
+ @request ||= Typhoeus::Request.new(args[:url], options)
17
+ end
18
+
19
+ def options
20
+ {
21
+ method: args[:method],
22
+ params: args[:params],
23
+ body: body,
24
+ headers: headers,
25
+ userpwd: token,
26
+ accept_encoding: "gzip"
27
+ }.reject {|k,v| v.nil?}
28
+ end
29
+
30
+ def headers
31
+ headers = args.fetch(:headers) { {} }
32
+
33
+ {
34
+ "Accept" => "application/json",
35
+ "Content-Type" => "application/json",
36
+ "User-Agent" => args[:user_agent],
37
+ }.merge(headers)
38
+ end
39
+
40
+ def body
41
+ body = args[:body]
42
+ body = MultiJson.dump(body) if body.is_a?(Hash)
43
+ body
44
+ end
45
+
46
+ def token
47
+ "#{args[:token]}:x"
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,17 @@
1
+ module Cobrato
2
+ module Resources
3
+ class BankAccount < Base
4
+
5
+ def collection_name
6
+ "bank_accounts"
7
+ end
8
+
9
+ def portfolio_codes(id)
10
+ http.get("#{resource_base_path}/#{id}/portfolio_codes") do |response|
11
+ parsed_body(response)["portfolio_codes"]
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,83 @@
1
+ require "cobrato/resources/hooks"
2
+
3
+ module Cobrato
4
+ module Resources
5
+ class Base
6
+ include Wisper::Publisher
7
+ extend Hooks
8
+ attr_accessor :http
9
+
10
+ def collection_name
11
+ "#{base_klass.downcase}s"
12
+ end
13
+
14
+ def initialize(http)
15
+ @http = http
16
+ end
17
+
18
+ def parsed_body(response)
19
+ MultiJson.load(response.body)
20
+ rescue MultiJson::ParseError
21
+ {}
22
+ end
23
+
24
+ def create(params)
25
+ http.post(resource_base_path, { body: params }) do |response|
26
+ respond_with_entity(response)
27
+ end
28
+ end
29
+
30
+ def show(id)
31
+ http.get("#{resource_base_path}/#{id}") do |response|
32
+ respond_with_entity(response)
33
+ end
34
+ end
35
+
36
+ def list
37
+ http.get(resource_base_path) do |response|
38
+ respond_with_collection(response)
39
+ end
40
+ end
41
+
42
+ def destroy(id)
43
+ http.delete("#{resource_base_path}/#{id}") do |response|
44
+ response.code == 204
45
+ end
46
+ end
47
+
48
+ def update(id, params)
49
+ http.put("#{resource_base_path}/#{id}", { body: params }) do |response|
50
+ respond_with_entity(response)
51
+ end
52
+ end
53
+
54
+ notify :create, :destroy
55
+
56
+ protected
57
+ def respond_with_collection(response, naked_klass = entity_klass)
58
+ hash = parsed_body(response)
59
+ hash[collection_name].map do |item|
60
+ naked_klass.new(item)
61
+ end
62
+ end
63
+
64
+ def respond_with_entity(response, naked_klass = entity_klass)
65
+ item = parsed_body(response)
66
+ naked_klass.new(item)
67
+ end
68
+
69
+ def resource_base_path
70
+ @resource_base_path ||= "/#{collection_name}"
71
+ end
72
+
73
+ def base_klass
74
+ @base_klass ||= self.class.name.split("::").last
75
+ end
76
+
77
+ def entity_klass
78
+ @entity_klass ||= Cobrato::Entities.const_get(base_klass.to_sym)
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,28 @@
1
+ module Cobrato
2
+ module Resources
3
+ class Charge < Base
4
+
5
+ def receive(id, params)
6
+ http.post("#{resource_base_path}/#{id}/receive", { body: params }) do |response|
7
+ respond_with_entity(response)
8
+ end
9
+ end
10
+
11
+ def undo_receive(id)
12
+ http.post("#{resource_base_path}/#{id}/undo_receive") do |response|
13
+ respond_with_entity(response)
14
+ end
15
+ end
16
+
17
+ def deliver_billet(id, emails=nil)
18
+ body = {to: emails}
19
+ http.post("#{resource_base_path}/#{id}/deliver_billet", { body: body }) do |response|
20
+ response.code == 200
21
+ end
22
+ end
23
+
24
+ notify :receive, :undo_receive
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,11 @@
1
+ module Cobrato
2
+ module Resources
3
+ class ChargeAccount < Base
4
+
5
+ def collection_name
6
+ "charge_accounts"
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module Cobrato
2
+ module Resources
3
+ module Hooks
4
+
5
+ def notify(*hooked_methods)
6
+ apply_hooks(hooked_methods.flatten)
7
+ end
8
+
9
+ private
10
+
11
+ def apply_hooks(hooked_methods)
12
+ hooked_methods.each do |method|
13
+ alias_method "#{method}_without_notifier", method
14
+
15
+ define_method method do |*args|
16
+ result = send("#{method}_without_notifier", *args)
17
+ publish("cobrato.#{base_klass.downcase}.#{method}", result, args.flatten)
18
+ result
19
+ end
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ module Cobrato
2
+ module Resources
3
+ class Payee < Base
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Cobrato
2
+ module Resources
3
+ class Webhook < Base
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ require "cobrato/exception"
2
+
3
+ module Cobrato
4
+ RequestTimeout = Class.new(Exception)
5
+ RequestError = Class.new(Exception)
6
+
7
+ class Response < SimpleDelegator
8
+ def resolve!(&block)
9
+ if success? #TODO: test redirect if need
10
+ block_given? ? yield(self) : self
11
+ elsif timed_out?
12
+ timeout!
13
+ else
14
+ error!
15
+ end
16
+ end
17
+
18
+ private
19
+ def timeout!
20
+ raise RequestTimeout
21
+ end
22
+
23
+ def error!
24
+ raise RequestError.new(
25
+ code: code,
26
+ message: status_message,
27
+ body: (MultiJson.load(body) rescue {})
28
+ )
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Cobrato
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,232 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cobrato-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcio Ricardo Santos, Rodrigo Tassinari de Oliveira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.11.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.11.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: virtus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: wisper
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.9'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.1'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.1'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.3'
139
+ - !ruby/object:Gem::Dependency
140
+ name: codeclimate-test-reporter
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.4'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.4'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.10'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.10'
167
+ description: This is the official Ruby client for the Cobrato API. See https://app.cobrato.com
168
+ for more information.
169
+ email:
170
+ - mrsantos.caxias@gmail.com
171
+ - rodrigo@pittlandia.net
172
+ executables: []
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - ".gitignore"
177
+ - ".hound.yml"
178
+ - ".travis.yml"
179
+ - Gemfile
180
+ - Gemfile.lock
181
+ - LICENSE
182
+ - README.md
183
+ - Rakefile
184
+ - bin/console
185
+ - bin/setup
186
+ - cobrato-client-ruby.gemspec
187
+ - lib/cobrato.rb
188
+ - lib/cobrato/client.rb
189
+ - lib/cobrato/configuration.rb
190
+ - lib/cobrato/entities/bank_account.rb
191
+ - lib/cobrato/entities/base.rb
192
+ - lib/cobrato/entities/charge.rb
193
+ - lib/cobrato/entities/charge_account.rb
194
+ - lib/cobrato/entities/payee.rb
195
+ - lib/cobrato/entities/webhook.rb
196
+ - lib/cobrato/exception.rb
197
+ - lib/cobrato/http.rb
198
+ - lib/cobrato/request.rb
199
+ - lib/cobrato/resources/bank_account.rb
200
+ - lib/cobrato/resources/base.rb
201
+ - lib/cobrato/resources/charge.rb
202
+ - lib/cobrato/resources/charge_account.rb
203
+ - lib/cobrato/resources/hooks.rb
204
+ - lib/cobrato/resources/payee.rb
205
+ - lib/cobrato/resources/webhook.rb
206
+ - lib/cobrato/response.rb
207
+ - lib/cobrato/version.rb
208
+ homepage: https://github.com/myfreecomm/cobrato-client-ruby/
209
+ licenses: []
210
+ metadata:
211
+ allowed_push_host: https://rubygems.org
212
+ post_install_message:
213
+ rdoc_options: []
214
+ require_paths:
215
+ - lib
216
+ required_ruby_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ requirements: []
227
+ rubyforge_project:
228
+ rubygems_version: 2.4.5
229
+ signing_key:
230
+ specification_version: 4
231
+ summary: This is the official Ruby client for the Cobrato API.
232
+ test_files: []