Method: Azure::Table::Batch#to_body

Defined in:
lib/azure/table/batch.rb

#to_bodyObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/azure/table/batch.rb', line 158

def to_body
  body = ""
  body.define_singleton_method(:add_line) do |a| self << (a||nil) + "\n" end

  body.add_line "--#{batch_id}"
  body.add_line "Content-Type: multipart/mixed; boundary=#{changeset_id}"
  body.add_line ""

  content_id = 1
  operations.each { |op|
    body.add_line "--#{changeset_id}"
    body.add_line "Content-Type: application/http"
    body.add_line "Content-Transfer-Encoding: binary"
    body.add_line ""
    body.add_line "#{op[:method].to_s.upcase} #{op[:uri]} HTTP/1.1"
    body.add_line "Content-ID: #{content_id}"

    if op[:headers]
      op[:headers].each { |k,v|
          body.add_line "#{k}: #{v}"
        }
    end

    if op[:body]
      body.add_line "Content-Type: application/atom+xml;type=entry"
      body.add_line "Content-Length: #{op[:body].bytesize.to_s}"
      body.add_line ""
      body.add_line op[:body]
    else
      body.add_line ""
    end

    content_id += 1
  }
  body.add_line "--#{changeset_id}--"
  body.add_line "--#{batch_id}--"
end