myfinance 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +23 -0
  4. data/.hound.yml +1063 -0
  5. data/.rspec +2 -0
  6. data/.travis.yml +7 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +94 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +209 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +7 -0
  14. data/lib/myfinance.rb +35 -0
  15. data/lib/myfinance/client.rb +31 -0
  16. data/lib/myfinance/configuration.rb +12 -0
  17. data/lib/myfinance/entities/base.rb +9 -0
  18. data/lib/myfinance/entities/collection.rb +57 -0
  19. data/lib/myfinance/entities/entity.rb +16 -0
  20. data/lib/myfinance/entities/entity_collection.rb +14 -0
  21. data/lib/myfinance/entities/financial_account.rb +30 -0
  22. data/lib/myfinance/entities/payable_account.rb +6 -0
  23. data/lib/myfinance/entities/receivable_account.rb +6 -0
  24. data/lib/myfinance/exception.rb +11 -0
  25. data/lib/myfinance/http.rb +33 -0
  26. data/lib/myfinance/request.rb +53 -0
  27. data/lib/myfinance/resources/base.rb +28 -0
  28. data/lib/myfinance/resources/entity.rb +39 -0
  29. data/lib/myfinance/resources/financial_account.rb +70 -0
  30. data/lib/myfinance/resources/payable_account.rb +33 -0
  31. data/lib/myfinance/resources/receivable_account.rb +33 -0
  32. data/lib/myfinance/response.rb +41 -0
  33. data/lib/myfinance/version.rb +3 -0
  34. data/myfinance.gemspec +45 -0
  35. data/spec/lib/myfinance/client_spec.rb +49 -0
  36. data/spec/lib/myfinance/configuration_spec.rb +26 -0
  37. data/spec/lib/myfinance/entities/base_spec.rb +28 -0
  38. data/spec/lib/myfinance/entities/collection_spec.rb +70 -0
  39. data/spec/lib/myfinance/entities/entity_collection_spec.rb +20 -0
  40. data/spec/lib/myfinance/entities/entity_spec.rb +11 -0
  41. data/spec/lib/myfinance/entities/payable_account_spec.rb +13 -0
  42. data/spec/lib/myfinance/entities/receivable_account_spec.rb +13 -0
  43. data/spec/lib/myfinance/http_spec.rb +37 -0
  44. data/spec/lib/myfinance/request_spec.rb +29 -0
  45. data/spec/lib/myfinance/resources/entity_spec.rb +63 -0
  46. data/spec/lib/myfinance/resources/payable_account_spec.rb +146 -0
  47. data/spec/lib/myfinance/resources/receivable_account_spec.rb +146 -0
  48. data/spec/lib/myfinance/response_spec.rb +58 -0
  49. data/spec/myfinance_spec.rb +25 -0
  50. data/spec/spec_helper.rb +39 -0
  51. data/spec/support/client.rb +3 -0
  52. data/spec/support/matchers/have_attr_accessor.rb +18 -0
  53. data/spec/support/shared_examples/entity_attributes.rb +9 -0
  54. data/spec/support/shared_examples/http_request_methods.rb +29 -0
  55. data/spec/support/vcr.rb +7 -0
  56. metadata +306 -0
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.1
5
+ - 2.2.2
6
+ script:
7
+ - 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 myfinance.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,94 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ myfinance (0.1.0)
5
+ multi_json (~> 1.9.0)
6
+ typhoeus (~> 0.7.1)
7
+ virtus (~> 1.0.5)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.3.8)
13
+ awesome_print (1.6.1)
14
+ axiom-types (0.1.1)
15
+ descendants_tracker (~> 0.0.4)
16
+ ice_nine (~> 0.11.0)
17
+ thread_safe (~> 0.3, >= 0.3.1)
18
+ codeclimate-test-reporter (0.4.7)
19
+ simplecov (>= 0.7.1, < 1.0.0)
20
+ coderay (1.1.0)
21
+ coercible (1.0.0)
22
+ descendants_tracker (~> 0.0.1)
23
+ crack (0.4.2)
24
+ safe_yaml (~> 1.0.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.9.3)
37
+ pry (0.10.1)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.8.1)
40
+ slop (~> 3.4)
41
+ pry-nav (0.2.4)
42
+ pry (>= 0.9.10, < 0.11.0)
43
+ rake (10.4.2)
44
+ rspec (3.3.0)
45
+ rspec-core (~> 3.3.0)
46
+ rspec-expectations (~> 3.3.0)
47
+ rspec-mocks (~> 3.3.0)
48
+ rspec-core (3.3.2)
49
+ rspec-support (~> 3.3.0)
50
+ rspec-expectations (3.3.1)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.3.0)
53
+ rspec-mocks (3.3.2)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.3.0)
56
+ rspec-support (3.3.0)
57
+ safe_yaml (1.0.4)
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
+ webmock (1.9.3)
74
+ addressable (>= 2.2.7)
75
+ crack (>= 0.3.2)
76
+
77
+ PLATFORMS
78
+ ruby
79
+
80
+ DEPENDENCIES
81
+ awesome_print (~> 1.1)
82
+ bundler (~> 1.10)
83
+ codeclimate-test-reporter (~> 0.4)
84
+ myfinance!
85
+ pry (~> 0.9)
86
+ pry-nav (~> 0.2)
87
+ rake (~> 10.0)
88
+ rspec
89
+ simplecov (~> 0.9)
90
+ vcr (~> 2.4)
91
+ webmock (~> 1.9.3)
92
+
93
+ BUNDLED WITH
94
+ 1.10.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Eduardo Hertz
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # myfinance-client-ruby
2
+
3
+ A Ruby client for the [Myfinance](http://www.myfinance.com.br) REST API
4
+
5
+ [![Gem version](https://badge.fury.io/rb/myfinance-client.png)](https://rubygems.org/gems/myfinance-client)
6
+ [![Build status](https://travis-ci.org/myfreecomm/myfinance-client-ruby.png?branch=master)](https://travis-ci.org/myfreecomm/myfinance-client-ruby)
7
+ [![Test coverage](https://codeclimate.com/github/myfreecomm/myfinance-client-ruby/badges/coverage.svg)](https://codeclimate.com/github/myfreecomm/myfinance-client-ruby)
8
+ [![Code Climate grade](https://codeclimate.com/github/myfreecomm/myfinance-client-ruby.png)](https://codeclimate.com/github/myfreecomm/myfinance-client-ruby)
9
+
10
+ Myfinance API docs: https://app.myfinance.com.br/docs/api
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'myfinance'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install myfinance
27
+
28
+ ## Usage
29
+
30
+ ##### Given your token, create an instance of Myfinance::Client, as below:
31
+
32
+ ```ruby
33
+ client = Myfinance.client("YOUR_TOKEN_HERE")
34
+ ```
35
+
36
+ ##### Now you have access to every API endpoint:
37
+
38
+ * [Entities API](https://app.myfinance.com.br/docs/api/entities) as `client.entities`
39
+ * [PayableAccounts API](https://app.myfinance.com.br/docs/api/payable_accounts) as `client.payable_accounts`
40
+ * [ReceivableAccounts API](https://app.myfinance.com.br/docs/api/receivable_accounts) as `client.receivable_accounts`
41
+
42
+ ### Endpoints
43
+
44
+ #### [Entities](https://app.myfinance.com.br/docs/api/entities)
45
+
46
+ <table>
47
+ <tr>
48
+ <th>HTTP method</th>
49
+ <th>Endpoint</th>
50
+ <th>Client method</th>
51
+ </tr>
52
+ <tr>
53
+ <td><code>GET</code></td>
54
+ <td>
55
+ <a href="https://app.myfinance.com.br/docs/api/entities#get_index" target="_blank">
56
+ /entities
57
+ </a>
58
+ </td>
59
+ <td>
60
+ <code>client.entities.find_all</code>
61
+ </td>
62
+ </tr>
63
+ <tr>
64
+ <td><code>GET</code></td>
65
+ <td>
66
+ <a href="https://app.myfinance.com.br/docs/api/entities#get_show" target="_blank">
67
+ /entities/:id
68
+ </a>
69
+ </td>
70
+ <td>
71
+ <code>client.entities.find</code>
72
+ </td>
73
+ </tr>
74
+ </table>
75
+
76
+ #### [PayableAccounts](https://app.myfinance.com.br/docs/api/payable_accounts)
77
+
78
+ <table>
79
+ <tr>
80
+ <th>HTTP method</th>
81
+ <th>Endpoint</th>
82
+ <th>Client method</th>
83
+ </tr>
84
+ <tr>
85
+ <td><code>POST</code></td>
86
+ <td>
87
+ <a href="https://app.myfinance.com.br/docs/api/payable_accounts#post_create" target="_blank">
88
+ /entities/:entity_id/payable_accounts
89
+ </a>
90
+ </td>
91
+ <td>
92
+ <code>client.payable_accounts.create</code>
93
+ </td>
94
+ </tr>
95
+ <tr>
96
+ <td><code>PUT</code></td>
97
+ <td>
98
+ <a href="https://app.myfinance.com.br/docs/api/payable_accounts#put_pay" target="_blank">
99
+ /entities/:entity_id/payable_accounts/:id/pay
100
+ </a>
101
+ </td>
102
+ <td>
103
+ <code>client.payable_accounts.pay</code>
104
+ </td>
105
+ </tr>
106
+ <tr>
107
+ <td><code>PUT</code></td>
108
+ <td>
109
+ <a href="https://app.myfinance.com.br/docs/api/payable_accounts#put_undo_payment" target="_blank">
110
+ /entities/:entity_id/payable_accounts/:id/undo_payment
111
+ </a>
112
+ </td>
113
+ <td>
114
+ <code>client.payable_accounts.undo_payment</code>
115
+ </td>
116
+ </tr>
117
+ <tr>
118
+ <td><code>DELETE</code></td>
119
+ <td>
120
+ <a href="https://app.myfinance.com.br/docs/api/payable_accounts#delete_destroy" target="_blank">
121
+ /entities/:entity_id/payable_accounts/:id
122
+ </a>
123
+ </td>
124
+ <td>
125
+ <code>client.payable_accounts.destroy</code>
126
+ </td>
127
+ </tr>
128
+ </table>
129
+
130
+ #### [ReceivableAccounts](https://app.myfinance.com.br/docs/api/receivable_accounts)
131
+
132
+ <table>
133
+ <tr>
134
+ <th>HTTP method</th>
135
+ <th>Endpoint</th>
136
+ <th>Client method</th>
137
+ </tr>
138
+ <tr>
139
+ <td><code>POST</code></td>
140
+ <td>
141
+ <a href="https://app.myfinance.com.br/docs/api/receivable_accounts#post_create" target="_blank">
142
+ /entities/:entity_id/receivable_accounts
143
+ </a>
144
+ </td>
145
+ <td>
146
+ <code>client.receivable_accounts.create</code>
147
+ </td>
148
+ </tr>
149
+ <tr>
150
+ <td><code>PUT</code></td>
151
+ <td>
152
+ <a href="https://app.myfinance.com.br/docs/api/receivable_accounts#put_receive" target="_blank">
153
+ /entities/:entity_id/receivable_accounts/:id/receive
154
+ </a>
155
+ </td>
156
+ <td>
157
+ <code>client.receivable_accounts.receive</code>
158
+ </td>
159
+ </tr>
160
+ <tr>
161
+ <td><code>PUT</code></td>
162
+ <td>
163
+ <a href="https://app.myfinance.com.br/docs/api/receivable_accounts#put_undo_receivement" target="_blank">
164
+ /entities/:entity_id/receivable_accounts/:id/undo_receivement
165
+ </a>
166
+ </td>
167
+ <td>
168
+ <code>client.receivable_accounts.undo_receivement</code>
169
+ </td>
170
+ </tr>
171
+ <tr>
172
+ <td><code>DELETE</code></td>
173
+ <td>
174
+ <a href="https://app.myfinance.com.br/docs/api/receivable_accounts#delete_destroy" target="_blank">
175
+ /entities/:entity_id/receivable_accounts/:id
176
+ </a>
177
+ </td>
178
+ <td>
179
+ <code>client.receivable_accounts.destroy</code>
180
+ </td>
181
+ </tr>
182
+ </table>
183
+
184
+ ### Configuration
185
+
186
+ ```ruby
187
+ require 'myfinance'
188
+
189
+ Myfinance.configure do |m|
190
+ m.url = 'https://sandbox.myfinance.com.br' # defaults to 'https://app.myfinance.com.br' if omitted
191
+ m.user_agent = 'My App v1.0' # optional, but you should pass a custom user-agent identifying your app
192
+ end
193
+ ```
194
+
195
+ ## Development
196
+
197
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
198
+
199
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
200
+
201
+ ## Contributing
202
+
203
+ Bug reports and pull requests are welcome on GitHub at https://github.com/myfreecomm/myfinance-client-ruby. This project is intended to be a safe and welcoming space for collaboration.
204
+
205
+
206
+ ## License
207
+
208
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
209
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "myfinance"
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
data/lib/myfinance.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "typhoeus"
2
+ require "multi_json"
3
+
4
+ require "myfinance/version"
5
+ require "myfinance/configuration"
6
+ require "myfinance/http"
7
+ require "myfinance/client"
8
+
9
+ require "myfinance/entities/base"
10
+ require "myfinance/entities/collection"
11
+ require "myfinance/entities/entity"
12
+ require "myfinance/entities/entity_collection"
13
+ require "myfinance/entities/financial_account"
14
+ require "myfinance/entities/payable_account"
15
+ require "myfinance/entities/receivable_account"
16
+
17
+ require "myfinance/resources/base"
18
+ require "myfinance/resources/entity"
19
+ require "myfinance/resources/financial_account"
20
+ require "myfinance/resources/payable_account"
21
+ require "myfinance/resources/receivable_account"
22
+
23
+ module Myfinance
24
+ def self.configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+
28
+ def self.configure
29
+ yield(configuration) if block_given?
30
+ end
31
+
32
+ def self.client(token)
33
+ Client.new(token)
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ require "myfinance/request"
2
+ require "myfinance/response"
3
+
4
+ module Myfinance
5
+ class Client
6
+ attr_reader :http
7
+
8
+ def initialize(token)
9
+ @http = Http.new(token)
10
+ end
11
+
12
+ def authenticated?
13
+ http.get("/accounts") { |response| response.code == 200 }
14
+ rescue RequestError => e
15
+ raise e unless [401, 403].include?(e.code)
16
+ false
17
+ end
18
+
19
+ def entities
20
+ Myfinance::Resources::Entity.new(http)
21
+ end
22
+
23
+ def payable_accounts
24
+ Myfinance::Resources::PayableAccount.new(http)
25
+ end
26
+
27
+ def receivable_accounts
28
+ Myfinance::Resources::ReceivableAccount.new(http)
29
+ end
30
+ end
31
+ end