sfrest 0.0.14 → 0.0.15
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/lib/sfrest/connection.rb +34 -37
- data/lib/sfrest/error.rb +6 -0
- data/lib/sfrest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 728d8a47e5b6c93f0dd88576f75b24d2e8cdd7a6a5aed22d89517d6835d5501d
|
4
|
+
data.tar.gz: c738283f50fe09d31b714791b44a3ec9130578e61f93b21687382a988254c6a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6663190218e40d64e6f0e6c327fe459a148d9eb8439e4d11590b44afa817d37f5ef1c91f7badfd346ac7451394bf3ea74caa3fe9fa7ab6dd4055c5b21b9ea7a
|
7
|
+
data.tar.gz: b1966f5b32571d9838106c4023dffaaec226683dccbba70375f8d921fe223643185bd028670ed616d2048fa23b4ecca5cf3605c5997eb1f88f30118a30d7e7dd
|
data/lib/sfrest/connection.rb
CHANGED
@@ -16,8 +16,8 @@ module SFRest
|
|
16
16
|
# http request via get
|
17
17
|
# @param [string] uri
|
18
18
|
# @return [Object] ruby representation of the json response
|
19
|
-
# if the
|
20
|
-
#
|
19
|
+
# if the reponse body does not parse, raises
|
20
|
+
# a SFRest::InvalidResponse
|
21
21
|
def get(uri)
|
22
22
|
headers = { 'Content-Type' => 'application/json' }
|
23
23
|
res = Excon.get(@base_url + uri.to_s,
|
@@ -25,18 +25,14 @@ module SFRest
|
|
25
25
|
user: username,
|
26
26
|
password: password,
|
27
27
|
ssl_verify_peer: false)
|
28
|
-
|
29
|
-
access_check JSON(res.body), res.status
|
30
|
-
rescue JSON::ParserError
|
31
|
-
res.body
|
32
|
-
end
|
28
|
+
api_response res
|
33
29
|
end
|
34
30
|
|
35
31
|
# http request via get
|
36
32
|
# @param [string] uri
|
37
33
|
# @return [Integer, Object] http status and the ruby representation
|
38
|
-
#
|
39
|
-
#
|
34
|
+
# if the reponse body does not parse, raises
|
35
|
+
# a SFRest::InvalidResponse
|
40
36
|
def get_with_status(uri)
|
41
37
|
headers = { 'Content-Type' => 'application/json' }
|
42
38
|
res = Excon.get(@base_url + uri.to_s,
|
@@ -44,19 +40,14 @@ module SFRest
|
|
44
40
|
user: username,
|
45
41
|
password: password,
|
46
42
|
ssl_verify_peer: false)
|
47
|
-
|
48
|
-
data = access_check JSON(res.body), res.status
|
49
|
-
return res.status, data
|
50
|
-
rescue JSON::ParserError
|
51
|
-
return res.status, res.body
|
52
|
-
end
|
43
|
+
api_response res, true
|
53
44
|
end
|
54
45
|
|
55
46
|
# http request via post
|
56
47
|
# @param [string] uri
|
57
48
|
# @return [Object] ruby representation of the json response
|
58
|
-
# if the
|
59
|
-
#
|
49
|
+
# if the reponse body does not parse, raises
|
50
|
+
# a SFRest::InvalidResponse
|
60
51
|
def post(uri, payload)
|
61
52
|
headers = { 'Content-Type' => 'application/json' }
|
62
53
|
res = Excon.post(@base_url + uri.to_s,
|
@@ -65,18 +56,14 @@ module SFRest
|
|
65
56
|
password: password,
|
66
57
|
ssl_verify_peer: false,
|
67
58
|
body: payload)
|
68
|
-
|
69
|
-
access_check JSON(res.body), res.status
|
70
|
-
rescue JSON::ParserError
|
71
|
-
res.body
|
72
|
-
end
|
59
|
+
api_response res
|
73
60
|
end
|
74
61
|
|
75
62
|
# http request via put
|
76
63
|
# @param [string] uri
|
77
64
|
# @return [Object] ruby representation of the json response
|
78
|
-
# if the
|
79
|
-
#
|
65
|
+
# if the reponse body does not parse, raises
|
66
|
+
# a SFRest::InvalidResponse
|
80
67
|
def put(uri, payload)
|
81
68
|
headers = { 'Content-Type' => 'application/json' }
|
82
69
|
res = Excon.put(@base_url + uri.to_s,
|
@@ -85,18 +72,14 @@ module SFRest
|
|
85
72
|
password: password,
|
86
73
|
ssl_verify_peer: false,
|
87
74
|
body: payload)
|
88
|
-
|
89
|
-
access_check JSON(res.body), res.status
|
90
|
-
rescue JSON::ParserError
|
91
|
-
res.body
|
92
|
-
end
|
75
|
+
api_response res
|
93
76
|
end
|
94
77
|
|
95
78
|
# http request via delete
|
96
79
|
# @param [string] uri
|
97
80
|
# @return [Object] ruby representation of the json response
|
98
|
-
# if the
|
99
|
-
#
|
81
|
+
# if the reponse body does not parse, raises
|
82
|
+
# a SFRest::InvalidResponse
|
100
83
|
def delete(uri)
|
101
84
|
headers = { 'Content-Type' => 'application/json' }
|
102
85
|
res = Excon.delete(@base_url + uri.to_s,
|
@@ -104,11 +87,22 @@ module SFRest
|
|
104
87
|
user: username,
|
105
88
|
password: password,
|
106
89
|
ssl_verify_peer: false)
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
90
|
+
api_response res
|
91
|
+
end
|
92
|
+
|
93
|
+
# Confirm that the result looks adequate
|
94
|
+
# @param [Excon::Response] res
|
95
|
+
# @param [Boolean] return_status If true returns the integer status
|
96
|
+
# with the reponse
|
97
|
+
# @return [Array|Object] if return_status then [int, Object]
|
98
|
+
# else Object
|
99
|
+
def api_response(res, return_status = false)
|
100
|
+
data = access_check JSON(res.body), res.status
|
101
|
+
ret_data = return_status ? [res.status, data] : data
|
102
|
+
return ret_data
|
103
|
+
rescue JSON::ParserError
|
104
|
+
message = "Invalid data, status #{res.status}, body: #{res.body}"
|
105
|
+
raise SFRest::InvalidResponse, message
|
112
106
|
end
|
113
107
|
|
114
108
|
# Throws an SFRest exception for requests that have problems
|
@@ -123,7 +117,9 @@ module SFRest
|
|
123
117
|
#
|
124
118
|
# The cyclomatic complexity check is being ignored here because we are
|
125
119
|
# collecting all the possible exception raising cases.
|
126
|
-
|
120
|
+
# rubocop: disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
121
|
+
def access_check(data, http_status)
|
122
|
+
raise SFRest::EmptyResult if data.size.zero?
|
127
123
|
if data.is_a?(Hash) && !data['message'].nil?
|
128
124
|
case data['message']
|
129
125
|
when /Access denied|Access Denied/
|
@@ -142,6 +138,7 @@ module SFRest
|
|
142
138
|
end
|
143
139
|
data
|
144
140
|
end
|
141
|
+
# rubocop: enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
145
142
|
|
146
143
|
# pings the SF api as an authenticated user
|
147
144
|
# responds with a pong
|
data/lib/sfrest/error.rb
CHANGED
@@ -22,4 +22,10 @@ module SFRest
|
|
22
22
|
|
23
23
|
# if you get in valid data
|
24
24
|
class InvalidDataError < SFRest::SFError; end
|
25
|
+
|
26
|
+
# If the return seems to contain no data
|
27
|
+
class EmptyResult < SFRest::SFError; end
|
28
|
+
|
29
|
+
# If the return cannot be parsed into something useful
|
30
|
+
class InvalidResponse < SFRest::SFError; end
|
25
31
|
end
|
data/lib/sfrest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sfrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ACSF Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|