secured_cloud_api_client 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/secured_cloud_api_client/http_client.rb +80 -49
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d6206f2d96d105b093a709d0c4ed98ef41fe447
|
4
|
+
data.tar.gz: 58ffd32666332b32f5031e8c35b6982a58249dce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9169c07d53fe554d1b974407532c6cda355c3c730e015bdd0877824e8968338be571096d8a51c3e97a8addb41aa93bdf67aced725b98ba2b2e4c06bf3911908
|
7
|
+
data.tar.gz: a75b25ded2f956be0fabfe0d7991744c86a8052a64f2b659326a5848e680287edcef8853944da35e98f952891a76a1bd6b21799968f03d6ab7f49bf0b285e115
|
@@ -7,6 +7,10 @@ require 'base64'
|
|
7
7
|
# Class HttpClient performs HTTP requests to the Secured Cloud API Server.
|
8
8
|
# Authentication is handled via the supplied application key and shared secret.
|
9
9
|
#
|
10
|
+
# This class expects the pem file "/cert/sc.pem" to be found in the working
|
11
|
+
# directory of the application using this library. This pem file is used for
|
12
|
+
# SSL validation.
|
13
|
+
#
|
10
14
|
# @author:: Alan Vella
|
11
15
|
##
|
12
16
|
|
@@ -41,7 +45,7 @@ class HttpClient
|
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
|
48
|
+
|
45
49
|
#Sends an HTTP GET request and returns response.
|
46
50
|
def self.sendGETRequest(authInfo, url)
|
47
51
|
|
@@ -49,22 +53,30 @@ class HttpClient
|
|
49
53
|
@sharedSecret = authInfo.getSharedSecret()
|
50
54
|
|
51
55
|
@url = URI.parse(url)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
|
57
|
+
#Setup SSL validation.
|
58
|
+
http = Net::HTTP.new(@url.host, @url.port)
|
59
|
+
http.use_ssl = true
|
60
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
61
|
+
http.cert_store = OpenSSL::X509::Store.new
|
62
|
+
http.cert_store.set_default_paths
|
63
|
+
http.cert_store.add_file(Dir.pwd + "/cert/sc.pem")
|
64
|
+
|
65
|
+
#Create and execute request
|
66
|
+
request = Net::HTTP::Get.new(@url.request_uri)
|
67
|
+
request['Accept'] = APP_CONTENT_TYPE
|
68
|
+
request['Authorization'] = AUTH_SCHEME + createAuthorization("GET", url)
|
69
|
+
response = http.request(request)
|
60
70
|
|
61
71
|
#Raise error if response is not successful.
|
62
|
-
self.handleResponseError(
|
72
|
+
self.handleResponseError(response)
|
63
73
|
|
64
74
|
#Return response.
|
65
|
-
return
|
75
|
+
return response
|
66
76
|
end
|
77
|
+
|
67
78
|
|
79
|
+
|
68
80
|
|
69
81
|
#Sends an HTTP POST request and returns response.
|
70
82
|
def self.sendPOSTRequest(authInfo, url, body)
|
@@ -73,22 +85,28 @@ class HttpClient
|
|
73
85
|
@sharedSecret = authInfo.getSharedSecret()
|
74
86
|
|
75
87
|
@url = URI.parse(url)
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
88
|
+
|
89
|
+
#Setup SSL validation.
|
90
|
+
http = Net::HTTP.new(@url.host, @url.port)
|
91
|
+
http.use_ssl = true
|
92
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
93
|
+
http.cert_store = OpenSSL::X509::Store.new
|
94
|
+
http.cert_store.set_default_paths
|
95
|
+
http.cert_store.add_file(Dir.pwd + "/cert/sc.pem")
|
96
|
+
|
97
|
+
#Create and execute request
|
98
|
+
request = Net::HTTP::Post.new(@url.request_uri)
|
99
|
+
request['Accept'] = APP_CONTENT_TYPE
|
100
|
+
request['Content-Type'] = APP_CONTENT_TYPE
|
101
|
+
request['Authorization'] = AUTH_SCHEME + createAuthorization("POST", url)
|
102
|
+
request.body = body
|
103
|
+
response = http.request(request)
|
86
104
|
|
87
105
|
#Raise error if response is not successful.
|
88
|
-
self.handleResponseError(
|
89
|
-
|
106
|
+
self.handleResponseError(response)
|
107
|
+
|
90
108
|
#Return response.
|
91
|
-
return
|
109
|
+
return response
|
92
110
|
end
|
93
111
|
|
94
112
|
|
@@ -110,21 +128,27 @@ class HttpClient
|
|
110
128
|
end
|
111
129
|
|
112
130
|
@url = URI.parse(url)
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
131
|
+
|
132
|
+
#Setup SSL validation.
|
133
|
+
http = Net::HTTP.new(@url.host, @url.port)
|
134
|
+
http.use_ssl = true
|
135
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
136
|
+
http.cert_store = OpenSSL::X509::Store.new
|
137
|
+
http.cert_store.set_default_paths
|
138
|
+
http.cert_store.add_file(Dir.pwd + "/cert/sc.pem")
|
139
|
+
|
140
|
+
#Create and execute request
|
141
|
+
request = Net::HTTP::Delete.new(@url.request_uri)
|
142
|
+
request['Accept'] = APP_CONTENT_TYPE
|
143
|
+
request['Content-Type'] = APP_CONTENT_TYPE
|
144
|
+
request['Authorization'] = AUTH_SCHEME + createAuthorization("DELETE", url)
|
145
|
+
response = http.request(request)
|
122
146
|
|
123
147
|
#Raise error if response is not successful.
|
124
|
-
self.handleResponseError(
|
125
|
-
|
148
|
+
self.handleResponseError(response)
|
149
|
+
|
126
150
|
#Return response.
|
127
|
-
return
|
151
|
+
return response
|
128
152
|
|
129
153
|
end
|
130
154
|
|
@@ -139,28 +163,35 @@ class HttpClient
|
|
139
163
|
if (params != nil) then
|
140
164
|
url += "?"
|
141
165
|
params.each do |param|
|
142
|
-
|
166
|
+
url += param[0] + "=" + param[1] + "&"
|
143
167
|
end
|
168
|
+
|
144
169
|
#Remove last ampersand
|
145
170
|
url = url[0...-1]
|
146
171
|
end
|
147
172
|
|
148
173
|
@url = URI.parse(url)
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
174
|
+
|
175
|
+
#Setup SSL validation.
|
176
|
+
http = Net::HTTP.new(@url.host, @url.port)
|
177
|
+
http.use_ssl = true
|
178
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
179
|
+
http.cert_store = OpenSSL::X509::Store.new
|
180
|
+
http.cert_store.set_default_paths
|
181
|
+
http.cert_store.add_file(Dir.pwd + "/cert/sc.pem")
|
182
|
+
|
183
|
+
#Create and execute request
|
184
|
+
request = Net::HTTP::Put.new(@url.request_uri)
|
185
|
+
request['Accept'] = APP_CONTENT_TYPE
|
186
|
+
request['Content-Type'] = APP_CONTENT_TYPE
|
187
|
+
request['Authorization'] = AUTH_SCHEME + createAuthorization("PUT", url)
|
188
|
+
response = http.request(request)
|
158
189
|
|
159
190
|
#Raise error if response is not successful.
|
160
|
-
self.handleResponseError(
|
161
|
-
|
191
|
+
self.handleResponseError(response)
|
192
|
+
|
162
193
|
#Return response.
|
163
|
-
return
|
194
|
+
return response
|
164
195
|
|
165
196
|
end
|
166
197
|
|