emites-client 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +31 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +366 -0
  8. data/Rakefile +9 -0
  9. data/emites-client.gemspec +37 -0
  10. data/lib/emites.rb +44 -0
  11. data/lib/emites/client.rb +30 -0
  12. data/lib/emites/configuration.rb +12 -0
  13. data/lib/emites/entities/account.rb +8 -0
  14. data/lib/emites/entities/base.rb +9 -0
  15. data/lib/emites/entities/emitter.rb +31 -0
  16. data/lib/emites/entities/nfse.rb +29 -0
  17. data/lib/emites/entities/nfse_status.rb +15 -0
  18. data/lib/emites/entities/nfse_status_transition.rb +14 -0
  19. data/lib/emites/entities/nfse_values.rb +28 -0
  20. data/lib/emites/entities/rps.rb +9 -0
  21. data/lib/emites/entities/taker.rb +20 -0
  22. data/lib/emites/entities/taker_address.rb +21 -0
  23. data/lib/emites/entities/taker_contact.rb +9 -0
  24. data/lib/emites/entities/webhook.rb +9 -0
  25. data/lib/emites/exception.rb +11 -0
  26. data/lib/emites/http.rb +34 -0
  27. data/lib/emites/request.rb +53 -0
  28. data/lib/emites/resources/base.rb +45 -0
  29. data/lib/emites/resources/emitter.rb +98 -0
  30. data/lib/emites/resources/hooks.rb +25 -0
  31. data/lib/emites/resources/nfse.rb +173 -0
  32. data/lib/emites/resources/webhook.rb +84 -0
  33. data/lib/emites/response.rb +38 -0
  34. data/lib/emites/version.rb +3 -0
  35. data/spec/emites/client_spec.rb +45 -0
  36. data/spec/emites/configuration_spec.rb +13 -0
  37. data/spec/emites/entities/account_spec.rb +14 -0
  38. data/spec/emites/entities/base_spec.rb +28 -0
  39. data/spec/emites/entities/emitter_spec.rb +20 -0
  40. data/spec/emites/entities/nfse_spec.rb +148 -0
  41. data/spec/emites/entities/nfse_status_spec.rb +16 -0
  42. data/spec/emites/entities/nfse_status_transition_spec.rb +23 -0
  43. data/spec/emites/entities/nfse_values_spec.rb +19 -0
  44. data/spec/emites/entities/rps_spec.rb +15 -0
  45. data/spec/emites/entities/taker_address_spec.rb +18 -0
  46. data/spec/emites/entities/taker_contact_spec.rb +13 -0
  47. data/spec/emites/entities/taker_spec.rb +18 -0
  48. data/spec/emites/entities/webhook_spec.rb +14 -0
  49. data/spec/emites/exception_spec.rb +21 -0
  50. data/spec/emites/http_spec.rb +62 -0
  51. data/spec/emites/resources/base_spec.rb +96 -0
  52. data/spec/emites/resources/emitter_spec.rb +119 -0
  53. data/spec/emites/resources/nfse_spec.rb +214 -0
  54. data/spec/emites/resources/webhook_spec.rb +62 -0
  55. data/spec/emites_spec.rb +63 -0
  56. data/spec/fixtures/certificate.pfx +0 -0
  57. data/spec/shared_examples/bound_notifiers.rb +8 -0
  58. data/spec/shared_examples/entity_attributes.rb +9 -0
  59. data/spec/spec_helper.rb +38 -0
  60. data/spec/support/matchers/have_attr_accessor.rb +18 -0
  61. data/spec/vcr_cassettes/client/authenticated/false.yml +48 -0
  62. data/spec/vcr_cassettes/client/authenticated/true.yml +259 -0
  63. data/spec/vcr_cassettes/emitters/create/error.yml +57 -0
  64. data/spec/vcr_cassettes/emitters/create/success.yml +80 -0
  65. data/spec/vcr_cassettes/emitters/destroy/error.yml +47 -0
  66. data/spec/vcr_cassettes/emitters/destroy/success.yml +44 -0
  67. data/spec/vcr_cassettes/emitters/info/error.yml +47 -0
  68. data/spec/vcr_cassettes/emitters/info/success.yml +77 -0
  69. data/spec/vcr_cassettes/emitters/list/success.yml +135 -0
  70. data/spec/vcr_cassettes/emitters/partial_update/success.yml +90 -0
  71. data/spec/vcr_cassettes/emitters/search/returns_empty.yml +47 -0
  72. data/spec/vcr_cassettes/emitters/search/success.yml +76 -0
  73. data/spec/vcr_cassettes/nfse/cancel/success.yml +49 -0
  74. data/spec/vcr_cassettes/nfse/create/given_taker.yml +109 -0
  75. data/spec/vcr_cassettes/nfse/create/incomplete.yml +73 -0
  76. data/spec/vcr_cassettes/nfse/create/success.yml +112 -0
  77. data/spec/vcr_cassettes/nfse/create/without_taker.yml +73 -0
  78. data/spec/vcr_cassettes/nfse/destroy/success.yml +46 -0
  79. data/spec/vcr_cassettes/nfse/history/success.yml +83 -0
  80. data/spec/vcr_cassettes/nfse/info/success.yml +113 -0
  81. data/spec/vcr_cassettes/nfse/list/success.yml +1353 -0
  82. data/spec/vcr_cassettes/nfse/pdf/success.yml +48 -0
  83. data/spec/vcr_cassettes/nfse/status/success.yml +51 -0
  84. data/spec/vcr_cassettes/nfse/update/success.yml +113 -0
  85. data/spec/vcr_cassettes/nfse/xml/success.yml +48 -0
  86. data/spec/vcr_cassettes/webhooks/create/success.yml +53 -0
  87. data/spec/vcr_cassettes/webhooks/destroy/success.yml +46 -0
  88. data/spec/vcr_cassettes/webhooks/list/success.yml +53 -0
  89. data/spec/vcr_cassettes/webhooks/update/success.yml +52 -0
  90. metadata +390 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 042560570f5b968a041ed46992d2dbd828e35e6d
