Class: Hitblocks::Item

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/hitblocks/item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#idObject

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

.listObject



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

Instance Method Details

#deleteObject



51
52
53
54
55
56
57
58
# File 'lib/hitblocks/item.rb', line 51

def delete
  self.class.base_uri Hitblocks.api_base
  response = self.class.delete("/items/#{self.id}",
                       basic_auth: { username: Hitblocks.api_key }
                      )

  return response
end

#postObject



60
61
62
63
64
65
66
67
# File 'lib/hitblocks/item.rb', line 60

def post
  self.class.base_uri Hitblocks.api_base
  response = self.class.post("/items/#{self.id}/post",
                             basic_auth: { username: Hitblocks.api_key }
                            )

  Hitblocks.construct_from(response)
end