billimatic-client 0.1.0
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.
- checksums.yaml +7 -0
- data/.codeclimate.yml +7 -0
- data/.gitignore +41 -0
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +120 -0
- data/Guardfile +70 -0
- data/LICENSE +21 -0
- data/README.md +184 -0
- data/Rakefile +9 -0
- data/billimatic-client-ruby.gemspec +43 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/billimatic.rb +53 -0
- data/lib/billimatic/client.rb +47 -0
- data/lib/billimatic/configuration.rb +12 -0
- data/lib/billimatic/entities/address_information.rb +15 -0
- data/lib/billimatic/entities/base.rb +9 -0
- data/lib/billimatic/entities/company.rb +25 -0
- data/lib/billimatic/entities/contract.rb +25 -0
- data/lib/billimatic/entities/customer.rb +12 -0
- data/lib/billimatic/entities/entity_service_item.rb +11 -0
- data/lib/billimatic/entities/invoice.rb +8 -0
- data/lib/billimatic/entities/invoice_rule.rb +8 -0
- data/lib/billimatic/entities/plan.rb +21 -0
- data/lib/billimatic/entities/product.rb +6 -0
- data/lib/billimatic/entities/subscription.rb +6 -0
- data/lib/billimatic/entities/webhook.rb +8 -0
- data/lib/billimatic/exception.rb +11 -0
- data/lib/billimatic/http.rb +32 -0
- data/lib/billimatic/request.rb +51 -0
- data/lib/billimatic/resources/base.rb +116 -0
- data/lib/billimatic/resources/company.rb +26 -0
- data/lib/billimatic/resources/contract.rb +10 -0
- data/lib/billimatic/resources/hooks.rb +25 -0
- data/lib/billimatic/resources/invoice.rb +11 -0
- data/lib/billimatic/resources/invoice_rule.rb +10 -0
- data/lib/billimatic/resources/plan.rb +11 -0
- data/lib/billimatic/resources/subscription.rb +19 -0
- data/lib/billimatic/resources/webhook.rb +10 -0
- data/lib/billimatic/response.rb +32 -0
- data/lib/billimatic/signature.rb +14 -0
- data/lib/billimatic/version.rb +3 -0
- metadata +272 -0
@@ -0,0 +1,116 @@
|
|
1
|
+
require "billimatic/resources/hooks"
|
2
|
+
|
3
|
+
module Billimatic
|
4
|
+
module Resources
|
5
|
+
class Base
|
6
|
+
include Wisper::Publisher
|
7
|
+
extend Hooks
|
8
|
+
attr_accessor :http
|
9
|
+
|
10
|
+
def self.crud(*args)
|
11
|
+
@crud ||= args
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(http)
|
15
|
+
@http = http
|
16
|
+
end
|
17
|
+
|
18
|
+
def collection_name
|
19
|
+
@collection_name ||= underscore_pluralized_klass_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def parsed_body(response)
|
23
|
+
MultiJson.load(response.body)
|
24
|
+
rescue MultiJson::ParseError
|
25
|
+
{}
|
26
|
+
end
|
27
|
+
|
28
|
+
def create(params)
|
29
|
+
crud_request do
|
30
|
+
http.post(resource_base_path, { body: params }) do |response|
|
31
|
+
respond_with_entity(response)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def show(id)
|
37
|
+
crud_request do
|
38
|
+
http.get("#{resource_base_path}/#{id}") do |response|
|
39
|
+
respond_with_entity(response)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def list
|
45
|
+
crud_request do
|
46
|
+
http.get(resource_base_path) do |response|
|
47
|
+
respond_with_collection(response)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def destroy(id)
|
53
|
+
crud_request do
|
54
|
+
http.delete("#{resource_base_path}/#{id}") do |response|
|
55
|
+
response.code == 204
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def update(id, params)
|
61
|
+
crud_request do
|
62
|
+
http.put("#{resource_base_path}/#{id}", { body: params }) do |response|
|
63
|
+
respond_with_entity(response)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
notify :create, :destroy
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
def crud_request
|
73
|
+
method = caller_locations(1,1)[0].label
|
74
|
+
if self.class.crud.include?(:all) || self.class.crud.include?(method.to_sym)
|
75
|
+
yield
|
76
|
+
else
|
77
|
+
raise RuntimeError, "#{base_klass} do not implement the #{method} method"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def respond_with_collection(response, class_name = base_klass)
|
82
|
+
parsed_body(response)[collection_name].map do |item|
|
83
|
+
entity_klass(class_name).new(item)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def respond_with_entity(response, naked_klass = entity_klass)
|
88
|
+
naked_klass.new(parsed_body(response)[underscored_klass_name])
|
89
|
+
end
|
90
|
+
|
91
|
+
def respond_with_openstruct(response)
|
92
|
+
OpenStruct.new(MultiJson.load(response.body))
|
93
|
+
end
|
94
|
+
|
95
|
+
def resource_base_path
|
96
|
+
@resource_base_path ||= "/#{collection_name}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def base_klass
|
100
|
+
@base_klass ||= self.class.name.split('::').last
|
101
|
+
end
|
102
|
+
|
103
|
+
def entity_klass(class_name = base_klass)
|
104
|
+
@entity_klass ||= Billimatic::Entities.const_get(class_name.to_sym)
|
105
|
+
end
|
106
|
+
|
107
|
+
def underscore_pluralized_klass_name
|
108
|
+
"#{underscored_klass_name}s"
|
109
|
+
end
|
110
|
+
|
111
|
+
def underscored_klass_name
|
112
|
+
base_klass.gsub(/(.)([A-Z])/, '\1_\2').downcase
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Billimatic
|
2
|
+
module Resources
|
3
|
+
class Company < Base
|
4
|
+
crud :create, :destroy
|
5
|
+
|
6
|
+
def initialize(http)
|
7
|
+
@collection_name = 'companies'
|
8
|
+
super(http)
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /api/v1/companies/search
|
12
|
+
def search(cnpj)
|
13
|
+
http.get("#{resource_base_path}/search", params: {cnpj: cnpj}) do |response|
|
14
|
+
respond_with_collection(response)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# PATCH /api/v1/companies/:id
|
19
|
+
def update(id, params)
|
20
|
+
http.patch("#{resource_base_path}/#{id}", body: params) do |response|
|
21
|
+
respond_with_entity(response)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Billimatic
|
2
|
+
module Resources
|
3
|
+
module Hooks
|
4
|
+
|
5
|
+
def notify(*hooked_methods)
|
6
|
+
apply_hooks(hooked_methods.flatten)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def apply_hooks(hooked_methods)
|
12
|
+
hooked_methods.each do |method|
|
13
|
+
alias_method "#{method}_without_notifier", method
|
14
|
+
|
15
|
+
define_method method do |*args|
|
16
|
+
result = send("#{method}_without_notifier", *args)
|
17
|
+
publish("billimatic.#{base_klass.downcase}.#{method}", result, args.flatten)
|
18
|
+
result
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Billimatic
|
2
|
+
module Resources
|
3
|
+
class Subscription < Base
|
4
|
+
crud :create
|
5
|
+
|
6
|
+
def show(token:)
|
7
|
+
http.get("#{resource_base_path}/token/#{token}") do |response|
|
8
|
+
respond_with_entity(response)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def cancel(token:)
|
13
|
+
http.patch("#{resource_base_path}/#{token}/cancel") do |response|
|
14
|
+
respond_with_entity response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "billimatic/exception"
|
2
|
+
|
3
|
+
module Billimatic
|
4
|
+
RequestTimeout = Class.new(Exception)
|
5
|
+
RequestError = Class.new(Exception)
|
6
|
+
|
7
|
+
class Response < SimpleDelegator
|
8
|
+
def resolve!(&block)
|
9
|
+
if success? #TODO: test redirect if need
|
10
|
+
block_given? ? yield(self) : self
|
11
|
+
elsif timed_out?
|
12
|
+
timeout!
|
13
|
+
else
|
14
|
+
error!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def timeout!
|
20
|
+
raise RequestTimeout
|
21
|
+
end
|
22
|
+
|
23
|
+
def error!
|
24
|
+
raise RequestError.new(
|
25
|
+
code: code,
|
26
|
+
message: status_message,
|
27
|
+
body: (MultiJson.load(body) rescue {})
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Billimatic
|
2
|
+
class Signature
|
3
|
+
attr_accessor :secret
|
4
|
+
|
5
|
+
def initialize(secret)
|
6
|
+
@secret = secret
|
7
|
+
end
|
8
|
+
|
9
|
+
def check?(billimatic_request_id, signature_to_check, body)
|
10
|
+
billimatic_signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), secret, "#{billimatic_request_id}#{body}")
|
11
|
+
signature_to_check == billimatic_signature
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,272 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: billimatic-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodrigo Tassinari de Oliveira
|
8
|
+
- Victor Franco
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-05-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: typhoeus
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.0.1
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 1.0.1
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: multi_json
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.11.2
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.11.2
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: virtus
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.0.5
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.5
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: wisper
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.6.1
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.6.1
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: bundler
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.11'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.11'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rake
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '11.1'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '11.1'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: vcr
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '3.0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '3.0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: pry-byebug
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - "~>"
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '3.3'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.3'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rspec
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - "~>"
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '3.4'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - "~>"
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '3.4'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: codeclimate-test-reporter
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0.5'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0.5'
|
154
|
+
- !ruby/object:Gem::Dependency
|
155
|
+
name: simplecov
|
156
|
+
requirement: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - "~>"
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0.11'
|
161
|
+
type: :development
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - "~>"
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0.11'
|
168
|
+
- !ruby/object:Gem::Dependency
|
169
|
+
name: guard-rspec
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - "~>"
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '4.6'
|
175
|
+
type: :development
|
176
|
+
prerelease: false
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - "~>"
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '4.6'
|
182
|
+
- !ruby/object:Gem::Dependency
|
183
|
+
name: test_notifier
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - "~>"
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '2.0'
|
189
|
+
type: :development
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - "~>"
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '2.0'
|
196
|
+
description: This is the official Ruby client for the Billimatic API. See http://www.billimatic.com,br
|
197
|
+
for more information.
|
198
|
+
email:
|
199
|
+
- rodrigo@pittlandia.net
|
200
|
+
- victor.alexandrefs@gmail.com
|
201
|
+
executables: []
|
202
|
+
extensions: []
|
203
|
+
extra_rdoc_files: []
|
204
|
+
files:
|
205
|
+
- ".codeclimate.yml"
|
206
|
+
- ".gitignore"
|
207
|
+
- ".rspec"
|
208
|
+
- ".travis.yml"
|
209
|
+
- Gemfile
|
210
|
+
- Gemfile.lock
|
211
|
+
- Guardfile
|
212
|
+
- LICENSE
|
213
|
+
- README.md
|
214
|
+
- Rakefile
|
215
|
+
- billimatic-client-ruby.gemspec
|
216
|
+
- bin/console
|
217
|
+
- bin/setup
|
218
|
+
- lib/billimatic.rb
|
219
|
+
- lib/billimatic/client.rb
|
220
|
+
- lib/billimatic/configuration.rb
|
221
|
+
- lib/billimatic/entities/address_information.rb
|
222
|
+
- lib/billimatic/entities/base.rb
|
223
|
+
- lib/billimatic/entities/company.rb
|
224
|
+
- lib/billimatic/entities/contract.rb
|
225
|
+
- lib/billimatic/entities/customer.rb
|
226
|
+
- lib/billimatic/entities/entity_service_item.rb
|
227
|
+
- lib/billimatic/entities/invoice.rb
|
228
|
+
- lib/billimatic/entities/invoice_rule.rb
|
229
|
+
- lib/billimatic/entities/plan.rb
|
230
|
+
- lib/billimatic/entities/product.rb
|
231
|
+
- lib/billimatic/entities/subscription.rb
|
232
|
+
- lib/billimatic/entities/webhook.rb
|
233
|
+
- lib/billimatic/exception.rb
|
234
|
+
- lib/billimatic/http.rb
|
235
|
+
- lib/billimatic/request.rb
|
236
|
+
- lib/billimatic/resources/base.rb
|
237
|
+
- lib/billimatic/resources/company.rb
|
238
|
+
- lib/billimatic/resources/contract.rb
|
239
|
+
- lib/billimatic/resources/hooks.rb
|
240
|
+
- lib/billimatic/resources/invoice.rb
|
241
|
+
- lib/billimatic/resources/invoice_rule.rb
|
242
|
+
- lib/billimatic/resources/plan.rb
|
243
|
+
- lib/billimatic/resources/subscription.rb
|
244
|
+
- lib/billimatic/resources/webhook.rb
|
245
|
+
- lib/billimatic/response.rb
|
246
|
+
- lib/billimatic/signature.rb
|
247
|
+
- lib/billimatic/version.rb
|
248
|
+
homepage: https://github.com/myfreecomm/billimatic-client-ruby/
|
249
|
+
licenses: []
|
250
|
+
metadata:
|
251
|
+
allowed_push_host: https://rubygems.org
|
252
|
+
post_install_message:
|
253
|
+
rdoc_options: []
|
254
|
+
require_paths:
|
255
|
+
- lib
|
256
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
257
|
+
requirements:
|
258
|
+
- - ">="
|
259
|
+
- !ruby/object:Gem::Version
|
260
|
+
version: '0'
|
261
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
262
|
+
requirements:
|
263
|
+
- - ">="
|
264
|
+
- !ruby/object:Gem::Version
|
265
|
+
version: '0'
|
266
|
+
requirements: []
|
267
|
+
rubyforge_project:
|
268
|
+
rubygems_version: 2.5.1
|
269
|
+
signing_key:
|
270
|
+
specification_version: 4
|
271
|
+
summary: This is the official Ruby client for the Billimatic API.
|
272
|
+
test_files: []
|