4
+ data.tar.gz: 9c948866300c115f656930ca0f5bdee24ea16701
5
+ SHA512:
6
+ metadata.gz: f93a4874a947fa979fef39bd232a1eff881633e015313ac4ff9cba8aacfad38fee79a1d2edc6907c1f227e962123bb219f18bc215bd65c7eb9782aff1b1d1fab
7
+ data.tar.gz: f5d7cbdeff9686490badf85ce937fd5151475a21b87d9689138c81a0fa73c35969e1211192b999e740b7c32d081be7186175d6d5e3d437eb08bc6a2ca4e1d1a4
data/.gitignore ADDED
@@ -0,0 +1,31 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .env
7
+ .envrc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ vendor
21
+ *.bundle
22
+ *.so
23
+ *.o
24
+ *.a
25
+ mkmf.log
26
+ *.swp
27
+ *.swo
28
+ *~
29
+ .ruby-gemset
30
+ .ruby-version
31
+ doc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.5
5
+ - 2.2.1
6
+ env:
7
+ global:
8
+ # CODECLIMATE_REPO_TOKEN
9
+ - secure: "XUWWSpmCnhSVT7xNnPbcaL1N8PuUbQVAQDJkO6StWbBjb+BJXRUW331/Yp4ANod49KuEJWNnIhVFuotGFwNvi9ZKVCTM2bUhQF8qNKk4bpCrsrN1TZdbDgHo0ZzqTlaZy5uEDI1o4yP2XIEufNl+tybbNnFP23dFIp7hiBn4VTw="
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 emites_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Free Communities Consultoria Em Informática Ltda.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,366 @@
1
+ # Emites Client
2
+
3
+ This is the official Ruby client for the [Emites](https://app.emites.com.br) API.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/emites-client.png)](https://rubygems.org/gems/emites-client)
6
+ [![Build Status](https://api.travis-ci.org/myfreecomm/emites-client-ruby.svg?branch=master)](https://travis-ci.org/myfreecomm/emites-client-ruby)
7
+ [![Test Coverage](https://codeclimate.com/github/myfreecomm/emites-client-ruby/badges/coverage.svg)](https://codeclimate.com/github/myfreecomm/emites-client-ruby)
8
+ [![Code Climate Grade](https://codeclimate.com/github/myfreecomm/emites-client-ruby/badges/gpa.svg)](https://codeclimate.com/github/myfreecomm/emites-client-ruby)
9
+ [![Inline docs](http://inch-ci.org/github/myfreecomm/emites-client-ruby.svg)](http://inch-ci.org/github/myfreecomm/emites-client-ruby)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'emites-client', require: 'emites'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install emites-client
24
+
25
+ ## Configuration
26
+
27
+ ##### Use Emites.configure to setup your environment:
28
+
29
+ ```ruby
30
+ require "emites"
31
+
32
+ Emites.configure do |config|
33
+ config.url = "https://sandbox.emites.com.br/api/v1" # defaults to "https://app.emites.com.br/api/v1"
34
+ config.user_agent = 'My App v1.0' # optional, but you should pass a custom user-agent identifying your app
35
+ end
36
+ ```
37
+ ##### Create a new token in your Emites account: https://app.emites.com.br/config/api
38
+
39
+ ## Usage
40
+
41
+ ##### Given your token, create an instance of Emites::Client, as below:
42
+
43
+ ```ruby
44
+ client = Emites.client("YOUR_TOKEN_HERE")
45
+ ```
46
+
47
+ ##### Now you have access to every API endpoint:
48
+
49
+ * [Emitters API](http://myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html) as `client.emitters`
50
+ * [Webhooks API](http://myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html) as `client.webhooks`
51
+ * [NFSe API](http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html) as `client.nfse`
52
+
53
+ ### Endpoints
54
+
55
+ #### [Emitters](http://myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html)
56
+
57
+ <table>
58
+ <tr>
59
+ <th>HTTP method</th>
60
+ <th>Endpoint</th>
61
+ <th>Client method</th>
62
+ </tr>
63
+ <tr>
64
+ <td><code>POST</code></td>
65
+ <td>
66
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html#criacao" target="_blank">
67
+ /api/v1/emitters
68
+ </a>
69
+ </td>
70
+ <td>
71
+ <code>client.emitters.create</code>
72
+ </td>
73
+ </tr>
74
+ <tr>
75
+ <td><code>GET</code></td>
76
+ <td>
77
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html#listagem" target="_blank">
78
+ /api/v1/emitters
79
+ </a>
80
+ </td>
81
+ <td>
82
+ <code>client.emitters.list</code>
83
+ </td>
84
+ </tr>
85
+ <tr>
86
+ <td><code>GET</code></td>
87
+ <td>
88
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html#detalhes" target="_blank">
89
+ /api/v1/emitters/:id
90
+ </a>
91
+ </td>
92
+ <td>
93
+ <code>client.emitters.info</code>
94
+ </td>
95
+ </tr>
96
+ <tr>
97
+ <td><code>GET</code></td>
98
+ <td>
99
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html#filtros" target="_blank">
100
+ /api/v1/emitters?cnpj=?:cnpj
101
+ </a>
102
+ </td>
103
+ <td>
104
+ <code>client.emitters.search</code>
105
+ </td>
106
+ </tr>
107
+ <tr>
108
+ <td><code>DELETE</code></td>
109
+ <td>
110
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html#remocao" target="_blank">
111
+ /api/v1/emitters/:id
112
+ </a>
113
+ </td>
114
+ <td>
115
+ <code>client.emitters.destroy</code>
116
+ </td>
117
+ </tr>
118
+ </table>
119
+
120
+ #### [Webhooks](http://myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html)
121
+
122
+ <table>
123
+ <tr>
124
+ <th>HTTP method</th>
125
+ <th>Endpoint</th>
126
+ <th>Client method</th>
127
+ </tr>
128
+ <tr>
129
+ <td><code>POST</code></td>
130
+ <td>
131
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html#criacao" target="_blank">
132
+ /api/v1/webhooks
133
+ </a>
134
+ </td>
135
+ <td>
136
+ <code>client.webhooks.create</code>
137
+ </td>
138
+ </tr>
139
+ <tr>
140
+ <td><code>GET</code></td>
141
+ <td>
142
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html#listagem" target="_blank">
143
+ /api/v1/webhooks
144
+ </a>
145
+ </td>
146
+ <td>
147
+ <code>client.webhooks.list</code>
148
+ </td>
149
+ </tr>
150
+ <tr>
151
+ <td><code>PUT</code></td>
152
+ <td>
153
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html#atualizacao" target="_blank">
154
+ /api/v1/webhooks/:id
155
+ </a>
156
+ </td>
157
+ <td>
158
+ <code>client.webhooks.update</code>
159
+ </td>
160
+ </tr>
161
+ <tr>
162
+ <td><code>DELETE</code></td>
163
+ <td>
164
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html#remocao" target="_blank">
165
+ /api/v1/webhooks/:id
166
+ </a>
167
+ </td>
168
+ <td>
169
+ <code>client.webhooks.destroy</code>
170
+ </td>
171
+ </tr>
172
+ </table>
173
+
174
+ #### [NFSe](http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html)
175
+
176
+ <table>
177
+ <tr>
178
+ <th>HTTP method</th>
179
+ <th>Endpoint</th>
180
+ <th>Client method</th>
181
+ </tr>
182
+ <tr>
183
+ <td><code>POST</code></td>
184
+ <td>
185
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#criacao" target="_blank">
186
+ /api/v1/nfse
187
+ </a>
188
+ </td>
189
+ <td>
190
+ <code>client.nfse.create</code>
191
+ </td>
192
+ </tr>
193
+ <tr>
194
+ <td><code>GET</code></td>
195
+ <td>
196
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#listagem" target="_blank">
197
+ /api/v1/nfse
198
+ </a>
199
+ </td>
200
+ <td>
201
+ <code>client.nfse.list</code>
202
+ </td>
203
+ </tr>
204
+ <tr>
205
+ <td><code>GET</code></td>
206
+ <td>
207
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#detalhes" target="_blank">
208
+ /api/v1/nfse/:id
209
+ </a>
210
+ </td>
211
+ <td>
212
+ <code>client.nfse.info</code>
213
+ </td>
214
+ </tr>
215
+ <tr>
216
+ <td><code>GET</code></td>
217
+ <td>
218
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#status" target="_blank">
219
+ /api/v1/nfse/:id/status
220
+ </a>
221
+ </td>
222
+ <td>
223
+ <code>client.nfse.status</code>
224
+ </td>
225
+ </tr>
226
+ <tr>
227
+ <td><code>GET</code></td>
228
+ <td>
229
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#historico" target="_blank">
230
+ /api/v1/nfse/:id/history
231
+ </a>
232
+ </td>
233
+ <td>
234
+ <code>client.nfse.history</code>
235
+ </td>
236
+ </tr>
237
+ <tr>
238
+ <td><code>GET</code></td>
239
+ <td>
240
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#pdf" target="_blank">
241
+ /api/v1/nfse/:id/pdf
242
+ </a>
243
+ </td>
244
+ <td>
245
+ <code>client.nfse.pdf</code>
246
+ </td>
247
+ </tr>
248
+ <tr>
249
+ <td><code>GET</code></td>
250
+ <td>
251
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#xml" target="_blank">
252
+ /api/v1/nfse/:id/xml
253
+ </a>
254
+ </td>
255
+ <td>
256
+ <code>client.nfse.xml</code>
257
+ </td>
258
+ </tr>
259
+ <tr>
260
+ <td><code>POST</code></td>
261
+ <td>
262
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#cancelamento" target="_blank">
263
+ /api/v1/nfse/:id/cancel
264
+ </a>
265
+ </td>
266
+ <td>
267
+ <code>client.nfse.cancel</code>
268
+ </td>
269
+ </tr>
270
+ <tr>
271
+ <td><code>DELETE</code></td>
272
+ <td>
273
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#remocao" target="_blank">
274
+ /api/v1/nfse/:id
275
+ </a>
276
+ </td>
277
+ <td>
278
+ <code>client.nfse.destroy</code>
279
+ </td>
280
+ </tr>
281
+ <tr>
282
+ <td><code>PUT</code></td>
283
+ <td>
284
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#atualizacao-parcial-e-completa" target="_blank">
285
+ /api/v1/nfse/:id
286
+ </a>
287
+ </td>
288
+ <td>
289
+ <code>client.nfse.update</code>
290
+ </td>
291
+ </tr>
292
+ </table>
293
+
294
+ ## Callbacks
295
+
296
+ 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.
297
+
298
+ #### Subscribing to an event
299
+
300
+ All you have to do is create a class that responds to a method `#call` with two arguments:
301
+
302
+ ```ruby
303
+ class MyListener
304
+ def call(result, args)
305
+ end
306
+ end
307
+ ```
308
+
309
+ **Where:**
310
+
311
+ * `result` is the return of a client method
312
+ * `args` is an array of arguments passed to the client method you called
313
+
314
+ Now you have a listener, you can subscribe to an event:
315
+
316
+ ```ruby
317
+ Emites.subscribe("emites.emitters.destroy", MyListener.new)
318
+ ```
319
+
320
+ **Example:**
321
+
322
+ When you call `client.emitters.destroy(1)`, an event `emites.emitters.destroy` will be triggered. Your listener method `#call` will receive:
323
+
324
+ * `result` would be `true or false` - depending on what `client.emitters.destroy(1)` returned
325
+ * `args` would be `[1]` - an array with the arguments passed to the client method
326
+
327
+ #### Available hooks
328
+
329
+ <table>
330
+ <tr>
331
+ <th>Resource</th>
332
+ <th>Events</th>
333
+ </tr>
334
+ <tr>
335
+ <td><code>emitters</code></td>
336
+ <td>
337
+ <code>emites.emitters.create</code><br />
338
+ <code>emites.emitters.destroy</code>
339
+ </td>
340
+ </tr>
341
+ <tr>
342
+ <td><code>webhooks</code></td>
343
+ <td>
344
+ <code>emites.webhooks.create</code><br />
345
+ <code>emites.webhooks.update</code><br />
346
+ <code>emites.webhooks.destroy</code>
347
+ </td>
348
+ </tr>
349
+ <tr>
350
+ <td><code>nfse</code></td>
351
+ <td>
352
+ <code>emites.nfse.create</code><br />
353
+ <code>emites.nfse.update</code><br />
354
+ <code>emites.nfse.destroy</code><br />
355
+ <code>emites.nfse.cancel</code>
356
+ </td>
357
+ </tr>
358
+ </table>
359
+
360
+ ## Contributing
361
+
362
+ 1. Fork it ( https://github.com/myfreecomm/emites-client-ruby/fork )
363
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
364
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
365
+ 4. Push to the branch (`git push origin my-new-feature`)
366
+ 5. Create a new Pull Request