sugarcrm_emp 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +29 -0
- data/Gemfile +14 -0
- data/LICENSE +20 -0
- data/README.rdoc +275 -0
- data/Rakefile +44 -0
- data/VERSION +1 -0
- data/WATCHLIST.rdoc +7 -0
- data/bin/sugarcrm +26 -0
- 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/associations/association.rb +170 -0
- data/lib/sugarcrm/associations/association_cache.rb +36 -0
- data/lib/sugarcrm/associations/association_collection.rb +141 -0
- data/lib/sugarcrm/associations/association_methods.rb +91 -0
- data/lib/sugarcrm/associations/associations.rb +61 -0
- data/lib/sugarcrm/associations.rb +5 -0
- data/lib/sugarcrm/attributes/attribute_methods.rb +203 -0
- data/lib/sugarcrm/attributes/attribute_serializers.rb +55 -0
- data/lib/sugarcrm/attributes/attribute_typecast.rb +44 -0
- data/lib/sugarcrm/attributes/attribute_validations.rb +62 -0
- data/lib/sugarcrm/attributes.rb +4 -0
- data/lib/sugarcrm/base.rb +355 -0
- data/lib/sugarcrm/config/sugarcrm.yaml +10 -0
- data/lib/sugarcrm/connection/api/get_available_modules.rb +22 -0
- data/lib/sugarcrm/connection/api/get_document_revision.rb +14 -0
- data/lib/sugarcrm/connection/api/get_entries.rb +23 -0
- data/lib/sugarcrm/connection/api/get_entries_count.rb +20 -0
- data/lib/sugarcrm/connection/api/get_entry.rb +23 -0
- data/lib/sugarcrm/connection/api/get_entry_list.rb +31 -0
- data/lib/sugarcrm/connection/api/get_module_fields.rb +15 -0
- data/lib/sugarcrm/connection/api/get_note_attachment.rb +14 -0
- data/lib/sugarcrm/connection/api/get_relationships.rb +30 -0
- data/lib/sugarcrm/connection/api/get_report_entries.rb +17 -0
- data/lib/sugarcrm/connection/api/get_server_info.rb +7 -0
- data/lib/sugarcrm/connection/api/get_user_id.rb +13 -0
- data/lib/sugarcrm/connection/api/get_user_team_id.rb +14 -0
- data/lib/sugarcrm/connection/api/login.rb +18 -0
- data/lib/sugarcrm/connection/api/logout.rb +15 -0
- data/lib/sugarcrm/connection/api/seamless_login.rb +13 -0
- data/lib/sugarcrm/connection/api/search_by_module.rb +25 -0
- data/lib/sugarcrm/connection/api/set_campaign_merge.rb +15 -0
- data/lib/sugarcrm/connection/api/set_document_revision.rb +35 -0
- data/lib/sugarcrm/connection/api/set_entries.rb +15 -0
- data/lib/sugarcrm/connection/api/set_entry.rb +15 -0
- data/lib/sugarcrm/connection/api/set_note_attachment.rb +25 -0
- data/lib/sugarcrm/connection/api/set_relationship.rb +27 -0
- data/lib/sugarcrm/connection/api/set_relationships.rb +22 -0
- data/lib/sugarcrm/connection/connection.rb +201 -0
- data/lib/sugarcrm/connection/helper.rb +50 -0
- data/lib/sugarcrm/connection/request.rb +61 -0
- data/lib/sugarcrm/connection/response.rb +91 -0
- data/lib/sugarcrm/connection.rb +5 -0
- data/lib/sugarcrm/connection_pool.rb +163 -0
- data/lib/sugarcrm/exceptions.rb +23 -0
- data/lib/sugarcrm/extensions/README.txt +23 -0
- data/lib/sugarcrm/finders/dynamic_finder_match.rb +41 -0
- data/lib/sugarcrm/finders/finder_methods.rb +243 -0
- data/lib/sugarcrm/finders.rb +2 -0
- data/lib/sugarcrm/module.rb +174 -0
- data/lib/sugarcrm/module_methods.rb +91 -0
- data/lib/sugarcrm/session.rb +218 -0
- data/lib/sugarcrm.rb +22 -0
- data/sugarcrm.gemspec +178 -0
- data/test/config_test.yaml +15 -0
- data/test/connection/test_get_available_modules.rb +9 -0
- data/test/connection/test_get_entries.rb +15 -0
- data/test/connection/test_get_entry.rb +22 -0
- data/test/connection/test_get_entry_list.rb +23 -0
- data/test/connection/test_get_module_fields.rb +11 -0
- data/test/connection/test_get_relationships.rb +12 -0
- data/test/connection/test_get_server_info.rb +9 -0
- data/test/connection/test_get_user_id.rb +9 -0
- data/test/connection/test_get_user_team_id.rb +9 -0
- data/test/connection/test_login.rb +9 -0
- data/test/connection/test_logout.rb +9 -0
- data/test/connection/test_set_document_revision.rb +28 -0
- data/test/connection/test_set_entry.rb +15 -0
- data/test/connection/test_set_note_attachment.rb +16 -0
- data/test/connection/test_set_relationship.rb +18 -0
- data/test/extensions_test/patch.rb +9 -0
- data/test/helper.rb +17 -0
- data/test/test_association_collection.rb +11 -0
- data/test/test_associations.rb +156 -0
- data/test/test_connection.rb +13 -0
- data/test/test_connection_pool.rb +40 -0
- data/test/test_finders.rb +201 -0
- data/test/test_module.rb +51 -0
- data/test/test_request.rb +35 -0
- data/test/test_response.rb +26 -0
- data/test/test_session.rb +136 -0
- data/test/test_sugarcrm.rb +213 -0
- metadata +266 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
module SugarCRM
|
2
|
+
# store the namespaces that have been used to prevent namespace collision
|
3
|
+
@@used_namespaces = []
|
4
|
+
def self.used_namespaces
|
5
|
+
@@used_namespaces
|
6
|
+
end
|
7
|
+
|
8
|
+
# return the namespaces linked to active sessions
|
9
|
+
def self.namespaces
|
10
|
+
result = []
|
11
|
+
@@used_namespaces.each{|n|
|
12
|
+
result << n if SugarCRM.const_defined? n
|
13
|
+
}
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
# store the various connected sessions
|
18
|
+
# key = session.object_id, value = session instance
|
19
|
+
@@sessions = {}
|
20
|
+
def self.sessions
|
21
|
+
@@sessions
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.add_session(session)
|
25
|
+
@@used_namespaces << session.namespace unless @@used_namespaces.include? session.namespace
|
26
|
+
@@sessions[session.object_id] = session
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.remove_session(session)
|
30
|
+
@@sessions.delete(session.object_id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.session
|
34
|
+
return nil if @@sessions.size < 1
|
35
|
+
(raise SugarCRM::MultipleSessions, "There are multiple active sessions: use the session namespace instead of SugarCRM") if @@sessions.size > 1
|
36
|
+
@@sessions.values.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.connection
|
40
|
+
return nil unless self.session
|
41
|
+
self.session.connection
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.connect(url, user, pass, options={})
|
45
|
+
session = SugarCRM::Session.new(url, user, pass, options)
|
46
|
+
# return the namespace module
|
47
|
+
session.namespace_const
|
48
|
+
end
|
49
|
+
|
50
|
+
class << self
|
51
|
+
alias :connect! :connect
|
52
|
+
end
|
53
|
+
|
54
|
+
def respond_to?(sym)
|
55
|
+
return true if @@sessions.size == 1 && SugarCRM.session.namespace_const.respond_to?(sym)
|
56
|
+
super
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.method_missing(sym, *args, &block)
|
60
|
+
(raise SugarCRM::NoActiveSession, "No session is active. Create a new session with 'SugarCRM.connect(...)'") if @@sessions.size < 1
|
61
|
+
(raise SugarCRM::MultipleSessions, "There are multiple active sessions: call methods on the session namespace instead of SugarCRM") if @@sessions.size > 1
|
62
|
+
if SugarCRM.session.namespace_const.respond_to? sym
|
63
|
+
SugarCRM.session.namespace_const.send(sym, *args, &block)
|
64
|
+
else
|
65
|
+
super
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# If a user tries to access a SugarCRM class before they're logged in,
|
70
|
+
# try to log in using credentials from config file.
|
71
|
+
# This will trigger module loading,
|
72
|
+
# and we can then attempt to return the requested class automagically
|
73
|
+
def self.const_missing(sym)
|
74
|
+
(raise SugarCRM::MultipleSessions, "There are multiple active sessions: use the session namespace instead of SugarCRM") if @@sessions.size > 1
|
75
|
+
# make sure we have an active session
|
76
|
+
begin
|
77
|
+
Session.new unless SugarCRM.connection && SugarCRM.connection.logged_in?
|
78
|
+
rescue SugarCRM::MissingCredentials => e
|
79
|
+
# unable to load necessary login credentials from config file => pass exception on
|
80
|
+
super
|
81
|
+
end
|
82
|
+
|
83
|
+
# if user calls (e.g.) SugarCRM::Account, delegate to SugarCRM::Namespace0::Account
|
84
|
+
namespace_const = SugarCRM.session.namespace_const
|
85
|
+
if namespace_const.const_defined? sym
|
86
|
+
namespace_const.const_get(sym)
|
87
|
+
else
|
88
|
+
super
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
# This class hold an individual connection to a SugarCRM server.
|
2
|
+
# There can be several such simultaneous connections
|
3
|
+
module SugarCRM; class Session
|
4
|
+
attr_reader :config, :connection_pool, :extensions_path, :namespace, :namespace_const
|
5
|
+
attr_accessor :modules
|
6
|
+
def initialize(url, user, pass, opts={})
|
7
|
+
options = {
|
8
|
+
:debug => false,
|
9
|
+
:register_modules => true
|
10
|
+
}.merge(opts)
|
11
|
+
|
12
|
+
@modules = []
|
13
|
+
@namespace = "Namespace#{SugarCRM.used_namespaces.size}"
|
14
|
+
@config = {:base_url => url,:username => user,:password => pass,:options => options}
|
15
|
+
@extensions_path = File.join(File.dirname(__FILE__), 'extensions')
|
16
|
+
|
17
|
+
setup_connection
|
18
|
+
register_namespace
|
19
|
+
connect(@config[:base_url], @config[:username], @config[:password], @config[:options])
|
20
|
+
end
|
21
|
+
|
22
|
+
# Creates a new session from the credentials present in a file
|
23
|
+
def self.from_file(path, opts={})
|
24
|
+
config_values = self.parse_config_file(path)
|
25
|
+
self.from_hash(config_values[:config], opts)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Creates a new session from the credentials in the hash
|
29
|
+
def self.from_hash(hash, opts={})
|
30
|
+
pool_options = parse_connection_pool_options(hash)
|
31
|
+
options = opts
|
32
|
+
(options = {:connection_pool => pool_options}.merge(opts)) if pool_options.size > 0
|
33
|
+
|
34
|
+
begin
|
35
|
+
session = self.new(hash[:base_url], hash[:username], hash[:password], options)
|
36
|
+
rescue MissingCredentials => e
|
37
|
+
return false
|
38
|
+
end
|
39
|
+
session.namespace_const
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns a hash with the content in the YAML argument file
|
43
|
+
def self.parse_config_file(path)
|
44
|
+
self.validate_path path
|
45
|
+
contents = YAML.load_file(path)
|
46
|
+
return {} unless contents
|
47
|
+
self.symbolize_keys(contents)
|
48
|
+
end
|
49
|
+
|
50
|
+
def setup_connection
|
51
|
+
load_config_files unless connection_info_loaded?
|
52
|
+
raise MissingCredentials, "Missing login credentials. Make sure you provide the SugarCRM URL, username, and password" unless connection_info_loaded?
|
53
|
+
end
|
54
|
+
|
55
|
+
def connect(url=nil, user=nil, pass=nil, opts={})
|
56
|
+
options = {
|
57
|
+
:debug => @config[:options][:debug],
|
58
|
+
:register_modules => true
|
59
|
+
}.merge(opts)
|
60
|
+
|
61
|
+
# store the params used to connect
|
62
|
+
{:base_url => url, :username => user, :password => pass}.each{|k,v|
|
63
|
+
@config[k] = v unless v.nil?
|
64
|
+
}
|
65
|
+
|
66
|
+
SugarCRM::Module.deregister_all(self)
|
67
|
+
@connection_pool = SugarCRM::ConnectionPool.new(self)
|
68
|
+
SugarCRM::Module.register_all(self)
|
69
|
+
SugarCRM.add_session(self)
|
70
|
+
load_extensions
|
71
|
+
true
|
72
|
+
end
|
73
|
+
alias :connect! :connect
|
74
|
+
|
75
|
+
# Re-uses this session and namespace if the user wants to connect with different credentials
|
76
|
+
def reconnect(url=nil, user=nil, pass=nil, opts={})
|
77
|
+
@connection_pool.disconnect!
|
78
|
+
connect(url, user, pass, opts)
|
79
|
+
end
|
80
|
+
alias :reconnect! :reconnect
|
81
|
+
alias :reload! :reconnect
|
82
|
+
|
83
|
+
# log out from SugarCRM and cleanup (deregister modules, remove session, etc.)
|
84
|
+
def disconnect
|
85
|
+
@connection_pool.disconnect!
|
86
|
+
SugarCRM::Module.deregister_all(self)
|
87
|
+
namespace = @namespace
|
88
|
+
SugarCRM.instance_eval{ remove_const namespace } # remove NamespaceX from SugarCRM
|
89
|
+
SugarCRM.remove_session(self)
|
90
|
+
end
|
91
|
+
alias :disconnect! :disconnect
|
92
|
+
|
93
|
+
# Returns a connection from the connection pool, if available
|
94
|
+
def connection
|
95
|
+
@connection_pool.connection
|
96
|
+
end
|
97
|
+
|
98
|
+
def extensions_folder=(folder, dirstring=nil)
|
99
|
+
path = File.expand_path(folder, dirstring)
|
100
|
+
@extensions_path = path
|
101
|
+
load_extensions
|
102
|
+
end
|
103
|
+
|
104
|
+
# load credentials from file, and (re)connect to SugarCRM
|
105
|
+
def load_config(path, opts = {})
|
106
|
+
opts.reverse_merge! :reconnect => true
|
107
|
+
new_config = self.class.parse_config_file(path)
|
108
|
+
update_config(new_config[:config]) if new_config and new_config[:config]
|
109
|
+
reconnect(@config[:base_url], @config[:username], @config[:password]) if opts[:reconnect] and connection_info_loaded?
|
110
|
+
@config
|
111
|
+
end
|
112
|
+
|
113
|
+
def update_config(params)
|
114
|
+
params.each{ |k,v| @config[k.to_sym] = v }
|
115
|
+
@config
|
116
|
+
end
|
117
|
+
|
118
|
+
# lazy load the SugarCRM version we're connecting to
|
119
|
+
def sugar_version
|
120
|
+
@version ||= connection.get_server_info["version"]
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
# Converts all hash keys to symbols (if a hash value is itself a hash, call the method recursively)
|
125
|
+
# Session.symbolize_keys({"one" => 1, "two" => {"foo" => "bar"}}) # => {:one => 1, :two => {:foo => "bar"}}
|
126
|
+
def self.symbolize_keys(hash)
|
127
|
+
hash.inject({}){|memo,(k,v)|
|
128
|
+
unless v.class == Hash
|
129
|
+
memo[k.to_sym] = v
|
130
|
+
else
|
131
|
+
memo[k.to_sym] = self.symbolize_keys(v)
|
132
|
+
end
|
133
|
+
memo
|
134
|
+
}
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.validate_path(path)
|
138
|
+
raise "Invalid path: #{path}" unless File.exists? path
|
139
|
+
end
|
140
|
+
|
141
|
+
def config_file_paths
|
142
|
+
# see README for reasoning behind the priorization
|
143
|
+
paths = ['/etc/sugarcrm.yaml', File.expand_path('~/.sugarcrm.yaml'), File.join(File.dirname(__FILE__), 'config', 'sugarcrm.yaml')]
|
144
|
+
paths.insert(1, File.join(ENV['USERPROFILE'], 'sugarcrm.yaml')) if ENV['USERPROFILE']
|
145
|
+
paths
|
146
|
+
end
|
147
|
+
|
148
|
+
def connection_info_loaded?
|
149
|
+
return false unless @config
|
150
|
+
@config[:base_url] && @config[:username] && @config[:password]
|
151
|
+
end
|
152
|
+
|
153
|
+
def generate_namespace_module
|
154
|
+
# Create a new module to have a separate namespace in which to register the SugarCRM modules.
|
155
|
+
# This will prevent issues with modules from separate SugarCRM instances colliding within the same namespace
|
156
|
+
# (e.g. 2 SugarCRM instances where only one has custom fields on the Account module)
|
157
|
+
namespace_module = Object::Module.new do
|
158
|
+
@session = nil
|
159
|
+
def self.session
|
160
|
+
@session
|
161
|
+
end
|
162
|
+
def self.session=(sess)
|
163
|
+
@session = sess
|
164
|
+
end
|
165
|
+
def self.current_user
|
166
|
+
(@session.namespace_const)::User.find_by_user_name(@session.config[:username])
|
167
|
+
end
|
168
|
+
def self.respond_to?(sym)
|
169
|
+
return true if @session.respond_to? sym
|
170
|
+
super
|
171
|
+
end
|
172
|
+
def self.method_missing(sym, *args, &block)
|
173
|
+
raise unless @session.respond_to? sym
|
174
|
+
@session.send(sym, *args, &block)
|
175
|
+
end
|
176
|
+
|
177
|
+
if RUBY_VERSION > '1.9'
|
178
|
+
# In Ruby 1.9 and above, constants are no longer lexically scoped;
|
179
|
+
# By default, const_defined? will check up the ancestor chain, which
|
180
|
+
# is *not* desirable in our case.
|
181
|
+
def self.const_defined?(sym, inherit=false)
|
182
|
+
super
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
# set the session: will be needed in SugarCRM::Base to call the API methods on the correct session
|
187
|
+
namespace_module.session = self
|
188
|
+
namespace_module
|
189
|
+
end
|
190
|
+
|
191
|
+
def load_config_files
|
192
|
+
# see README for reasoning behind the priorization
|
193
|
+
config_file_paths.each{|path|
|
194
|
+
load_config path if File.exists? path
|
195
|
+
}
|
196
|
+
end
|
197
|
+
|
198
|
+
def register_namespace
|
199
|
+
SugarCRM.const_set(@namespace, generate_namespace_module)
|
200
|
+
@namespace_const = SugarCRM.const_get(@namespace)
|
201
|
+
end
|
202
|
+
|
203
|
+
# load all the monkey patch extension files in the provided folder
|
204
|
+
def load_extensions
|
205
|
+
self.class.validate_path @extensions_path
|
206
|
+
Dir[File.join(@extensions_path, '**', '*.rb').to_s].each { |f| load(f) }
|
207
|
+
end
|
208
|
+
|
209
|
+
# Returns hash containing only keys/values relating to connection pool options. These are removed from parameter hash.
|
210
|
+
def self.parse_connection_pool_options(config_values)
|
211
|
+
result = {}
|
212
|
+
pool_size = config_values.delete(:pool)
|
213
|
+
result[:size] = pool_size if pool_size
|
214
|
+
wait_timeout = config_values.delete(:wait_timeout)
|
215
|
+
result[:wait_timeout] = wait_timeout if wait_timeout
|
216
|
+
result
|
217
|
+
end
|
218
|
+
end; end
|
data/lib/sugarcrm.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'pp'
|
3
|
+
require 'set'
|
4
|
+
require 'cgi'
|
5
|
+
require 'uri'
|
6
|
+
require 'base64'
|
7
|
+
require 'rubygems'
|
8
|
+
require 'active_support/core_ext'
|
9
|
+
require 'json'
|
10
|
+
require 'httpclient'
|
11
|
+
|
12
|
+
require 'sugarcrm/session'
|
13
|
+
require 'sugarcrm/module_methods'
|
14
|
+
require 'sugarcrm/connection_pool'
|
15
|
+
require 'sugarcrm/connection'
|
16
|
+
require 'sugarcrm/exceptions'
|
17
|
+
require 'sugarcrm/finders'
|
18
|
+
require 'sugarcrm/attributes'
|
19
|
+
require 'sugarcrm/associations'
|
20
|
+
require 'sugarcrm/module'
|
21
|
+
require 'sugarcrm/base'
|
22
|
+
|
data/sugarcrm.gemspec
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "sugarcrm_emp"
|
8
|
+
s.version = "0.10.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Carl Hicks", "David Sulc", "Dimitar Kostov"]
|
12
|
+
s.date = "2011-12-13"
|
13
|
+
s.email = "dimitar@emerchantpay.com"
|
14
|
+
s.executables = ["sugarcrm"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"WATCHLIST.rdoc",
|
28
|
+
"bin/sugarcrm",
|
29
|
+
"lib/rails/generators/sugarcrm/config/config_generator.rb",
|
30
|
+
"lib/rails/generators/sugarcrm/config/templates/initializer.rb",
|
31
|
+
"lib/rails/generators/sugarcrm/config/templates/sugarcrm.yml",
|
32
|
+
"lib/sugarcrm.rb",
|
33
|
+
"lib/sugarcrm/associations.rb",
|
34
|
+
"lib/sugarcrm/associations/association.rb",
|
35
|
+
"lib/sugarcrm/associations/association_cache.rb",
|
36
|
+
"lib/sugarcrm/associations/association_collection.rb",
|
37
|
+
"lib/sugarcrm/associations/association_methods.rb",
|
38
|
+
"lib/sugarcrm/associations/associations.rb",
|
39
|
+
"lib/sugarcrm/attributes.rb",
|
40
|
+
"lib/sugarcrm/attributes/attribute_methods.rb",
|
41
|
+
"lib/sugarcrm/attributes/attribute_serializers.rb",
|
42
|
+
"lib/sugarcrm/attributes/attribute_typecast.rb",
|
43
|
+
"lib/sugarcrm/attributes/attribute_validations.rb",
|
44
|
+
"lib/sugarcrm/base.rb",
|
45
|
+
"lib/sugarcrm/config/sugarcrm.yaml",
|
46
|
+
"lib/sugarcrm/connection.rb",
|
47
|
+
"lib/sugarcrm/connection/api/get_available_modules.rb",
|
48
|
+
"lib/sugarcrm/connection/api/get_document_revision.rb",
|
49
|
+
"lib/sugarcrm/connection/api/get_entries.rb",
|
50
|
+
"lib/sugarcrm/connection/api/get_entries_count.rb",
|
51
|
+
"lib/sugarcrm/connection/api/get_entry.rb",
|
52
|
+
"lib/sugarcrm/connection/api/get_entry_list.rb",
|
53
|
+
"lib/sugarcrm/connection/api/get_module_fields.rb",
|
54
|
+
"lib/sugarcrm/connection/api/get_note_attachment.rb",
|
55
|
+
"lib/sugarcrm/connection/api/get_relationships.rb",
|
56
|
+
"lib/sugarcrm/connection/api/get_report_entries.rb",
|
57
|
+
"lib/sugarcrm/connection/api/get_server_info.rb",
|
58
|
+
"lib/sugarcrm/connection/api/get_user_id.rb",
|
59
|
+
"lib/sugarcrm/connection/api/get_user_team_id.rb",
|
60
|
+
"lib/sugarcrm/connection/api/login.rb",
|
61
|
+
"lib/sugarcrm/connection/api/logout.rb",
|
62
|
+
"lib/sugarcrm/connection/api/seamless_login.rb",
|
63
|
+
"lib/sugarcrm/connection/api/search_by_module.rb",
|
64
|
+
"lib/sugarcrm/connection/api/set_campaign_merge.rb",
|
65
|
+
"lib/sugarcrm/connection/api/set_document_revision.rb",
|
66
|
+
"lib/sugarcrm/connection/api/set_entries.rb",
|
67
|
+
"lib/sugarcrm/connection/api/set_entry.rb",
|
68
|
+
"lib/sugarcrm/connection/api/set_note_attachment.rb",
|
69
|
+
"lib/sugarcrm/connection/api/set_relationship.rb",
|
70
|
+
"lib/sugarcrm/connection/api/set_relationships.rb",
|
71
|
+
"lib/sugarcrm/connection/connection.rb",
|
72
|
+
"lib/sugarcrm/connection/helper.rb",
|
73
|
+
"lib/sugarcrm/connection/request.rb",
|
74
|
+
"lib/sugarcrm/connection/response.rb",
|
75
|
+
"lib/sugarcrm/connection_pool.rb",
|
76
|
+
"lib/sugarcrm/exceptions.rb",
|
77
|
+
"lib/sugarcrm/extensions/README.txt",
|
78
|
+
"lib/sugarcrm/finders.rb",
|
79
|
+
"lib/sugarcrm/finders/dynamic_finder_match.rb",
|
80
|
+
"lib/sugarcrm/finders/finder_methods.rb",
|
81
|
+
"lib/sugarcrm/module.rb",
|
82
|
+
"lib/sugarcrm/module_methods.rb",
|
83
|
+
"lib/sugarcrm/session.rb",
|
84
|
+
"sugarcrm.gemspec",
|
85
|
+
"test/config_test.yaml",
|
86
|
+
"test/connection/test_get_available_modules.rb",
|
87
|
+
"test/connection/test_get_entries.rb",
|
88
|
+
"test/connection/test_get_entry.rb",
|
89
|
+
"test/connection/test_get_entry_list.rb",
|
90
|
+
"test/connection/test_get_module_fields.rb",
|
91
|
+
"test/connection/test_get_relationships.rb",
|
92
|
+
"test/connection/test_get_server_info.rb",
|
93
|
+
"test/connection/test_get_user_id.rb",
|
94
|
+
"test/connection/test_get_user_team_id.rb",
|
95
|
+
"test/connection/test_login.rb",
|
96
|
+
"test/connection/test_logout.rb",
|
97
|
+
"test/connection/test_set_document_revision.rb",
|
98
|
+
"test/connection/test_set_entry.rb",
|
99
|
+
"test/connection/test_set_note_attachment.rb",
|
100
|
+
"test/connection/test_set_relationship.rb",
|
101
|
+
"test/extensions_test/patch.rb",
|
102
|
+
"test/helper.rb",
|
103
|
+
"test/test_association_collection.rb",
|
104
|
+
"test/test_associations.rb",
|
105
|
+
"test/test_connection.rb",
|
106
|
+
"test/test_connection_pool.rb",
|
107
|
+
"test/test_finders.rb",
|
108
|
+
"test/test_module.rb",
|
109
|
+
"test/test_request.rb",
|
110
|
+
"test/test_response.rb",
|
111
|
+
"test/test_session.rb",
|
112
|
+
"test/test_sugarcrm.rb"
|
113
|
+
]
|
114
|
+
s.homepage = "http://github.com/eMerchantPay/sugarcrm"
|
115
|
+
s.require_paths = ["lib"]
|
116
|
+
s.rubygems_version = "1.8.11"
|
117
|
+
s.summary = "A less clunky way to interact with SugarCRM via REST."
|
118
|
+
s.test_files = [
|
119
|
+
"test/config_test.yaml",
|
120
|
+
"test/connection/test_get_available_modules.rb",
|
121
|
+
"test/connection/test_get_entries.rb",
|
122
|
+
"test/connection/test_get_entry.rb",
|
123
|
+
"test/connection/test_get_entry_list.rb",
|
124
|
+
"test/connection/test_get_module_fields.rb",
|
125
|
+
"test/connection/test_get_relationships.rb",
|
126
|
+
"test/connection/test_get_server_info.rb",
|
127
|
+
"test/connection/test_get_user_id.rb",
|
128
|
+
"test/connection/test_get_user_team_id.rb",
|
129
|
+
"test/connection/test_login.rb",
|
130
|
+
"test/connection/test_logout.rb",
|
131
|
+
"test/connection/test_set_document_revision.rb",
|
132
|
+
"test/connection/test_set_entry.rb",
|
133
|
+
"test/connection/test_set_note_attachment.rb",
|
134
|
+
"test/connection/test_set_relationship.rb",
|
135
|
+
"test/extensions_test/patch.rb",
|
136
|
+
"test/helper.rb",
|
137
|
+
"test/test_association_collection.rb",
|
138
|
+
"test/test_associations.rb",
|
139
|
+
"test/test_connection.rb",
|
140
|
+
"test/test_connection_pool.rb",
|
141
|
+
"test/test_finders.rb",
|
142
|
+
"test/test_module.rb",
|
143
|
+
"test/test_request.rb",
|
144
|
+
"test/test_response.rb",
|
145
|
+
"test/test_session.rb",
|
146
|
+
"test/test_sugarcrm.rb"
|
147
|
+
]
|
148
|
+
|
149
|
+
if s.respond_to? :specification_version then
|
150
|
+
s.specification_version = 3
|
151
|
+
|
152
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
153
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.10"])
|
154
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
155
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
156
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
157
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
158
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
159
|
+
else
|
160
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.10"])
|
161
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
162
|
+
s.add_dependency(%q<json>, [">= 0"])
|
163
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
164
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
165
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
166
|
+
s.add_dependency(%q<httpclient>, [">= 2.2.5"])
|
167
|
+
end
|
168
|
+
else
|
169
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.10"])
|
170
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
171
|
+
s.add_dependency(%q<json>, [">= 0"])
|
172
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
173
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
174
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
175
|
+
s.add_dependency(%q<httpclient>, [">= 2.2.5"])
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# below is an example configuration file
|
2
|
+
#
|
3
|
+
# to create you own configuration file, simply copy and adapt the text below, removing the '#' in front of the key-value pairs
|
4
|
+
#
|
5
|
+
# you'll find an example of a configuration file (used for tests) in test/config_test.yaml
|
6
|
+
#
|
7
|
+
# config:
|
8
|
+
# base_url: http://127.0.0.1/sugarcrm # where your SugarCRM instance is located
|
9
|
+
# username: admin
|
10
|
+
# password: letmein
|
11
|
+
|
12
|
+
config:
|
13
|
+
base_url: http://127.0.0.1/sugarcrm # where your SugarCRM instance is located
|
14
|
+
username: admin
|
15
|
+
password: letmein
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGetAvailableModules < ActiveSupport::TestCase
|
4
|
+
context "A SugarCRM.connection" do
|
5
|
+
should "return an array of modules when #get_modules" do
|
6
|
+
assert_instance_of SugarCRM::Module, SugarCRM.connection.get_modules[0]
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGetEntries < ActiveSupport::TestCase
|
4
|
+
context "A SugarCRM.connection" do
|
5
|
+
should "return an object when #get_entries" do
|
6
|
+
@response = SugarCRM.connection.get_entries(
|
7
|
+
"Users",
|
8
|
+
[1,"seed_sally_id"],
|
9
|
+
{:fields => ["first_name", "last_name"]}
|
10
|
+
)
|
11
|
+
assert_instance_of Array, @response
|
12
|
+
assert_instance_of SugarCRM::User, @response[0]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGetEntry < ActiveSupport::TestCase
|
4
|
+
context "A SugarCRM.connection" do
|
5
|
+
setup do
|
6
|
+
@response = SugarCRM.connection.get_entry(
|
7
|
+
"Users",
|
8
|
+
1,
|
9
|
+
{:fields => ["first_name", "last_name", "deleted", "date_modified"]}
|
10
|
+
)
|
11
|
+
end
|
12
|
+
should "return an object when #get_entry" do
|
13
|
+
assert_instance_of SugarCRM::User, @response
|
14
|
+
end
|
15
|
+
should "typecast boolean fields properly" do
|
16
|
+
assert_instance_of FalseClass, @response.deleted
|
17
|
+
end
|
18
|
+
should "typecast date_time fields properly" do
|
19
|
+
assert_instance_of DateTime, @response.date_modified
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGetEntryList < ActiveSupport::TestCase
|
4
|
+
context "A SugarCRM.connection" do
|
5
|
+
should "return a list of entries when sent #get_entry_list" do
|
6
|
+
users = SugarCRM.connection.get_entry_list(
|
7
|
+
"Users",
|
8
|
+
"users.deleted = 0"
|
9
|
+
)
|
10
|
+
assert_kind_of Array, users
|
11
|
+
assert_equal SugarCRM.config[:username], users.first.user_name
|
12
|
+
end
|
13
|
+
should "return an object when #get_entry_list" do
|
14
|
+
@response = SugarCRM.connection.get_entry_list(
|
15
|
+
"Users",
|
16
|
+
"users.deleted = 0",
|
17
|
+
{:fields => ["first_name", "last_name"]}
|
18
|
+
)
|
19
|
+
assert_instance_of Array, @response
|
20
|
+
assert_instance_of SugarCRM::User, @response[0]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestModuleFields < ActiveSupport::TestCase
|
4
|
+
context "A SugarCRM.connection" do
|
5
|
+
should "return a hash of module fields when #get_module_fields" do
|
6
|
+
fields = SugarCRM.connection.get_module_fields("Users")
|
7
|
+
assert_kind_of Hash, fields
|
8
|
+
assert "address_city", fields.keys[0]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestGetRelationships < ActiveSupport::TestCase
|
4
|
+
context "A SugarCRM.connection" do
|
5
|
+
should "return a list of email_addresses when sent #get_relationship and a user_id" do
|
6
|
+
email_addresses = SugarCRM.connection.get_relationships(
|
7
|
+
"Users",1,"email_addresses"
|
8
|
+
)
|
9
|
+
assert_instance_of SugarCRM::EmailAddress, email_addresses.first
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|