rubyzoho 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
- - jruby-19mode # JRuby in 1.9 mode
4
+ # - jruby-19mode # JRuby in 1.9 mode
5
5
  # - rbx-19mode
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'httparty'
3
+ gem 'httmultiparty'
4
4
  gem 'roxml'
5
5
 
6
6
 
data/Gemfile.lock CHANGED
@@ -17,6 +17,9 @@ GEM
17
17
  gherkin (2.11.6)
18
18
  json (>= 1.7.6)
19
19
  git (1.2.5)
20
+ httmultiparty (0.3.8)
21
+ httparty (>= 0.7.3)
22
+ multipart-post
20
23
  httparty (0.10.2)
21
24
  multi_json (~> 1.0)
22
25
  multi_xml (>= 0.5.2)
@@ -33,6 +36,7 @@ GEM
33
36
  metaclass (~> 0.0.1)
34
37
  multi_json (1.5.1)
35
38
  multi_xml (0.5.3)
39
+ multipart-post (1.1.5)
36
40
  nokogiri (1.5.6)
37
41
  rake (10.0.3)
38
42
  rdoc (3.12.1)
@@ -73,7 +77,7 @@ PLATFORMS
73
77
  DEPENDENCIES
74
78
  bundler
75
79
  cucumber
76
- httparty
80
+ httmultiparty
77
81
  jeweler (~> 1.8.4)
78
82
  rdoc
79
83
  relish
data/README.rdoc CHANGED
@@ -11,6 +11,8 @@ ActiveRecord lifecycle but without ActiveRecord.
11
11
  == Configure
12
12
  Put the following in an initializer (e.g. zoho.rb):
13
13
 
14
+ require 'ruby_zoho'
15
+
14
16
  RubyZoho.configure do |config|
15
17
  config.api_key = '<< API Key from Zoho>>'
16
18
  # config.crm_modules = ['Accounts', 'Contacts', 'Leads', 'Potentials'] # Defaults to free edition if not set
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/lib/ruby_zoho.rb CHANGED
@@ -37,9 +37,20 @@ module RubyZoho
37
37
  @fields = RubyZoho.configuration.api.module_fields[
38
38
  ApiUtils.string_to_symbol(Crm.module_name)]
39
39
  RubyZoho::Crm.create_accessor(self.class, @fields)
