rubyzoho 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -30,8 +30,8 @@ To get a list of supported attributes for a Zoho CRM contact:
30
30
  require 'ruby_zoho'
31
31
 
32
32
  c = RubyZoho::Crm::Contact.new
33
- c.attr_writers # => Give a list of updatable attributes
34
- c.fields # => Hash of all fields
33
+ c.attr_writers # => List of updatable attributes
34
+ c.fields # => Array of all fields
35
35
 
36
36
  Attributes are reflected from the current API instance of Zoho, dynamically on
37
37
  initialization of the API, when the RubyZoho.configure block is called. This
@@ -40,8 +40,8 @@ includes custom fields.
40
40
  Another example:
41
41
 
42
42
  l = RubyZoho::Crm::Lead.new
43
- l.attr_writers # => Give a list of updatable attributes
44
- l.fields # => Hash of all fields
43
+ l.attr_writers # => List of updatable attributes
44
+ l.fields # => Array of all fields
45
45
 
46
46
  To retrieve an existing record:
47
47
 
@@ -70,6 +70,25 @@ Or for all quotes:
70
70
  pp quote.quote_name
71
71
  end
72
72
 
73
+ To get the first quote:
74
+ q.first
75
+
76
+ Or the last one:
77
+ q.last
78
+
79
+ Since the result is Enumerable:
80
+ q.map { |m| m.last_name }
81
+ works.
82
+
83
+ To sort a result set:
84
+ r = RubyZoho::Crm::Contact.all
85
+ sorted = r.sort {|a, b| a.last_name <=> b.last_name }
86
+ pp sorted.collect { |c| c.last_name }
87
+
88
+ To find by ID, note well, ID is a *string*:
89
+ leads = RubyZoho::Crm::Lead.all
90
+ l = RubyZoho::Crm::Lead.find_by_leadid(leads.last.leadid)
91
+
73
92
  To create a new record:
74
93
 
75
94
  c = RubyZoho::Crm::Contact.new(
@@ -80,7 +99,7 @@ To create a new record:
80
99
  )
81
100
  c.save
82
101
  r = RubyZoho::Crm::Contact.find_by_email('email@domain.com')
83
- r[0].contactid # => Has the newly created contact's ID
102
+ r.first.contactid # => Has the newly created contact's ID
84
103
 
85
104
 
86
105
  To add a contact to an existing account:
@@ -90,8 +109,8 @@ To add a contact to an existing account:
90
109
  :first_name => 'First Name',
91
110
  :last_name => 'Last Name',
92
111
  :email => 'email@domain.com',
93
- :account_name => a[0].account_name,
94
- :accountid => a[0].accountid # accountid instead of account_id because of Zoho's convention
112
+ :account_name => a.first.account_name,
113
+ :accountid => a.first.accountid # accountid instead of account_id because of Zoho's convention
95
114
  etc.
96
115
  )
97
116
  c.save
@@ -121,8 +140,13 @@ Please open an issue on GitHub. Or better yet, send in a pull request.
121
140
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
122
141
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
123
142
 
143
+ == Trademarks
144
+
145
+ Zoho, the Zoho suite and related applications are owned, trademarked and copyrighted by the Zoho Corporation Pvt. Ltd.
146
+ This software is not associated in anyway with the Zoho Corporation Pvt. Ltd.
147
+
148
+
124
149
  == Copyright
125
150
 
126
151
  Copyright (c) 2013 amalc. Released under the MIT license. See LICENSE.txt for
127
152
  further details.
128
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/lib/zoho_api.rb CHANGED
@@ -45,6 +45,20 @@ module ZohoApi
45
45
  row
46
46
  end
47
47
 
48
+ def attach_file(module_name, record_id, file_content)
49
+ pp module_name
50
+ pp record_id
51
+ pp file_content.size
52
+ r = self.class.post(create_url(module_name, 'uploadFile'),
53
+ :query => { :newFormat => 1, :authtoken => @auth_token,
54
+ :scope => 'crmapi',
55
+ :id => record_id, :content => Base64.encode64(file_content) },
56
+ :headers => { 'Content-length' => '0' })
57
+ pp r
58
+ raise('Adding record failed', RuntimeError, r.response.body.to_s) unless r.response.code == '200'
59
+ r.response.code
60
+ end
61
+
48
62
  def create_url(module_name, api_call)
