sugarcrm 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +62 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/net/http_digest_auth.rb +44 -0
- data/lib/stdlib/array.rb +14 -0
- data/lib/stdlib/hash.rb +17 -0
- data/lib/stdlib/object.rb +5 -0
- data/lib/sugarcrm.rb +141 -0
- data/lib/sugarcrm/get_entries.rb +23 -0
- data/lib/sugarcrm/get_entry.rb +25 -0
- data/lib/sugarcrm/get_entry_list.rb +31 -0
- data/lib/sugarcrm/get_module_fields.rb +15 -0
- data/lib/sugarcrm/get_relationships.rb +20 -0
- data/test/helper.rb +10 -0
- data/test/test_json_to_obj.rb +48 -0
- data/test/test_sugarcrm.rb +50 -0
- metadata +115 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Carl Hicks
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
= SugarCRM
|
2
|
+
|
3
|
+
* http://github.com/chicks/sugarcrm
|
4
|
+
|
5
|
+
REST Bindings for SugarCRM!
|
6
|
+
|
7
|
+
== SUMMARY:
|
8
|
+
|
9
|
+
Ruby Gem for interacting with SugarCRM via REST
|
10
|
+
|
11
|
+
== FEATURES/PROBLEMS:
|
12
|
+
|
13
|
+
* The response hash gets converted into a Ruby object, via Hash#to_obj method.
|
14
|
+
* Only the following methods are currently implemented:
|
15
|
+
|
16
|
+
* get_entry
|
17
|
+
* get_entries
|
18
|
+
* get_entry_list
|
19
|
+
* get_module_fields
|
20
|
+
* get_relationships
|
21
|
+
|
22
|
+
== SYNOPSIS:
|
23
|
+
|
24
|
+
require 'sugarcrm'
|
25
|
+
sugarcrm = SugarCRM::Base.new("http://localhost/sugarcrm", 'user', 'password', {:debug => false})
|
26
|
+
|
27
|
+
# Lookup a user by name. Find any associated accounts
|
28
|
+
sugarcrm.get_entry_list(
|
29
|
+
"Users",
|
30
|
+
"users.user_name = \'#{USER}\'",
|
31
|
+
{
|
32
|
+
:fields => ["first_name", "last_name"],
|
33
|
+
:link_fields => [
|
34
|
+
{
|
35
|
+
"name" => "accounts",
|
36
|
+
"value" => ["id", "name"]
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}
|
40
|
+
)
|
41
|
+
|
42
|
+
== REQUIREMENTS:
|
43
|
+
|
44
|
+
* json gem
|
45
|
+
|
46
|
+
== INSTALL:
|
47
|
+
|
48
|
+
* sudo gem install sugarcrm
|
49
|
+
|
50
|
+
== Note on Patches/Pull Requests
|
51
|
+
|
52
|
+
* Fork the project.
|
53
|
+
* Make your feature addition or bug fix.
|
54
|
+
* Add tests for it. This is important so I don't break it in a
|
55
|
+
future version unintentionally.
|
56
|
+
* Commit, do not mess with rakefile, version, or history.
|
57
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
58
|
+
* Send me a pull request. Bonus points for topic branches.
|
59
|
+
|
60
|
+
== Copyright
|
61
|
+
|
62
|
+
Copyright (c) 2010 Carl Hicks. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "sugarcrm"
|
8
|
+
gem.summary = %Q{Ruby based REST client for SugarCRM}
|
9
|
+
gem.description = %Q{A Ruby based REST client for SugarCRM.}
|
10
|
+
gem.email = "carl.hicks@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/chicks/sugarcrm"
|
12
|
+
gem.authors = ["Carl Hicks"]
|
13
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
+
gem.add_dependency "json", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "sugarcrm #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.1
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# net_http_digest_auth.rb
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module Net
|
6
|
+
module HTTPHeader
|
7
|
+
@@nonce_count = -1
|
8
|
+
CNONCE = Digest::MD5.new.update("%x" % (Time.now.to_i + rand(65535))).hexdigest
|
9
|
+
def digest_auth(user, password, response)
|
10
|
+
# based on http://segment7.net/projects/ruby/snippets/digest_auth.rb
|
11
|
+
@@nonce_count += 1
|
12
|
+
|
13
|
+
response['www-authenticate'] =~ /^(\w+) (.*)/
|
14
|
+
|
15
|
+
params = {}
|
16
|
+
$2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
|
17
|
+
|
18
|
+
a_1 = "#{user}:#{params['realm']}:#{password}"
|
19
|
+
a_2 = "#{@method}:#{@path}"
|
20
|
+
request_digest = ''
|
21
|
+
request_digest << Digest::MD5.new.update(a_1).hexdigest
|
22
|
+
request_digest << ':' << params['nonce']
|
23
|
+
request_digest << ':' << ('%08x' % @@nonce_count)
|
24
|
+
request_digest << ':' << CNONCE
|
25
|
+
request_digest << ':' << params['qop']
|
26
|
+
request_digest << ':' << Digest::MD5.new.update(a_2).hexdigest
|
27
|
+
|
28
|
+
header = []
|
29
|
+
header << "Digest username=\"#{user}\""
|
30
|
+
header << "realm=\"#{params['realm']}\""
|
31
|
+
|
32
|
+
header << "qop=#{params['qop']}"
|
33
|
+
|
34
|
+
header << "algorithm=MD5"
|
35
|
+
header << "uri=\"#{@path}\""
|
36
|
+
header << "nonce=\"#{params['nonce']}\""
|
37
|
+
header << "nc=#{'%08x' % @@nonce_count}"
|
38
|
+
header << "cnonce=\"#{CNONCE}\""
|
39
|
+
header << "response=\"#{Digest::MD5.new.update(request_digest).hexdigest}\""
|
40
|
+
|
41
|
+
@header['Authorization'] = header
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/stdlib/array.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# A fancy way of iterating over an array and converting hashes to objects
|
2
|
+
class Array
|
3
|
+
def to_obj
|
4
|
+
# Make a deep copy of the array
|
5
|
+
a = Marshal.load(Marshal.dump(self))
|
6
|
+
a.each do |i|
|
7
|
+
case i.class.to_s
|
8
|
+
when "Hash" then i = i.to_obj
|
9
|
+
when "Array" then i = i.to_obj
|
10
|
+
end
|
11
|
+
end
|
12
|
+
a
|
13
|
+
end
|
14
|
+
end
|
data/lib/stdlib/hash.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# A fancy way of iterating over a hash and converting hashes to objects
|
2
|
+
class Hash
|
3
|
+
def to_obj
|
4
|
+
o = Object.new
|
5
|
+
self.each do |k,v|
|
6
|
+
# If we're looking at a hash or array, we need to look through them and convert any hashes to objects as well
|
7
|
+
case v.class.to_s
|
8
|
+
when "Hash" then v = v.to_obj
|
9
|
+
when "Array" then v = v.to_obj
|
10
|
+
end
|
11
|
+
o.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair
|
12
|
+
o.class.send(:define_method, k, proc{o.instance_variable_get("@#{k}")}) ## create the getter that returns the instance variable
|
13
|
+
o.class.send(:define_method, "#{k}=", proc{|v| o.instance_variable_set("@#{k}", v)}) ## create the setter that sets the instance variable
|
14
|
+
end
|
15
|
+
o
|
16
|
+
end
|
17
|
+
end
|
data/lib/sugarcrm.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
module SugarCRM
|
4
|
+
|
5
|
+
Dir["#{File.dirname(__FILE__)}/sugarcrm/**/*.rb"].each { |f| load(f) }
|
6
|
+
Dir["#{File.dirname(__FILE__)}/stdlib/**/*.rb"].each { |f| load(f) }
|
7
|
+
|
8
|
+
require 'pp'
|
9
|
+
require 'ostruct'
|
10
|
+
require 'uri'
|
11
|
+
require 'net/https'
|
12
|
+
require 'openssl'
|
13
|
+
require 'digest/md5'
|
14
|
+
|
15
|
+
require 'rubygems'
|
16
|
+
require 'json'
|
17
|
+
|
18
|
+
class LoginError < RuntimeError
|
19
|
+
end
|
20
|
+
|
21
|
+
class EmptyResponse < RuntimeError
|
22
|
+
end
|
23
|
+
|
24
|
+
class UnhandledResponse < RuntimeError
|
25
|
+
end
|
26
|
+
|
27
|
+
class InvalidSugarCRMUrl < RuntimeError
|
28
|
+
end
|
29
|
+
|
30
|
+
class Base
|
31
|
+
|
32
|
+
URL = "/service/v2/rest.php"
|
33
|
+
attr :url, true
|
34
|
+
attr :user, false
|
35
|
+
attr :pass, false
|
36
|
+
attr :ssl, false
|
37
|
+
attr :connection, true
|
38
|
+
attr :session, true
|
39
|
+
attr :debug, true
|
40
|
+
|
41
|
+
def initialize(url, user, pass, options={})
|
42
|
+
{:debug => false}.merge! options
|
43
|
+
|
44
|
+
@user = user
|
45
|
+
@pass = pass
|
46
|
+
@url = URI.parse(url)
|
47
|
+
@debug = options[:debug]
|
48
|
+
|
49
|
+
# Handles http/https in url string
|
50
|
+
@ssl = false
|
51
|
+
@ssl = true if @url.scheme == "https"
|
52
|
+
|
53
|
+
# Appends the rest.php path onto the end of the URL if it's not included
|
54
|
+
if @url.path !~ /rest.php$/
|
55
|
+
@url.path += URL
|
56
|
+
end
|
57
|
+
|
58
|
+
login!
|
59
|
+
raise LoginError, "Invalid Login" unless logged_in?
|
60
|
+
end
|
61
|
+
|
62
|
+
def connected?
|
63
|
+
return false unless @connection
|
64
|
+
return false unless @connection.started?
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
68
|
+
def logged_in?
|
69
|
+
@session ? true : false
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
75
|
+
def connect!
|
76
|
+
@connection = Net::HTTP.new(@url.host, @url.port)
|
77
|
+
if @ssl
|
78
|
+
@connection.use_ssl = true
|
79
|
+
@connection.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
80
|
+
end
|
81
|
+
@connection.start
|
82
|
+
end
|
83
|
+
|
84
|
+
def login!
|
85
|
+
connect! unless connected?
|
86
|
+
json = <<-EOF
|
87
|
+
{
|
88
|
+
\"user_auth\": {
|
89
|
+
\"user_name\": \"#{@user}\"\,
|
90
|
+
\"password\": \"#{OpenSSL::Digest::MD5.new(@pass)}\"\,
|
91
|
+
\"version\": \"2\"\,
|
92
|
+
},
|
93
|
+
\"application\": \"\"
|
94
|
+
}
|
95
|
+
EOF
|
96
|
+
json.gsub!(/^\s{8}/,'')
|
97
|
+
response = get(:login, json)
|
98
|
+
@session = response.id
|
99
|
+
end
|
100
|
+
|
101
|
+
def get(method,json)
|
102
|
+
query = @url.path.dup
|
103
|
+
query << '?method=' << method.to_s
|
104
|
+
query << '&input_type=JSON'
|
105
|
+
query << '&response_type=JSON'
|
106
|
+
query << '&rest_data=' << json
|
107
|
+
|
108
|
+
if @debug
|
109
|
+
puts "#{method}: Request"
|
110
|
+
puts query
|
111
|
+
puts "\n"
|
112
|
+
end
|
113
|
+
response = @connection.get(URI.escape(query))
|
114
|
+
|
115
|
+
case response
|
116
|
+
when Net::HTTPOK
|
117
|
+
raise EmptyResponse unless response.body
|
118
|
+
response_json = JSON.parse response.body
|
119
|
+
return false if response_json["result_count"] == 0
|
120
|
+
if @debug
|
121
|
+
puts "#{method}: JSON Response:"
|
122
|
+
pp response_json
|
123
|
+
puts "\n"
|
124
|
+
end
|
125
|
+
response_obj = response_json.to_obj
|
126
|
+
return response_obj
|
127
|
+
when Net::HTTPNotFound
|
128
|
+
raise InvalidSugarCRMUrl, "#{@url} is invalid"
|
129
|
+
else
|
130
|
+
if @debug
|
131
|
+
puts "#{method}: Raw Response:"
|
132
|
+
puts response.body
|
133
|
+
puts "\n"
|
134
|
+
end
|
135
|
+
raise UnhandledResponse, "Can't handle response #{response}"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SugarCRM; class Base
|
2
|
+
# Retrieve a list of SugarBeans by ID. This method will not
|
3
|
+
# work with the report module.
|
4
|
+
def get_entries(module_name, ids, options={})
|
5
|
+
login! unless logged_in?
|
6
|
+
{
|
7
|
+
:fields => '',
|
8
|
+
:link_fields => [],
|
9
|
+
}.merge! options
|
10
|
+
|
11
|
+
json = <<-EOF
|
12
|
+
{
|
13
|
+
\"session\": \"#{@session}\"\,
|
14
|
+
\"module_name\": \"#{module_name}\"\,
|
15
|
+
\"ids\": \"#{ids.to_json}\"\,
|
16
|
+
\"select_fields\": #{options[:fields].to_json}\,
|
17
|
+
\"link_name_to_fields_array\": #{options[:link_fields].to_json}\,
|
18
|
+
}
|
19
|
+
EOF
|
20
|
+
json.gsub!(/^\s{6}/,'')
|
21
|
+
get(:get_entries, json)
|
22
|
+
end
|
23
|
+
end; end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SugarCRM; class Base
|
2
|
+
def get_entry(module_name, id, options={})
|
3
|
+
login! unless logged_in?
|
4
|
+
{ :fields => [],
|
5
|
+
:link_fields => [],
|
6
|
+
}.merge! options
|
7
|
+
|
8
|
+
json = <<-EOF
|
9
|
+
{
|
10
|
+
\"session\": \"#{@session}\"\,
|
11
|
+
\"module_name\": \"#{module_name}\"\,
|
12
|
+
\"id\": \"#{id}\"\,
|
13
|
+
\"select_fields\": #{options[:fields].to_json}\,
|
14
|
+
}
|
15
|
+
EOF
|
16
|
+
|
17
|
+
placeholder = <<-EOF
|
18
|
+
\"select_fields\": [\"name\"]
|
19
|
+
\"link_name_to_fields_array\": \"#{options[:link_fields]}\"\,
|
20
|
+
EOF
|
21
|
+
|
22
|
+
json.gsub!(/^\s{6}/,'')
|
23
|
+
get(:get_entry, json)
|
24
|
+
end
|
25
|
+
end; end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SugarCRM; class Base
|
2
|
+
# Retrieve a list of SugarBeans. This is the primary method for getting
|
3
|
+
# a list of SugarBeans using the REST API.
|
4
|
+
def get_entry_list(module_name, query, options={})
|
5
|
+
login! unless logged_in?
|
6
|
+
{
|
7
|
+
:order_by => '',
|
8
|
+
:offset => '',
|
9
|
+
:fields => '',
|
10
|
+
:link_fields => [],
|
11
|
+
:max_results => '',
|
12
|
+
:deleted => ''
|
13
|
+
}.merge! options
|
14
|
+
|
15
|
+
json = <<-EOF
|
16
|
+
{
|
17
|
+
\"session\": \"#{@session}\"\,
|
18
|
+
\"module_name\": \"#{module_name}\"\,
|
19
|
+
\"query\": \"#{query}\"\,
|
20
|
+
\"order_by\": \"#{options[:order_by]}\"\,
|
21
|
+
\"offset\": \"#{options[:offset]}\"\,
|
22
|
+
\"select_fields\": #{options[:fields].to_json}\,
|
23
|
+
\"link_name_to_fields_array\": #{options[:link_fields].to_json}\,
|
24
|
+
\"max_results\": \"#{options[:max_results]}\"\,
|
25
|
+
\"deleted\": #{options[:deleted]}
|
26
|
+
}
|
27
|
+
EOF
|
28
|
+
json.gsub!(/^\s{6}/,'')
|
29
|
+
get(:get_entry_list, json)
|
30
|
+
end
|
31
|
+
end; end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SugarCRM; class Base
|
2
|
+
|
3
|
+
def get_module_fields(module_name)
|
4
|
+
login! unless logged_in?
|
5
|
+
json = <<-"EOF"
|
6
|
+
{
|
7
|
+
\"session\": \"#{@session}\"\,
|
8
|
+
\"module_name": \"#{module_name}"
|
9
|
+
}
|
10
|
+
EOF
|
11
|
+
json.gsub!(/^\s{6}/,'')
|
12
|
+
get(:get_module_fields, json)
|
13
|
+
end
|
14
|
+
|
15
|
+
end; end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SugarCRM; class Base
|
2
|
+
# A standard REST call to get a list of relationships
|
3
|
+
def get_relationships(module_name, id, related_to, options={})
|
4
|
+
login! unless logged_in?
|
5
|
+
json = <<-EOF
|
6
|
+
{
|
7
|
+
\"session\": \"#{@session}\"\,
|
8
|
+
\"module_name\": \"#{module_name}\"\,
|
9
|
+
\"module_ids\": \"#{id}\"\,
|
10
|
+
\"link_field_name\": \"#{related_to.downcase}\"\,
|
11
|
+
\"related_module_query\": \"#{options[:related_module_query]}\"\,
|
12
|
+
\"related_fields\": #{options[:related_fields].to_json}\,
|
13
|
+
\"related_module_link_name_to_fields_array\": #{options[:related_link_fields].to_json}\,
|
14
|
+
\"deleted\": #{options[:deleted]}
|
15
|
+
}
|
16
|
+
EOF
|
17
|
+
json.gsub!(/^\s{6}/,'')
|
18
|
+
get(:get_relationships, json)
|
19
|
+
end
|
20
|
+
end; end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestJson2Object < Test::Unit::TestCase
|
4
|
+
def test_object
|
5
|
+
json = {"string" => "value"}.to_json
|
6
|
+
obj = JSON.parse(json).to_obj
|
7
|
+
assert_equal("value", obj.string)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_nested_object
|
11
|
+
json = {"dogs" => {"retriever" => "sparky", "basset" => "jennie", "pinscher" => "carver"}}.to_json
|
12
|
+
obj = JSON.parse(json).to_obj
|
13
|
+
assert_equal("sparky", obj.dogs.retriever)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_array_of_objects
|
17
|
+
json = [{"retriever" => "sparky"}, {"basset" => "jennie"}, {"pinscher" => "carver"}].to_json
|
18
|
+
obj = JSON.parse(json).to_obj
|
19
|
+
assert_equal("sparky", obj[0].retriever)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_deep_nest_mixed
|
23
|
+
json = {"kennels" => [
|
24
|
+
{"dallas" => [
|
25
|
+
{"name" => "north"},
|
26
|
+
{"name" => "east"},
|
27
|
+
]},
|
28
|
+
{"frisco" => [
|
29
|
+
{"name" => "south"},
|
30
|
+
{"name" => "west"}
|
31
|
+
],
|
32
|
+
"company" => "Doggie Daze"
|
33
|
+
}
|
34
|
+
]}.to_json
|
35
|
+
obj = JSON.parse(json).to_obj
|
36
|
+
assert_equal("west", obj.kennels[1].frisco[0].name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_deep_nest_hash
|
40
|
+
json = {"kennels" => {
|
41
|
+
"kennel" => {
|
42
|
+
"dallas" => ["north", "south"],
|
43
|
+
"frisco" => ["east", "west"]}}
|
44
|
+
}.to_json
|
45
|
+
obj = JSON.parse(json).to_obj
|
46
|
+
assert_equal("north", obj.kennels.kennel.dallas[0])
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
# Replace these with your test instance
|
4
|
+
URL = "http://valet/sugarcrm"
|
5
|
+
USER = "admin"
|
6
|
+
PASS = 'letmein'
|
7
|
+
|
8
|
+
class TestSugarcrm < Test::Unit::TestCase
|
9
|
+
context "A SugarCRM::Base instance" do
|
10
|
+
setup do
|
11
|
+
@sugarcrm = SugarCRM::Base.new(URL, USER, PASS, {:debug => true})
|
12
|
+
end
|
13
|
+
|
14
|
+
should "return a single entry when sent #get_entry." do
|
15
|
+
response = @sugarcrm.get_entry(
|
16
|
+
"Users",
|
17
|
+
1,
|
18
|
+
{:fields => ["first_name", "last_name"]}
|
19
|
+
)
|
20
|
+
assert_respond_to 'response', :entry_list
|
21
|
+
end
|
22
|
+
|
23
|
+
should "return a list of entries when sent #get_entries." do
|
24
|
+
response = @sugarcrm.get_entries(
|
25
|
+
"Users",
|
26
|
+
[1],
|
27
|
+
{:fields => ["first_name", "last_name"]}
|
28
|
+
)
|
29
|
+
assert_respond_to 'response', :entry_list
|
30
|
+
end
|
31
|
+
|
32
|
+
should "return a list of entries when sent #get_entry_list." do
|
33
|
+
response = @sugarcrm.get_entry_list(
|
34
|
+
"Users",
|
35
|
+
"users.user_name = \'#{USER}\'",
|
36
|
+
{
|
37
|
+
:fields => ["first_name", "last_name"],
|
38
|
+
:link_fields => [
|
39
|
+
{
|
40
|
+
"name" => "accounts",
|
41
|
+
"value" => ["id", "name"]
|
42
|
+
}
|
43
|
+
]
|
44
|
+
}
|
45
|
+
)
|
46
|
+
assert_respond_to 'response', :entry_list
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sugarcrm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 1
|
10
|
+
version: 0.5.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Carl Hicks
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-16 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: json
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: A Ruby based REST client for SugarCRM.
|
50
|
+
email: carl.hicks@gmail.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- LICENSE
|
57
|
+
- README.rdoc
|
58
|
+
files:
|
59
|
+
- .document
|
60
|
+
- .gitignore
|
61
|
+
- LICENSE
|
62
|
+
- README.rdoc
|
63
|
+
- Rakefile
|
64
|
+
- VERSION
|
65
|
+
- lib/net/http_digest_auth.rb
|
66
|
+
- lib/stdlib/array.rb
|
67
|
+
- lib/stdlib/hash.rb
|
68
|
+
- lib/stdlib/object.rb
|
69
|
+
- lib/sugarcrm.rb
|
70
|
+
- lib/sugarcrm/get_entries.rb
|
71
|
+
- lib/sugarcrm/get_entry.rb
|
72
|
+
- lib/sugarcrm/get_entry_list.rb
|
73
|
+
- lib/sugarcrm/get_module_fields.rb
|
74
|
+
- lib/sugarcrm/get_relationships.rb
|
75
|
+
- test/helper.rb
|
76
|
+
- test/test_json_to_obj.rb
|
77
|
+
- test/test_sugarcrm.rb
|
78
|
+
has_rdoc: true
|
79
|
+
homepage: http://github.com/chicks/sugarcrm
|
80
|
+
licenses: []
|
81
|
+
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options:
|
84
|
+
- --charset=UTF-8
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.3.7
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Ruby based REST client for SugarCRM
|
112
|
+
test_files:
|
113
|
+
- test/helper.rb
|
114
|
+
- test/test_json_to_obj.rb
|
115
|
+
- test/test_sugarcrm.rb
|