Class: Rest::Wrappers::ExconWrapper
Instance Method Summary
collapse
Methods inherited from BaseWrapper
#close, #post_file, #to_json_parts
Constructor Details
Returns a new instance of ExconWrapper.
34
35
36
37
38
|
# File 'lib/rest/wrappers/excon_wrapper.rb', line 34
def initialize(client)
@client = client
end
|
Instance Method Details
40
41
42
|
# File 'lib/rest/wrappers/excon_wrapper.rb', line 40
def
{}
end
|
#delete(url, req_hash = {}) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/rest/wrappers/excon_wrapper.rb', line 108
def delete(url, req_hash={})
response = nil
begin
req_hash[:method] = :delete
req_hash[:url] = url
response = excon_request(url, req_hash)
rescue Rest::RestClient::Exception => ex
raise RestClientExceptionWrapper.new(ex)
end
response
end
|
#excon_request(url, req_hash) ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/rest/wrappers/excon_wrapper.rb', line 61
def excon_request(url, req_hash)
conn = Excon.new(url)
r2 = conn.request(req_hash)
response = ExconResponseWrapper.new(r2)
if response.code >= 400
raise HttpError.new(response, response.code)
end
response
end
|
#get(url, req_hash = {}) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/rest/wrappers/excon_wrapper.rb', line 44
def get(url, req_hash={})
response = nil
begin
uri = URI(url)
req_hash[:method] = :get
req_hash[:url] = url
req_hash[:headers] ||=
req_hash[:query] = req_hash[:params] if req_hash[:params]
response = excon_request(url, req_hash)
rescue Rest::RestClient::Exception => ex
raise ExconExceptionWrapper.new(ex)
end
response
end
|
#patch(url, req_hash = {}) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/rest/wrappers/excon_wrapper.rb', line 96
def patch(url, req_hash={})
response = nil
begin
req_hash[:method] = :patch
req_hash[:url] = url
response = excon_request(url, req_hash)
rescue RestClient::Exception => ex
raise RestClientExceptionWrapper.new(ex)
end
response
end
|
#post(url, req_hash = {}) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/rest/wrappers/excon_wrapper.rb', line 71
def post(url, req_hash={})
response = nil
begin
req_hash[:method] = :post
req_hash[:url] = url
to_json_parts(req_hash)
response = excon_request(url, req_hash)
rescue Rest::RestClient::Exception => ex
raise HttpError.new(ex.response, ex.http_code)
end
response
end
|
#put(url, req_hash = {}) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/rest/wrappers/excon_wrapper.rb', line 84
def put(url, req_hash={})
response = nil
begin
req_hash[:method] = :put
req_hash[:url] = url
response = excon_request(url, req_hash)
rescue Rest::RestClient::Exception => ex
raise RestClientExceptionWrapper.new(ex)
end
response
end
|