49
63
  "https://crm.zoho.com/crm/private/xml/#{module_name}/#{api_call}"
50
64
  end
@@ -68,11 +82,25 @@ module ZohoApi
68
82
 
69
83
  def find_records(module_name, field, condition, value)
70
84
  sc_field = ApiUtils.symbol_to_string(field)
85
+ sc_field.rindex('id').nil? ? find_record_by_field(module_name, sc_field, condition, value) :
86
+ find_record_by_id(module_name, value)
87
+ end
88
+
89
+ def find_record_by_field(module_name, sc_field, condition, value)
71
90
  search_condition = '(' + sc_field + '|' + condition + '|' + value + ')'
72
91
  r = self.class.get(create_url("#{module_name}", 'getSearchRecords'),
92
+ :query => {:newFormat => 2, :authtoken => @auth_token, :scope => 'crmapi',
93
+ :selectColumns => 'All', :searchCondition => search_condition,
94
+ :fromIndex => 1, :toIndex => NUMBER_OF_RECORDS_TO_GET})
95
+ raise(RuntimeError, 'Bad query', "#{sc_field} #{condition} #{value}") unless r.body.index('<error>').nil?
96
+ x = REXML::Document.new(r.body).elements.to_a("/response/result/#{module_name}/row")
97
+ to_hash(x)
98
+ end
99
+
100
+ def find_record_by_id(module_name, id)
101
+ r = self.class.get(create_url("#{module_name}", 'getRecordById'),
73
102
  :query => { :newFormat => 2, :authtoken => @auth_token, :scope => 'crmapi',
74
- :selectColumns => 'All', :searchCondition => search_condition,
75
- :fromIndex => 1, :toIndex => NUMBER_OF_RECORDS_TO_GET })
103
+ :selectColumns => 'All', :id => id})
76
104
  raise(RuntimeError, 'Bad query', "#{sc_field} #{condition} #{value}") unless r.body.index('<error>').nil?
77
105
  x = REXML::Document.new(r.body).elements.to_a("/response/result/#{module_name}/row")
78
106
  to_hash(x)
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.0.3"
8
+ s.version = "0.0.4"
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-12"
12
+ s.date = "2013-02-13"
13
13
  s.description = ""
14
14
  s.email = ""
