Class: Postful::Section
Instance Method Summary collapse
- #build_request(builder) ⇒ Object
- #do_upload ⇒ Object
- #filename(filename) ⇒ Object
-
#initialize(name, email, password) ⇒ Section
constructor
A new instance of Section.
- #requires_upload? ⇒ Boolean
- #text(text) ⇒ Object
Constructor Details
#initialize(name, email, password) ⇒ Section
Returns a new instance of Section.
5 6 7 8 9 10 |
# File 'lib/postful/section.rb', line 5 def initialize(name, email, password) @name = name @email = email @password = password @requires_upload = false end |
Instance Method Details
#build_request(builder) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/postful/section.rb', line 37 def build_request(builder) builder.section do builder.name @name builder.text @text if @text builder. @attachment if @attachment end end |
#do_upload ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/postful/section.rb', line 26 def do_upload content = open(@filename, "rb") { |io| io.read } 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>/ @attachment = $1 else raise 'Attachment name not found in response' end end |
#filename(filename) ⇒ Object
16 17 18 19 20 |
# File 'lib/postful/section.rb', line 16 def filename(filename) raise "File '#{filename}' not found" unless File.exist? filename @requires_upload = true @filename = filename end |
#requires_upload? ⇒ Boolean
22 23 24 |
# File 'lib/postful/section.rb', line 22 def requires_upload? @requires_upload end |
#text(text) ⇒ Object
12 13 14 |
# File 'lib/postful/section.rb', line 12 def text(text) @text = text end |