class ZohoReports::Client

Attributes

api_version[RW]

ZohoReports provides the ruby based language binding to the http based api of ZohoReports.

auth_token[RW]

ZohoReports provides the ruby based language binding to the http based api of ZohoReports.

login_email[RW]

ZohoReports provides the ruby based language binding to the http based api of ZohoReports.

Public Class Methods

new() click to toggle source
# File lib/zoho_reports/client.rb, line 14
def initialize
  self.api_version = '1.0'
end
zoho_attributes(attributes) click to toggle source

Converts formats to appropriate JSON value that can be consumed by Zoho Reports Hint, hint…datetimes

# File lib/zoho_reports/client.rb, line 234
def self.zoho_attributes(attributes)
  zohoified_attributes = Hash.new 

  attributes.map do |k,v| 
    if v.instance_of?(ActiveSupport::TimeWithZone)
      # Zoho doesn't currently deal well with JSON dates (particularly ones with milliseconds) so we'll convert to a string first
      zohoified_attributes[k] = v.strftime('%Y/%m/%d %T %Z')
      puts "#{k}: #{zohoified_attributes[k]}"
    else
      zohoified_attributes[k] = v
      puts "NOT TIME: #{k} - #{attributes[k].class}"
    end
  end

  return zohoified_attributes

end

Public Instance Methods

activate_user(email_ids) click to toggle source

Activate the users in the Zoho Reports Account

# File lib/zoho_reports/client.rb, line 103
def activate_user(email_ids)
  options = {
    :query => {
      'ZOHO_ACTION' => 'ACTIVATEUSER',
      'ZOHO_EMAILS' => email_ids,
    }
  }

  send_request get_user_uri, 'post', options
end
add_row(table_name, column_values) click to toggle source

Adds a row to the specified table identified by the URI

# File lib/zoho_reports/client.rb, line 127
def add_row(table_name, column_values)
  options = {
    :query => {
      'ZOHO_ACTION' => 'ADDROW',
    },
    :body => column_values
  }

  send_request get_uri(table_name), 'post', options
end
add_user(email_ids) click to toggle source

Add the users to the Zoho Reports Account

# File lib/zoho_reports/client.rb, line 79
def add_user(email_ids)
  options = {
    :query => {
      'ZOHO_ACTION' => 'ADDUSER',
      'ZOHO_EMAILS' => email_ids,
    }
  }

  send_request get_user_uri, 'post', options
end
copy_database() click to toggle source

Copy the specified database identified by the URI

# File lib/zoho_reports/client.rb, line 59
def copy_database
  options = {
    :query => { 'ZOHO_ACTION' => 'COPYDATABASE' }
  }

  send_request get_db_uri, 'post', options
end
deactivate_user(email_ids) click to toggle source

Deactivate the users in the Zoho Reports Account

# File lib/zoho_reports/client.rb, line 115
def deactivate_user(email_ids)
  options = {
    :query => {
      'ZOHO_ACTION' => 'DEACTIVATEUSER',
      'ZOHO_EMAILS' => email_ids,
    }
  }

  send_request get_user_uri, 'post', options
end
default_query() click to toggle source

Returns default settings for url query string on requests

# File lib/zoho_reports/client.rb, line 19
def default_query
  {
    'authtoken' => ZohoReports.configuration.auth_token,
    'ZOHO_OUTPUT_FORMAT' => 'JSON',
    'ZOHO_ERROR_FORMAT' => 'JSON',
    'ZOHO_API_VERSION' => self.api_version,
  }
end
delete_data(table_name, criteria, config={}) click to toggle source

Delete the data in the specified table identified by the URI.

# File lib/zoho_reports/client.rb, line 154
def delete_data(table_name, criteria, config={})
  body = {'ZOHO_CRITERIA' => criteria}
  body = body.merge!(config) if config.present?

  options = {
    :query => {
      'ZOHO_ACTION' => 'DELETE',
    },
    :body => body
  }

  send_request get_uri(table_name), 'post', options
end
delete_database() click to toggle source

Delete the specified database

# File lib/zoho_reports/client.rb, line 68
def delete_database
  options = {
    :query => {
      'ZOHO_ACTION' => 'DELETEDATABASE',
      'ZOHO_DATABASE_NAME' => database_name,
    }
  }
  send_request get_user_uri, 'post', options
end
export_data(table_or_report_name, format, criteria, config={}) click to toggle source

Export the data in the specified table identified by the URI.

# File lib/zoho_reports/client.rb, line 169
def export_data(table_or_report_name, format, criteria, config={})
  body = {'ZOHO_CRITERIA' => criteria}
  body = body.merge!(config) if config.present?

  options = {
    :query => {
      'ZOHO_ACTION' => 'EXPORT',
      'ZOHO_OUTPUT_FORMAT' => format,
    },
    :body => body
  }

  result = send_request get_uri(table_or_report_name), 'post', options
  result
  # TODO: Figure out to what to do with File objects response
