class CrateAPI::Crates
Crates
class which is used to add, list, manipulate the Crates
on a given account.
Constants
- CRATE_ACTIONS
Hash of available actions to take upon the
Crates
endpoint.
Public Class Methods
from_array(array)
click to toggle source
Class method to return an array of crate objects.
@return [Array] an array of initialized Crate
objects.
# File lib/crate_api/crates.rb, line 46 def self.from_array(array) return [] unless array != nil crates = Array.new array.each do |crate| crates.push(Crate.new(crate)) end return crates end
Public Instance Methods
add(name)
click to toggle source
Add a new crate.
@param [String] name of the crate to add. @return [nil] no output from this method is expected if everything goes right.
# 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()
click to toggle source
Get a list of crates (w/ files).
@return [Array] an array of crate objects.
# 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()
click to toggle source
Get a list of crates (w/o files).
@return [Array] an array of crate objects. @note This will not return crate objects with the files they contain. @see Crates#all
# 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