emites-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +146 -0
- data/emites-client.gemspec +2 -2
- data/lib/emites.rb +3 -0
- data/lib/emites/client.rb +8 -0
- data/lib/emites/entities/service.rb +29 -0
- data/lib/emites/resources/service.rb +98 -0
- data/lib/emites/resources/taker.rb +98 -0
- data/lib/emites/version.rb +1 -1
- data/spec/emites/client_spec.rb +12 -0
- data/spec/emites/entities/services_spec.rb +21 -0
- data/spec/emites/resources/service_spec.rb +107 -0
- data/spec/emites/resources/taker_spec.rb +117 -0
- data/spec/vcr_cassettes/services/create/error.yml +49 -0
- data/spec/vcr_cassettes/services/create/success.yml +74 -0
- data/spec/vcr_cassettes/services/destroy/error.yml +49 -0
- data/spec/vcr_cassettes/services/destroy/success.yml +44 -0
- data/spec/vcr_cassettes/services/info/error.yml +49 -0
- data/spec/vcr_cassettes/services/info/success.yml +75 -0
- data/spec/vcr_cassettes/services/list/success.yml +215 -0
- data/spec/vcr_cassettes/services/search/returns_empty.yml +49 -0
- data/spec/vcr_cassettes/services/search/success.yml +76 -0
- data/spec/vcr_cassettes/takers/create/error.yml +49 -0
- data/spec/vcr_cassettes/takers/create/success.yml +58 -0
- data/spec/vcr_cassettes/takers/destroy/error.yml +49 -0
- data/spec/vcr_cassettes/takers/destroy/success.yml +44 -0
- data/spec/vcr_cassettes/takers/info/error.yml +49 -0
- data/spec/vcr_cassettes/takers/info/success.yml +57 -0
- data/spec/vcr_cassettes/takers/list/success.yml +308 -0
- data/spec/vcr_cassettes/takers/search/returns_empty.yml +49 -0
- data/spec/vcr_cassettes/takers/search/success.yml +58 -0
- metadata +49 -2
data/lib/emites/version.rb
CHANGED
data/spec/emites/client_spec.rb
CHANGED
@@ -42,4 +42,16 @@ describe Emites::Client do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
describe "#takers" do
|
46
|
+
it "returns an instance of Emites::Resources::Taker" do
|
47
|
+
expect(subject.takers).to be_a(Emites::Resources::Taker)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#services" do
|
52
|
+
it "returns an instance of Emites::Resources::Service" do
|
53
|
+
expect(subject.services).to be_a(Emites::Resources::Service)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
45
57
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Emites::Entities::Service do
|
4
|
+
let(:attributes) do
|
5
|
+
{
|
6
|
+
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { described_class.new(attributes) }
|
11
|
+
|
12
|
+
it_behaves_like "entity_attributes", [
|
13
|
+
:id, :emitter_id, :name, :service_amount, :calculation_base,
|
14
|
+
:deduction_percentage, :retained_iss, :iss_percentage,
|
15
|
+
:pis_percentage, :cofins_percentage, :inss_percentage,
|
16
|
+
:ir_percentage, :csll_percentage, :discount_conditioning_percentage,
|
17
|
+
:service_item_code, :city_tax_code, :cnae_code,
|
18
|
+
:description, :city_code, :nfse_liquid_amount,
|
19
|
+
:other_retentions_percentage, :retained_iss_percentage, :unconditioned_discount_percentage
|
20
|
+
]
|
21
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Emites::Resources::Service do
|
4
|
+
let(:http) { Emites::Http.new("2C58AFD8E960A7BFE0BC912EBF47A960") }
|
5
|
+
let(:entity_klass) { Emites::Entities::Service }
|
6
|
+
let(:params) do
|
7
|
+
{
|
8
|
+
emitter_id: 10,
|
9
|
+
name: "Serviços de informática",
|
10
|
+
service_amount: 99.90
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
subject { described_class.new(http) }
|
15
|
+
|
16
|
+
it "has a instance of Emites::Http" do
|
17
|
+
expect(subject.http).to eq http
|
18
|
+
end
|
19
|
+
|
20
|
+
it_behaves_like "bound_notifiers", [:create, :destroy]
|
21
|
+
|
22
|
+
describe "#create" do
|
23
|
+
it "creates a service" do
|
24
|
+
VCR.use_cassette("services/create/success") do
|
25
|
+
service = subject.create(params)
|
26
|
+
expect(service).to be_a(entity_klass)
|
27
|
+
expect(service.name).to eq(params[:name])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns RequestError" do
|
32
|
+
VCR.use_cassette("services/create/error") do
|
33
|
+
expect {
|
34
|
+
subject.create({ service_amount: 99.90 })
|
35
|
+
}.to raise_error(Emites::RequestError)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#info" do
|
41
|
+
it "returns a Service instance where id is 50" do
|
42
|
+
VCR.use_cassette("services/info/success") do
|
43
|
+
service = subject.info(50)
|
44
|
+
expect(service).to be_a(entity_klass)
|
45
|
+
expect(service.name).to eq("Serviços de informática")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns RequestError" do
|
50
|
+
VCR.use_cassette("services/info/error") do
|
51
|
+
expect {
|
52
|
+
subject.info(51)
|
53
|
+
}.to raise_error(Emites::RequestError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#list" do
|
59
|
+
it "returns an array of services" do
|
60
|
+
VCR.use_cassette("services/list/success") do
|
61
|
+
entities = subject.list
|
62
|
+
expect(entities).to be_a(Array)
|
63
|
+
entities.each do |e|
|
64
|
+
expect(e).to be_a(entity_klass)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#search" do
|
71
|
+
it "returns an array of services where name is 'Serviços de informática'" do
|
72
|
+
VCR.use_cassette("services/search/success") do
|
73
|
+
entities = subject.search({ name: "Serviços de informática" })
|
74
|
+
expect(entities).to be_a(Array)
|
75
|
+
expect(entities.count).to eq(1)
|
76
|
+
entities.each do |e|
|
77
|
+
expect(e).to be_a(entity_klass)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns empty" do
|
83
|
+
VCR.use_cassette("services/search/returns_empty") do
|
84
|
+
entities = subject.search({ name: "abc" })
|
85
|
+
expect(entities).to be_a(Array)
|
86
|
+
expect(entities).to be_empty
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#destroy" do
|
92
|
+
it "deletes a service" do
|
93
|
+
VCR.use_cassette("services/destroy/success") do
|
94
|
+
result = subject.destroy(50)
|
95
|
+
expect(result).to be_truthy
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "returns RequestError" do
|
100
|
+
VCR.use_cassette("services/destroy/error") do
|
101
|
+
expect {
|
102
|
+
subject.destroy(51)
|
103
|
+
}.to raise_error(Emites::RequestError)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Emites::Resources::Taker do
|
4
|
+
let(:http) { Emites::Http.new("2C58AFD8E960A7BFE0BC912EBF47A960") }
|
5
|
+
let(:entity_klass) { Emites::Entities::Taker }
|
6
|
+
let(:params) do
|
7
|
+
{
|
8
|
+
email: "wanderson.policarpo@myfreecomm.com.br",
|
9
|
+
social_reason: "My Fake, Inc",
|
10
|
+
cnpj: "01001001000113",
|
11
|
+
fancy_name: "My Fake",
|
12
|
+
city_inscription: "3304557",
|
13
|
+
state: "RJ",
|
14
|
+
city: "3",
|
15
|
+
neighborhood: "Icaraí",
|
16
|
+
street_type: "RUA",
|
17
|
+
street: "Avenida Roberto Silveira - de 472 ao fim - lado par",
|
18
|
+
number: 43,
|
19
|
+
zip_code: "24230-163",
|
20
|
+
phone: "2199999999"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
subject { described_class.new(http) }
|
25
|
+
|
26
|
+
it "has a instance of Emites::Http" do
|
27
|
+
expect(subject.http).to eq http
|
28
|
+
end
|
29
|
+
|
30
|
+
it_behaves_like "bound_notifiers", [:create, :destroy]
|
31
|
+
|
32
|
+
describe "#create" do
|
33
|
+
it "creates a taker" do
|
34
|
+
VCR.use_cassette("takers/create/success") do
|
35
|
+
taker = subject.create(params)
|
36
|
+
expect(taker).to be_a(entity_klass)
|
37
|
+
expect(taker.cnpj).to eq(params[:cnpj])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns RequestError" do
|
42
|
+
VCR.use_cassette("takers/create/error") do
|
43
|
+
expect {
|
44
|
+
subject.create({ email: "email@example.com" })
|
45
|
+
}.to raise_error(Emites::RequestError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#info" do
|
51
|
+
it "returns a Taker instance where id is 135" do
|
52
|
+
VCR.use_cassette("takers/info/success") do
|
53
|
+
taker = subject.info(135)
|
54
|
+
expect(taker).to be_a(entity_klass)
|
55
|
+
expect(taker.cnpj).to eq("01001001000113")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns RequestError" do
|
60
|
+
VCR.use_cassette("takers/info/error") do
|
61
|
+
expect {
|
62
|
+
subject.info(136)
|
63
|
+
}.to raise_error(Emites::RequestError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#list" do
|
69
|
+
it "returns an array of takers" do
|
70
|
+
VCR.use_cassette("takers/list/success") do
|
71
|
+
entities = subject.list
|
72
|
+
expect(entities).to be_a(Array)
|
73
|
+
entities.each do |e|
|
74
|
+
expect(e).to be_a(entity_klass)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#search" do
|
81
|
+
it "returns an array of takers where CNPJ is '01001001000113'" do
|
82
|
+
VCR.use_cassette("takers/search/success") do
|
83
|
+
entities = subject.search({ cnpj: "01001001000113" })
|
84
|
+
expect(entities).to be_a(Array)
|
85
|
+
expect(entities.count).to eq(1)
|
86
|
+
entities.each do |e|
|
87
|
+
expect(e).to be_a(entity_klass)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns empty" do
|
93
|
+
VCR.use_cassette("takers/search/returns_empty") do
|
94
|
+
entities = subject.search({ cnpj: "1775" })
|
95
|
+
expect(entities).to be_a(Array)
|
96
|
+
expect(entities).to be_empty
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#destroy" do
|
102
|
+
it "deletes a taker" do
|
103
|
+
VCR.use_cassette("takers/destroy/success") do
|
104
|
+
result = subject.destroy(135)
|
105
|
+
expect(result).to be_truthy
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it "returns RequestError" do
|
110
|
+
VCR.use_cassette("takers/destroy/error") do
|
111
|
+
expect {
|
112
|
+
subject.destroy(136)
|
113
|
+
}.to raise_error(Emites::RequestError)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://sandbox.emites.com.br/api/v1/service-values
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"service_amount":99.9}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Emites Ruby Client v0.0.2
|
12
|
+
Accept:
|
13
|
+
- application/json
|
14
|
+
Content-Type:
|
15
|
+
- application/json
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 422
|
19
|
+
message: UNPROCESSABLE ENTITY
|
20
|
+
headers:
|
21
|
+
Allow:
|
22
|
+
- GET, POST, HEAD, OPTIONS
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Date:
|
26
|
+
- Fri, 28 Aug 2015 13:25:19 GMT
|
27
|
+
Server:
|
28
|
+
- nginx/1.6.2
|
29
|
+
User-Agent:
|
30
|
+
- emites-sandbox-v1
|
31
|
+
Vary:
|
32
|
+
- Cookie
|
33
|
+
X-Frame-Options:
|
34
|
+
- SAMEORIGIN
|
35
|
+
Content-Length:
|
36
|
+
- '100'
|
37
|
+
Connection:
|
38
|
+
- keep-alive
|
39
|
+
body:
|
40
|
+
encoding: ASCII-8BIT
|
41
|
+
string: !binary |-
|
42
|
+
eyJlbWl0dGVyX2lkIjogWyJFc3RlIGNhbXBvIG7Do28gcG9kZSBlc3RhciB2
|
43
|
+
YXppby4iXSwgIm5hbWUiOiBbIkVzdGUgY2FtcG8gbsOjbyBwb2RlIGVzdGFy
|
44
|
+
IHZhemlvLiJdfQ==
|
45
|
+
http_version: '1.1'
|
46
|
+
adapter_metadata:
|
47
|
+
effective_url: https://sandbox.emites.com.br/api/v1/service-values
|
48
|
+
recorded_at: Fri, 28 Aug 2015 13:25:19 GMT
|
49
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,74 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://sandbox.emites.com.br/api/v1/service-values
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"emitter_id":10,"name":"Serviços de informática","service_amount":99.9}'
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Emites Ruby Client v0.0.2
|
12
|
+
Accept:
|
13
|
+
- application/json
|
14
|
+
Content-Type:
|
15
|
+
- application/json
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 201
|
19
|
+
message: CREATED
|
20
|
+
headers:
|
21
|
+
Allow:
|
22
|
+
- GET, POST, HEAD, OPTIONS
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Date:
|
26
|
+
- Fri, 28 Aug 2015 13:24:43 GMT
|
27
|
+
Location:
|
28
|
+
- https://sandbox.emites.com.br/api/v1/service-values/50
|
29
|
+
Server:
|
30
|
+
- nginx/1.6.2
|
31
|
+
User-Agent:
|
32
|
+
- emites-sandbox-v1
|
33
|
+
Vary:
|
34
|
+
- Cookie
|
35
|
+
X-Frame-Options:
|
36
|
+
- SAMEORIGIN
|
37
|
+
transfer-encoding:
|
38
|
+
- chunked
|
39
|
+
Connection:
|
40
|
+
- keep-alive
|
41
|
+
body:
|
42
|
+
encoding: ASCII-8BIT
|
43
|
+
string: !binary |-
|
44
|
+
eyJfbGlua3MiOiBbeyJocmVmIjogImh0dHBzOi8vc2FuZGJveC5lbWl0ZXMu
|
45
|
+
Y29tLmJyL2FwaS92MS9zZXJ2aWNlLXZhbHVlcy81MCIsICJtZXRob2QiOiAi
|
46
|
+
R0VUIiwgInJlbCI6ICJzZWxmIn0sIHsiaHJlZiI6ICJodHRwczovL3NhbmRi
|
47
|
+
b3guZW1pdGVzLmNvbS5ici9hcGkvdjEvc2VydmljZS12YWx1ZXMvNTAiLCAi
|
48
|
+
bWV0aG9kIjogIlBVVCIsICJyZWwiOiAidXBkYXRlIn0sIHsiaHJlZiI6ICJo
|
49
|
+
dHRwczovL3NhbmRib3guZW1pdGVzLmNvbS5ici9hcGkvdjEvc2VydmljZS12
|
50
|
+
YWx1ZXMvNTAiLCAibWV0aG9kIjogIkRFTEVURSIsICJyZWwiOiAiZGVzdHJv
|
51
|
+
eSJ9LCB7ImhyZWYiOiAiaHR0cHM6Ly9zYW5kYm94LmVtaXRlcy5jb20uYnIv
|
52
|
+
c2VydmljZXMvZWRpdC81MCIsICJtZXRob2QiOiAiR0VUIiwgInJlbCI6ICJo
|
53
|
+
dG1sIn1dLCAiZW1pdHRlcl9pZCI6IDEwLCAiaWQiOiA1MCwgIm5hbWUiOiAi
|
54
|
+
U2VydmnDp29zIGRlIGluZm9ybcOhdGljYSIsICJjaXR5X2NvZGUiOiBudWxs
|
55
|
+
LCAiY2l0eV90YXhfY29kZSI6IG51bGwsICJzZXJ2aWNlX2l0ZW1fY29kZSI6
|
56
|
+
IG51bGwsICJjbmFlX2NvZGUiOiBudWxsLCAic2VydmljZV9hbW91bnQiOiAi
|
57
|
+
OTkuOSIsICJkaXNjb3VudF9jb25kaXRpb25pbmdfcGVyY2VudGFnZSI6IG51
|
58
|
+
bGwsICJ1bmNvbmRpdGlvbmVkX2Rpc2NvdW50X3BlcmNlbnRhZ2UiOiBudWxs
|
59
|
+
LCAiZGVkdWN0aW9uX3BlcmNlbnRhZ2UiOiBudWxsLCAib3RoZXJfcmV0ZW50
|
60
|
+
aW9uc19wZXJjZW50YWdlIjogbnVsbCwgImNhbGN1bGF0aW9uX2Jhc2UiOiBu
|
61
|
+
dWxsLCAiaXNzX3BlcmNlbnRhZ2UiOiBudWxsLCAicGlzX3BlcmNlbnRhZ2Ui
|
62
|
+
OiBudWxsLCAiY29maW5zX3BlcmNlbnRhZ2UiOiBudWxsLCAiaW5zc19wZXJj
|
63
|
+
ZW50YWdlIjogbnVsbCwgImlyX3BlcmNlbnRhZ2UiOiBudWxsLCAiY3NsbF9w
|
64
|
+
ZXJjZW50YWdlIjogbnVsbCwgInJldGFpbmVkX2lzcyI6IGZhbHNlLCAicmV0
|
65
|
+
YWluZWRfaXNzX3BlcmNlbnRhZ2UiOiBudWxsLCAibmZzZV9saXF1aWRfYW1v
|
66
|
+
dW50IjogbnVsbCwgImRlc2NyaXB0aW9uIjogbnVsbCwgImNpdHlfdGF4X2Nv
|
67
|
+
ZGVfZGVzYyI6IG51bGwsICJjaXR5X2NvZGVfZGVzYyI6IG51bGwsICJjbmFl
|
68
|
+
X2NvZGVfZGVzYyI6IG51bGwsICJzZXJ2aWNlX2l0ZW1fY29kZV9kZXNjIjog
|
69
|
+
bnVsbH0=
|
70
|
+
http_version: '1.1'
|
71
|
+
adapter_metadata:
|
72
|
+
effective_url: https://sandbox.emites.com.br/api/v1/service-values
|
73
|
+
recorded_at: Fri, 28 Aug 2015 13:24:43 GMT
|
74
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: delete
|
5
|
+
uri: https://sandbox.emites.com.br/api/v1/service-values/51
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Emites Ruby Client v0.0.2
|
12
|
+
Accept:
|
13
|
+
- application/json
|
14
|
+
Content-Type:
|
15
|
+
- application/json
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 404
|
19
|
+
message: NOT FOUND
|
20
|
+
headers:
|
21
|
+
Allow:
|
22
|
+
- GET, PUT, PATCH, DELETE, HEAD, OPTIONS
|
23
|
+
Content-Encoding:
|
24
|
+
- gzip
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Date:
|
28
|
+
- Fri, 28 Aug 2015 13:30:02 GMT
|
29
|
+
Server:
|
30
|
+
- nginx/1.6.2
|
31
|
+
User-Agent:
|
32
|
+
- emites-sandbox-v1
|
33
|
+
Vary:
|
34
|
+
- Accept-Encoding
|
35
|
+
- Cookie
|
36
|
+
X-Frame-Options:
|
37
|
+
- SAMEORIGIN
|
38
|
+
Content-Length:
|
39
|
+
- '43'
|
40
|
+
Connection:
|
41
|
+
- keep-alive
|
42
|
+
body:
|
43
|
+
encoding: UTF-8
|
44
|
+
string: '{"detail": "Not found"}'
|
45
|
+
http_version: '1.1'
|
46
|
+
adapter_metadata:
|
47
|
+
effective_url: https://sandbox.emites.com.br/api/v1/service-values/51
|
48
|
+
recorded_at: Fri, 28 Aug 2015 13:30:02 GMT
|
49
|
+
recorded_with: VCR 2.9.3
|