sugarcrm_rest 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +35 -0
- data/README.md +3 -3
- data/lib/sugarcrm_rest/version.rb +1 -1
- data/lib/sugarcrm_rest.rb +29 -38
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a5b18767557cc5a9690182ecd85b79b1fa791203086381b2a7dfa2d6ef7e7fd
|
4
|
+
data.tar.gz: aad29dfd73cbaf51984a53480cb7741d0aa4f65bb23462b05dcf525fbeff854a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e81d1f164586e522f7292070c99a7d664d2ef3246a47b5e7aa7b67b1e511b1be092a482824953013d30f41c0bc6fa0b86ecaedc3ffbfef770efdabdce86e039e
|
7
|
+
data.tar.gz: 88fa55c2ce95943de79da77696020dfcef23621b5744ff8067a40fbcb3ae8058f9b4e963650e1bc3fb3f99d31b14c9f16ee7109e5152514624df5d125173e8aa
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sugarcrm_rest (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.10.0)
|
12
|
+
rspec-core (~> 3.10.0)
|
13
|
+
rspec-expectations (~> 3.10.0)
|
14
|
+
rspec-mocks (~> 3.10.0)
|
15
|
+
rspec-core (3.10.1)
|
16
|
+
rspec-support (~> 3.10.0)
|
17
|
+
rspec-expectations (3.10.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.10.0)
|
20
|
+
rspec-mocks (3.10.2)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.10.0)
|
23
|
+
rspec-support (3.10.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
x64-mingw32
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.17)
|
30
|
+
rake (~> 10.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
sugarcrm_rest!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.17.2
|
data/README.md
CHANGED
@@ -22,9 +22,9 @@ Or install it yourself as:
|
|
22
22
|
```r
|
23
23
|
connect=SugarcrmRest::Connect.new(consumer_key,consumer_secret,username,password,platform,url) #Provide the connection object
|
24
24
|
SugarcrmRest::Fetch_Data.fetch_single_record(connect,module_name,id) #Give the record with specified id from specified module
|
25
|
-
SugarcrmRest::Fetch_Data.fetch_all_data(connect,module_name,offset) #Fetch data from specified module according to offset
|
26
|
-
SugarcrmRest::Fetch_Data.fetch_data_with_filters(connect,module_name,filter_json,fields=["no"]
|
27
|
-
SugarcrmRest::Fetch_Data.upload_document(connect,id,
|
25
|
+
SugarcrmRest::Fetch_Data.fetch_all_data(connect,module_name,offset,maxnum) #Fetch data from specified module according to offset
|
26
|
+
SugarcrmRest::Fetch_Data.fetch_data_with_filters(connect,module_name,filter_json,offset=0,fields=["no"]) #Return a json object of data having specified fields by applying specified filters.The filter format is filter=[{"name":"example"},{"age":{"$gte":age}}]
|
27
|
+
SugarcrmRest::Fetch_Data.upload_document(connect,id,path) #upload the file having specified path and id to doccument module
|
28
28
|
|
29
29
|
SugarcrmRest::Update_Sugar.create_new_record(connect,module_name,params) #Creating new record in specified module
|
30
30
|
SugarcrmRest::Update_Sugar.update_data(connect,module_name,params,id) #update fields of specified id and module
|
data/lib/sugarcrm_rest.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
require "sugarcrm_rest/version"
|
2
|
+
require 'active_support'
|
3
|
+
require "net/https"
|
4
|
+
require "rest-client"
|
5
|
+
require "uri"
|
6
|
+
require "rubygems"
|
7
|
+
require "json"
|
2
8
|
|
3
9
|
module SugarcrmRest
|
4
10
|
|
@@ -33,11 +39,11 @@ end
|
|
33
39
|
if response.kind_of? Net::HTTPSuccess
|
34
40
|
token = JSON.parse response.body
|
35
41
|
end
|
36
|
-
|
42
|
+
|
37
43
|
return token['access_token']
|
38
44
|
end
|
39
45
|
rescue Exception=>e
|
40
|
-
|
46
|
+
|
41
47
|
retry if ($count += 1) < 3
|
42
48
|
|
43
49
|
end
|
@@ -45,6 +51,7 @@ end
|
|
45
51
|
|
46
52
|
|
47
53
|
def self.execute_uri(connect,url)
|
54
|
+
|
48
55
|
begin
|
49
56
|
uri = URI.parse url
|
50
57
|
http = Net::HTTP.new uri.host, uri.port
|
@@ -57,7 +64,7 @@ end
|
|
57
64
|
end
|
58
65
|
rescue Exception=>e
|
59
66
|
|
60
|
-
|
67
|
+
|
61
68
|
retry if ($count += 1) < 3
|
62
69
|
end
|
63
70
|
|
@@ -79,32 +86,16 @@ class Fetch_Data
|
|
79
86
|
end
|
80
87
|
end
|
81
88
|
#fetch all data from agiven module
|
82
|
-
def self.fetch_all_data(connect,module_name,offset)
|
83
|
-
url = ''+"#{connect.url}"+"#{module_name}"+"?offset="+"#{offset}"+''
|
89
|
+
def self.fetch_all_data(connect,module_name,offset=0,max_num=100)
|
90
|
+
url = ''+"#{connect.url}"+"#{module_name}"+"?offset="+"#{offset}"+"&max_num="+"+#{max_num}"+''
|
84
91
|
response = Get_Token_Process_Url.execute_uri(connect,url)
|
85
92
|
if response.kind_of? Net::HTTPSuccess
|
86
93
|
root = JSON.parse response.body
|
87
|
-
p root
|
88
|
-
return root
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.build_filter(filter_json)
|
93
|
-
filter_hash = JSON.parse(filter_json)
|
94
|
-
filter_keys=JSON.parse(filter_json).keys
|
95
|
-
filter="?"
|
96
|
-
and_op=""
|
97
|
-
count=0
|
98
|
-
filter_keys.each do |k|
|
99
|
-
f1=filter_hash[k]
|
100
|
-
value=filter_hash[k].keys
|
101
|
-
filter=filter+"filter[0]["+"#{value[0]}"+"]["+"#{k}"+"]="+"#{f1[value[0]]}"
|
102
|
-
filter=filter+"&" if (count += 1) < filter_keys.length
|
103
94
|
|
95
|
+
return root
|
104
96
|
end
|
105
|
-
return filter
|
106
|
-
|
107
97
|
end
|
98
|
+
|
108
99
|
def self.adding_fields(connect,module_name,filter,fields)
|
109
100
|
offset=0
|
110
101
|
count=0
|
@@ -121,8 +112,8 @@ class Fetch_Data
|
|
121
112
|
result=Hash.new
|
122
113
|
i=0
|
123
114
|
while offset >= 0 do
|
124
|
-
url =''+"#{connect.url}"+"#{module_name}"+"
|
125
|
-
|
115
|
+
url =''+"#{connect.url}"+"#{module_name}"+"?filter=#{filter}"+'&max_num=100&offset='+offset.to_s
|
116
|
+
|
126
117
|
response = Get_Token_Process_Url.execute_uri(connect,url)
|
127
118
|
if response.kind_of? Net::HTTPSuccess
|
128
119
|
root = JSON.parse response.body
|
@@ -140,15 +131,18 @@ class Fetch_Data
|
|
140
131
|
return result.to_json
|
141
132
|
end
|
142
133
|
|
143
|
-
def self.fetch_data_with_filters(connect,module_name,filter_json,fields=["no"]
|
144
|
-
filter=
|
134
|
+
def self.fetch_data_with_filters(connect,module_name,filter_json,offset=0,fields=["no"])
|
135
|
+
filter=filter_json
|
145
136
|
|
146
137
|
|
147
138
|
if (fields[0]=="no")
|
148
139
|
|
149
|
-
url =''+"#{connect.url}"+"#{module_name}"+"
|
140
|
+
url =''+"#{connect.url}"+"#{module_name}"+"?filter=#{filter_json}"+'&max_num=100&offset='+offset.to_s
|
150
141
|
|
151
142
|
response = Get_Token_Process_Url.execute_uri(connect,url)
|
143
|
+
|
144
|
+
root = JSON.parse response.body
|
145
|
+
|
152
146
|
if response.kind_of? Net::HTTPSuccess
|
153
147
|
root = JSON.parse response.body
|
154
148
|
return root
|
@@ -160,11 +154,9 @@ class Fetch_Data
|
|
160
154
|
end
|
161
155
|
|
162
156
|
|
163
|
-
def upload_document(connect,id,
|
157
|
+
def self.upload_document(connect,id,path)
|
164
158
|
|
165
|
-
@token=Get_Token_Process_Url.authenticate
|
166
|
-
puts @token
|
167
|
-
path = File.join(__dir__,filename)
|
159
|
+
@token=Get_Token_Process_Url.authenticate(connect)
|
168
160
|
f=File.new(path,'rb')
|
169
161
|
response = RestClient::Request.execute(
|
170
162
|
:url => "#{connect.url}/Documents/#{id}/file/filename",
|
@@ -193,7 +185,7 @@ class Fetch_Data
|
|
193
185
|
|
194
186
|
def self.create_new_record(connect,module_name,params)
|
195
187
|
|
196
|
-
url=
|
188
|
+
url=''+"#{connect.url}"+module_name
|
197
189
|
uri = URI.parse url
|
198
190
|
http = Net::HTTP.new(uri.host, uri.port)
|
199
191
|
request = Net::HTTP::Post.new(uri)
|
@@ -203,7 +195,7 @@ class Fetch_Data
|
|
203
195
|
request.add_field('Content-Type','application/json')
|
204
196
|
request.body=params.to_json
|
205
197
|
response = http.request request
|
206
|
-
|
198
|
+
|
207
199
|
if response.kind_of? Net::HTTPSuccess
|
208
200
|
root = JSON.parse response.body
|
209
201
|
end
|
@@ -212,8 +204,8 @@ class Fetch_Data
|
|
212
204
|
|
213
205
|
|
214
206
|
def self.update_data(connect,module_name,params,id)
|
207
|
+
|
215
208
|
url=''+"#{connect.url}"+module_name+'/'+id
|
216
|
-
p url
|
217
209
|
uri = URI.parse url
|
218
210
|
http = Net::HTTP.new(uri.host, uri.port)
|
219
211
|
request = Net::HTTP::Put.new(uri)
|
@@ -224,7 +216,7 @@ class Fetch_Data
|
|
224
216
|
request.body=params.to_json
|
225
217
|
|
226
218
|
response = http.request request
|
227
|
-
|
219
|
+
|
228
220
|
if response.kind_of? Net::HTTPSuccess
|
229
221
|
root = JSON.parse response.body
|
230
222
|
end
|
@@ -233,7 +225,6 @@ class Fetch_Data
|
|
233
225
|
|
234
226
|
def self.delete_record(connect,module_name,id)
|
235
227
|
url=''+"#{connect.url}"+module_name+'/'+id
|
236
|
-
p url
|
237
228
|
uri = URI.parse url
|
238
229
|
http = Net::HTTP.new(uri.host, uri.port)
|
239
230
|
request = Net::HTTP::Delete.new(uri)
|
@@ -243,7 +234,7 @@ class Fetch_Data
|
|
243
234
|
request.add_field('Content-Type','application/json')
|
244
235
|
|
245
236
|
response = http.request request
|
246
|
-
|
237
|
+
|
247
238
|
if response.kind_of? Net::HTTPSuccess
|
248
239
|
root = JSON.parse response.body
|
249
240
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugarcrm_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sruthi PN
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- pn.sruthinarayanan@gmail.com
|
58
58
|
executables: []
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".rspec"
|
64
64
|
- ".travis.yml"
|
65
65
|
- Gemfile
|
66
|
+
- Gemfile.lock
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
68
69
|
- Rakefile
|
@@ -75,7 +76,7 @@ homepage: https://bitbucket.org/sruthipn96/sugarcrm_rest
|
|
75
76
|
licenses:
|
76
77
|
- MIT
|
77
78
|
metadata: {}
|
78
|
-
post_install_message:
|
79
|
+
post_install_message:
|
79
80
|
rdoc_options: []
|
80
81
|
require_paths:
|
81
82
|
- lib
|
@@ -90,8 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
91
|
- !ruby/object:Gem::Version
|
91
92
|
version: '0'
|
92
93
|
requirements: []
|
93
|
-
rubygems_version: 3.
|
94
|
-
signing_key:
|
94
|
+
rubygems_version: 3.2.3
|
95
|
+
signing_key:
|
95
96
|
specification_version: 4
|
96
97
|
summary: A gem for communicating with sugarcrm
|
97
98
|
test_files: []
|