Class: Cloudxls::ReadRequest

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

Constant Summary collapse

DATA_PARAMETERS =
%w[excel file]

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.



228
229
230
# File 'lib/cloudxls.rb', line 228

def client_options
  @client_options
end

#file_formatObject

Returns the value of attribute file_format.



229
230
231
# File 'lib/cloudxls.rb', line 229

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”]]



227
228
229
# File 'lib/cloudxls.rb', line 227

def post_data
  @post_data
end

Instance Method Details

#add_data(params) ⇒ Object



233
234
235
236
237
238
239
240
241
242
# File 'lib/cloudxls.rb', line 233

def add_data(params)
  params.map do |key,value|
    key = key.to_s
    if DATA_PARAMETERS.include?(key)
      value = UploadIO.new(value, "text/csv", "data.csv")
    end
    @post_data << [key, value]
  end
  self
end

#as_csvObject

Set request to CSV



257
258
259
260
# File 'lib/cloudxls.rb', line 257

def as_csv
  self.file_format = "csv"
  ReadResponse.new(self)
end

#as_jsonObject

Set request to JSON



248
249
250
251
# File 'lib/cloudxls.rb', line 248

def as_json
  self.file_format = "json"
  ReadResponse.new(self)
end