Class: Cloth::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/cloth/item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, data) ⇒ Item

Returns a new instance of Item.



3
4
5
6
7
# File 'lib/cloth/item.rb', line 3

def initialize(id, data)
  @id = id
  @data = data
  @user = data["user_id"] if @data && data["user_id"]
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/cloth/item.rb', line 9

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/cloth/item.rb', line 10

def id
  @id
end

#userObject (readonly)

Returns the value of attribute user.



11
12
13
# File 'lib/cloth/item.rb', line 11

def user
  @user
end

Class Method Details

.recommend(id, data = nil) ⇒ Object



31
32
33
# File 'lib/cloth/item.rb', line 31

def recommend(id, data = nil)
  Item.new(id, data).recommend
end

.recommendations(id, data = nil) ⇒ Object



39
40
41
# File 'lib/cloth/item.rb', line 39

def recommendations(id, data = nil)
  Item.new(id, data).recommendations
end

.unrecommend(id, data = nil) ⇒ Object



35
36
37
# File 'lib/cloth/item.rb', line 35

def unrecommend(id, data = nil)
  Item.new(id, data).unrecommend
end

Instance Method Details

#recommendObject



13
14
15
# File 'lib/cloth/item.rb', line 13

def recommend
  Cloth.client.post("/api/items/recommend", { body: { item: { id: id, data: data } } })
end

#recommendationsObject



21
22
23
24
25
26
27
28
# File 'lib/cloth/item.rb', line 21

def recommendations
  resp = Cloth.client.get("/api/items/#{id}/recommendations")
  if resp['recommendations']
    resp['recommendations']
  else
    resp
  end
end

#unrecommendObject



17
18
19
# File 'lib/cloth/item.rb', line 17

def unrecommend
  Cloth.client.post("/api/items/unrecommend", { body: { item: { id: id, data: data } } })
end