Class: Zoop::Request
Constant Summary collapse
- DEFAULT_HEADERS =
{ 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'User-Agent' => "zoop-ruby/#{Zoop::VERSION}" }
Instance Attribute Summary collapse
-
#full_api_url ⇒ Object
Returns the value of attribute full_api_url.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#path ⇒ Object
Returns the value of attribute path.
-
#query ⇒ Object
Returns the value of attribute query.
Class Method Summary collapse
- .delete(url, options = {}) ⇒ Object
- .get(url, options = {}) ⇒ Object
- .post(url, options = {}) ⇒ Object
- .put(url, options = {}) ⇒ Object
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(path, method, options = {}) ⇒ Request
constructor
A new instance of Request.
- #run ⇒ Object
Constructor Details
#initialize(path, method, options = {}) ⇒ Request
Returns a new instance of Request.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/zoop/request.rb', line 15 def initialize(path, method, ={}) raise Zoop::RequestError, 'You need to configure a Zoop.marketplace_id (ZOOP_MARKETPLACE_ID), Zoop.user_auth (ZOOP_USER_AUTH), Zoop.password_auth (ZOOP_PASSWORD_AUTH) before performing requests.' unless Zoop.marketplace_id && Zoop.user_auth && Zoop.password_auth @path = path @method = method @full_api_url = [:full_api_url] @query = [:query] || Hash.new @parameters = [:params] || Hash.new @headers = [:headers] || Hash.new end |
Instance Attribute Details
#full_api_url ⇒ Object
Returns the value of attribute full_api_url.
7 8 9 |
# File 'lib/zoop/request.rb', line 7 def full_api_url @full_api_url end |
#headers ⇒ Object
Returns the value of attribute headers.
7 8 9 |
# File 'lib/zoop/request.rb', line 7 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
7 8 9 |
# File 'lib/zoop/request.rb', line 7 def method @method end |
#parameters ⇒ Object
Returns the value of attribute parameters.
7 8 9 |
# File 'lib/zoop/request.rb', line 7 def parameters @parameters end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/zoop/request.rb', line 7 def path @path end |
#query ⇒ Object
Returns the value of attribute query.
7 8 9 |
# File 'lib/zoop/request.rb', line 7 def query @query end |
Class Method Details
.delete(url, options = {}) ⇒ Object
65 66 67 |
# File 'lib/zoop/request.rb', line 65 def self.delete(url, ={}) self.new url, 'DELETE', end |
.get(url, options = {}) ⇒ Object
53 54 55 |
# File 'lib/zoop/request.rb', line 53 def self.get(url, ={}) self.new url, 'GET', end |
.post(url, options = {}) ⇒ Object
57 58 59 |
# File 'lib/zoop/request.rb', line 57 def self.post(url, ={}) self.new url, 'POST', end |
.put(url, options = {}) ⇒ Object
61 62 63 |
# File 'lib/zoop/request.rb', line 61 def self.put(url, ={}) self.new url, 'PUT', end |
Instance Method Details
#call ⇒ Object
49 50 51 |
# File 'lib/zoop/request.rb', line 49 def call ZoopObject.convert run end |
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zoop/request.rb', line 26 def run response = RestClient::Request.execute request_params MultiJson.decode response.body rescue RestClient::Exception => error begin parsed_error = MultiJson.decode error.http_body if error.is_a? RestClient::ResourceNotFound raise Zoop::NotFound.new(parsed_error, request_params, error) else raise Zoop::ResponseError.new(request_params, parsed_error) end rescue MultiJson::ParseError raise Zoop::ResponseError.new(request_params, error.http_body) end rescue MultiJson::ParseError raise Zoop::ResponseError.new(request_params, response.body) rescue SocketError raise Zoop::ConnectionError.new $! rescue RestClient::ServerBrokeConnection raise Zoop::ConnectionError.new $! end |