Class: Epubify::Item

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) {|_self| ... } ⇒ Item

Returns a new instance of Item.

Yields:

  • (_self)

Yield Parameters:

  • _self (Epubify::Item)

    the object that the method was called on



9
10
11
12
13
14
15
16
17
# File 'lib/shelf/item.rb', line 9

def initialize hash = nil, &block
  summary = ""
  description = ""
  language = "no"
  issued = "#{Date.today.to_s}"

  from_hash hash if hash
  yield self if block
end

Instance Attribute Details

#cover_urlObject

Returns the value of attribute cover_url.



7
8
9
# File 'lib/shelf/item.rb', line 7

def cover_url
  @cover_url
end

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/shelf/item.rb', line 7

def description
  @description
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/shelf/item.rb', line 7

def id
  @id
end

#issuedObject

Returns the value of attribute issued.



7
8
9
# File 'lib/shelf/item.rb', line 7

def issued
  @issued
end

#languageObject

Returns the value of attribute language.



7
8
9
# File 'lib/shelf/item.rb', line 7

def language
  @language
end

#periodical_idObject

Returns the value of attribute periodical_id.



7
8
9
# File 'lib/shelf/item.rb', line 7

def periodical_id
  @periodical_id
end

#periodical_tokenObject

Returns the value of attribute periodical_token.



7
8
9
# File 'lib/shelf/item.rb', line 7

def periodical_token
  @periodical_token
end

#summaryObject

Returns the value of attribute summary.



7
8
9
# File 'lib/shelf/item.rb', line 7

def summary
  @summary
end

#thumbnail_urlObject

Returns the value of attribute thumbnail_url.



7
8
9
# File 'lib/shelf/item.rb', line 7

def thumbnail_url
  @thumbnail_url
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/shelf/item.rb', line 7

def title
  @title
end

Class Method Details

.find(id) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/shelf/item.rb', line 19

def self.find id
  res = ShelfApi.item(id)

  item = res["item"]
  Item.new do |i|
    i.from_hash item
  end
end

Instance Method Details

#destroyObject



52
53
54
# File 'lib/shelf/item.rb', line 52

def destroy
  ShelfApi.destroy_item(id) if id
end

#downloadsObject



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

def downloads
  res = ShelfApi.downloads(id)
  d = []
  res["downloads"].each do |hash|
    d << Download.new(hash)
  end
  d
end

#from_hash(h) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/shelf/item.rb', line 28

def from_hash h
  self.id = h["id"]
  self.periodical_id = h["periodical_id"]
  self.title = h["title"]
  self.summary = h["summary"]
  self.description = h["description"]
  self.cover_url = h["cover_url"]
  self.thumbnail_url = h["thumbnail_url"]
  self.language = h["language"]
  self.issued = h["issued"]
end

#saveObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/shelf/item.rb', line 40

def save
  @query = { :item => { :periodical_token => periodical_token, :title => title, :summary => summary, :description => description, :cover_url => cover_url, :thumbnail_url => thumbnail_url, :language => language, :issued => issued } }

  if id
    res = ShelfApi.update_item(id, @query)
  else
    res = ShelfApi.create_item(@query)
    from_hash res["item"]
  end
  res
end

#share(item_id) ⇒ Object



56
57
58
59
# File 'lib/shelf/item.rb', line 56

def share item_id
  @query = { :shelf_item => { :shelf_id => nil, :item_id => item_id } }
  ShelfApi.share_item(@query)
end