kenna 0.1.2 → 0.1.3
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 +1 -1
- data/lib/kenna.rb +46 -45
- data/lib/kenna/version.rb +1 -1
- 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: 9600a1d39f8347074e28831e4473d51a88e0ff2c
|
4
|
+
data.tar.gz: fd9fbf79911a68917bb1e02e40842d108f7f1326
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c703b3c4998b3a399d2986fb521f05709eb440fd85774a0f7768274d50b60f7f7c1a13983fcbed90398cbc071507de68538b68921b31a1301065ef7ff3bd7a7d
|
7
|
+
data.tar.gz: fbe2f7f8a5a917ffff78583d1e3915c32db18e9be641c43d108b8e0ddb0b8f1410c44a26cfe3b1d2f86fae34b8437a9184e3c0c92322a21f8b0ac4984d0c8f4b
|
data/Gemfile.lock
CHANGED
data/lib/kenna.rb
CHANGED
@@ -14,6 +14,9 @@ module Kenna
|
|
14
14
|
# Must have a token to continue
|
15
15
|
def initialize(token)
|
16
16
|
$token = token
|
17
|
+
|
18
|
+
# Slow it down 500ms due to throttling
|
19
|
+
sleep(0.5)
|
17
20
|
end
|
18
21
|
|
19
22
|
# TODO (Maynard Black): ask Kenna about API versioning
|
@@ -29,17 +32,16 @@ module Kenna
|
|
29
32
|
# TODO (Important - Maynard Black): Refactor to return the whole response including headers
|
30
33
|
# This means updating the tests first! Then the API Browser App!
|
31
34
|
# I am currently only returning a JSON parsed body so there is no way to catch 404s and such
|
32
|
-
#
|
35
|
+
# UPDATE: DONE
|
33
36
|
# TODO (Maynard Black): Refactor the 2 post, put, getAllUsers, getUserById methods to return headers
|
34
37
|
# TODO (Maynard Black): Catch exceptions when hitting server, that is the only way to
|
35
38
|
# catch certain response codes (like 404) with the client I am using
|
36
39
|
|
37
|
-
|
40
|
+
#################### Post ####################
|
41
|
+
|
38
42
|
def post(uri, body)
|
39
43
|
body = body.to_json
|
40
44
|
@url = $base_url + uri
|
41
|
-
|
42
|
-
|
43
45
|
@response = RestClient.post(@url, body, headers={'X-Risk-Token' => $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
44
46
|
|
45
47
|
rescue StandardError => e
|
@@ -51,53 +53,42 @@ module Kenna
|
|
51
53
|
#ensure
|
52
54
|
end
|
53
55
|
|
54
|
-
def postByResource(resource, body)
|
55
|
-
body = body.to_json
|
56
|
-
@url = $base_url +'/'+ resource
|
57
|
-
@response = RestClient.post(@url, body, headers={'X-Risk-Token' => $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
58
|
-
JSON.parse(@response.body)
|
59
|
-
end
|
60
56
|
|
61
|
-
|
57
|
+
#################### Get ####################
|
62
58
|
def get(uri)
|
63
59
|
@url = $base_url + uri
|
64
60
|
@response = RestClient.get(@url, headers={'X-Risk-Token' => $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
65
61
|
end
|
66
62
|
|
67
|
-
|
68
|
-
|
69
|
-
RestClient.get(@url, headers={'X-Risk-Token' => $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
70
|
-
end
|
71
|
-
|
72
|
-
# Update
|
73
|
-
def update(uri, body)
|
63
|
+
#################### Put ####################
|
64
|
+
def put(uri, body)
|
74
65
|
body = body.to_json
|
75
66
|
@url = $base_url + uri
|
76
67
|
@response = RestClient.put(@url, body, headers={'X-Risk-Token' => $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
68
|
+
|
69
|
+
rescue StandardError => e
|
70
|
+
@return = {}
|
71
|
+
@return['http_code'] = e.http_code
|
72
|
+
@return['message'] = e.message
|
73
|
+
@return.to_json
|
74
|
+
#ensure
|
77
75
|
end
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
@url = $base_url +'/'+ resource +'/' + id.to_s
|
82
|
-
@response = RestClient.put(@url, body, headers={'X-Risk-Token' => $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
83
|
-
end
|
84
|
-
|
85
|
-
# Delete
|
77
|
+
|
78
|
+
#################### Delete ####################
|
86
79
|
def delete(uri)
|
87
80
|
@url = $base_url + uri
|
88
81
|
@response = RestClient.delete(@url, headers={'X-Risk-Token' => $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
89
82
|
end
|
90
83
|
|
91
|
-
def deleteById(resource, id)
|
92
|
-
@url = $base_url +'/'+ resource +'/' + id.to_s
|
93
|
-
@response = RestClient.delete(@url, headers={'X-Risk-Token' => $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
94
|
-
end
|
95
84
|
|
96
|
-
|
85
|
+
#################### User Specific Methods ####################
|
86
|
+
|
97
87
|
# TODO (Maynard Black): Finish all User options
|
98
88
|
# TODO (Maynard Black): Do this for all other endpoints
|
99
89
|
# TODO (Maynard Black): Some endpoint calls will require an array of id's, the app can fill
|
100
90
|
# in the rest
|
91
|
+
|
101
92
|
def getAllUsers()
|
102
93
|
@url = $base_url + '/users'
|
103
94
|
@response = RestClient.get(@url, headers={'X-Risk-Token' => $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json'})
|
@@ -110,8 +101,8 @@ module Kenna
|
|
110
101
|
JSON.parse(@response.body)["user"]
|
111
102
|
end
|
112
103
|
|
113
|
-
|
114
|
-
|
104
|
+
#################### Generate a unique fake user for testing ####################
|
105
|
+
|
115
106
|
def fakeUser
|
116
107
|
@roles = ['administrator', 'normal user', 'Linux Test Environment']
|
117
108
|
@role = @roles[rand(0..2)]
|
@@ -126,12 +117,13 @@ module Kenna
|
|
126
117
|
}
|
127
118
|
end
|
128
119
|
|
129
|
-
|
120
|
+
#################### Pretty version for API Browser ####################
|
130
121
|
def fakeUserPretty
|
131
122
|
@fup = JSON.pretty_generate JSON.parse(fakeUser)
|
132
123
|
@fup.to_s
|
133
124
|
end
|
134
125
|
|
126
|
+
########################################################################
|
135
127
|
end
|
136
128
|
end
|
137
129
|
|
@@ -158,10 +150,11 @@ $api = Kenna::Api.new("ty9hxcpmgdrvnuqe")
|
|
158
150
|
|
159
151
|
# @new_user = $api.post('/users', $api.fakeUser)
|
160
152
|
# @new_user = JSON.parse(@new_user)
|
161
|
-
# if
|
153
|
+
# if @new_user['message']
|
154
|
+
# puts '*ERROR* *ERROR* *ERROR* *ERROR* *ERROR* *ERROR* '
|
162
155
|
# puts @new_user
|
163
156
|
# else
|
164
|
-
# puts @new_user['
|
157
|
+
# puts @new_user['user']['id']
|
165
158
|
# end
|
166
159
|
|
167
160
|
# @new_user = $api.postByResource('users', $api.fakeUser)
|
@@ -187,26 +180,34 @@ $api = Kenna::Api.new("ty9hxcpmgdrvnuqe")
|
|
187
180
|
|
188
181
|
################################### PUT ########################################
|
189
182
|
|
190
|
-
#
|
191
|
-
# @
|
192
|
-
#
|
193
|
-
|
183
|
+
# $id = 35665
|
184
|
+
# @b = {"user":{"firstname":"Maynard"}}
|
185
|
+
# @api_response = $api.put('/users/' + $id.to_s, @b)
|
186
|
+
|
187
|
+
# if @api_response.class != RestClient::Response
|
188
|
+
# puts @api_response
|
189
|
+
# else
|
190
|
+
# @get_api_response = $api.get('/users/' + $id.to_s)
|
191
|
+
# puts @get_api_response
|
192
|
+
# end
|
194
193
|
|
195
|
-
|
194
|
+
|
196
195
|
# @body = {"firstname":"KERMIT"}
|
197
|
-
# $api.
|
196
|
+
# $api.put('/users/' + $id.to_s, @body)
|
198
197
|
|
199
198
|
|
200
199
|
################################### DELETE #####################################
|
201
200
|
|
202
|
-
# $id = $api.getAllUsers()
|
203
|
-
#
|
201
|
+
# $id = $api.getAllUsers()
|
202
|
+
# sleep(0.1) # it looks like if there are a lot of records you can't get one by index until the query is done. IDK. Need to learn more.
|
203
|
+
# $id = $id[9]['id']
|
204
204
|
|
205
205
|
# @delete = $api.delete('/users/' + $id.to_s)
|
206
|
-
# puts @delete.code
|
206
|
+
# puts @delete.code
|
207
207
|
|
208
|
+
# $id = 35940
|
208
209
|
# @user = $api.get('/users/' + $id.to_s)
|
209
|
-
|
210
|
+
# puts @user
|
210
211
|
################################### Custom - /user #############################
|
211
212
|
|
212
213
|
# @users = JSON.parse(@users)
|
data/lib/kenna/version.rb
CHANGED