sugarcrm 0.9.11 → 0.9.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +11 -0
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/rails/generators/sugarcrm/config/config_generator.rb +22 -0
- data/lib/rails/generators/sugarcrm/config/templates/initializer.rb +4 -0
- data/lib/rails/generators/sugarcrm/config/templates/sugarcrm.yml +19 -0
- data/lib/sugarcrm.rb +1 -0
- data/lib/sugarcrm/associations/association_collection.rb +7 -0
- data/lib/sugarcrm/associations/associations.rb +5 -0
- data/lib/sugarcrm/attributes/attribute_methods.rb +17 -0
- data/lib/sugarcrm/base.rb +1 -1
- data/lib/sugarcrm/connection/api/get_available_modules.rb +1 -1
- data/lib/sugarcrm/connection/api/get_document_revision.rb +2 -2
- data/lib/sugarcrm/connection/api/get_entries.rb +1 -1
- data/lib/sugarcrm/connection/api/get_entries_count.rb +1 -1
- data/lib/sugarcrm/connection/api/get_entry.rb +1 -1
- data/lib/sugarcrm/connection/api/get_entry_list.rb +1 -1
- data/lib/sugarcrm/connection/api/get_module_fields.rb +1 -1
- data/lib/sugarcrm/connection/api/get_note_attachment.rb +1 -1
- data/lib/sugarcrm/connection/api/get_relationships.rb +2 -2
- data/lib/sugarcrm/connection/api/get_report_entries.rb +1 -1
- data/lib/sugarcrm/connection/api/get_user_id.rb +1 -1
- data/lib/sugarcrm/connection/api/get_user_team_id.rb +1 -1
- data/lib/sugarcrm/connection/api/logout.rb +1 -1
- data/lib/sugarcrm/connection/api/seamless_login.rb +1 -1
- data/lib/sugarcrm/connection/api/search_by_module.rb +1 -1
- data/lib/sugarcrm/connection/api/set_campaign_merge.rb +1 -1
- data/lib/sugarcrm/connection/api/set_document_revision.rb +18 -4
- data/lib/sugarcrm/connection/api/set_entries.rb +1 -1
- data/lib/sugarcrm/connection/api/set_entry.rb +1 -1
- data/lib/sugarcrm/connection/api/set_note_attachment.rb +1 -1
- data/lib/sugarcrm/connection/api/set_relationship.rb +1 -1
- data/lib/sugarcrm/connection/api/set_relationships.rb +1 -1
- data/lib/sugarcrm/connection/connection.rb +9 -5
- data/lib/sugarcrm/connection_pool.rb +162 -0
- data/lib/sugarcrm/exceptions.rb +1 -0
- data/lib/sugarcrm/module_methods.rb +3 -3
- data/lib/sugarcrm/session.rb +63 -28
- data/sugarcrm.gemspec +143 -0
- data/sugarcrm.tmproj +952 -0
- data/test/connection/test_login.rb +1 -2
- data/test/connection/test_set_document_revision.rb +28 -0
- data/test/helper.rb +1 -1
- data/test/test_connection_pool.rb +33 -0
- data/test/test_session.rb +33 -16
- data/test/test_sugarcrm.rb +2 -5
- metadata +71 -61
- data/.document +0 -5
- data/test/config_test.yaml +0 -15
data/README.rdoc
CHANGED
@@ -140,6 +140,17 @@ A less clunky way to interact with SugarCRM via REST.
|
|
140
140
|
}
|
141
141
|
)
|
142
142
|
|
143
|
+
== USING THE GEM WITH RAILS 3
|
144
|
+
|
145
|
+
Note: this gem requires Rails 3 as it depends on Active Support >= 3.
|
146
|
+
|
147
|
+
1. Add the sugarcrm gem to your Gemfile (sugarcrm gem version >= 0.9.12)
|
148
|
+
2. Run `bundle install`
|
149
|
+
4. Run `rails g sugarcrm:config`
|
150
|
+
5. Edit the configuration file in `config/sugarcrm.yml` to match your environment
|
151
|
+
|
152
|
+
Example app here: https://github.com/davidsulc/sugar_on_rails_basic
|
153
|
+
|
143
154
|
== USING A CONFIGURATION FILE
|
144
155
|
|
145
156
|
If you want to use a configuration file instead of always specifying the url, username, and password to connect to SugarCRM, you can add your credentials to one (or more) of
|
data/Rakefile
CHANGED
@@ -18,6 +18,7 @@ Jeweler::Tasks.new do |gem|
|
|
18
18
|
gem.homepage = "http://github.com/chicks/sugarcrm"
|
19
19
|
gem.authors = ["Carl Hicks", "David Sulc"]
|
20
20
|
gem.executables = ['sugarcrm']
|
21
|
+
gem.files = FileList['./lib/**/*', './*'].exclude("*.lock").to_a
|
21
22
|
end
|
22
23
|
Jeweler::RubygemsDotOrgTasks.new
|
23
24
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.12
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Sugarcrm
|
4
|
+
module Generators
|
5
|
+
class ConfigGenerator < Rails::Generators::Base
|
6
|
+
desc 'Creates a SugarCRM gem configuration file at config/sugarcrm.yml, and an initializer at config/initializers/sugarcrm.rb'
|
7
|
+
|
8
|
+
def self.source_root
|
9
|
+
@_sugarcrm_source_root ||= File.expand_path("../templates", __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_config_file
|
13
|
+
template 'sugarcrm.yml', File.join('config', 'sugarcrm.yml')
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_initializer_file
|
17
|
+
template 'initializer.rb', File.join('config', 'initializers', 'sugarcrm.rb')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,4 @@
|
|
1
|
+
# Load the values in config/sugarcrm.yml into a hash
|
2
|
+
config_values = SugarCRM::Session.parse_config_file(File.join(Rails.root, 'config', 'sugarcrm.yml'))
|
3
|
+
# Connect to appropriate SugarCRM instance (depending on Rails environment)
|
4
|
+
SugarCRM::Session.from_hash(config_values[Rails.env.to_sym])
|
@@ -0,0 +1,19 @@
|
|
1
|
+
development:
|
2
|
+
base_url: http://127.0.0.1/sugarcrm # where your SugarCRM instance is located
|
3
|
+
username: admin
|
4
|
+
password: letmein
|
5
|
+
# connection pool settings
|
6
|
+
# if you don't know what purpose this serves, you can safely ignore these settings
|
7
|
+
# works similarly to Rails' database connection pooling (documented here: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html)
|
8
|
+
# pool: 3 # the maximum number of simulatenous connections the gem should open with the SugarCRM server (default is 5)
|
9
|
+
# wait_timeout: 7 # maximum time to wait for an available connection to SugarCRM server, in seconds (default is 5)
|
10
|
+
|
11
|
+
test:
|
12
|
+
base_url: http://127.0.0.1/sugarcrm
|
13
|
+
username: admin
|
14
|
+
password: letmein
|
15
|
+
|
16
|
+
production:
|
17
|
+
base_url: http://127.0.0.1/sugarcrm
|
18
|
+
username: admin
|
19
|
+
password: letmein
|
data/lib/sugarcrm.rb
CHANGED
@@ -81,6 +81,13 @@ module SugarCRM
|
|
81
81
|
@collection.send(method_name.to_sym, *args, &block)
|
82
82
|
end
|
83
83
|
|
84
|
+
# respond correctly for delegated methods
|
85
|
+
def respond_to?(method_name)
|
86
|
+
load
|
87
|
+
return true if @collection.respond_to? method_name
|
88
|
+
super
|
89
|
+
end
|
90
|
+
|
84
91
|
def save
|
85
92
|
begin
|
86
93
|
save!
|
@@ -54,6 +54,10 @@ module SugarCRM; module AttributeMethods
|
|
54
54
|
false
|
55
55
|
end
|
56
56
|
|
57
|
+
def destroyed?
|
58
|
+
@attributes[:deleted]
|
59
|
+
end
|
60
|
+
|
57
61
|
def attributes_changed?
|
58
62
|
@modified_attributes.length > 0
|
59
63
|
end
|
@@ -62,11 +66,17 @@ module SugarCRM; module AttributeMethods
|
|
62
66
|
def new?
|
63
67
|
@attributes[:id].blank?
|
64
68
|
end
|
69
|
+
alias :new_record? :new?
|
65
70
|
|
66
71
|
# List the required attributes for save
|
67
72
|
def required_attributes
|
68
73
|
self.class._module.required_fields
|
69
74
|
end
|
75
|
+
alias :required_fields :required_attributes
|
76
|
+
|
77
|
+
def to_model
|
78
|
+
self
|
79
|
+
end
|
70
80
|
|
71
81
|
protected
|
72
82
|
|
@@ -99,6 +109,9 @@ module SugarCRM; module AttributeMethods
|
|
99
109
|
def #{k}=(value)
|
100
110
|
write_attribute :#{k},value
|
101
111
|
end
|
112
|
+
def #{k}\?
|
113
|
+
has_attribute\? :#{k}
|
114
|
+
end
|
102
115
|
?
|
103
116
|
end
|
104
117
|
self.class.attribute_methods_generated = true
|
@@ -158,5 +171,9 @@ module SugarCRM; module AttributeMethods
|
|
158
171
|
@attributes[key] = value
|
159
172
|
end
|
160
173
|
|
174
|
+
def has_attribute?(key)
|
175
|
+
@attributes.has_key? key
|
176
|
+
end
|
177
|
+
|
161
178
|
end; end
|
162
179
|
|
data/lib/sugarcrm/base.rb
CHANGED
@@ -154,7 +154,7 @@ module SugarCRM; class Base
|
|
154
154
|
params = {}
|
155
155
|
params[:id] = serialize_id
|
156
156
|
params[:deleted]= {:name => "deleted", :value => "1"}
|
157
|
-
(self.class.connection.set_entry(self.class._module.name, params).class == Hash)
|
157
|
+
@attributes[:deleted] = (self.class.connection.set_entry(self.class._module.name, params).class == Hash)
|
158
158
|
end
|
159
159
|
|
160
160
|
# Reloads the record from SugarCRM
|
@@ -10,7 +10,7 @@ module SugarCRM; class Connection
|
|
10
10
|
|
11
11
|
json = <<-EOF
|
12
12
|
{
|
13
|
-
"session": "#{@
|
13
|
+
"session": "#{@sugar_session_id}",
|
14
14
|
"module_name": "#{module_name}",
|
15
15
|
"ids": #{ids.to_json},
|
16
16
|
"select_fields": #{resolve_fields(module_name, options[:fields])},
|
@@ -8,12 +8,12 @@ module SugarCRM; class Connection
|
|
8
8
|
:query => '',
|
9
9
|
:fields => [],
|
10
10
|
:link_fields => [],
|
11
|
-
:deleted =>
|
11
|
+
:deleted => 0
|
12
12
|
}.merge! opts
|
13
13
|
|
14
14
|
json = <<-EOF
|
15
15
|
{
|
16
|
-
"session": "#{@
|
16
|
+
"session": "#{@sugar_session_id}",
|
17
17
|
"module_name": "#{module_name}",
|
18
18
|
"module_id": "#{id}",
|
19
19
|
"link_field_name": "#{related_to.downcase}",
|
@@ -1,12 +1,26 @@
|
|
1
1
|
module SugarCRM; class Connection
|
2
2
|
# Sets a new revision for a document.
|
3
|
-
def set_document_revision(
|
3
|
+
def set_document_revision(document_id, revision_number, opts={})
|
4
|
+
options = {
|
5
|
+
:file => '',
|
6
|
+
:file_name => ''
|
7
|
+
}.merge! opts
|
8
|
+
|
9
|
+
# Raise an exception of we try to pass :file, but not :file_name
|
10
|
+
if (!options[:file].empty? && options[:file_name].empty?)
|
11
|
+
raise ArgumentException, ":file_name must be specified if :file is specified"
|
12
|
+
end
|
13
|
+
|
4
14
|
login! unless logged_in?
|
5
15
|
json = <<-EOF
|
6
16
|
{
|
7
|
-
"session": "#{@
|
8
|
-
"document_revision":
|
9
|
-
|
17
|
+
"session": "#{@sugar_session_id}",
|
18
|
+
"document_revision": {
|
19
|
+
"id": "#{document_id}",
|
20
|
+
"filename": "#{options[:file_name]}",
|
21
|
+
"file": "#{Base64.encode64(options[:file])}",
|
22
|
+
"revision": "#{revision_number}"
|
23
|
+
}
|
10
24
|
}
|
11
25
|
EOF
|
12
26
|
json.gsub!(/^\s{6}/,'')
|
@@ -9,7 +9,7 @@ module SugarCRM; class Connection
|
|
9
9
|
raise ArgumentError, "related_ids must be an Array" unless related_ids.class == Array
|
10
10
|
json = <<-EOF
|
11
11
|
{
|
12
|
-
"session": "#{@
|
12
|
+
"session": "#{@sugar_session_id}",
|
13
13
|
"module_name": "#{module_name}",
|
14
14
|
"module_id": "#{module_id}",
|
15
15
|
"link_field_name": "#{link_field_name}",
|
@@ -9,7 +9,7 @@ module SugarCRM; class Connection
|
|
9
9
|
|
10
10
|
json = <<-EOF
|
11
11
|
{
|
12
|
-
"session": "#{@
|
12
|
+
"session": "#{@sugar_session_id}",
|
13
13
|
"module_names": "#{module_names.to_json}",
|
14
14
|
"module_ids": #{module_ids.to_json},
|
15
15
|
"link_field_names": #{link_field_names.to_json},
|
@@ -8,8 +8,8 @@ module SugarCRM; class Connection
|
|
8
8
|
attr :url, true
|
9
9
|
attr :user, false
|
10
10
|
attr :pass, false
|
11
|
-
attr :
|
12
|
-
|
11
|
+
attr :session, true
|
12
|
+
attr :sugar_session_id, true
|
13
13
|
attr :connection, true
|
14
14
|
attr :options, true
|
15
15
|
attr :request, true
|
@@ -29,21 +29,25 @@ module SugarCRM; class Connection
|
|
29
29
|
@response = ""
|
30
30
|
resolve_url
|
31
31
|
login!
|
32
|
-
@session.update_config({:base_url => url, :username => user, :password => pass}) if @session
|
33
32
|
self
|
34
33
|
end
|
35
34
|
|
36
35
|
# Check to see if we are logged in
|
37
36
|
def logged_in?
|
38
37
|
connect! unless connected?
|
39
|
-
@
|
38
|
+
@sugar_session_id ? true : false
|
40
39
|
end
|
41
40
|
|
42
41
|
# Login
|
43
42
|
def login!
|
44
|
-
@
|
43
|
+
@sugar_session_id = login["id"]
|
45
44
|
raise SugarCRM::LoginError, "Invalid Login" unless logged_in?
|
46
45
|
end
|
46
|
+
|
47
|
+
def logout
|
48
|
+
logout
|
49
|
+
@sugar_session_id = nil
|
50
|
+
end
|
47
51
|
|
48
52
|
# Check to see if we are connected
|
49
53
|
def connected?
|