emites-client 0.0.2 → 0.0.3

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/README.md +146 -0
  4. data/emites-client.gemspec +2 -2
  5. data/lib/emites.rb +3 -0
  6. data/lib/emites/client.rb +8 -0
  7. data/lib/emites/entities/service.rb +29 -0
  8. data/lib/emites/resources/service.rb +98 -0
  9. data/lib/emites/resources/taker.rb +98 -0
  10. data/lib/emites/version.rb +1 -1
  11. data/spec/emites/client_spec.rb +12 -0
  12. data/spec/emites/entities/services_spec.rb +21 -0
  13. data/spec/emites/resources/service_spec.rb +107 -0
  14. data/spec/emites/resources/taker_spec.rb +117 -0
  15. data/spec/vcr_cassettes/services/create/error.yml +49 -0
  16. data/spec/vcr_cassettes/services/create/success.yml +74 -0
  17. data/spec/vcr_cassettes/services/destroy/error.yml +49 -0
  18. data/spec/vcr_cassettes/services/destroy/success.yml +44 -0
  19. data/spec/vcr_cassettes/services/info/error.yml +49 -0
  20. data/spec/vcr_cassettes/services/info/success.yml +75 -0
  21. data/spec/vcr_cassettes/services/list/success.yml +215 -0
  22. data/spec/vcr_cassettes/services/search/returns_empty.yml +49 -0
  23. data/spec/vcr_cassettes/services/search/success.yml +76 -0
  24. data/spec/vcr_cassettes/takers/create/error.yml +49 -0
  25. data/spec/vcr_cassettes/takers/create/success.yml +58 -0
  26. data/spec/vcr_cassettes/takers/destroy/error.yml +49 -0
  27. data/spec/vcr_cassettes/takers/destroy/success.yml +44 -0
  28. data/spec/vcr_cassettes/takers/info/error.yml +49 -0
  29. data/spec/vcr_cassettes/takers/info/success.yml +57 -0
  30. data/spec/vcr_cassettes/takers/list/success.yml +308 -0
  31. data/spec/vcr_cassettes/takers/search/returns_empty.yml +49 -0
  32. data/spec/vcr_cassettes/takers/search/success.yml +58 -0
  33. metadata +49 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 042560570f5b968a041ed46992d2dbd828e35e6d
4
- data.tar.gz: 9c948866300c115f656930ca0f5bdee24ea16701
3
+ metadata.gz: 35ee5886f9670b36b13c739e52fe97eb6fd55083
4
+ data.tar.gz: 55f09d9701274a1fe515a5497a81192f8c5d6fcd
5
5
  SHA512:
6
- metadata.gz: f93a4874a947fa979fef39bd232a1eff881633e015313ac4ff9cba8aacfad38fee79a1d2edc6907c1f227e962123bb219f18bc215bd65c7eb9782aff1b1d1fab
7
- data.tar.gz: f5d7cbdeff9686490badf85ce937fd5151475a21b87d9689138c81a0fa73c35969e1211192b999e740b7c32d081be7186175d6d5e3d437eb08bc6a2ca4e1d1a4
6
+ metadata.gz: d3462da3bb29c13edb6034082a7cb1af64ab81f4f2ce3006abc7ae53c668ef3e3695ca70de4a47f7d1eed3c19eb8a39159b53c4dca1eca1c473faa4410ab227e
7
+ data.tar.gz: a21b28b99a7f8ed3e96c5739b3ed23162d03a026db6593d87679b154132d6a946c39ac1f0d78c4d9dff53aeba77798c1bbf3cfba301f8dfbda5974ddefb09b4f
data/.gitignore CHANGED
@@ -28,4 +28,6 @@ mkmf.log
28
28
  *~
29
29
  .ruby-gemset
30
30
  .ruby-version
31
+ .rvmrc
32
+ .idea/
31
33
  doc
data/README.md CHANGED
@@ -47,6 +47,8 @@ client = Emites.client("YOUR_TOKEN_HERE")
47
47
  ##### Now you have access to every API endpoint:
48
48
 