end
export_data_using_sql(table_or_report_uri, format, sql, config={}) click to toggle source

Export the data with the specified SQL query identified by the URI.

# File lib/zoho_reports/client.rb, line 187
def export_data_using_sql(table_or_report_uri, format, sql, config={})
  body = {'ZOHO_SQLQUERY' => sql}
  body = body.merge!(config) if config.present?

  options = {
    :query => {
      'ZOHO_ACTION' => 'EXPORT',
      'ZOHO_OUTPUT_FORMAT' => format,
    },
    :body => body
  }

  result = send_request get_uri(table_or_report_name), 'post', options
  result
  # TODO: Figure out to what to do with File objectsw response
end
get_copy_db_key() click to toggle source

Gets copy database key for specified database identified by the URI

# File lib/zoho_reports/client.rb, line 49
def get_copy_db_key
  # payLoad = ReportClientHelper.getAsPayLoad([config],None,None)
  options = {
    :query => { 'ZOHO_ACTION' => 'GETCOPYDBKEY' }
  } 

  send_request get_db_uri, 'post', options
end
get_db_uri() click to toggle source

Returns the URI for the specified database

# File lib/zoho_reports/client.rb, line 258
def get_db_uri
  "#{URI.encode ZohoReports.configuration.login_email}/#{URI.encode ZohoReports.configuration.zoho_database_name}"
end
get_uri(table_or_report_name) click to toggle source

Returns the URI for the specified database table (or report).

# File lib/zoho_reports/client.rb, line 253
def get_uri(table_or_report_name)
  "/#{URI.encode ZohoReports.configuration.login_email}/#{URI.encode ZohoReports.configuration.zoho_database_name}/#{URI.encode table_or_report_name}"
end
get_user_uri() click to toggle source

Returns the URI for the specified user

# File lib/zoho_reports/client.rb, line 263
def get_user_uri
  "/#{URI.encode ZohoReports.configuration.login_email}"
end
import_data(table_name, import_type, import_content, import_config={}) click to toggle source

Bulk import data into the table identified by the URI.

# File lib/zoho_reports/client.rb, line 205
def import_data(table_name, import_type, import_content, import_config={})
  raise "Import Type must be APPEND, TRUNCATEADD or UPDATEADD" unless ["APPEND", "TRUNCATEADD", "UPDATEADD"].include?(import_type)

  body = {
    'ZOHO_AUTO_IDENTIFY' => 'true',
    'ZOHO_ON_IMPORT_ERROR' => 'SETCOLUMNEMPTY',
    'ZOHO_CREATE_TABLE' => 'false',
    'ZOHO_IMPORT_TYPE' => import_type,
    'ZOHO_IMPORT_DATA' => import_content,
    'ZOHO_IMPORT_FILETYPE' => 'JSON',
    'ZOHO_DATE_FORMAT' => "yyyy/MM/dd HH:mm:ss Z",
    'ZOHO_MATCHING_COLUMNS' => 'id', 
  }
  puts body['ZOHO_IMPORT_DATA']
  body = body.merge!(import_config) if import_config.any?

  options = {
    :query => {
      'ZOHO_ACTION' => 'IMPORT',
    },
    :body => body
  }

  send_request get_uri(table_name), 'post', options
  # TODO: Figure out to what to do with File objectsw response
end
remove_user(email_ids) click to toggle source

Remove the users from the Zoho Reports Account

# File lib/zoho_reports/client.rb, line 91
def remove_user(email_ids)
  options = {
    :query => {
      'ZOHO_ACTION' => 'REMOVEUSER',
      'ZOHO_EMAILS' => email_ids,
    }
  }

  send_request get_user_uri, 'post', options
end
send_request(url, http_method, options = {}) click to toggle source
# File lib/zoho_reports/client.rb, line 28
def send_request(url, http_method, options = {})
  # Merge our default query string values with the specificed query values
  options[:query] = default_query.merge!(options[:query])
  
  #Convert form variables to encoded string if exists
  if options.has_key?(:body)
    uri = Addressable::URI.new
    uri.query_values = options[:body]
    options[:body] = uri.query
  end

  response = self.class.send(http_method,url, options)

  if response.success?
    response
  else
    raise response.parsed_response
  end
end
update_data(table_name, column_values, criteria, config={}) click to toggle source

Update the data in the specified table identified by the URI.

# File lib/zoho_reports/client.rb, line 139
def update_data(table_name, column_values, criteria, config={})
  body = column_values.merge!({:ZOHO_CRITERIA => criteria})
  body = body.merge!(config) if config.any?

  options = {
    :query => {
      'ZOHO_ACTION' => 'UPDATE',
    },
    :body => body
  }

  send_request get_uri(table_name), 'post', options
end