lib/rmega/session.rb in rmega-0.0.2 vs lib/rmega/session.rb in rmega-0.0.3
- old
+ new
@@ -55,24 +55,19 @@
def random_request_id
rand(1E7..1E9).to_i
end
- def error_response? response
- response = response.first if response.respond_to? :first
- !!Integer(response) rescue false
- end
-
def request body
self.request_id += 1
url = "#{api_url}?id=#{request_id}"
url << "&sid=#{sid}" if sid
debug "POST #{url}"
debug "#{body.inspect}"
response = HTTPClient.new.post url, [body].to_json, timeout: api_request_timeout
debug "#{response.code}\n#{response.body}"
resp = JSON.parse(response.body).first
- raise "Error code received: #{resp}" if error_response?(resp)
+ raise ApiRequestError.new(resp) if ApiRequestError.is_error_code?(resp)
resp
end
end
end