Class: Cloudxls::WriteRequest

Inherits:
Object
  • Object
show all
Includes:
BaseRequest
Defined in:
lib/cloudxls.rb

Constant Summary collapse

DATA_PARAMETERS =
%w[data data_url csv csv_url json json_url]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseRequest

#api_base, #api_key, #build_request, #each, #initialize, #path_to, #start, #test_key?, #user_agent

Instance Attribute Details

#client_optionsObject (readonly)

Returns the value of attribute client_options.



285
286
287
# File 'lib/cloudxls.rb', line 285

def client_options
  @client_options
end

#file_formatObject

Returns the value of attribute file_format.



287
288
289
# File 'lib/cloudxls.rb', line 287

def file_format
  @file_format
end

#post_dataObject (readonly)

post_data is an array of key,value arrays. Reason:

  • A key can appear multiple times (for multiple sheets)

  • Parameters need to be in the right order: template - config - data

Example: [[“separator”, “,”], [“csv”, “hello,world”]]



284
285
286
# File 'lib/cloudxls.rb', line 284

def post_data
  @post_data
end

Instance Method Details

#add_data(params = nil) ⇒ Object

Add another configuration block, consisting of sheet configuration and data element.



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/cloudxls.rb', line 296

def add_data(params = nil)
  data_params = []
  params.each do |key, value|
    key = key.to_s
    if DATA_PARAMETERS.include?(key)
      if value.is_a?(File)
        value = UploadIO.new(value, "text/csv", "data")
      end
      data_params << [key, value]
    else
      @post_data << [key, value]
    end
  end
  @post_data += data_params
  self
end

#append_to(target_file) ⇒ Object

Sets request to XLSX



335
336
337
338
339
# File 'lib/cloudxls.rb', line 335

def append_to(target_file)
  io = UploadIO.new(target_file, "application/octet-stream", "target-file")
  @post_data = [["target_file", io]] + @post_data
  self
end

#as_xlsObject

Set request to XLS



317
318
319
320
# File 'lib/cloudxls.rb', line 317

def as_xls
  self.file_format = "xls"
  WriteResponse.new(self)
end

#as_xlsxObject

Set request to XLSX



326
327
328
329
# File 'lib/cloudxls.rb', line 326

def as_xlsx
  self.file_format = "xlsx"
  WriteResponse.new(self)
end