Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for the newformat field to be set #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ for example,
and wrap the code calling the API in a <tt>begin ... rescue</tt> 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.

Expand Down Expand Up @@ -94,7 +99,7 @@ To retrieve an existing record:

Returns one or more records matching the query. The find_by_<attribute> 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.

Expand Down Expand Up @@ -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

7 changes: 4 additions & 3 deletions lib/ruby_zoho.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions lib/zoho_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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],
Expand All @@ -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'})
Expand Down Expand Up @@ -267,4 +269,3 @@ def valid_related?(module_name, field)
end

end