Module: CloudXLS
- Defined in:
- lib/cloudxls.rb,
 lib/cloudxls/version.rb,
 lib/cloudxls/csv_writer.rb,
 lib/cloudxls/csv_writer.rb
Defined Under Namespace
Classes: CSV, CSVWriter, Util, XpipeResponse
Constant Summary collapse
- VERSION =
- '0.6.2'
- DATETIME_FORMAT =
- "%FT%T.%L%z".freeze 
- DATE_FORMAT =
- "%F".freeze 
Class Attribute Summary collapse
- 
  
    
      .api_base  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute api_base. 
- 
  
    
      .api_key  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute api_key. 
- 
  
    
      .api_version  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute api_version. 
- 
  
    
      .https  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute https. 
- 
  
    
      .verify_ssl_certs  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute verify_ssl_certs. 
Class Method Summary collapse
- .api_url(path = '') ⇒ Object
- 
  
    
      .convert(params = {})  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    CloudXLS.xpipe :data => File.new(‘/path/to/data.csv’, ‘r’) CloudXLS.xpipe :data => File.new(“foo,barnlorem,ipsum”) CloudXLS.xpipe :data_url => “example.com/data.csv” CloudXLS.xpipe :data_url => “username:[email protected]/data.csv”. 
- .execute_request ⇒ Object
- .general_api_error(rcode, rbody) ⇒ Object
- .parse_response(response) ⇒ Object
- .xpipe(params = {}) ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.api_base ⇒ Object
Returns the value of attribute api_base.
| 21 22 23 | # File 'lib/cloudxls.rb', line 21 def api_base @api_base end | 
.api_key ⇒ Object
Returns the value of attribute api_key.
| 21 22 23 | # File 'lib/cloudxls.rb', line 21 def api_key @api_key end | 
.api_version ⇒ Object
Returns the value of attribute api_version.
| 21 22 23 | # File 'lib/cloudxls.rb', line 21 def api_version @api_version end | 
.https ⇒ Object
Returns the value of attribute https.
| 21 22 23 | # File 'lib/cloudxls.rb', line 21 def https @https end | 
.verify_ssl_certs ⇒ Object
Returns the value of attribute verify_ssl_certs.
| 21 22 23 | # File 'lib/cloudxls.rb', line 21 def verify_ssl_certs @verify_ssl_certs end | 
Class Method Details
.api_url(path = '') ⇒ Object
| 24 25 26 27 | # File 'lib/cloudxls.rb', line 24 def self.api_url(path = '') # @api_base + url "http#{@https ? 's' : ''}://#{@api_key}:@#{@api_base}/v1/#{path}" end | 
.convert(params = {}) ⇒ Object
CloudXLS.xpipe :data => File.new(‘/path/to/data.csv’, ‘r’) CloudXLS.xpipe :data => File.new(“foo,barnlorem,ipsum”) CloudXLS.xpipe :data_url => “example.com/data.csv” CloudXLS.xpipe :data_url => “username:[email protected]/data.csv”
| 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # File 'lib/cloudxls.rb', line 45 def self.convert(params = {}) check_api_key! headers = {} response = execute_request do RestClient.post(api_url("xpipe"), params, headers) end if params[:mode].to_s == 'inline' response else XpipeResponse.new(response) end end | 
.execute_request ⇒ Object
| 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | # File 'lib/cloudxls.rb', line 69 def self.execute_request begin return yield rescue SocketError => e handle_restclient_error(e) rescue NoMethodError => e # Work around RestClient bug if e. =~ /\WRequestFailed\W/ e = APIConnectionError.new('Unexpected HTTP response code') handle_restclient_error(e) else raise end rescue RestClient::ExceptionWithResponse => e if rcode = e.http_code and rbody = e.http_body # TODO # handle_api_error(rcode, rbody) handle_restclient_error(e) else handle_restclient_error(e) end rescue RestClient::Exception, Errno::ECONNREFUSED => e handle_restclient_error(e) end end | 
.general_api_error(rcode, rbody) ⇒ Object
| 101 102 103 104 | # File 'lib/cloudxls.rb', line 101 def self.general_api_error(rcode, rbody) StandardError.new("Invalid response object from API: #{rbody.inspect} " + "(HTTP response code was #{rcode})" ) #, rcode, rbody) end | 
.parse_response(response) ⇒ Object
| 95 96 97 98 99 | # File 'lib/cloudxls.rb', line 95 def self.parse_response(response) json = MultiJson.load(response.body) rescue MultiJson::DecodeError => e raise general_api_error(response.code, response.body) end | 
.xpipe(params = {}) ⇒ Object
| 61 62 63 | # File 'lib/cloudxls.rb', line 61 def self.xpipe(params = {}) convert(params) end | 
Instance Method Details
#validate_params(params) ⇒ Object
| 65 66 67 | # File 'lib/cloudxls.rb', line 65 def validate_params(params) # complain if excel_format together with template end |