Class: Hitblocks::Item
- Inherits:
-
Object
- Object
- Hitblocks::Item
- Includes:
- HTTParty
- Defined in:
- lib/hitblocks/item.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(params = {}) ⇒ Item
constructor
A new instance of Item.
- #post ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Item
Returns a new instance of Item.
9 10 11 12 |
# File 'lib/hitblocks/item.rb', line 9 def initialize(params = {}) self.class.raise_missing_parameters if params.fetch(:id, nil).nil? @id = params[:id] end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/hitblocks/item.rb', line 6 def id @id end |
Class Method Details
.create(params) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hitblocks/item.rb', line 34 def create(params) self.base_uri Hitblocks.api_base payload = Hash.new payload[:item] = params.reject {|x| x == :hitblock} response = self.post("/hitblocks/#{params[:hitblock].id}/items", body: payload.to_json, headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }, basic_auth: { username: Hitblocks.api_key } ) Hitblocks.construct_from(response) end |
.list ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/hitblocks/item.rb', line 15 def list self.base_uri Hitblocks.api_base response = self.get('/items', basic_auth: { username: Hitblocks.api_key } ) Hitblocks.construct_from(response) end |
.retrieve(id = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/hitblocks/item.rb', line 24 def retrieve(id = nil) self.raise_missing_parameters unless id self.base_uri Hitblocks.api_base response = self.get("/items/#{id}", basic_auth: { username: Hitblocks.api_key } ) Hitblocks.construct_from(response) end |