asaas-ruby 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/asaas-ruby-0.1.3.gem +0 -0
- data/bin/console +1 -1
- data/lib/asaas/api/base.rb +61 -13
- data/lib/asaas/entity.rb +2 -0
- data/lib/asaas/entity/error.rb +10 -0
- data/lib/asaas/entity/error_item.rb +9 -0
- data/lib/asaas/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 068d38ad9f1570c2e0dc3b0fd943ffd1f2dfd46c
|
4
|
+
data.tar.gz: b070ebb21e0ad32a6a0ad8a83a69e84b4a765081
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fc41b5bfb8e46307b3e16bb7e2ee9bd3f66782552ea517f1fee77d6bbe12a31f402d06337b09db2012902589a2dc2729b6687cfcb1656c9d2c74ecbc2544edf
|
7
|
+
data.tar.gz: 07429a1f31d312df774126675226ebf079f2e9ebeb6b351d716e855bfe0b703c6f79c82d88fec40c4b5b27ebb64891471a4be0fada35be54cc4af3a806454044
|
Binary file
|
data/bin/console
CHANGED
data/lib/asaas/api/base.rb
CHANGED
@@ -54,19 +54,20 @@ module Asaas
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def parse_response
|
57
|
-
ap
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
57
|
+
ap @response
|
58
|
+
res = case @response.response_code
|
59
|
+
when 200
|
60
|
+
response_success
|
61
|
+
when 400
|
62
|
+
response_bad_request
|
63
|
+
when 401
|
64
|
+
response_unauthorized
|
65
|
+
when 404
|
66
|
+
response_not_found
|
67
|
+
when 500
|
68
|
+
response_internal_server_error
|
69
69
|
end
|
70
|
+
res
|
70
71
|
end
|
71
72
|
|
72
73
|
def convert_data_to_entity(type)
|
@@ -74,15 +75,62 @@ module Asaas
|
|
74
75
|
end
|
75
76
|
|
76
77
|
def request(method, params = {}, body = nil)
|
78
|
+
body = body && body.try(:attributes)
|
77
79
|
@response = Typhoeus::Request.new(
|
78
80
|
parse_url(params.fetch(:id, false)),
|
79
81
|
method: method,
|
80
|
-
body: body
|
82
|
+
body: body,
|
81
83
|
params: params,
|
82
84
|
headers: { 'access_token': @token || Asaas::Configuration.token }
|
83
85
|
).run
|
84
86
|
end
|
85
87
|
|
88
|
+
def response_success
|
89
|
+
hash = JSON.parse(@response.body)
|
90
|
+
if hash.fetch("object", false) === "list"
|
91
|
+
entity = Asaas::Entity::Meta.new(hash)
|
92
|
+
else
|
93
|
+
entity = convert_data_to_entity(hash.fetch("object", false))
|
94
|
+
entity.new(hash) if entity
|
95
|
+
end
|
96
|
+
entity
|
97
|
+
end
|
98
|
+
|
99
|
+
def response_unauthorized
|
100
|
+
error = Asaas::Entity::Error.new
|
101
|
+
error.errors << Asaas::Entity::ErrorItem.new(code: 'invalid_token', description: 'The api_key is invalid')
|
102
|
+
error
|
103
|
+
end
|
104
|
+
|
105
|
+
def response_internal_server_error
|
106
|
+
error = Asaas::Entity::Error.new
|
107
|
+
error.errors << Asaas::Entity::ErrorItem.new(code: 'internal_server_error', description: 'Internal Server Error')
|
108
|
+
error
|
109
|
+
end
|
110
|
+
|
111
|
+
def response_not_found
|
112
|
+
error = Asaas::Entity::Error.new
|
113
|
+
error.errors << Asaas::Entity::ErrorItem.new(code: 'not_found', description: 'Object not found')
|
114
|
+
error
|
115
|
+
end
|
116
|
+
|
117
|
+
def response_bad_request
|
118
|
+
error = Asaas::Entity::Error.new
|
119
|
+
begin
|
120
|
+
hash = JSON.parse(@response.body)
|
121
|
+
errors = hash.fetch("errors", [])
|
122
|
+
errors.each do |item|
|
123
|
+
error.errors << Asaas::Entity::ErrorItem.new(item)
|
124
|
+
end
|
125
|
+
error
|
126
|
+
rescue
|
127
|
+
error = Asaas::Entity::Error.new
|
128
|
+
error.errors << Asaas::Entity::ErrorItem.new(code: 'bad_request', description: 'Bad Request')
|
129
|
+
error
|
130
|
+
end
|
131
|
+
error
|
132
|
+
end
|
133
|
+
|
86
134
|
def get_headers
|
87
135
|
{ 'access_token': @token || Asaas::Configuration.token }
|
88
136
|
end
|
data/lib/asaas/entity.rb
CHANGED
@@ -5,6 +5,8 @@ module Asaas
|
|
5
5
|
autoload :BankAccount, 'asaas/entity/bank_account'
|
6
6
|
autoload :City, 'asaas/entity/city'
|
7
7
|
autoload :Customer, 'asaas/entity/customer'
|
8
|
+
autoload :Error, 'asaas/entity/error'
|
9
|
+
autoload :ErrorItem, 'asaas/entity/error_item'
|
8
10
|
autoload :Installment, 'asaas/entity/installment'
|
9
11
|
autoload :Meta, 'asaas/entity/meta'
|
10
12
|
autoload :Notification, 'asaas/entity/notification'
|
data/lib/asaas/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asaas-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Junior
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- asaas-ruby-0.1.0.gem
|
161
161
|
- asaas-ruby-0.1.1.gem
|
162
162
|
- asaas-ruby-0.1.2.gem
|
163
|
+
- asaas-ruby-0.1.3.gem
|
163
164
|
- asaas-ruby.gemspec
|
164
165
|
- bin/console
|
165
166
|
- bin/setup
|
@@ -180,6 +181,8 @@ files:
|
|
180
181
|
- lib/asaas/entity/base.rb
|
181
182
|
- lib/asaas/entity/city.rb
|
182
183
|
- lib/asaas/entity/customer.rb
|
184
|
+
- lib/asaas/entity/error.rb
|
185
|
+
- lib/asaas/entity/error_item.rb
|
183
186
|
- lib/asaas/entity/installment.rb
|
184
187
|
- lib/asaas/entity/meta.rb
|
185
188
|
- lib/asaas/entity/notification.rb
|