15
15
  s.extra_rdoc_files = [
@@ -30,9 +30,9 @@ 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.2.gem",
34
33
  "rubyzoho.gemspec",
35
34
  "spec/api_utils_spec.rb",
35
+ "spec/fixtures/sample.pdf",
36
36
  "spec/fixtures/sample_contact.xml",
37
37
  "spec/fixtures/sample_contact_search.xml",
38
38
  "spec/fixtures/sample_contacts.xml",
Binary file
@@ -93,6 +93,22 @@ describe RubyZoho::Crm do
93
93
  r.map { |r| r.class.should eq(RubyZoho::Crm::Quote) }
94
94
  end
95
95
 
96
+ it 'should find a contact by ID' do
97
+ contacts = RubyZoho::Crm::Contact.all
98
+ contact_id = contacts.first.contactid
99
+ c = RubyZoho::Crm::Contact.find_by_contactid(contact_id)
100
+ c.first.contactid.should eq(contact_id)
101
+ c.first.last_name.should eq(contacts.first.last_name)
102
+ c.first.email.should eq(contacts.first.email)
103
+ end
104
+
105
+ it 'should find a lead by ID' do
106
+ leads = RubyZoho::Crm::Lead.all
107
+ lead_id = leads.first.leadid
108
+ l = RubyZoho::Crm::Lead.find_by_leadid(lead_id)
109
+ l.first.leadid.should eq(lead_id)
110
+ end
111
+
96
112
  it 'should save a contact record' do
97
113
  c = RubyZoho::Crm::Contact.new(
98
114
  :first_name => 'Raj',
@@ -100,9 +116,16 @@ describe RubyZoho::Crm do
100
116
  :email => 'raj@portra.com')
101
117
  c.save
102
118
  r = RubyZoho::Crm::Contact.find_by_email('raj@portra.com')
119
+ r.first.email.should eq('raj@portra.com')
103
120
  r.each { |c| RubyZoho::Crm::Contact.delete(c.contactid) }
104
121
  end
105
122
 
123
+ it 'should sort contact records' do
124
+ r = RubyZoho::Crm::Contact.all
125
+ sorted = r.sort {|a, b| a.last_name <=> b.last_name }
126
+ sorted.collect { |c| c.last_name }.should_not eq(nil)
127
+ end
128
+
106
129
  it 'should save a lead record' do
107
130
  l = RubyZoho::Crm::Lead.new(
108
131
  :first_name => 'Raj',
@@ -24,6 +24,7 @@ describe ZohoApi do
24
24
  config_file = File.join(base_path, 'zoho_api_configuration.yaml')
25
25
  #params = YAML.load(File.open(config_file))
26
26
  #@zoho = ZohoApi::Crm.new(params['auth_token'])
27
+ @sample_pdf = File.join(base_path, 'sample.pdf')
27
28
  @zoho = ZohoApi::Crm.new('62cedfe9427caef8afb9ea3b5bf68154')
28
29
  end
29
30
 
@@ -42,6 +43,25 @@ describe ZohoApi do
42
43
  contact.count.should eq(1)
43
44
  end
44
45
 
46
+ it 'should attach a file to a contact record' do
47
+ pending
48
+ h = { :first_name => 'Robert',
49
+ :last_name => 'Smith',
50
+ :email => 'rsmith@smithereens.com',
51
+ :department => 'Waste Collection and Management',
52
+ :phone => '13452129087',
53
+ :mobile => '12341238790'
54
+ }
55
+ #@zoho.add_record('Contacts', h)
56
+ contact = @zoho.find_records('Contacts', :email, '=', h[:email])
57
+ pp contact[0][:contactid]
58
+ pp File.read(@sample_pdf).size
59
+ pp Base64.encode64(File.read(@sample_pdf)).size
60
+ @zoho.attach_file('Contacts', contact[0][:contactid],
61
+ File.read(@sample_pdf))
62
+ #@zoho.delete_record('Contacts', contact[0][:contactid])
63
+ end
64
+
45
65
  it 'should delete a contact record with id' do
46
66
  add_dummy_contact
47
67
  c = @zoho.find_records('Contacts', :email, '=', 'bob@smith.com')
@@ -55,6 +75,16 @@ describe ZohoApi do
55
75
  delete_dummy_contact
56
76
  end
57
77
 
78
+ it 'should find by module and id' do
79
+ add_dummy_contact
80
+ r = @zoho.find_records('Contacts', :email, '=', 'bob@smith.com')
81
+ r[0][:email].should eq('bob@smith.com')
82
+ id = r[0][:contactid]
83
+ c = @zoho.find_record_by_id('Contacts', id)
84
+ c[0][:contactid].should eq(id)
85
+ delete_dummy_contact
86
+ end
87
+
58
88
  it 'should get a list of fields for a module' do
59
89
  r = @zoho.fields('Contacts')
60
90
  r.count.should be >= 43
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.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-12 00:00:00.000000000 Z
12
+ date: 2013-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -208,9 +208,9 @@ files:
208
208
  - lib/api_utils.rb
209
209
  - lib/ruby_zoho.rb
210
210
  - lib/zoho_api.rb
211
- - rubyzoho-0.0.2.gem
212
211
  - rubyzoho.gemspec
213
212
  - spec/api_utils_spec.rb
213
+ - spec/fixtures/sample.pdf
214
214
  - spec/fixtures/sample_contact.xml
215
215
  - spec/fixtures/sample_contact_search.xml
216
216
  - spec/fixtures/sample_contacts.xml
data/rubyzoho-0.0.2.gem DELETED
Binary file