sugarcrm 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/sugarcrm.rb +26 -8
  3. data/test/test_sugarcrm.rb +12 -0
  4. metadata +3 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.5.2
data/lib/sugarcrm.rb CHANGED
@@ -37,14 +37,22 @@ class Base
37
37
  attr :connection, true
38
38
  attr :session, true
39
39
  attr :debug, true
40
+ attr :to_obj, true
40
41
 
41
- def initialize(url, user, pass, options={})
42
- {:debug => false}.merge! options
42
+ def initialize(url, user, pass, opts={})
43
+ options = {
44
+ :debug => false,
45
+ :to_obj => true
46
+ }.merge(opts)
43
47
 
48
+ @debug = options[:debug]
49
+ @to_obj = options[:to_obj]
50
+
51
+ pp options
52
+
53
+ @url = URI.parse(url)
44
54
  @user = user
45
55
  @pass = pass
46
- @url = URI.parse(url)
47
- @debug = options[:debug]
48
56
 
49
57
  # Handles http/https in url string
50
58
  @ssl = false
@@ -69,7 +77,6 @@ class Base
69
77
  @session ? true : false
70
78
  end
71
79
 
72
-
73
80
  protected
74
81
 
75
82
  def connect!
@@ -95,7 +102,13 @@ class Base
95
102
  EOF
96
103
  json.gsub!(/^\s{8}/,'')
97
104
  response = get(:login, json)
98
- @session = response.id
105
+
106
+ if @to_obj
107
+ @session = response.id
108
+ else
109
+ @session = response["id"]
110
+ #puts "Session: #{@session}"
111
+ end
99
112
  end
100
113
 
101
114
  def get(method,json)
@@ -122,8 +135,13 @@ class Base
122
135
  pp response_json
123
136
  puts "\n"
124
137
  end
125
- response_obj = response_json.to_obj
126
- return response_obj
138
+ response_obj = response_json.to_obj
139
+
140
+ if @to_obj
141
+ return response_obj
142
+ else
143
+ return response_json
144
+ end
127
145
  when Net::HTTPNotFound
128
146
  raise InvalidSugarCRMUrl, "#{@url} is invalid"
129
147
  else
@@ -1,4 +1,6 @@
1
1
  require 'helper'
2
+ require "test/unit"
3
+ require "pp"
2
4
 
3
5
  # Replace these with your test instance
4
6
  URL = "http://valet/sugarcrm"
@@ -11,6 +13,16 @@ class TestSugarcrm < Test::Unit::TestCase
11
13
  @sugarcrm = SugarCRM::Base.new(URL, USER, PASS, {:debug => true})
12
14
  end
13
15
 
16
+ should "return a single entry in JSON format when option :to_obj => false" do
17
+ @test = SugarCRM::Base.new(URL, USER, PASS, {:debug => true, :to_obj => false})
18
+ response = @test.get_entry(
19
+ "Users",
20
+ 1,
21
+ {:fields => ["first_name", "last_name"]}
22
+ )
23
+ assert_kind_of Hash, response
24
+ end
25
+
14
26
  should "return a single entry when sent #get_entry." do
15
27
  response = @sugarcrm.get_entry(
16
28
  "Users",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcrm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 1
10
- version: 0.5.1
9
+ - 2
10
+ version: 0.5.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Carl Hicks