Class: Cloudxls::WriteRequest
- Inherits:
-
Object
- Object
- Cloudxls::WriteRequest
- 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
-
#client_options ⇒ Object
readonly
Returns the value of attribute client_options.
-
#file_format ⇒ Object
Returns the value of attribute file_format.
-
#post_data ⇒ Object
readonly
post_data is an array of key,value arrays.
Instance Method Summary collapse
-
#add_data(params = nil) ⇒ Object
Add another configuration block, consisting of sheet configuration and data element.
-
#append_to(target_file) ⇒ Object
Sets request to XLSX.
-
#as_xls ⇒ Object
Set request to XLS.
-
#as_xlsx ⇒ Object
Set request to XLSX.
Methods included from BaseRequest
#api_base, #api_key, #build_request, #each, #initialize, #path_to, #start, #test_key?, #user_agent
Instance Attribute Details
#client_options ⇒ Object (readonly)
Returns the value of attribute client_options.
285 286 287 |
# File 'lib/cloudxls.rb', line 285 def @client_options end |
#file_format ⇒ Object
Returns the value of attribute file_format.
287 288 289 |
# File 'lib/cloudxls.rb', line 287 def file_format @file_format end |
#post_data ⇒ Object (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_xls ⇒ Object
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_xlsx ⇒ Object
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 |