diff --git a/README.rdoc b/README.rdoc
index 6154f60..60924b7 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -48,6 +48,11 @@ for example,
and wrap the code calling the API in a begin ... rescue block.
+ config.save_format = 2
+
+Allows us to set the ```newFormat``` parameter while inserting or updating the Zoho API.
+
+
=== Ruby
Make sure the following block is executed prior to making calls to the gem.
@@ -94,7 +99,7 @@ To retrieve an existing record:
Returns one or more records matching the query. The find_by_ follows
ActiveRecord style reflections, so if the attribute is present in the API, it can
-be queried. There is currently a single attribute limitation imposed by the Zoho
+be queried. There is currently a single attribute limitation imposed by the Zoho
API. Note, what is returned is an Array class which is also Enumerable. Use +.each+,
+.map+, +.first+, +.last+, etc to navigate through the result set.
@@ -337,4 +342,3 @@ Copyright (c) 2013 - 2015 amalc (\@\amalc). Released under the MIT license. See
[0.1.1 - 0.1.6] Alpha Releases
1. Configuration block signature changed
[0.0.1 - 0.0.5] Alpha Releases
-
diff --git a/lib/ruby_zoho.rb b/lib/ruby_zoho.rb
index e61ca32..1fe57f9 100644
--- a/lib/ruby_zoho.rb
+++ b/lib/ruby_zoho.rb
@@ -5,7 +5,7 @@
module RubyZoho
class Configuration
- attr_accessor :api, :api_key, :cache_fields, :cache_path, :crm_modules, :ignore_fields_with_bad_names
+ attr_accessor :api, :api_key, :cache_fields, :cache_path, :crm_modules, :ignore_fields_with_bad_names, :save_format
def initialize
self.api_key = nil
@@ -14,6 +14,7 @@ def initialize
self.cache_path = File.join(File.dirname(__FILE__), '..', 'spec', 'fixtures')
self.crm_modules = nil
self.ignore_fields_with_bad_names = true
+ self.save_format = 1
end
end
@@ -37,9 +38,9 @@ def self.init_api(api_key, modules, cache_fields, cache_path)
if File.exists?(File.join(cache_path, 'fields.snapshot')) && cache_fields == true
fields = YAML.load(File.read(File.join(cache_path, 'fields.snapshot')))
zoho = ZohoApi::Crm.new(api_key, modules,
- self.configuration.ignore_fields_with_bad_names, fields)
+ self.configuration.ignore_fields_with_bad_names, self.configuration.save_format, fields)
else
- zoho = ZohoApi::Crm.new(api_key, modules, self.configuration.ignore_fields_with_bad_names)
+ zoho = ZohoApi::Crm.new(api_key, modules, self.configuration.ignore_fields_with_bad_names, self.configuration.save_format)
fields = zoho.module_fields
File.open(File.join(cache_path, 'fields.snapshot'), 'wb') { |file| file.write(fields.to_yaml) } if cache_fields == true
end
diff --git a/lib/zoho_api.rb b/lib/zoho_api.rb
index 0e01a0b..253a788 100644
--- a/lib/zoho_api.rb
+++ b/lib/zoho_api.rb
@@ -25,11 +25,12 @@ class Crm
attr_reader :auth_token, :module_fields
- def initialize(auth_token, modules, ignore_fields, fields = nil)
+ def initialize(auth_token, modules, ignore_fields, save_format, fields = nil)
@auth_token = auth_token
@modules = %w(Accounts Contacts Events Leads Potentials Tasks Users).concat(modules).uniq
@module_fields = fields.nil? ? reflect_module_fields : fields
@ignore_fields = ignore_fields
+ @save_format = save_format
end
def add_record(module_name, fields_values_hash)
@@ -38,7 +39,7 @@ def add_record(module_name, fields_values_hash)
row = element.add_element 'row', {'no' => '1'}
fields_values_hash.each_pair { |k, v| add_field(row, k, v, module_name) }
r = self.class.post(create_url(module_name, 'insertRecords'),
- :query => {:newFormat => 1, :authtoken => @auth_token,
+ :query => {:newFormat => @save_format, :authtoken => @auth_token,
:scope => 'crmapi', :xmlData => x, :wfTrigger => 'true'},
:headers => {'Content-length' => '0'})
check_for_errors(r)
@@ -56,7 +57,7 @@ def bulk_insert(module_name, records)
end
r = self.class.post(create_url(module_name, 'insertRecords'),
- :query => {:newFormat => 1, :authtoken => @auth_token,
+ :query => {:newFormat => @save_format, :authtoken => @auth_token,
:scope => 'crmapi', :xmlData => x, :wfTrigger => 'true'},
:headers => {'Content-length' => '0'})
check_for_errors(r)
@@ -114,7 +115,7 @@ def method_name?(n)
def post_action(module_name, record_id, action_type)
r = self.class.post(create_url(module_name, action_type),
- :query => {:newFormat => 1, :authtoken => @auth_token,
+ :query => {:newFormat => @save_format, :authtoken => @auth_token,
:scope => 'crmapi', :id => record_id},
:headers => {'Content-length' => '0'})
raise('Adding contact failed', RuntimeError, r.response.body.to_s) unless r.response.code == '200'
@@ -185,7 +186,7 @@ def update_related_records(parent_module, parent_record_id, related_module_field
related_module_fields[:xml_data].each_pair { |k, v| add_field(row, k, v, parent_module) }
r = self.class.post(create_url("#{parent_module}", 'updateRelatedRecords'),
- :query => {:newFormat => 1,
+ :query => {:newFormat => @save_format,
:id => parent_record_id,
:authtoken => @auth_token, :scope => 'crmapi',
:relatedModule => related_module_fields[:related_module],
@@ -200,8 +201,9 @@ def update_record(module_name, id, fields_values_hash)
contacts = x.add_element module_name
row = contacts.add_element 'row', {'no' => '1'}
fields_values_hash.each_pair { |k, v| add_field(row, k, v, module_name) }
+
r = self.class.post(create_url(module_name, 'updateRecords'),
- :query => {:newFormat => 1, :authtoken => @auth_token,
+ :query => {:newFormat => @save_format, :authtoken => @auth_token,
:scope => 'crmapi', :id => id,
:xmlData => x, :wfTrigger => 'true'},
:headers => {'Content-length' => '0'})
@@ -267,4 +269,3 @@ def valid_related?(module_name, field)
end
end
-