Class: MakePrintable::Client
- Defined in:
- lib/makeprintable/client.rb,
lib/makeprintable/client/jobs.rb,
lib/makeprintable/client/endpoints.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
Instance Method Summary collapse
- #base_uri(path = '/') ⇒ Object
- #configure_payload(path, opts = {}) ⇒ Object
-
#delete_item(id) ⇒ Object
Delete a specific item from server.
- #delete_request(uri) ⇒ Object
-
#find_item(id) ⇒ Object
Return specific item information.
-
#find_repaired(id) ⇒ Object
Returns repair information for a specific repair request, including status, progress and download links.
- #get_request(uri) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#items ⇒ Object
Return a list of previously uploaded models.
- #post_request(path, opts) ⇒ Object
-
#repair(opts = {}) ⇒ Object
Repairs an uploaded item.
-
#repaired ⇒ Object
Return a list of repaired items.
-
#upload(opts = {}) ⇒ Object
Upload a model to fix it later.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/makeprintable/client.rb', line 8 def initialize @api_key = MakePrintable.configuration.api_key end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/makeprintable/client.rb', line 6 def api_key @api_key end |
Instance Method Details
#base_uri(path = '/') ⇒ Object
3 4 5 |
# File 'lib/makeprintable/client/endpoints.rb', line 3 def base_uri(path='/') "https://api.makeprintable.com/v1#{path}" end |
#configure_payload(path, opts = {}) ⇒ Object
7 8 9 |
# File 'lib/makeprintable/client/endpoints.rb', line 7 def configure_payload(path, opts={}) base_uri(path) + opts.to_params end |
#delete_item(id) ⇒ Object
Delete a specific item from server.
15 16 17 |
# File 'lib/makeprintable/client/jobs.rb', line 15 def delete_item(id) delete_request configure_payload("/items/#{id}") end |
#delete_request(uri) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/makeprintable/client/endpoints.rb', line 27 def delete_request(uri) begin Crack::XML.parse RestClient::Request.execute(method: :delete, url: uri, headers: {key: self.api_key}) rescue => e Crack::XML.parse e.response end end |
#find_item(id) ⇒ Object
Return specific item information
10 11 12 |
# File 'lib/makeprintable/client/jobs.rb', line 10 def find_item(id) get_request configure_payload("/items/#{id}") end |
#find_repaired(id) ⇒ Object
Returns repair information for a specific repair request, including status, progress and download links.
31 32 33 |
# File 'lib/makeprintable/client/jobs.rb', line 31 def find_repaired(id) get_request configure_payload("/fixes/#{id}") end |
#get_request(uri) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/makeprintable/client/endpoints.rb', line 11 def get_request(uri) begin Crack::XML.parse RestClient::Request.execute(method: :get, url: uri, headers: {key: self.api_key}) rescue => e Crack::XML.parse e.response end end |
#items ⇒ Object
Return a list of previously uploaded models
20 21 22 |
# File 'lib/makeprintable/client/jobs.rb', line 20 def items get_request configure_payload('/items') end |
#post_request(path, opts) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/makeprintable/client/endpoints.rb', line 19 def post_request(path, opts) begin Crack::XML.parse RestClient.post(base_uri(path), opts, key: self.api_key) rescue => e Crack::XML.parse e.response end end |
#repair(opts = {}) ⇒ Object
Repairs an uploaded item
25 26 27 28 |
# File 'lib/makeprintable/client/jobs.rb', line 25 def repair(opts={}) opts.assert_valid_keys(:item_id, :callback_url, :name, :wall_thickness, :print_quality, :pre_optimize, :post_optimize, :secure) post_request '/fixes', opts end |
#repaired ⇒ Object
Return a list of repaired items
36 37 38 |
# File 'lib/makeprintable/client/jobs.rb', line 36 def repaired get_request configure_payload('/fixes') end |
#upload(opts = {}) ⇒ Object
Upload a model to fix it later
4 5 6 7 |
# File 'lib/makeprintable/client/jobs.rb', line 4 def upload(opts={}) opts.assert_valid_keys(:file, :fileurl) post_request '/items', opts end |