Class: Postful::SimpleDocument

Inherits:
Document
  • Object
show all
Defined in:
lib/postful/simple_document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Document

#do_upload, #initialize

Constructor Details

This class inherits a constructor from Postful::Document

Instance Attribute Details

#attachment_nameObject

Returns the value of attribute attachment_name.



8
9
10
# File 'lib/postful/simple_document.rb', line 8

def attachment_name
  @attachment_name
end

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/postful/simple_document.rb', line 7

def content
  @content
end

#formatObject

Returns the value of attribute format.



6
7
8
# File 'lib/postful/simple_document.rb', line 6

def format
  @format
end

#urlObject

Returns the value of attribute url.



9
10
11
# File 'lib/postful/simple_document.rb', line 9

def url
  @url
end

Instance Method Details

#build_request(builder) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/postful/simple_document.rb', line 11

def build_request(builder)
  builder.document do
    builder.type format
    builder.attachment attachment_name if attachment_name
    builder.url url if url
  end
end

#requires_upload?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/postful/simple_document.rb', line 19

def requires_upload?
  true if !url
end

#uploadObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/postful/simple_document.rb', line 23

def upload
  if requires_upload?
    headers = { 
        'Content-Type' => 'application/octet-stream',
        'Content-Length' => content.size.to_s
    }              
    response = post_request_on_path('/service/upload', content, @email, @password, headers)
    if response.is_a?(Net::HTTPOK) && response.body =~ /<id>(.*)<\/id>/        
      self.attachment_name = $1 
    else
      # raise stuff
    end
  end
end