49
49
  * [Emitters API](http://myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html) as `client.emitters`
50
+ * [Takers API](http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html) as `client.takers`
51
+ * [Services API](http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html) as `client.services`
50
52
  * [Webhooks API](http://myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html) as `client.webhooks`
51
53
  * [NFSe API](http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html) as `client.nfse`
52
54
 
@@ -117,6 +119,136 @@ client = Emites.client("YOUR_TOKEN_HERE")
117
119
  </tr>
118
120
  </table>
119
121
 
122
+ #### [Takers](http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html)
123
+
124
+ <table>
125
+ <tr>
126
+ <th>HTTP method</th>
127
+ <th>Endpoint</th>
128
+ <th>Client method</th>
129
+ </tr>
130
+ <tr>
131
+ <td><code>POST</code></td>
132
+ <td>
133
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html#criacao" target="_blank">
134
+ /api/v1/takers
135
+ </a>
136
+ </td>
137
+ <td>
138
+ <code>client.takers.create</code>
139
+ </td>
140
+ </tr>
141
+ <tr>
142
+ <td><code>GET</code></td>
143
+ <td>
144
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html#listagem" target="_blank">
145
+ /api/v1/takers
146
+ </a>
147
+ </td>
148
+ <td>
149
+ <code>client.takers.list</code>
150
+ </td>
151
+ </tr>
152
+ <tr>
153
+ <td><code>GET</code></td>
154
+ <td>
155
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html#detalhes" target="_blank">
156
+ /api/v1/takers/:id
157
+ </a>
158
+ </td>
159
+ <td>
160
+ <code>client.takers.info</code>
161
+ </td>
162
+ </tr>
163
+ <tr>
164
+ <td><code>GET</code></td>
165
+ <td>
166
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html#filtros" target="_blank">
167
+ /api/v1/takers?cnpj=:cnpj
168
+ </a>
169
+ </td>
170
+ <td>
171
+ <code>client.takers.search</code>
172
+ </td>
173
+ </tr>
174
+ <tr>
175
+ <td><code>DELETE</code></td>
176
+ <td>
177
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html#remocao" target="_blank">
178
+ /api/v1/takers/:id
179
+ </a>
180
+ </td>
181
+ <td>
182
+ <code>client.takers.destroy</code>
183
+ </td>
184
+ </tr>
185
+ </table>
186
+
187
+ #### [Services](http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html)
188
+
189
+ <table>
190
+ <tr>
191
+ <th>HTTP method</th>
192
+ <th>Endpoint</th>
193
+ <th>Client method</th>
194
+ </tr>
195
+ <tr>
196
+ <td><code>POST</code></td>
197
+ <td>
198
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#criacao" target="_blank">
199
+ /api/v1/service-values
200
+ </a>
201
+ </td>
202
+ <td>
203
+ <code>client.services.create</code>
204
+ </td>
205
+ </tr>
206
+ <tr>
207
+ <td><code>GET</code></td>
208
+ <td>
209
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#listagem" target="_blank">
210
+ /api/v1/service-values
211
+ </a>
212
+ </td>
213
+ <td>
214
+ <code>client.services.list</code>
215
+ </td>
216
+ </tr>
217
+ <tr>
218
+ <td><code>GET</code></td>
219
+ <td>
220
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#detalhes" target="_blank">
221
+ /api/v1/service-values/:id
222
+ </a>
223
+ </td>
224
+ <td>
225
+ <code>client.services.info</code>
226
+ </td>
227
+ </tr>
228
+ <tr>
229
+ <td><code>GET</code></td>
230
+ <td>
231
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#filtros" target="_blank">
232
+ /api/v1/service-values?name=:name
233
+ </a>
234
+ </td>
235
+ <td>
236
+ <code>client.services.search</code>
237
+ </td>
238
+ </tr>
239
+ <tr>
240
+ <td><code>DELETE</code></td>
241
+ <td>
242
+ <a href="http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#remocao" target="_blank">
243
+ /api/v1/service-values/:id
244
+ </a>
245
+ </td>
246
+ <td>
247
+ <code>client.services.destroy</code>
248
+ </td>
249
+ </tr>
250
+ </table>
251
+
120
252
  #### [Webhooks](http://myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html)
121
253
 
122
254
  <table>
@@ -338,6 +470,20 @@ When you call `client.emitters.destroy(1)`, an event `emites.emitters.destroy` w
338
470
  <code>emites.emitters.destroy</code>
339
471
  </td>
340
472
  </tr>
473
+ <tr>
474
+ <td><code>takers</code></td>
475
+ <td>
476
+ <code>emites.takers.create</code><br />
477
+ <code>emites.takers.destroy</code>
478
+ </td>
479
+ </tr>
480
+ <tr>
481
+ <td><code>services</code></td>
482
+ <td>
483
+ <code>emites.services.create</code><br />
484
+ <code>emites.services.destroy</code>
485
+ </td>
486
+ </tr>
341
487
  <tr>
342
488
  <td><code>webhooks</code></td>
343
489
  <td>
@@ -7,8 +7,8 @@ require "emites/version"
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "emites-client"
9
9
  spec.version = Emites::VERSION
10
- spec.authors = ["Leandro Thimóteo", "Rodrigo Tassinari", "Vagner Zampieri", "Wanderson Policarpo"]
11
- spec.email = %w(leandro.thimoteo rodrigo.tassinari vagner.zampieri wanderson.policarpo).map { |nick| "#{nick}@myfreecomm.com.br" }
10
+ spec.authors = ["Leandro Thimóteo", "Marcos Tagomori", "Rodrigo Tassinari", "Vagner Zampieri", "Wanderson Policarpo"]
11
+ spec.email = %w(leandro.thimoteo marcos.tagomori rodrigo.tassinari vagner.zampieri wanderson.policarpo).map { |nick| "#{nick}@myfreecomm.com.br" }
12
12
  spec.summary = %q{Official Ruby client for the Emites API.}
13
13
  spec.description = %q{Official Ruby client for the Emites API. Emites is a system for creating "notas fiscais eletrônicas" (NFe / NFSe) in Brazil.}
14
14
  spec.homepage = "https://github.com/myfreecomm/emites-client-ruby"
data/lib/emites.rb CHANGED
@@ -19,11 +19,14 @@ require "emites/entities/nfse_status_transition"
19
19
  require "emites/entities/nfse_values"
20
20
  require "emites/entities/nfse"
21
21
  require "emites/entities/webhook"
22
+ require "emites/entities/service"
22
23
 
23
24
  require "emites/resources/base"
24
25
  require "emites/resources/emitter"
25
26
  require "emites/resources/webhook"
26
27
  require "emites/resources/nfse"
28
+ require "emites/resources/taker"
29
+ require "emites/resources/service"
27
30
 
28
31
  module Emites
29
32
  def self.configuration
data/lib/emites/client.rb CHANGED
@@ -26,5 +26,13 @@ module Emites
26
26
  def nfse
27
27
  Resources::Nfse.new(http)
28
28
  end
29
+
30
+ def takers
31
+ Resources::Taker.new(http)
32
+ end
33
+
34
+ def services
35
+ Resources::Service.new(http)
36
+ end
29
37
  end
30
38
  end
@@ -0,0 +1,29 @@
1
+ module Emites
2
+ module Entities
3
+ class Service < Base
4
+ attribute :id, Integer
5
+ attribute :emitter_id, Integer
6
+ attribute :name, String
7
+ attribute :service_amount, Decimal, precision: 16, scale: 2
8
+ attribute :calculation_base, Decimal, precision: 16, scale: 2
9
+ attribute :deduction_percentage, Decimal, precision: 5, scale: 2
10
+ attribute :retained_iss, Boolean
11
+ attribute :iss_percentage, Decimal, precision: 5, scale: 2
12
+ attribute :pis_percentage, Decimal, precision: 5, scale: 2
13
+ attribute :cofins_percentage, Decimal, precision: 5, scale: 2
14
+ attribute :inss_percentage, Decimal, precision: 5, scale: 2
15
+ attribute :ir_percentage, Decimal, precision: 5, scale: 2
16
+ attribute :csll_percentage, Decimal, precision: 5, scale: 2
17
+ attribute :discount_conditioning_percentage, Decimal, precision: 5, scale: 2
18
+ attribute :service_item_code, String
19
+ attribute :city_tax_code, String
20
+ attribute :cnae_code, Integer
21
+ attribute :description, String
22
+ attribute :city_code, Integer
23
+ attribute :nfse_liquid_amount, Decimal, precision: 16, scale: 2
24
+ attribute :other_retentions_percentage, Decimal, precision: 5, scale: 2
25
+ attribute :retained_iss_percentage, Decimal, precision: 5, scale: 2
26
+ attribute :unconditioned_discount_percentage, Decimal, precision: 5, scale: 2
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,98 @@
1
+ module Emites
2
+ module Resources
3
+
4
+ # A wrapper to Emites services API
5
+ #
6
+ # [API]
7
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html
8
+ #
9
+ # @example Listing all services:
10
+ # client = Emites.client("MY_SECRET_TOKEN")
11
+ # client.services.list
12
+ #
13
+ # @example Creating a service:
14
+ # client = Emites.client("MY_SECRET_TOKEN")
15
+ # client.services.create({emitter_id: 1, name: "Serviço"})
16
+ #
17
+ # @see Emites.client
18
+ class Service < Base
19
+
20
+ # Creates a Service related to the Account
21
+ #
22
+ # [API]
23
+ # Method: <tt>POST /api/v1/service-values</tt>
24
+ #
25
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#criacao
26
+ #
27
+ # @param params [Hash] a hash with Service attributes
28
+ # @return [Emites::Entities::Service] the created Service
29
+ def create(params)
30
+ http.post("/service-values", { body: params }) do |response|
31
+ respond_with_entity(response)
32
+ end
33
+ end
34
+
35
+ # Retrieves a Service by it's id
36
+ #
37
+ # [API]
38
+ # Method: <tt>GET /api/v1/service-values/:id</tt>
39
+ #
40
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#detalhes
41
+ #
42
+ # @param id [Integer] the Service id
43
+ # @return [Emites::Entities::Service] the Service by it's id
44
+ def info(id)
45
+ http.get("/service-values/#{id}") do |response|
46
+ respond_with_entity(response)
47
+ end
48
+ end
49
+
50
+ # Lists all services related to the account
51
+ #
52
+ # [API]
53
+ # Method: <tt>GET /api/v1/service-values</tt>
54
+ #
55
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#listagem
56
+ #
57
+ # @return [Array] an array of Service
58
+ def list
59
+ http.get("/service-values") do |response|
60
+ respond_with_collection(response)
61
+ end
62
+ end
63
+
64
+ # Lists all services related to the account matching search results
65
+ #
66
+ # [API]
67
+ # Method: <tt>GET /api/v1/service-values?name=:name</tt>
68
+ #
69
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#filtros
70
+ #
71
+ # @param params [Hash] a hash with Service attributes
72
+ # @return [Array] an array of Service
73
+ def search(params)
74
+ http.get("/service-values", { params: params }) do |response|
75
+ respond_with_collection(response)
76
+ end
77
+ end
78
+
79
+ # Deletes a Service by it's id. Returns <tt>true</true> if deletion performed well, otherwise,
80
+ # returns <tt>false</tt>.
81
+ #
82
+ # [API]
83
+ # Method: <tt>DELETE /api/v1/service-values/:id</tt>
84
+ #
85
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/service_values.html#remocao
86
+ #
87
+ # @param id [Integer] the Service id
88
+ # @return [Boolean] whether deletion was performed or not
89
+ def destroy(id)
90
+ http.delete("/service-values/#{id}") do |response|
91
+ response.code == 204
92
+ end
93
+ end
94
+
95
+ notify :create, :destroy
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,98 @@
1
+ module Emites
2
+ module Resources
3
+
4
+ # A wrapper to Emites takers API
5
+ #
6
+ # [API]
7
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html
8
+ #
9
+ # @example Listing all takers:
10
+ # client = Emites.client("MY_SECRET_TOKEN")
11
+ # client.takers.list
12
+ #
13
+ # @example Creating an taker:
14
+ # client = Emites.client("MY_SECRET_TOKEN")
15
+ # client.takers.create({cnpj: "01001001000113"})
16
+ #
17
+ # @see Emites.client
18
+ class Taker < Base
19
+
20
+ # Creates a Taker related to the Account
21
+ #
22
+ # [API]
23
+ # Method: <tt>POST /api/v1/takers</tt>
24
+ #
25
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html#criacao
26
+ #
27
+ # @param params [Hash] a hash with Taker attributes
28
+ # @return [Emites::Entities::Taker] the created Taker
29
+ def create(params)
30
+ http.post("/takers", { body: params }) do |response|
31
+ respond_with_entity(response)
32
+ end
33
+ end
34
+
35
+ # Retrieves a Taker by it's id
36
+ #
37
+ # [API]
38
+ # Method: <tt>GET /api/v1/takers/:id</tt>
39
+ #
40
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html#detalhes
41
+ #
42
+ # @param id [Integer] the Taker id
43
+ # @return [Emites::Entities::Taker] the Taker by it's id
44
+ def info(id)
45
+ http.get("/takers/#{id}") do |response|
46
+ respond_with_entity(response)
47
+ end
48
+ end
49
+
50
+ # Lists all takers related to the account
51
+ #
52
+ # [API]
53
+ # Method: <tt>GET /api/v1/takers</tt>
54
+ #
55
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html#listagem
56
+ #
57
+ # @return [Array] an array of Taker
58
+ def list
59
+ http.get("/takers") do |response|
60
+ respond_with_collection(response)
61
+ end
62
+ end
63
+
64
+ # Lists all takers related to the account matching search results
65
+ #
66
+ # [API]
67
+ # Method: <tt>GET /api/v1/takers?cnpj=:cnpj</tt>
68
+ #
69
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html#filtros
70
+ #
71
+ # @param params [Hash] a hash with Taker attributes
72
+ # @return [Array] an array of Taker
73
+ def search(params)
74
+ http.get("/takers", { params: params }) do |response|
75
+ respond_with_collection(response)
76
+ end
77
+ end
78
+
79
+ # Deletes a Taker by it's id. Returns <tt>true</true> if deletion performed well, otherwise,
80
+ # returns <tt>false</tt>.
81
+ #
82
+ # [API]
83
+ # Method: <tt>DELETE /api/v1/takers/:id</tt>
84
+ #
85
+ # Documentation: http://myfreecomm.github.io/emites/sandbox/v1/modules/taker.html#remocao
86
+ #
87
+ # @param id [Integer] the Taker id
88
+ # @return [Boolean] whether deletion was performed or not
89
+ def destroy(id)
90
+ http.delete("/takers/#{id}") do |response|
91
+ response.code == 204
92
+ end
93
+ end
94
+
95
+ notify :create, :destroy
96
+ end
97
+ end
98
+ end