Class: Postful::Postcard::Section

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/postful/postcard.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(email, password, name, content, kind) ⇒ Section

Returns a new instance of Section.



131
132
133
134
135
136
137
# File 'lib/postful/postcard.rb', line 131

def initialize(email, password, name, content, kind)
  @email = email
  @password = password
  @name = name
  @content = content
  @kind = kind
end

Instance Method Details

#build_request(builder) ⇒ Object



139
140
141
142
143
144
145
146
147
148
# File 'lib/postful/postcard.rb', line 139

def build_request(builder)
  builder.section do           
    builder.name @name
    if @kind == :image
      builder.attachment @attachment_name
    elsif @kind == :text
      builder.text @content
    end
  end
end

#uploadObject



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/postful/postcard.rb', line 150

def upload
  return if @kind == :text
  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_name = $1 
  else
    # raise stuff
  end
end