Class: Issuu::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/issuu/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Document

Returns a new instance of Document.



5
6
7
8
9
10
11
# File 'lib/issuu/document.rb', line 5

def initialize(hash)
  @attributes = hash
  hash.each do |key, value|
    metaclass.send :attr_accessor, key
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



3
4
5
# File 'lib/issuu/document.rb', line 3

def attributes
  @attributes
end

Class Method Details

.delete(filenames, params = {}) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/issuu/document.rb', line 55

def delete(filenames, params={})        
  Cli.http_post(
    Issuu::API_URL,
    ParameterSet.new("issuu.document.delete", params.merge({:names => filenames.join(',')})).output
  )
  return true
end

.list(params = {}) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/issuu/document.rb', line 47

def list(params={})        
  response = Cli.http_get(
    Issuu::API_URL,
    ParameterSet.new("issuu.documents.list", params).output
  )
  response["rsp"]["_content"]["result"]["_content"].map{|document_hash| Document.new(document_hash["document"]) }
end

.update(filename, params = {}) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/issuu/document.rb', line 39

def update(filename, params={})
  response = Cli.http_post(
    Issuu::API_URL,
    ParameterSet.new("issuu.document.update", params.merge({:name => filename})).output
  )
  Document.new(response["rsp"]["_content"]["document"])
end

.upload(file_path, file_type, params = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/issuu/document.rb', line 28

def upload(file_path, file_type, params={})
  file_to_upload = UploadIO.new(file_path, file_type)
  
  response = Cli.http_multipart_post(
    Issuu::API_UPLOAD_URL,
    file_to_upload,
    ParameterSet.new("issuu.document.upload", params).output
  )
  Document.new(response["rsp"]["_content"]["document"])
end

.url_upload(url, params = {}) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/issuu/document.rb', line 20

def url_upload(url, params={})
  response = Cli.http_post(
    Issuu::API_URL,
    ParameterSet.new("issuu.document.url_upload", params.merge({:slurpUrl => url})).output
  )
  Document.new(response["rsp"]["_content"]["document"])
end

Instance Method Details

#metaclassObject



13
14
15
16
17
# File 'lib/issuu/document.rb', line 13

def metaclass
  class << self
    self
  end
end