myfinance 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -2
- data/.hound.yml +3 -1063
- data/.overcommit.yml +33 -0
- data/.rubocop.yml +19 -1131
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +3 -1
- data/README.md +200 -0
- data/Rakefile +1 -1
- data/bin/rspec +21 -0
- data/lib/myfinance.rb +4 -59
- data/lib/myfinance/client.rb +14 -2
- data/lib/myfinance/configuration.rb +2 -2
- data/lib/myfinance/entities/collection.rb +13 -5
- data/lib/myfinance/entities/sale.rb +32 -0
- data/lib/myfinance/entities/sale_account.rb +18 -0
- data/lib/myfinance/entities/sale_account_collection.rb +13 -0
- data/lib/myfinance/entities/sale_collection.rb +13 -0
- data/lib/myfinance/entities/sale_rule.rb +16 -0
- data/lib/myfinance/entities/sale_rule_collection.rb +13 -0
- data/lib/myfinance/http.rb +10 -11
- data/lib/myfinance/request.rb +2 -3
- data/lib/myfinance/resources/base.rb +1 -1
- data/lib/myfinance/resources/sale.rb +39 -0
- data/lib/myfinance/resources/sale_account.rb +39 -0
- data/lib/myfinance/resources/sale_rule.rb +39 -0
- data/lib/myfinance/response.rb +6 -6
- data/lib/myfinance/version.rb +1 -1
- data/myfinance.gemspec +14 -9
- data/spec/lib/myfinance/client_spec.rb +14 -0
- data/spec/lib/myfinance/entities/sale_account_collection_spec.rb +5 -0
- data/spec/lib/myfinance/entities/sale_account_spec.rb +18 -0
- data/spec/lib/myfinance/entities/sale_collection_spec.rb +5 -0
- data/spec/lib/myfinance/entities/sale_rule_collection_spec.rb +5 -0
- data/spec/lib/myfinance/entities/sale_rule_spec.rb +16 -0
- data/spec/lib/myfinance/entities/sale_spec.rb +32 -0
- data/spec/lib/myfinance/resources/sale_account.spec.rb +124 -0
- data/spec/lib/myfinance/resources/sale_account_spec.rb +116 -0
- data/spec/lib/myfinance/resources/sale_rule_spec.rb +126 -0
- data/spec/lib/myfinance/resources/sale_spec.rb +126 -0
- data/spec/support/shared_examples/entity_collection.rb +21 -0
- data/spec/support/shared_examples/http_request_methods.rb +12 -5
- metadata +51 -3
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
myfinance (1.
|
4
|
+
myfinance (1.3.0)
|
5
5
|
mime-types (~> 2.99)
|
6
6
|
multi_json (~> 1.11)
|
7
|
+
require_all (~> 1.4.0)
|
7
8
|
typhoeus (~> 0.8)
|
8
9
|
virtus (~> 1.0.5)
|
9
10
|
|
@@ -45,6 +46,7 @@ GEM
|
|
45
46
|
pry (>= 0.9.10, < 0.11.0)
|
46
47
|
public_suffix (2.0.5)
|
47
48
|
rake (10.5.0)
|
49
|
+
require_all (1.4.0)
|
48
50
|
rspec (3.5.0)
|
49
51
|
rspec-core (~> 3.5.0)
|
50
52
|
rspec-expectations (~> 3.5.0)
|
data/README.md
CHANGED
@@ -64,6 +64,9 @@ client = Myfinance.client("YOUR_TOKEN_HERE")
|
|
64
64
|
* [CreditCardsTransactions API](https://app.myfinance.com.br/docs/api/credit_cards_transactions) as `client.credit_cards_transactions`
|
65
65
|
* [Reconciles API](https://app.myfinance.com.br/docs/api/reconciles) as `client.reconciles`
|
66
66
|
* [BankStatements API](https://app.myfinance.com.br/docs/api/bank_statements) as `client.bank_statements`
|
67
|
+
* [Sales API](https://app.myfinance.com.br/docs/api/sales) as `client.sales`
|
68
|
+
* [SaleAccounts API](https://app.myfinance.com.br/docs/api/sale_accounts) as `client.sale_accounts`
|
69
|
+
* [SaleRules API](https://app.myfinance.com.br/docs/api/sale_rules) as `client.sale_rules`
|
67
70
|
|
68
71
|
### Endpoints
|
69
72
|
|
@@ -1022,6 +1025,203 @@ client = Myfinance.client("YOUR_TOKEN_HERE")
|
|
1022
1025
|
</tr>
|
1023
1026
|
</table>
|
1024
1027
|
|
1028
|
+
#### [Sales](https://app.myfinance.com.br/docs/api/sales)
|
1029
|
+
|
1030
|
+
<table>
|
1031
|
+
<tr>
|
1032
|
+
<th>HTTP method</th>
|
1033
|
+
<th>Endpoint</th>
|
1034
|
+
<th>Client method</th>
|
1035
|
+
</tr>
|
1036
|
+
<tr>
|
1037
|
+
<td><code>GET</code></td>
|
1038
|
+
<td>
|
1039
|
+
<a href="https://app.myfinance.com.br/docs/api/sales#get_index" target="_blank">
|
1040
|
+
/entities/:entity_id/sales
|
1041
|
+
</a>
|
1042
|
+
</td>
|
1043
|
+
<td>
|
1044
|
+
<code>client.sales.find_all</code>
|
1045
|
+
</td>
|
1046
|
+
</tr>
|
1047
|
+
<tr>
|
1048
|
+
<td><code>GET</code></td>
|
1049
|
+
<td>
|
1050
|
+
<a href="https://app.myfinance.com.br/docs/api/sales#get_show" target="_blank">
|
1051
|
+
/entities/:entity_id/sales/:id
|
1052
|
+
</a>
|
1053
|
+
</td>
|
1054
|
+
<td>
|
1055
|
+
<code>client.sales.find</code>
|
1056
|
+
</td>
|
1057
|
+
</tr>
|
1058
|
+
<tr>
|
1059
|
+
<td><code>POST</code></td>
|
1060
|
+
<td>
|
1061
|
+
<a href="https://app.myfinance.com.br/docs/api/sales#post_create" target="_blank">
|
1062
|
+
/entities/:entity_id/sales
|
1063
|
+
</a>
|
1064
|
+
</td>
|
1065
|
+
<td>
|
1066
|
+
<code>client.sales.create</code>
|
1067
|
+
</td>
|
1068
|
+
</tr>
|
1069
|
+
<tr>
|
1070
|
+
<td><code>PUT</code></td>
|
1071
|
+
<td>
|
1072
|
+
<a href="https://app.myfinance.com.br/docs/api/sales#put_update" target="_blank">
|
1073
|
+
/entities/:entity_id/sales/:id
|
1074
|
+
</a>
|
1075
|
+
</td>
|
1076
|
+
<td>
|
1077
|
+
<code>client.sales.update</code>
|
1078
|
+
</td>
|
1079
|
+
</tr>
|
1080
|
+
<tr>
|
1081
|
+
<td><code>DELETE</code></td>
|
1082
|
+
<td>
|
1083
|
+
<a href="https://app.myfinance.com.br/docs/api/sales#delete_destroy" target="_blank">
|
1084
|
+
/entities/:entity_id/sales/:id
|
1085
|
+
</a>
|
1086
|
+
</td>
|
1087
|
+
<td>
|
1088
|
+
<code>client.sales.destroy</code>
|
1089
|
+
</td>
|
1090
|
+
</tr>
|
1091
|
+
</table>
|
1092
|
+
|
1093
|
+
|
1094
|
+
#### [SaleAccounts](https://app.myfinance.com.br/docs/api/sale_accounts)
|
1095
|
+
|
1096
|
+
<table>
|
1097
|
+
<tr>
|
1098
|
+
<th>HTTP method</th>
|
1099
|
+
<th>Endpoint</th>
|
1100
|
+
<th>Client method</th>
|
1101
|
+
</tr>
|
1102
|
+
<tr>
|
1103
|
+
<td><code>GET</code></td>
|
1104
|
+
<td>
|
1105
|
+
<a href="https://app.myfinance.com.br/docs/api/sale_accounts#get_index" target="_blank">
|
1106
|
+
/entities/:entity_id/sale_accounts
|
1107
|
+
</a>
|
1108
|
+
</td>
|
1109
|
+
<td>
|
1110
|
+
<code>client.sale_accounts.find_all</code>
|
1111
|
+
</td>
|
1112
|
+
</tr>
|
1113
|
+
<tr>
|
1114
|
+
<td><code>GET</code></td>
|
1115
|
+
<td>
|
1116
|
+
<a href="https://app.myfinance.com.br/docs/api/sale_accounts#get_show" target="_blank">
|
1117
|
+
/entities/:entity_id/sale_accounts/:id
|
1118
|
+
</a>
|
1119
|
+
</td>
|
1120
|
+
<td>
|
1121
|
+
<code>client.sale_accounts.find</code>
|
1122
|
+
</td>
|
1123
|
+
</tr>
|
1124
|
+
<tr>
|
1125
|
+
<td><code>POST</code></td>
|
1126
|
+
<td>
|
1127
|
+
<a href="https://app.myfinance.com.br/docs/api/sale_accounts#post_create" target="_blank">
|
1128
|
+
/entities/:entity_id/sale_accounts
|
1129
|
+
</a>
|
1130
|
+
</td>
|
1131
|
+
<td>
|
1132
|
+
<code>client.sale_accounts.create</code>
|
1133
|
+
</td>
|
1134
|
+
</tr>
|
1135
|
+
<tr>
|
1136
|
+
<td><code>PUT</code></td>
|
1137
|
+
<td>
|
1138
|
+
<a href="https://app.myfinance.com.br/docs/api/sale_accounts#put_update" target="_blank">
|
1139
|
+
/entities/:entity_id/sale_accounts/:id
|
1140
|
+
</a>
|
1141
|
+
</td>
|
1142
|
+
<td>
|
1143
|
+
<code>client.sale_accounts.update</code>
|
1144
|
+
</td>
|
1145
|
+
</tr>
|
1146
|
+
<tr>
|
1147
|
+
<td><code>DELETE</code></td>
|
1148
|
+
<td>
|
1149
|
+
<a href="https://app.myfinance.com.br/docs/api/sale_accounts#delete_destroy" target="_blank">
|
1150
|
+
/entities/:entity_id/sale_accounts/:id
|
1151
|
+
</a>
|
1152
|
+
</td>
|
1153
|
+
<td>
|
1154
|
+
<code>client.sale_accounts.destroy</code>
|
1155
|
+
</td>
|
1156
|
+
</tr>
|
1157
|
+
</table>
|
1158
|
+
|
1159
|
+
#### [SaleRules](https://app.myfinance.com.br/docs/api/sale_rules)
|
1160
|
+
|
1161
|
+
<table>
|
1162
|
+
<tr>
|
1163
|
+
<th>HTTP method</th>
|
1164
|
+
<th>Endpoint</th>
|
1165
|
+
<th>Client method</th>
|
1166
|
+
</tr>
|
1167
|
+
<tr>
|
1168
|
+
<td><code>GET</code></td>
|
1169
|
+
<td>
|
1170
|
+
<a href="https://app.myfinance.com.br/docs/api/sale_rules#get_index" target="_blank">
|
1171
|
+
/entities/:entity_id/sale_rules
|
1172
|
+
</a>
|
1173
|
+
</td>
|
1174
|
+
<td>
|
1175
|
+
<code>client.sale_rules.find_all</code>
|
1176
|
+
</td>
|
1177
|
+
</tr>
|
1178
|
+
<tr>
|
1179
|
+
<td><code>GET</code></td>
|
1180
|
+
<td>
|
1181
|
+
<a href="https://app.myfinance.com.br/docs/api/sale_rules#get_show" target="_blank">
|
1182
|
+
/entities/:entity_id/sale_rules/:id
|
1183
|
+
</a>
|
1184
|
+
</td>
|
1185
|
+
<td>
|
1186
|
+
<code>client.sale_rules.find</code>
|
1187
|
+
</td>
|
1188
|
+
</tr>
|
1189
|
+
<tr>
|
1190
|
+
<td><code>POST</code></td>
|
1191
|
+
<td>
|
1192
|
+
<a href="https://app.myfinance.com.br/docs/api/sale_rules#post_create" target="_blank">
|
1193
|
+
/entities/:entity_id/sale_rules
|
1194
|
+
</a>
|
1195
|
+
</td>
|
1196
|
+
<td>
|
1197
|
+
<code>client.sale_rules.create</code>
|
1198
|
+
</td>
|
1199
|
+
</tr>
|
1200
|
+
<tr>
|
1201
|
+
<td><code>PUT</code></td>
|
1202
|
+
<td>
|
1203
|
+
<a href="https://app.myfinance.com.br/docs/api/sale_rules#put_update" target="_blank">
|
1204
|
+
/entities/:entity_id/sale_rules/:id
|
1205
|
+
</a>
|
1206
|
+
</td>
|
1207
|
+
<td>
|
1208
|
+
<code>client.sale_rules.update</code>
|
1209
|
+
</td>
|
1210
|
+
</tr>
|
1211
|
+
<tr>
|
1212
|
+
<td><code>DELETE</code></td>
|
1213
|
+
<td>
|
1214
|
+
<a href="https://app.myfinance.com.br/docs/api/sale_rules#delete_destroy" target="_blank">
|
1215
|
+
/entities/:entity_id/sale_rules/:id
|
1216
|
+
</a>
|
1217
|
+
</td>
|
1218
|
+
<td>
|
1219
|
+
<code>client.sale_rules.destroy</code>
|
1220
|
+
</td>
|
1221
|
+
</tr>
|
1222
|
+
</table>
|
1223
|
+
|
1224
|
+
|
1025
1225
|
### Configuration
|
1026
1226
|
|
1027
1227
|
```ruby
|
data/Rakefile
CHANGED
data/bin/rspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
begin
|
3
|
+
load File.expand_path("../spring", __FILE__)
|
4
|
+
rescue LoadError => e
|
5
|
+
raise unless e.message.include?("spring")
|
6
|
+
end
|
7
|
+
#
|
8
|
+
# This file was generated by Bundler.
|
9
|
+
#
|
10
|
+
# The application "rspec" is installed as part of a gem, and
|
11
|
+
# this file is here to facilitate running it.
|
12
|
+
#
|
13
|
+
|
14
|
+
require "pathname"
|
15
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
16
|
+
Pathname.new(__FILE__).realpath)
|
17
|
+
|
18
|
+
require "rubygems"
|
19
|
+
require "bundler/setup"
|
20
|
+
|
21
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/lib/myfinance.rb
CHANGED
@@ -1,68 +1,13 @@
|
|
1
1
|
require "typhoeus"
|
2
2
|
require "multi_json"
|
3
|
-
require
|
3
|
+
require "mime/types"
|
4
|
+
require "require_all"
|
4
5
|
|
5
|
-
|
6
|
-
require "myfinance/configuration"
|
7
|
-
require "myfinance/http"
|
8
|
-
require "myfinance/client"
|
9
|
-
|
10
|
-
require "myfinance/entities/base"
|
11
|
-
require "myfinance/entities/collection"
|
12
|
-
require "myfinance/entities/entity"
|
13
|
-
require "myfinance/entities/entity_collection"
|
14
|
-
require "myfinance/entities/attachment_collection"
|
15
|
-
require "myfinance/entities/financial_transaction"
|
16
|
-
require "myfinance/entities/financial_transaction_collection"
|
17
|
-
require "myfinance/entities/financial_account"
|
18
|
-
require "myfinance/entities/payable_account"
|
19
|
-
require "myfinance/entities/payable_account_collection"
|
20
|
-
require "myfinance/entities/receivable_account"
|
21
|
-
require "myfinance/entities/receivable_account_collection"
|
22
|
-
require "myfinance/entities/attachment"
|
23
|
-
require "myfinance/entities/classification_center"
|
24
|
-
require "myfinance/entities/classification_center_collection"
|
25
|
-
require "myfinance/entities/category"
|
26
|
-
require "myfinance/entities/category_collection"
|
27
|
-
require "myfinance/entities/account"
|
28
|
-
require "myfinance/entities/account_collection"
|
29
|
-
require "myfinance/entities/deposit_account"
|
30
|
-
require "myfinance/entities/deposit_account_collection"
|
31
|
-
require "myfinance/entities/person"
|
32
|
-
require "myfinance/entities/person_collection"
|
33
|
-
require "myfinance/entities/webhook"
|
34
|
-
require "myfinance/entities/webhook_collection"
|
35
|
-
require "myfinance/entities/tax"
|
36
|
-
require "myfinance/entities/tax_collection"
|
37
|
-
require "myfinance/entities/credit_card"
|
38
|
-
require "myfinance/entities/credit_card_collection"
|
39
|
-
require "myfinance/entities/credit_card_transaction"
|
40
|
-
require "myfinance/entities/credit_card_transaction_collection"
|
41
|
-
require "myfinance/entities/reconcile_collection"
|
42
|
-
require "myfinance/entities/bank_statement"
|
43
|
-
|
44
|
-
require "myfinance/resources/base"
|
45
|
-
require "myfinance/resources/entity"
|
46
|
-
require "myfinance/resources/financial_transaction"
|
47
|
-
require "myfinance/resources/financial_account"
|
48
|
-
require "myfinance/resources/payable_account"
|
49
|
-
require "myfinance/resources/receivable_account"
|
50
|
-
require "myfinance/resources/attachment"
|
51
|
-
require "myfinance/resources/classification_center"
|
52
|
-
require "myfinance/resources/category"
|
53
|
-
require "myfinance/resources/account"
|
54
|
-
require "myfinance/resources/deposit_account"
|
55
|
-
require "myfinance/resources/person"
|
56
|
-
require "myfinance/resources/webhook"
|
57
|
-
require "myfinance/resources/tax"
|
58
|
-
require "myfinance/resources/credit_card"
|
59
|
-
require "myfinance/resources/credit_card_transaction"
|
60
|
-
require "myfinance/resources/reconcile"
|
61
|
-
require "myfinance/resources/bank_statement"
|
6
|
+
require_all "lib/myfinance"
|
62
7
|
|
63
8
|
module Myfinance
|
64
9
|
def self.configuration
|
65
|
-
@configuration ||=
|
10
|
+
@configuration ||= Configuration.new
|
66
11
|
end
|
67
12
|
|
68
13
|
def self.configure
|
data/lib/myfinance/client.rb
CHANGED
@@ -43,7 +43,7 @@ module Myfinance
|
|
43
43
|
def categories
|
44
44
|
Myfinance::Resources::Category.new(http)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def accounts
|
48
48
|
Myfinance::Resources::Account.new(http)
|
49
49
|
end
|
@@ -54,7 +54,7 @@ module Myfinance
|
|
54
54
|
|
55
55
|
def people
|
56
56
|
Myfinance::Resources::Person.new(http)
|
57
|
-
end
|
57
|
+
end
|
58
58
|
|
59
59
|
def webhooks
|
60
60
|
Myfinance::Resources::Webhook.new(http)
|
@@ -79,5 +79,17 @@ module Myfinance
|
|
79
79
|
def bank_statements
|
80
80
|
Myfinance::Resources::BankStatement.new(http)
|
81
81
|
end
|
82
|
+
|
83
|
+
def sales
|
84
|
+
Myfinance::Resources::Sale.new(http)
|
85
|
+
end
|
86
|
+
|
87
|
+
def sale_accounts
|
88
|
+
Myfinance::Resources::SaleAccount.new(http)
|
89
|
+
end
|
90
|
+
|
91
|
+
def sale_rules
|
92
|
+
Myfinance::Resources::SaleRule.new(http)
|
93
|
+
end
|
82
94
|
end
|
83
95
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require
|
1
|
+
require "base64"
|
2
2
|
|
3
3
|
module Myfinance
|
4
4
|
class Configuration
|
5
5
|
attr_accessor :url, :user_agent
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@url =
|
8
|
+
@url = "https://app.myfinance.com.br"
|
9
9
|
@user_agent = "Myfinance Ruby Client v#{Myfinance::VERSION}"
|
10
10
|
end
|
11
11
|
end
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module Myfinance
|
2
2
|
module Entities
|
3
3
|
#
|
4
|
-
# A wrapper to Myfinance collection returns from API.
|
4
|
+
# A wrapper to Myfinance collection returns from API.
|
5
|
+
# This wrapper represents a collection and it's responsible for
|
6
|
+
# processing pagination information as well.
|
5
7
|
#
|
6
8
|
class Collection < Base
|
7
9
|
PAGE_REGEX = /page=(\d+)/
|
@@ -11,11 +13,15 @@ module Myfinance
|
|
11
13
|
def initialize(response)
|
12
14
|
@response = response
|
13
15
|
@collection = []
|
14
|
-
@headers =
|
16
|
+
@headers = begin
|
17
|
+
response.headers["Link"].split(",")
|
18
|
+
rescue
|
19
|
+
[]
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def self.build(response)
|
18
|
-
|
24
|
+
new(response).build
|
19
25
|
end
|
20
26
|
|
21
27
|
def build
|
@@ -42,11 +48,13 @@ module Myfinance
|
|
42
48
|
private
|
43
49
|
|
44
50
|
def page_for(page_rel)
|
45
|
-
header_link_for(page_rel).match(PAGE_REGEX)[1].to_i
|
51
|
+
header_link_for(page_rel).match(PAGE_REGEX)[1].to_i
|
52
|
+
rescue
|
53
|
+
nil
|
46
54
|
end
|
47
55
|
|
48
56
|
def header_link_for(rel)
|
49
|
-
headers.select{|n| n =~ /rel=#{rel}/}.first
|
57
|
+
headers.select { |n| n =~ /rel=#{rel}/ }.first
|
50
58
|
end
|
51
59
|
|
52
60
|
def build_collection
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Myfinance
|
2
|
+
module Entities
|
3
|
+
class Sale < Base
|
4
|
+
attribute :id
|
5
|
+
attribute :nominal_amount
|
6
|
+
attribute :receivable_amount
|
7
|
+
attribute :fixed_fee_amount
|
8
|
+
attribute :fee_percentage
|
9
|
+
attribute :fee_percentage_amount
|
10
|
+
attribute :issuer
|
11
|
+
attribute :payment_method
|
12
|
+
attribute :status
|
13
|
+
attribute :summary
|
14
|
+
attribute :description
|
15
|
+
attribute :observation
|
16
|
+
attribute :category_id
|
17
|
+
attribute :classification_center_id
|
18
|
+
attribute :person_id
|
19
|
+
attribute :days_to_liquidation
|
20
|
+
attribute :sale_account_id
|
21
|
+
attribute :financial_account_id
|
22
|
+
attribute :liquidation_week_day
|
23
|
+
attribute :estimated_liquidated_at
|
24
|
+
attribute :liquidated_at
|
25
|
+
attribute :occurred_at
|
26
|
+
attribute :confirmed_at
|
27
|
+
attribute :created_at
|
28
|
+
attribute :updated_at
|
29
|
+
attribute :custom_classifications
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|