Class: GunBroker::API
- Inherits:
-
Object
- Object
- GunBroker::API
- Defined in:
- lib/gun_broker/api.rb
Overview
Generic REST adapter for the GunBroker API.
Constant Summary collapse
- ROOT_URL =
Root URL of the GunBroker API.
'https://api.gunbroker.com/v1'
- ROOT_URL_SANDBOX =
Root URL of the GunBroker sandbox API.
'https://api.sandbox.gunbroker.com/v1'
- PAGE_SIZE =
Used to return the maximum number of results from paginated responses.
300
- MAX_ITEMS_TIME_FRAME =
1
- MAX_ORDERS_TIME_FRAME =
7
- USER_AGENT =
"gun_broker rubygems.org/gems/gun_broker v(#{GunBroker::VERSION})"
Class Method Summary collapse
-
.delete(*args) ⇒ Object
Wrapper for
new(*args).delete!
. -
.get(*args) ⇒ Object
Wrapper for
new(*args).get!
. -
.multipart_post(*args) ⇒ Object
Wrapper for
new(*args).multipart_post!
. -
.post(*args) ⇒ Object
Wrapper for
new(*args).post!
. -
.put(*args) ⇒ Object
Wrapper for
new(*args).put!
.
Instance Method Summary collapse
-
#delete! ⇒ Object
Sends a DELETE request to the given
path
. -
#get! ⇒ Object
Sends a GET request to the given
path
. -
#initialize(path, params = {}, headers = {}) ⇒ API
constructor
A new instance of API.
-
#multipart_post! ⇒ Object
Sends a multipart form POST to the given
path
. -
#post! ⇒ Object
Sends a POST request to the given
path
. -
#put! ⇒ Object
Sends a PUT request to the given
path
.
Constructor Details
#initialize(path, params = {}, headers = {}) ⇒ API
Returns a new instance of API.
26 27 28 29 30 31 32 33 34 |
# File 'lib/gun_broker/api.rb', line 26 def initialize(path, params = {}, headers = {}) raise GunBroker::Error.new("Path must start with '/': #{path}") unless path.start_with?('/') @base_api_url = GunBroker.sandbox ? ROOT_URL_SANDBOX : ROOT_URL @path = path @params = params @headers = headers end |
Class Method Details
.delete(*args) ⇒ Object
Wrapper for new(*args).delete!
38 39 40 |
# File 'lib/gun_broker/api.rb', line 38 def self.delete(*args) new(*args).delete! end |
.get(*args) ⇒ Object
Wrapper for new(*args).get!
44 45 46 |
# File 'lib/gun_broker/api.rb', line 44 def self.get(*args) new(*args).get! end |
.multipart_post(*args) ⇒ Object
Wrapper for new(*args).multipart_post!
56 57 58 |
# File 'lib/gun_broker/api.rb', line 56 def self.multipart_post(*args) new(*args).multipart_post! end |
.post(*args) ⇒ Object
Wrapper for new(*args).post!
50 51 52 |
# File 'lib/gun_broker/api.rb', line 50 def self.post(*args) new(*args).post! end |
.put(*args) ⇒ Object
Wrapper for new(*args).put!
62 63 64 |
# File 'lib/gun_broker/api.rb', line 62 def self.put(*args) new(*args).put! end |
Instance Method Details
#delete! ⇒ Object
Sends a DELETE request to the given path
.
67 68 69 70 71 |
# File 'lib/gun_broker/api.rb', line 67 def delete! request = Net::HTTP::Delete.new(uri) response = get_response(request) GunBroker::Response.new(response) end |
#get! ⇒ Object
Sends a GET request to the given path
.
74 75 76 77 78 79 80 |
# File 'lib/gun_broker/api.rb', line 74 def get! uri.query = URI.encode_www_form(@params) request = Net::HTTP::Get.new(uri) response = get_response(request) GunBroker::Response.new(response) end |
#multipart_post! ⇒ Object
Sends a multipart form POST to the given path
.
92 93 94 95 96 97 98 |
# File 'lib/gun_broker/api.rb', line 92 def multipart_post! request = Net::HTTP::Post.new(uri) request.body = build_request_body response = get_response(request) GunBroker::Response.new(response) end |