Class: ZohoReports::Client
- Inherits:
-
Object
- Object
- ZohoReports::Client
- Includes:
- HTTMultiParty
- Defined in:
- lib/zoho_reports/client.rb
Instance Attribute Summary collapse
-
#api_version ⇒ Object
ZohoReports provides the ruby based language binding to the http based api of ZohoReports.
-
#auth_token ⇒ Object
ZohoReports provides the ruby based language binding to the http based api of ZohoReports.
-
#login_email ⇒ Object
ZohoReports provides the ruby based language binding to the http based api of ZohoReports.
Class Method Summary collapse
-
.zoho_attributes(attributes) ⇒ Object
Converts formats to appropriate JSON value that can be consumed by Zoho Reports Hint, hint…datetimes.
Instance Method Summary collapse
-
#activate_user(email_ids) ⇒ Object
Activate the users in the Zoho Reports Account.
-
#add_row(table_name, column_values) ⇒ Object
Adds a row to the specified table identified by the URI.
-
#add_user(email_ids) ⇒ Object
Add the users to the Zoho Reports Account.
-
#copy_database ⇒ Object
Copy the specified database identified by the URI.
-
#deactivate_user(email_ids) ⇒ Object
Deactivate the users in the Zoho Reports Account.
-
#default_query ⇒ Object
Returns default settings for url query string on requests.
-
#delete_data(table_name, criteria, config = {}) ⇒ Object
Delete the data in the specified table identified by the URI.
-
#delete_database ⇒ Object
Delete the specified database.
-
#export_data(table_or_report_name, format, criteria, config = {}) ⇒ Object
Export the data in the specified table identified by the URI.
-
#export_data_using_sql(table_or_report_uri, format, sql, config = {}) ⇒ Object
Export the data with the specified SQL query identified by the URI.
-
#get_copy_db_key ⇒ Object
Gets copy database key for specified database identified by the URI.
-
#get_db_uri ⇒ Object
Returns the URI for the specified database.
-
#get_uri(table_or_report_name) ⇒ Object
Returns the URI for the specified database table (or report).
-
#get_user_uri ⇒ Object
Returns the URI for the specified user.
-
#import_data(table_name, import_type, import_content, import_config = {}) ⇒ Object
Bulk import data into the table identified by the URI.
-
#initialize ⇒ Client
constructor
A new instance of Client.
-
#remove_user(email_ids) ⇒ Object
Remove the users from the Zoho Reports Account.
- #send_request(url, http_method, options = {}) ⇒ Object
-
#update_data(table_name, column_values, criteria, config = {}) ⇒ Object
Update the data in the specified table identified by the URI.
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
14 15 16 |
# File 'lib/zoho_reports/client.rb', line 14 def initialize self.api_version = '1.0' end |
Instance Attribute Details
#api_version ⇒ Object
ZohoReports provides the ruby based language binding to the http based api of ZohoReports.
10 11 12 |
# File 'lib/zoho_reports/client.rb', line 10 def api_version @api_version end |
#auth_token ⇒ Object
ZohoReports provides the ruby based language binding to the http based api of ZohoReports.
10 11 12 |
# File 'lib/zoho_reports/client.rb', line 10 def auth_token @auth_token end |
#login_email ⇒ Object
ZohoReports provides the ruby based language binding to the http based api of ZohoReports.
10 11 12 |
# File 'lib/zoho_reports/client.rb', line 10 def login_email @login_email end |
Class Method Details
.zoho_attributes(attributes) ⇒ Object
Converts formats to appropriate JSON value that can be consumed by Zoho Reports Hint, hint…datetimes
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# 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 |
Instance Method Details
#activate_user(email_ids) ⇒ Object
Activate the users in the Zoho Reports Account
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/zoho_reports/client.rb', line 103 def activate_user(email_ids) = { :query => { 'ZOHO_ACTION' => 'ACTIVATEUSER', 'ZOHO_EMAILS' => email_ids, } } send_request get_user_uri, 'post', end |
#add_row(table_name, column_values) ⇒ Object
Adds a row to the specified table identified by the URI
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/zoho_reports/client.rb', line 127 def add_row(table_name, column_values) = { :query => { 'ZOHO_ACTION' => 'ADDROW', }, :body => column_values } send_request get_uri(table_name), 'post', end |
#add_user(email_ids) ⇒ Object
Add the users to the Zoho Reports Account
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/zoho_reports/client.rb', line 79 def add_user(email_ids) = { :query => { 'ZOHO_ACTION' => 'ADDUSER', 'ZOHO_EMAILS' => email_ids, } } send_request get_user_uri, 'post', end |
#copy_database ⇒ Object
Copy the specified database identified by the URI
59 60 61 62 63 64 65 |
# File 'lib/zoho_reports/client.rb', line 59 def copy_database = { :query => { 'ZOHO_ACTION' => 'COPYDATABASE' } } send_request get_db_uri, 'post', end |
#deactivate_user(email_ids) ⇒ Object
Deactivate the users in the Zoho Reports Account
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/zoho_reports/client.rb', line 115 def deactivate_user(email_ids) = { :query => { 'ZOHO_ACTION' => 'DEACTIVATEUSER', 'ZOHO_EMAILS' => email_ids, } } send_request get_user_uri, 'post', end |
#default_query ⇒ Object
Returns default settings for url query string on requests
19 20 21 22 23 24 25 26 |
# 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 = {}) ⇒ Object
Delete the data in the specified table identified by the URI.
154 155 156 157 158 159 160 161 162 163 164 165 166 |
# 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? = { :query => { 'ZOHO_ACTION' => 'DELETE', }, :body => body } send_request get_uri(table_name), 'post', end |
#delete_database ⇒ Object
Delete the specified database
68 69 70 71 72 73 74 75 76 |
# File 'lib/zoho_reports/client.rb', line 68 def delete_database = { :query => { 'ZOHO_ACTION' => 'DELETEDATABASE', 'ZOHO_DATABASE_NAME' => database_name, } } send_request get_user_uri, 'post', end |
#export_data(table_or_report_name, format, criteria, config = {}) ⇒ Object
Export the data in the specified table identified by the URI.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# 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? = { :query => { 'ZOHO_ACTION' => 'EXPORT', 'ZOHO_OUTPUT_FORMAT' => format, }, :body => body } result = send_request get_uri(table_or_report_name), 'post', result # TODO: Figure out to what to do with File objects response end |
#export_data_using_sql(table_or_report_uri, format, sql, config = {}) ⇒ Object
Export the data with the specified SQL query identified by the URI.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# 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? = { :query => { 'ZOHO_ACTION' => 'EXPORT', 'ZOHO_OUTPUT_FORMAT' => format, }, :body => body } result = send_request get_uri(table_or_report_name), 'post', result # TODO: Figure out to what to do with File objectsw response end |
#get_copy_db_key ⇒ Object
Gets copy database key for specified database identified by the URI
49 50 51 52 53 54 55 56 |
# File 'lib/zoho_reports/client.rb', line 49 def get_copy_db_key # payLoad = ReportClientHelper.getAsPayLoad([config],None,None) = { :query => { 'ZOHO_ACTION' => 'GETCOPYDBKEY' } } send_request get_db_uri, 'post', end |
#get_db_uri ⇒ Object
Returns the URI for the specified database
258 259 260 |
# 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) ⇒ Object
Returns the URI for the specified database table (or report).
253 254 255 |
# 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 ⇒ Object
Returns the URI for the specified user
263 264 265 |
# 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 = {}) ⇒ Object
Bulk import data into the table identified by the URI.
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# 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? = { :query => { 'ZOHO_ACTION' => 'IMPORT', }, :body => body } send_request get_uri(table_name), 'post', # TODO: Figure out to what to do with File objectsw response end |
#remove_user(email_ids) ⇒ Object
Remove the users from the Zoho Reports Account
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/zoho_reports/client.rb', line 91 def remove_user(email_ids) = { :query => { 'ZOHO_ACTION' => 'REMOVEUSER', 'ZOHO_EMAILS' => email_ids, } } send_request get_user_uri, 'post', end |
#send_request(url, http_method, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/zoho_reports/client.rb', line 28 def send_request(url, http_method, = {}) # Merge our default query string values with the specificed query values [:query] = default_query.merge!([:query]) #Convert form variables to encoded string if exists if .has_key?(:body) uri = Addressable::URI.new uri.query_values = [:body] [:body] = uri.query end response = self.class.send(http_method,url, ) if response.success? response else raise response.parsed_response end end |
#update_data(table_name, column_values, criteria, config = {}) ⇒ Object
Update the data in the specified table identified by the URI.
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# 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? = { :query => { 'ZOHO_ACTION' => 'UPDATE', }, :body => body } send_request get_uri(table_name), 'post', end |