sugarcrm 0.6.2 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -8
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/sugarcrm.rb +7 -139
- data/lib/sugarcrm/association_methods.rb +45 -0
- data/lib/sugarcrm/attribute_methods.rb +65 -0
- data/lib/sugarcrm/base.rb +85 -0
- data/lib/sugarcrm/connection.rb +126 -103
- data/lib/sugarcrm/{api → connection/api}/get_available_modules.rb +6 -1
- data/lib/sugarcrm/{api → connection/api}/get_document_revision.rb +2 -1
- data/lib/sugarcrm/{api → connection/api}/get_entries.rb +5 -6
- data/lib/sugarcrm/{api → connection/api}/get_entries_count.rb +3 -5
- data/lib/sugarcrm/{api → connection/api}/get_entry.rb +6 -6
- data/lib/sugarcrm/{api → connection/api}/get_entry_list.rb +6 -6
- data/lib/sugarcrm/{api → connection/api}/get_module_fields.rb +2 -1
- data/lib/sugarcrm/{api → connection/api}/get_note_attachment.rb +1 -1
- data/lib/sugarcrm/connection/api/get_relationships.rb +34 -0
- data/lib/sugarcrm/{api → connection/api}/get_report_entries.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/get_server_info.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/get_user_id.rb +2 -2
- data/lib/sugarcrm/{api → connection/api}/get_user_team_id.rb +2 -2
- data/lib/sugarcrm/{api → connection/api}/login.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/logout.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/seamless_login.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/search_by_module.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/set_campaign_merge.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/set_document_revision.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/set_entries.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/set_entry.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/set_note_attachment.rb +0 -0
- data/lib/sugarcrm/{api → connection/api}/set_relationship.rb +1 -1
- data/lib/sugarcrm/{api → connection/api}/set_relationships.rb +1 -1
- data/lib/sugarcrm/connection/helper.rb +10 -0
- data/lib/sugarcrm/exceptions.rb +6 -0
- data/lib/sugarcrm/module.rb +105 -6
- data/lib/sugarcrm/module_methods.rb +18 -0
- data/lib/sugarcrm/request.rb +13 -3
- data/lib/sugarcrm/response.rb +75 -25
- data/test/connection/test_get_available_modules.rb +12 -0
- data/test/connection/test_get_entries.rb +21 -0
- data/test/connection/test_get_entry.rb +20 -0
- data/test/connection/test_get_entry_list.rb +28 -0
- data/test/connection/test_get_module_fields.rb +14 -0
- data/test/connection/test_get_relationships.rb +15 -0
- data/test/connection/test_get_server_info.rb +12 -0
- data/test/connection/test_get_user_id.rb +12 -0
- data/test/connection/test_get_user_team_id.rb +12 -0
- data/test/connection/test_login.rb +12 -0
- data/test/connection/test_logout.rb +12 -0
- data/test/helper.rb +4 -1
- data/test/test_connection.rb +12 -48
- data/test/test_module.rb +14 -0
- data/test/test_response.rb +5 -14
- data/test/test_sugarcrm.rb +16 -14
- metadata +60 -34
- data/lib/sugarcrm/api/get_relationship.rb +0 -25
- data/lib/sugarcrm/core_ext/attribute.rb +0 -67
- data/lib/sugarcrm/core_ext/remove_method.rb +0 -6
- data/lib/sugarcrm/core_ext/singleton_class.rb +0 -13
@@ -9,7 +9,12 @@ module SugarCRM; class Connection
|
|
9
9
|
EOF
|
10
10
|
|
11
11
|
json.gsub!(/^\s{6}/,'')
|
12
|
-
|
12
|
+
mods = send!(:get_available_modules, json)["modules"]
|
13
|
+
modules = []
|
14
|
+
mods.each do |mod|
|
15
|
+
modules << Module.new(mod)
|
16
|
+
end
|
17
|
+
modules
|
13
18
|
end
|
14
19
|
|
15
20
|
alias :get_modules :get_available_modules
|
@@ -1,23 +1,22 @@
|
|
1
1
|
module SugarCRM; class Connection
|
2
2
|
# Retrieve a list of SugarBeans by ID. This method will not
|
3
3
|
# work with the report module.
|
4
|
-
def get_entries(module_name, ids,
|
4
|
+
def get_entries(module_name, ids, opts={})
|
5
5
|
login! unless logged_in?
|
6
|
-
{
|
7
|
-
:fields => '',
|
6
|
+
options = { :fields => [],
|
8
7
|
:link_fields => [],
|
9
|
-
}.merge!
|
8
|
+
}.merge! opts
|
10
9
|
|
11
10
|
json = <<-EOF
|
12
11
|
{
|
13
12
|
\"session\": \"#{@session}\"\,
|
14
13
|
\"module_name\": \"#{module_name}\"\,
|
15
14
|
\"ids\": #{ids.to_json}\,
|
16
|
-
\"select_fields\": #{options[:fields]
|
15
|
+
\"select_fields\": #{resolve_fields(module_name, options[:fields])}\,
|
17
16
|
\"link_name_to_fields_array\": #{options[:link_fields].to_json}\,
|
18
17
|
}
|
19
18
|
EOF
|
20
19
|
json.gsub!(/^\s{6}/,'')
|
21
|
-
|
20
|
+
SugarCRM::Response.handle(send!(:get_entries, json))
|
22
21
|
end
|
23
22
|
end; end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module SugarCRM; class Connection
|
2
2
|
# Retrieves the specified number of records in a module.
|
3
|
-
def get_entries_count(module_name, query,
|
3
|
+
def get_entries_count(module_name, query, opts={})
|
4
4
|
login! unless logged_in?
|
5
|
-
{
|
6
|
-
:deleted => 0,
|
7
|
-
}.merge! options
|
5
|
+
options = {:deleted => 0}.merge! opts
|
8
6
|
|
9
7
|
json = <<-EOF
|
10
8
|
{
|
@@ -15,6 +13,6 @@ def get_entries_count(module_name, query, options={})
|
|
15
13
|
}
|
16
14
|
EOF
|
17
15
|
json.gsub!(/^\s{6}/,'')
|
18
|
-
|
16
|
+
send!(:get_entries_count, json)
|
19
17
|
end
|
20
18
|
end; end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module SugarCRM; class Connection
|
2
2
|
# Retrieves a single SugarBean based on the ID.
|
3
|
-
def get_entry(module_name, id,
|
3
|
+
def get_entry(module_name, id, opts={})
|
4
4
|
login! unless logged_in?
|
5
|
-
{ :fields => [],
|
5
|
+
options = { :fields => [],
|
6
6
|
:link_fields => [],
|
7
|
-
}.merge!
|
8
|
-
|
7
|
+
}.merge! opts
|
8
|
+
|
9
9
|
json = <<-EOF
|
10
10
|
{
|
11
11
|
\"session\": \"#{@session}\"\,
|
12
12
|
\"module_name\": \"#{module_name}\"\,
|
13
13
|
\"id\": \"#{id}\"\,
|
14
|
-
\"select_fields\": #{options[:fields]
|
14
|
+
\"select_fields\": #{resolve_fields(module_name, options[:fields])}\,
|
15
15
|
\"link_name_to_fields_array\": #{options[:link_fields]}\,
|
16
16
|
}
|
17
17
|
EOF
|
18
18
|
|
19
19
|
json.gsub!(/^\s{6}/,'')
|
20
|
-
SugarCRM::Response.
|
20
|
+
SugarCRM::Response.handle(send!(:get_entry, json))
|
21
21
|
end
|
22
22
|
end; end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module SugarCRM; class Connection
|
2
2
|
# Retrieve a list of SugarBeans. This is the primary method for getting
|
3
3
|
# a list of SugarBeans using the REST API.
|
4
|
-
def get_entry_list(module_name, query,
|
4
|
+
def get_entry_list(module_name, query, opts={})
|
5
5
|
login! unless logged_in?
|
6
|
-
{
|
6
|
+
options = {
|
7
7
|
:order_by => '',
|
8
8
|
:offset => '',
|
9
|
-
:fields =>
|
9
|
+
:fields => [],
|
10
10
|
:link_fields => [],
|
11
11
|
:max_results => '',
|
12
12
|
:deleted => ''
|
13
|
-
}.merge!
|
13
|
+
}.merge! opts
|
14
14
|
|
15
15
|
json = <<-EOF
|
16
16
|
{
|
@@ -19,13 +19,13 @@ def get_entry_list(module_name, query, options={})
|
|
19
19
|
\"query\": \"#{query}\"\,
|
20
20
|
\"order_by\": \"#{options[:order_by]}\"\,
|
21
21
|
\"offset\": \"#{options[:offset]}\"\,
|
22
|
-
\"select_fields\": #{options[:fields]
|
22
|
+
\"select_fields\": #{resolve_fields(module_name, options[:fields])}\,
|
23
23
|
\"link_name_to_fields_array\": #{options[:link_fields].to_json}\,
|
24
24
|
\"max_results\": \"#{options[:max_results]}\"\,
|
25
25
|
\"deleted\": #{options[:deleted]}
|
26
26
|
}
|
27
27
|
EOF
|
28
28
|
json.gsub!(/^\s{6}/,'')
|
29
|
-
|
29
|
+
SugarCRM::Response.handle(send!(:get_entry_list, json))
|
30
30
|
end
|
31
31
|
end; end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SugarCRM; class Connection
|
2
|
+
# Retrieves a collection of beans that are related
|
3
|
+
# to the specified bean and, optionally, returns
|
4
|
+
# relationship data
|
5
|
+
def get_relationships(module_name, id, related_to, opts={})
|
6
|
+
login! unless logged_in?
|
7
|
+
options = {
|
8
|
+
:query => '',
|
9
|
+
:fields => [],
|
10
|
+
:link_fields => [],
|
11
|
+
:deleted => ''
|
12
|
+
}.merge! opts
|
13
|
+
|
14
|
+
related_module = related_to.classify
|
15
|
+
|
16
|
+
json = <<-EOF
|
17
|
+
{
|
18
|
+
\"session\": \"#{@session}\"\,
|
19
|
+
\"module_name\": \"#{module_name}\"\,
|
20
|
+
\"module_id\": \"#{id}\"\,
|
21
|
+
\"link_field_name\": \"#{related_to.downcase}\"\,
|
22
|
+
\"related_module_query\": \"#{options[:query]}\"\,
|
23
|
+
\"related_fields\": #{resolve_fields(related_module, options[:fields])}\,
|
24
|
+
\"related_module_link_name_to_fields_array\": #{options[:link_fields].to_json}\,
|
25
|
+
\"deleted\": #{options[:deleted]}
|
26
|
+
}
|
27
|
+
EOF
|
28
|
+
json.gsub!(/^\s{6}/,'')
|
29
|
+
SugarCRM::Response.new(send!(:get_relationships, json)).to_obj
|
30
|
+
end
|
31
|
+
|
32
|
+
alias :get_relationship :get_relationships
|
33
|
+
|
34
|
+
end; end
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module SugarCRM; class Connection
|
2
|
+
def resolve_fields(module_name, fields)
|
3
|
+
# FIXME: This is to work around a bug in SugarCRM 6.0
|
4
|
+
# where no fields are returned if no fields are specified
|
5
|
+
if fields.length == 0
|
6
|
+
fields = Module.find(module_name).fields.keys
|
7
|
+
end
|
8
|
+
return fields.to_json
|
9
|
+
end
|
10
|
+
end; end
|
data/lib/sugarcrm/exceptions.rb
CHANGED
data/lib/sugarcrm/module.rb
CHANGED
@@ -1,11 +1,110 @@
|
|
1
1
|
module SugarCRM
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
# A class for handling SugarCRM Modules
|
3
|
+
class Module
|
4
|
+
attr :name, false
|
5
|
+
attr :klass, false
|
6
|
+
attr :fields, false
|
7
|
+
attr :link_fields, false
|
8
|
+
|
9
|
+
# Dynamically register objects based on Module name
|
10
|
+
# I.e. a SugarCRM Module named Users will generate
|
11
|
+
# a SugarCRM::User class.
|
12
|
+
def initialize(name)
|
13
|
+
@name = name
|
14
|
+
@klass = name.classify
|
15
|
+
@fields = {}
|
16
|
+
@link_fields = {}
|
17
|
+
@fields_registered = false
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def fields
|
22
|
+
return @fields if fields?
|
23
|
+
all_fields = SugarCRM.connection.get_fields(@name)
|
24
|
+
@fields = all_fields["module_fields"]
|
25
|
+
@link_fields= all_fields["link_fields"]
|
26
|
+
@fields_registered = true
|
27
|
+
@fields
|
28
|
+
end
|
29
|
+
|
30
|
+
def fields?
|
31
|
+
@fields_registered
|
32
|
+
end
|
33
|
+
|
34
|
+
def link_fields
|
35
|
+
self.fields unless link_fields?
|
36
|
+
handle_empty_array
|
37
|
+
@link_fields
|
38
|
+
end
|
39
|
+
|
40
|
+
def link_fields?
|
41
|
+
@fields_registered
|
42
|
+
end
|
43
|
+
|
44
|
+
def handle_empty_array
|
45
|
+
if @link_fields.class == Array && @link_fields.length == 0
|
46
|
+
@link_fields = {}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Registers a single module by name
|
51
|
+
# Adds module to SugarCRM.modules (SugarCRM.modules << Module.new("Users"))
|
52
|
+
# Adds module class to SugarCRM parent module (SugarCRM.constants << User)
|
53
|
+
# Note, SugarCRM::User.module == Module.find("Users")
|
54
|
+
def register
|
55
|
+
return self if registered?
|
56
|
+
mod_instance = self
|
57
|
+
# class Class < SugarCRM::Base
|
58
|
+
# module_name = "Accounts"
|
59
|
+
# end
|
60
|
+
klass = Class.new(SugarCRM::Base) do
|
61
|
+
self._module = mod_instance
|
62
|
+
end
|
63
|
+
|
64
|
+
# class Account < SugarCRM::Base
|
65
|
+
SugarCRM.const_set self.klass, klass
|
66
|
+
self
|
8
67
|
end
|
9
68
|
|
69
|
+
def registered?
|
70
|
+
SugarCRM.const_defined? @klass
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_s
|
74
|
+
@name
|
75
|
+
end
|
76
|
+
|
77
|
+
def to_class
|
78
|
+
SugarCRM.const_get(@klass).new
|
79
|
+
end
|
80
|
+
|
81
|
+
class << self
|
82
|
+
@initialized = false
|
83
|
+
|
84
|
+
# Registers all of the SugarCRM Modules
|
85
|
+
def register_all
|
86
|
+
SugarCRM.connection.get_modules.each do |m|
|
87
|
+
SugarCRM.modules << m.register
|
88
|
+
end
|
89
|
+
@initialized = true
|
90
|
+
true
|
91
|
+
end
|
92
|
+
|
93
|
+
# Finds a module by name, or klass name
|
94
|
+
def find(name)
|
95
|
+
register_all unless initialized?
|
96
|
+
SugarCRM.modules.each do |m|
|
97
|
+
return m if m.name == name
|
98
|
+
return m if m.klass == name
|
99
|
+
end
|
100
|
+
false
|
101
|
+
end
|
102
|
+
|
103
|
+
# Class variable to track if we've initialized or not
|
104
|
+
def initialized?
|
105
|
+
@initialized ||= false
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
10
109
|
end
|
11
110
|
end
|