Class: Cloudxls::ReadRequest
- Inherits:
- 
      Object
      
        - Object
- Cloudxls::ReadRequest
 
- Includes:
- BaseRequest
- Defined in:
- lib/cloudxls.rb
Constant Summary collapse
- DATA_PARAMETERS =
- %w[excel file] 
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) ⇒ Object
- 
  
    
      #as_csv  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Set request to CSV. 
- 
  
    
      #as_json  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Set request to JSON. 
- 
  
    
      #response_body  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Response as string. 
- 
  
    
      #to_h  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Response as Hash (used with json). 
Methods included from BaseRequest
#api_base, #api_key, #data, #each, #initialize, #path_to, #save_as, #start, #test_key?, #write_to
Instance Attribute Details
#client_options ⇒ Object (readonly)
Returns the value of attribute client_options.
| 160 161 162 | # File 'lib/cloudxls.rb', line 160 def @client_options end | 
#file_format ⇒ Object
Returns the value of attribute file_format.
| 161 162 163 | # File 'lib/cloudxls.rb', line 161 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”]]
| 159 160 161 | # File 'lib/cloudxls.rb', line 159 def post_data @post_data end | 
Instance Method Details
#add_data(params) ⇒ Object
| 165 166 167 168 169 170 171 172 173 174 | # File 'lib/cloudxls.rb', line 165 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_csv ⇒ Object
Set request to CSV
| 202 203 204 205 | # File 'lib/cloudxls.rb', line 202 def as_csv self.file_format = "csv" self end | 
#as_json ⇒ Object
Set request to JSON
| 193 194 195 196 | # File 'lib/cloudxls.rb', line 193 def as_json self.file_format = "json" self end | 
#response_body ⇒ String
Response as string
| 180 181 182 183 184 185 186 187 | # File 'lib/cloudxls.rb', line 180 def response_body # TODO: optimize str = "" each do |chunk| str << chunk end str end | 
#to_h ⇒ String
Response as Hash (used with json)
| 211 212 213 | # File 'lib/cloudxls.rb', line 211 def to_h JSON.load(response_body) end |