Class: CrateAPI::Crates
- Inherits:
-
Object
- Object
- CrateAPI::Crates
- Defined in:
- lib/crate_api/crates.rb
Overview
Crates class which is used to add, list, manipulate the Crates on a given account.
Constant Summary collapse
- CRATE_ACTIONS =
Hash of available actions to take upon the Crates endpoint.
{ :add => "add.json", :list => "list.json", :rename => "rename/%s.json", :destroy => "destroy/%s.json" }
Class Method Summary collapse
-
.from_array(array) ⇒ Array
Class method to return an array of crate objects.
Instance Method Summary collapse
-
#add(name) ⇒ nil
Add a new crate.
-
#all ⇒ Array
Get a list of crates (w/ files).
-
#list ⇒ Array
Get a list of crates (w/o files).
Class Method Details
Instance Method Details
#add(name) ⇒ nil
Add a new crate.
20 21 22 23 |
# File 'lib/crate_api/crates.rb', line 20 def add(name) response = JSON.parse(CrateAPI::Base.call("#{CrateAPI::Base::CRATES_URL}/#{CRATE_ACTIONS[:add]}", :post, {:body => {:name => name}})) raise CrateLimitReachedError, response["message"] unless response["status"] != "failure" end |
#all ⇒ Array
Get a list of crates (w/ files).
38 39 40 41 |
# File 'lib/crate_api/crates.rb', line 38 def all hash = JSON.parse(CrateAPI::Base.call("#{CrateAPI::Base::ITEMS_URL}/#{CRATE_ACTIONS[:list]}", :get)) return Crates.from_array(hash["crates"]) end |
#list ⇒ Array
Note:
This will not return crate objects with the files they contain.
Get a list of crates (w/o files).
30 31 32 33 |
# File 'lib/crate_api/crates.rb', line 30 def list hash = JSON.parse(CrateAPI::Base.call("#{CrateAPI::Base::CRATES_URL}/#{CRATE_ACTIONS[:list]}", :get)) return Crates.from_array(hash["crates"]) end |