40
- object_attribute_hash.map { |(k, v)| public_send("#{k}=", v) }
40
+ retry_counter = -1
41
+ begin
42
+ object_attribute_hash.map { |(k, v)| public_send("#{k}=", v) }
43
+ rescue NoMethodError => e
44
+ m = e.message.slice(/`[a-z]*id='/) # Get method name with id
45
+ RubyZoho::Crm.create_accessor(self.class,
46
+ [ApiUtils.string_to_symbol(m.slice(/[a-z]*=/).chop)]) unless m.nil?
47
+ retry_counter += 1
48
+ retry if retry_counter <= 0
49
+ end
50
+ self
41
51
  end
42
52
 
53
+
43
54
  def attr_writers
44
55
  self.methods.grep(/\w=$/)
45
56
  end
@@ -48,12 +59,17 @@ module RubyZoho
48
59
  names.each do |name|
49
60
  n = name
50
61
  n = name.to_s if name.class == Symbol
62
+ raise(RuntimeError, "Bad field name: #{name}") unless method_name?(name)
51
63
  create_getter(klass, n)
52
64
  create_setter(klass, n)
53
65
  end
54
66
  names
55
67
  end
56
68
 
69
+ def self.method_name?(n)
70
+ return /[@$"]/ !~ n.inspect
71
+ end
72
+
57
73
  def self.create_getter(klass, *names)
58
74
  names.each do |name|
59
75
  klass.send(:define_method, "#{name}") { instance_variable_get("@#{name}") }
@@ -74,6 +90,7 @@ module RubyZoho
74
90
  def save
75
91
  h = {}
76
92
  @fields.each { |f| h.merge!({ f => eval("self.#{f.to_s}") }) }
93
+ h.delete_if { |k, v| v.nil? }
77
94
  RubyZoho.configuration.api.add_record(Crm.module_name, h)
78
95
  end
79
96
 
@@ -111,7 +128,7 @@ module RubyZoho
111
128
  end
112
129
 
113
130
  def self.update(object_attribute_hash)
114
- raise(RuntimeError, 'No ID found', object_attribute_hash) if object_attribute_hash[:id].nil?
131
+ raise(RuntimeError, 'No ID found', object_attribute_hash.to_s) if object_attribute_hash[:id].nil?
115
132
  id = object_attribute_hash[:id]
116
133
  object_attribute_hash.delete(:id)
117
134
  RubyZoho.configuration.api.update_record(Crm.module_name, id, object_attribute_hash)
data/lib/zoho_api.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  $:.unshift File.join('..', File.dirname(__FILE__), 'lib')
2
2
 
3
- require 'httparty'
3
+ require 'httmultiparty'
4
4
  require 'rexml/document'
5
+ require 'net/http/post/multipart'
6
+ require 'mime/types'
5
7
  require 'ruby_zoho'
6
8
  require 'yaml'
7
9
  require 'api_utils'
@@ -13,7 +15,9 @@ module ZohoApi
13
15
  class Crm
14
16
  NUMBER_OF_RECORDS_TO_GET = 200
15
17
 
16
- include HTTParty
18
+ include HTTMultiParty
19
+
20
+ @@module_fields = {}
17
21
 
18
22
  #debug_output $stderr
19
23
 
@@ -27,8 +31,8 @@ module ZohoApi
27
31
 
28
32
  def add_record(module_name, fields_values_hash)
29
33
  x = REXML::Document.new
30
- contacts = x.add_element module_name
31
- row = contacts.add_element 'row', { 'no' => '1'}
34
+ element = x.add_element module_name
35
+ row = element.add_element 'row', { 'no' => '1'}
32
36
  fields_values_hash.each_pair { |k, v| add_field(row, ApiUtils.symbol_to_string(k), v) }
33
37
  r = self.class.post(create_url(module_name, 'insertRecords'),
34
38
  :query => { :newFormat => 1, :authtoken => @auth_token,
@@ -46,18 +50,49 @@ module ZohoApi
46
50
  row
47
51
  end
48
52
 
49
- def attach_file(module_name, record_id, file_content)
50
- pp module_name
51
- pp record_id
52
- pp file_content.size
53
+ def attach_file(module_name, record_id, file_path)
53
54
  r = self.class.post(create_url(module_name, 'uploadFile'),
54
55
  :query => { :newFormat => 1, :authtoken => @auth_token,
55
56
  :scope => 'crmapi',
56
- :id => record_id, :content => Base64.encode64(file_content) },
57
+ :id => record_id, :content => File.open(file_path) },
57
58
  :headers => { 'Content-length' => '0' })
58
- pp r
59
- raise('Adding record failed', RuntimeError, r.response.body.to_s) unless r.response.code == '200'
60
- r.response.code
59
+ pp r.code
60
+ pp r.body
61
+ raise(RuntimeError, 'Attaching file failed.', r.body.to_s) unless r.response.code == '200'
62
+ r.code
63
+ end
64
+
65
+ def add_file(module_name, record_id, file_path)
66
+ url = URI.parse(create_url(module_name, 'uploadFile'))
67
+ r = nil
68
+ pp record_id
69
+ mime_type = (MIME::Types.type_for(file_path)[0] || MIME::Types["application/octet-stream"][0])
70
+ f = File.open(file_path)
71
+ req = Net::HTTP::Post::Multipart.new url.path,
72
+ { 'authtoken' => '@auth_token', 'scope' => 'crmapi',
73
+ 'id' => record_id,
74
+ 'content' => UploadIO.new(f, mime_type, File.basename(file_path)) }
75
+ http = Net::HTTP.new(url.host, url.port)
76
+ http.use_ssl = true
77
+ pp req.to_hash
78
+ r = http.start { |http| http.request(req) }
79
+ pp r.body.to_s
80
+ (r.nil? or r.body.nil? or r.body.empty?) ? nil : REXML::Document.new(r.body).to_s
81
+ end
82
+
83
+ def to_byte_array(num)
84
+ result = []
85
+ begin
86
+ result << (num & 0xff)
87
+ num >>= 8
88
+ end until (num == 0 || num == -1) && (result.last[7] == num[7])
89
+ result.reverse
90
+ end
91
+
92
+ def check_for_errors(response)
93
+ return
94
+ raise(RuntimeError, 'Exceeded API calls.') unless response.body.to_s.index('You crossed your API search limit').nil?
95
+ response
61
96
  end
62
97
 
63
98
  def create_url(module_name, api_call)
@@ -70,11 +105,25 @@ module ZohoApi
70
105
  :scope => 'crmapi', :id => record_id },
71
106
  :headers => { 'Content-length' => '0' })
72
107
  raise('Adding contact failed', RuntimeError, r.response.body.to_s) unless r.response.code == '200'
108
+ check_for_errors(r)
73
109
  end
74
110
 
75
111
  def fields(module_name)
76
- record = first(module_name)
77
- record[0].keys
112
+ mod_name = ApiUtils.string_to_symbol(module_name)
113
+ return @@module_fields[mod_name] unless @@module_fields[mod_name].nil?
114
+ r = self.class.post(create_url(module_name, 'getFields'),
115
+ :query => { :authtoken => @auth_token, :scope => 'crmapi' },
116
+ :headers => { 'Content-length' => '0' })
117
+ @@module_fields[mod_name] = []
118
+ x = REXML::Document.new(r.body)
119
+ REXML::XPath.each(x, "/#{module_name}/section/FL/@dv") do |f|
120
+ field = ApiUtils.string_to_symbol(f.to_s)
121
+ @@module_fields[mod_name] << field if method_name?(field)
122
+ end
123
+ raise('Getting fields failed', RuntimeError, module_name) unless r.response.code == '200'
124
+ check_for_errors(r)
125
+ @@module_fields[mod_name] << ApiUtils.string_to_symbol(module_name.chop + 'id')
126
+ @@module_fields
78
127
  end
79
128
 
80
129
  def first(module_name)
@@ -90,35 +139,51 @@ module ZohoApi
90
139
  def find_record_by_field(module_name, sc_field, condition, value)
91
140
  search_condition = '(' + sc_field + '|' + condition + '|' + value + ')'
92
141
  r = self.class.get(create_url("#{module_name}", 'getSearchRecords'),
93
- :query => {:newFormat => 2, :authtoken => @auth_token, :scope => 'crmapi',
142
+ :query => {:newFormat => 1, :authtoken => @auth_token, :scope => 'crmapi',
94
143
  :selectColumns => 'All', :searchCondition => search_condition,
95
144
  :fromIndex => 1, :toIndex => NUMBER_OF_RECORDS_TO_GET})
96
145
  raise(RuntimeError, 'Bad query', "#{sc_field} #{condition} #{value}") unless r.body.index('<error>').nil?
146
+ check_for_errors(r)
97
147
  x = REXML::Document.new(r.body).elements.to_a("/response/result/#{module_name}/row")
98
148
  to_hash(x)
99
149
  end
100
150
 
101
151
  def find_record_by_id(module_name, id)
102
152
  r = self.class.get(create_url("#{module_name}", 'getRecordById'),
103
- :query => { :newFormat => 2, :authtoken => @auth_token, :scope => 'crmapi',
153
+ :query => { :newFormat => 1, :authtoken => @auth_token, :scope => 'crmapi',
104
154
  :selectColumns => 'All', :id => id})
105
- raise(RuntimeError, 'Bad query', "#{sc_field} #{condition} #{value}") unless r.body.index('<error>').nil?
155
+ raise(RuntimeError, 'Bad query', "#{module_name} #{id}") unless r.body.index('<error>').nil?
156
+ check_for_errors(r)
106
157
  x = REXML::Document.new(r.body).elements.to_a("/response/result/#{module_name}/row")
107
158
  to_hash(x)
108
159
  end
109
160
 
161
+ def method_name?(n)
162
+ return /[@$"]/ !~ n.inspect
163
+ end
164
+
110
165
  def reflect_module_fields
111
- module_names = @modules
112
- module_fields = {}
113
- module_names.each { |n| module_fields.merge!({ ApiUtils.string_to_symbol(n) => fields(n) }) }
114
- module_fields
166
+ @modules.each { |m| fields(m) }
167
+ @@module_fields
168
+ end
169
+
170
+ def related_records(module_name, id)
171
+ r = self.class.get(create_url("#{module_name}", 'getRelatedRecords'),
172
+ :query => { :newFormat => 1, :authtoken => @auth_token, :scope => 'crmapi',
173
+ :parentModule => module_name, :id => id})
174
+ raise(RuntimeError, 'Bad query for related records', module_name) unless r.body.index('<error>').nil?
175
+ check_for_errors(r)
176
+ x = REXML::Document.new(r.body).elements.to_a("/response/result/#{module_name}/row")
177
+ puts "====="
178
+ pp x.each { |i| i.to_s }
115
179
  end
116
180
 
117
181
  def some(module_name, index = 1, number_of_records = nil)
118
182
  r = self.class.get(create_url(module_name, 'getRecords'),
119
- :query => { :newFormat => 2, :authtoken => @auth_token, :scope => 'crmapi',
183
+ :query => { :newFormat => 1, :authtoken => @auth_token, :scope => 'crmapi',
120
184
  :fromIndex => index, :toIndex => number_of_records || NUMBER_OF_RECORDS_TO_GET })
121
185
  return nil unless r.response.code == '200'
186
+ check_for_errors(r)
122
187
  x = REXML::Document.new(r.body).elements.to_a("/response/result/#{module_name}/row")
123
188
  to_hash(x)
124
189
  end
@@ -148,6 +213,7 @@ module ZohoApi
148
213
  :scope => 'crmapi', :id => id,
149
214
  :xmlData => x },
150
215
  :headers => { 'Content-length' => '0' })
216
+ check_for_errors(r)
151
217
  raise('Updating record failed', RuntimeError, r.response.body.to_s) unless r.response.code == '200'
152
218
  r.response.code
153
219
  end
data/rubyzoho.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rubyzoho"
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["amalc"]
12
- s.date = "2013-02-13"
12
+ s.date = "2013-02-16"
13
13
  s.description = ""
14
14
  s.email = ""
15
15
  s.extra_rdoc_files = [
@@ -30,9 +30,6 @@ Gem::Specification.new do |s|
30
30
  "lib/api_utils.rb",
31
31
  "lib/ruby_zoho.rb",
32
32
  "lib/zoho_api.rb",
33
- "rubyzoho-0.0.3.gem",
34
- "rubyzoho-0.0.4.gem",
35
- "rubyzoho-0.1.0.gem",
36
33
  "rubyzoho.gemspec",
37
34
  "spec/api_utils_spec.rb",
38
35
  "spec/fixtures/sample.pdf",
@@ -48,14 +45,14 @@ Gem::Specification.new do |s|
48
45
  s.homepage = "http://github.com/amalc/rubyzoho"
49
46
  s.licenses = ["MIT"]
50
47
  s.require_paths = ["lib"]
51
- s.rubygems_version = "1.8.24"
48
+ s.rubygems_version = "1.8.23"
52
49
  s.summary = "A set of Ruby classes supporting the ActiveRecord lifecycle for the Zoho API."
53
50
 
54
51
  if s.respond_to? :specification_version then
55
52
  s.specification_version = 3
56
53
 
57
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
58
- s.add_runtime_dependency(%q<httparty>, [">= 0"])
55
+ s.add_runtime_dependency(%q<httmultiparty>, [">= 0"])
59
56
  s.add_runtime_dependency(%q<roxml>, [">= 0"])
60
57
  s.add_development_dependency(%q<bundler>, [">= 0"])
61
58
  s.add_development_dependency(%q<cucumber>, [">= 0"])
@@ -67,7 +64,7 @@ Gem::Specification.new do |s|
67
64
  s.add_development_dependency(%q<xml-simple>, [">= 0"])
68
65
  s.add_development_dependency(%q<simplecov>, [">= 0"])
69
66
  else
70
- s.add_dependency(%q<httparty>, [">= 0"])
67
+ s.add_dependency(%q<httmultiparty>, [">= 0"])
71
68
  s.add_dependency(%q<roxml>, [">= 0"])
72
69
  s.add_dependency(%q<bundler>, [">= 0"])
73
70
  s.add_dependency(%q<cucumber>, [">= 0"])
@@ -80,7 +77,7 @@ Gem::Specification.new do |s|
80
77
  s.add_dependency(%q<simplecov>, [">= 0"])
81
78
  end
82
79
  else
83
- s.add_dependency(%q<httparty>, [">= 0"])
80
+ s.add_dependency(%q<httmultiparty>, [">= 0"])
84
81
  s.add_dependency(%q<roxml>, [">= 0"])
85
82
  s.add_dependency(%q<bundler>, [">= 0"])
86
83
  s.add_dependency(%q<cucumber>, [">= 0"])
@@ -11,6 +11,7 @@ describe RubyZoho::Crm do
11
11
  #params = YAML.load(File.open(config_file))
12
12
  RubyZoho.configure do |config|
13
13
  #config.api_key = params['auth_token']
14
+ #config.api_key = 'e194b2951fb238e26bc096de9d0cf5f8'
14
15
  config.api_key = '62cedfe9427caef8afb9ea3b5bf68154'
15
16
  config.crm_modules = ['Accounts', 'Contacts', 'Leads', 'Potentials', 'Quotes']
16
17
  end
@@ -29,6 +30,8 @@ describe RubyZoho::Crm do
29
30
  end
30
31
 
31
32
  it 'should find a contact by email or last name' do
33
+ r = RubyZoho::Crm::Contact.find_by_email('bob@smith.com')
34
+ r.each { |m| RubyZoho::Crm::Contact.delete(m.contactid) } unless r.nil?
32
35
  1.upto(3) do
33
36
  c = RubyZoho::Crm::Contact.new(
34
37
  :first_name => 'Bob',
@@ -36,14 +39,12 @@ describe RubyZoho::Crm do
36
39
  :email => 'bob@smith.com')
37
40
  c.save
38
41
  end
39
- r = RubyZoho::Crm::Contact.find_by_email('bob@smith.com')
42
+ r = RubyZoho::Crm::Contact.find_by_email('bob@smith.com')
40
43
  r.should_not eq(nil)
41
44
  r.count.should eq(3)
42
45
  r.each { |m| m.email.should eq('bob@smith.com') }
43
46
  r = RubyZoho::Crm::Contact.find_by_last_name('Smithereens')
44
47
  r.should_not eq(nil)
45
- r.first.should_not eq(nil)
46
- r.last.should_not eq(nil)
47
48
  r.map { |c| c.last_name }.count.should eq(3)
48
49
  r.first.last_name.should eq('Smithereens')
49
50
  r.each { |m| RubyZoho::Crm::Contact.delete(m.contactid) }
@@ -51,27 +52,27 @@ describe RubyZoho::Crm do
51
52
 
52
53
  it 'should get a list of attr_writers for accounts' do
53
54
  c = RubyZoho::Crm::Account.new
54
- c.attr_writers.count.should be >= 34
55
+ c.attr_writers.count.should be >= 18
55
56
  end
56
57
 
57
58
  it 'should get a list of attr_writers for contacts' do
58
59
  c = RubyZoho::Crm::Contact.new
59
- c.attr_writers.count.should be >= 43
60
+ c.attr_writers.count.should be >= 21
60
61
  end
61
62
 
62
63
  it 'should get a list of attr_writers for leads' do
63
64
  c = RubyZoho::Crm::Lead.new
64
- c.attr_writers.count.should be >= 34
65
+ c.attr_writers.count.should be >= 16
65
66
  end
66
67
 
67
68
  it 'should get a list of attr_writers for potentials' do
68
69
  c = RubyZoho::Crm::Potential.new
69
- c.attr_writers.count.should be >= 26
70
+ c.attr_writers.count.should be >= 14
70
71
  end
71
72
 
72
73
  it 'should get a list of attr_writers for quotes' do
73
74
  c = RubyZoho::Crm::Quote.new
74
- c.attr_writers.count.should be >= 33
75
+ c.attr_writers.count.should be >= 18
75
76
  end
76
77
 
77
78
  it 'should get a list of accounts' do
@@ -138,20 +139,23 @@ describe RubyZoho::Crm do
138
139
  :email => 'raj@portra.com')
139
140
  l.save
140
141
  r = RubyZoho::Crm::Lead.find_by_email('raj@portra.com')
142
+ r.should_not eq(nil)
143
+ r.first.email.should eq(l.email)
141
144
  r.each { |c| RubyZoho::Crm::Lead.delete(c.leadid) }
142
145
  end
143
146
 
144
147
  it 'should save a potential record' do
145
- potentials = RubyZoho::Crm::Potential.all
148
+ accounts = RubyZoho::Crm::Account.all
146
149
  p = RubyZoho::Crm::Potential.new(
147
150
  :potential_name => 'A very big potential INDEED!!!!!!!!!!!!!',
148
- :accountid => potentials[0].accountid,
149
- :account_name => potentials[0].account_name,
151
+ :accountid => accounts.first.accountid,
152
+ :account_name => accounts.first.account_name,
150
153
  :closing_date => '1/1/2014',
151
154
  :type => 'New Business',
152
155
  :stage => 'Needs Analysis')
153
156
  p.save
154
157
  r = RubyZoho::Crm::Potential.find_by_potential_name(p.potential_name)
158
+ r.first.potential_name.should eq('A very big potential INDEED!!!!!!!!!!!!!')
155
159
  r.each { |c| RubyZoho::Crm::Potential.delete(c.potentialid) }
156
160
  end
157
161
 
@@ -172,4 +176,11 @@ describe RubyZoho::Crm do
172
176
  r.each { |c| RubyZoho::Crm::Lead.delete(c.leadid) }
173
177
  end
174
178
 
179
+ it 'should validate a field name' do
180
+ good_names = ['This is OK', 'OK_to_use']
181
+ bad_names = ['This % is not', 'Bad()']
182
+ good_names.map { |f| RubyZoho::Crm.method_name?(ApiUtils.string_to_symbol(f)).should_not eq(false)}
183
+ bad_names.map { |f| RubyZoho::Crm.method_name?(ApiUtils.string_to_symbol(f)).should eq(false)}
184
+ end
185
+
175
186
  end
@@ -25,42 +25,36 @@ describe ZohoApi do
25
25
  #params = YAML.load(File.open(config_file))
26
26
  #@zoho = ZohoApi::Crm.new(params['auth_token'])
27
27
  @sample_pdf = File.join(base_path, 'sample.pdf')
28
- modules = ['Accounts', 'Contacts', 'Leads', 'Potentials', 'Quotes']
29
- @zoho = ZohoApi::Crm.new('62cedfe9427caef8afb9ea3b5bf68154', modules)
30
- end
31
-
32
- it 'should add a new contact' do
33
- h = { :first_name => 'Robert',
28
+ modules = ['Accounts', 'Contacts', 'Leads', 'Potentials']
29
+ #api_key = '783539943dc16d7005b0f3b78367d5d2'
30
+ #api_key = 'e194b2951fb238e26bc096de9d0cf5f8'
31
+ api_key = '62cedfe9427caef8afb9ea3b5bf68154'
32
+ @zoho = ZohoApi::Crm.new(api_key, modules)
33
+ @h_smith = { :first_name => 'Robert',
34
34
  :last_name => 'Smith',
35
35
  :email => 'rsmith@smithereens.com',
36
36
  :department => 'Waste Collection and Management',
37
37
  :phone => '13452129087',
38
38
  :mobile => '12341238790'
39
39
  }
40
- @zoho.add_record('Contacts', h)
41
- contact = @zoho.find_records('Contacts', :email, '=', h[:email])
42
- @zoho.delete_record('Contacts', contact[0][:contactid])
43
- contact.should_not eq(nil)
44
- contact.count.should eq(1)
40
+ contacts = @zoho.find_records('Contacts', :email, '=', @h_smith[:email])
41
+ contacts.each { |c| @zoho.delete_record('Contacts', c[:contactid]) } unless contacts.nil?
42
+ end
43
+
44
+ it 'should add a new contact' do
45
+ @zoho.add_record('Contacts', @h_smith)
46
+ contacts = @zoho.find_records('Contacts', :email, '=', @h_smith[:email])
47
+ @zoho.delete_record('Contacts', contacts[0][:contactid])
48
+ contacts.should_not eq(nil)
49
+ contacts.count.should eq(1)
45
50
  end
46
51
 
47
52
  it 'should attach a file to a contact record' do
48
53
  pending
49
- h = { :first_name => 'Robert',
50
- :last_name => 'Smith',
51
- :email => 'rsmith@smithereens.com',
52
- :department => 'Waste Collection and Management',
53
- :phone => '13452129087',
54
- :mobile => '12341238790'
55
- }
56
- #@zoho.add_record('Contacts', h)
57
- contact = @zoho.find_records('Contacts', :email, '=', h[:email])
58
- pp contact[0][:contactid]
59
- pp File.read(@sample_pdf).size
60
- pp Base64.encode64(File.read(@sample_pdf)).size
61
- @zoho.attach_file('Contacts', contact[0][:contactid],
62
- File.read(@sample_pdf))
63
- #@zoho.delete_record('Contacts', contact[0][:contactid])
54
+ @zoho.add_record('Contacts', @h_smith)
55
+ contacts = @zoho.find_records('Contacts', :email, '=', @h_smith[:email])
56
+ @zoho.add_file('Contacts', contacts[0][:contactid], @sample_pdf)
57
+ #@zoho.delete_record('Contacts', contacts[0][:contactid])
64
58
  end
65
59
 
66
60
  it 'should delete a contact record with id' do
@@ -88,15 +82,13 @@ describe ZohoApi do
88
82
 
89
83
  it 'should get a list of fields for a module' do
90
84
  r = @zoho.fields('Contacts')
91
- r.count.should be >= 43
85
+ r.count.should be >= 35
92
86
  r = @zoho.fields('Leads')
93
- r.count.should be >= 34
94
- r = @zoho.fields('Quotes')
95
- r.count.should be >= 33
96
- r = @zoho.fields('SalesOrders')
97
- r.count.should >= 45
98
- r = @zoho.fields('Invoices')
99
- r.count.should >= 41
87
+ r.count.should be >= 23
88
+ r = @zoho.fields('Potentials')
89
+ r.count.should be >= 15
90
+ r = @zoho.fields('Accounts')
91
+ r.count.should >= 30
100
92
  end
101
93
 
102
94
  it 'should retrieve records by module name' do
@@ -106,16 +98,17 @@ describe ZohoApi do
106
98
  r.count.should be > 1
107
99
  end
108
100
 
101
+ it 'should return related records by module and id' do
102
+ pending
103
+ r = @zoho.some('Contacts')
104
+ pp r.first
105
+ related = @zoho.related_records('Contacts', r.first[:contactid])
106
+ pp related
107
+ end
108
+
109
109
  it 'should update a contact' do
110
- h = { :first_name => 'Robert',
111
- :last_name => 'Smith',
112
- :email => 'rsmith@smithereens.com',
113
- :department => 'Waste Collection and Management',
114
- :phone => '13452129087',
115
- :mobile => '12341238790'
116
- }
117
- @zoho.add_record('Contacts', h)
118
- contact = @zoho.find_records('Contacts', :email, '=', h[:email])
110
+ @zoho.add_record('Contacts', @h_smith)
111
+ contact = @zoho.find_records('Contacts', :email, '=', @h_smith[:email])
119
112
  h_changed = { :email => 'robert.smith@smithereens.com' }
120
113
  @zoho.update_record('Contacts', contact[0][:contactid], h_changed)
121
114
  changed_contact = @zoho.find_records('Contacts', :email, '=', h_changed[:email])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyzoho
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,10 +9,10 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-13 00:00:00.000000000 Z
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: httparty
15
+ name: httmultiparty
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
@@ -208,9 +208,6 @@ files:
208
208
  - lib/api_utils.rb
209
209
  - lib/ruby_zoho.rb
210
210
  - lib/zoho_api.rb
211
- - rubyzoho-0.0.3.gem
212
- - rubyzoho-0.0.4.gem
213
- - rubyzoho-0.1.0.gem
214
211
  - rubyzoho.gemspec
215
212
  - spec/api_utils_spec.rb
216
213
  - spec/fixtures/sample.pdf
@@ -243,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
240
  version: '0'
244
241
  requirements: []
245
242
  rubyforge_project:
246
- rubygems_version: 1.8.24
243
+ rubygems_version: 1.8.23
247
244
  signing_key:
248
245
  specification_version: 3
249
246
  summary: A set of Ruby classes supporting the ActiveRecord lifecycle for the Zoho
data/rubyzoho-0.0.3.gem DELETED
Binary file
data/rubyzoho-0.0.4.gem DELETED
Binary file