9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/smspilot/request.rb', line 9
def send_request(body)
json_body = request_json body
begin
response = connection.post do |req|
req.body = json_body
logger.info("--------\n" + req.body)
end
response_error = (response.status == 200) ? Smspilot::Error::WrongStatusError : nil
rescue Exception => e
if e.kind_of? Faraday::Error::TimeoutError
response_error = Smspilot::Error::TimeoutError
elsif e.kind_of? Faraday::Error::ParsingError
response_error = Smspilot::Error::ParsingError
end
end
unless response.body["error"].nil?
response_error = Error::ApiError.get_by_code(response.body["error"]["code"]).new()
end
response.instance_eval <<-RESP
def error; #{response_error} end
RESP
response
end
|