Class: Epubify::Download

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h = nil) {|_self| ... } ⇒ Download

Returns a new instance of Download.

Yields:

  • (_self)

Yield Parameters:



8
9
10
11
12
13
# File 'lib/shelf/download.rb', line 8

def initialize h = nil, &block
  content_type = "application/epub+zip"

  from_hash h if h
  yield self if block
end

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



6
7
8
# File 'lib/shelf/download.rb', line 6

def content_type
  @content_type
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/shelf/download.rb', line 6

def id
  @id
end

#item_idObject

Returns the value of attribute item_id.



6
7
8
# File 'lib/shelf/download.rb', line 6

def item_id
  @item_id
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/shelf/download.rb', line 6

def url
  @url
end

Class Method Details

.find(id) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/shelf/download.rb', line 35

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

  download = res["download"]
  Download.new do |d|
    d.from_hash download
  end
end

Instance Method Details

#destroyObject



45
46
47
# File 'lib/shelf/download.rb', line 45

def destroy
  ShelfApi.destroy_download(id) if id
end

#from_hash(h) ⇒ Object



16
17
18
19
20
21
# File 'lib/shelf/download.rb', line 16

def from_hash h
  self.id = h["id"]
  self.item_id = h["item_id"]
  self.content_type = h["content_type"]
  self.url = h["url"]
end

#itemObject



30
31
32
# File 'lib/shelf/download.rb', line 30

def item
  @item
end

#item=(v) ⇒ Object



24
25
26
27
# File 'lib/shelf/download.rb', line 24

def item= v
  @item = v
  item_id = v.id
end

#saveObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/shelf/download.rb', line 50

def save
  @query = { :download => { :item_id => item_id, :content_type => content_type, :url => url } }

  if id
    res = ShelfApi.update_download(id, @query)
  else
    res = ShelfApi.create_download(@query)
    from_hash res["download"]
  end

  res
end