osc_ruby 0.0.12 → 0.0.13
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/README.md +10 -10
- data/lib/osc_ruby/connect.rb +55 -8
- data/lib/osc_ruby/version.rb +1 -1
- data/spec/core/connect_spec.rb +85 -6
- metadata +2 -3
- data/example.rb +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb6373870e5f1ee93e5a0de7320a8aeec19d3306
|
4
|
+
data.tar.gz: d2cad823e12b8f1d983062520835a07a860f3a98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deca4bb2bf62f3ceae093392f92177eafd80eded0380d7a14921938e28466d911a64120b42a82223f8e763539d4f3f4569fd42519fd48a1d9bd5e08cd5b34971
|
7
|
+
data.tar.gz: d978e17cd42c61420e1d8c764271b29fdddce3151de81dd099513fc70026794e1e86969749778b6cc230f830c3ca2f3d6807f21ea9a4fd23a0c245d8cb40eabf
|
data/README.md
CHANGED
@@ -30,8 +30,8 @@ The ultimate goal is to use this gem to make a Rails app for advanced administra
|
|
30
30
|
|
31
31
|
names = []
|
32
32
|
|
33
|
-
names[0] = {:labelText => 'QTH45', :language => {:id => 1}}
|
34
|
-
names[1] = {:labelText => 'QTH45', :language => {:id => 11}}
|
33
|
+
names[0] = {:labelText => 'QTH45-test', :language => {:id => 1}}
|
34
|
+
names[1] = {:labelText => 'QTH45-test', :language => {:id => 11}}
|
35
35
|
|
36
36
|
parent = {:id => 102}
|
37
37
|
|
@@ -67,21 +67,21 @@ The ultimate goal is to use this gem to make a Rails app for advanced administra
|
|
67
67
|
|
68
68
|
- [x] Add in Code Climate or something to show the percentage of covered methods for testing
|
69
69
|
|
70
|
-
- [
|
70
|
+
- [x] Put the URL generator method into the get class
|
71
71
|
|
72
|
-
- [
|
72
|
+
- [x] Have the get method make a get request using the Net::HTTP class
|
73
73
|
|
74
|
-
- [
|
74
|
+
- [x] Need to add tests for passing resources, query/id/other param into the URL generator class
|
75
75
|
|
76
|
-
- [
|
76
|
+
- [x] Need to figure out how to pass resources and some sort of query/id/other param into the URL generator class
|
77
77
|
|
78
|
-
- [
|
78
|
+
- [x] Add in tests for Post requests
|
79
79
|
|
80
|
-
- [
|
80
|
+
- [x] Make a Post method
|
81
81
|
|
82
|
-
- [ ] Add in tests for
|
82
|
+
- [ ] Add in tests for patch requests
|
83
83
|
|
84
|
-
- [ ] Make a
|
84
|
+
- [ ] Make a patch method
|
85
85
|
|
86
86
|
- [ ] Add in tests for delete requests
|
87
87
|
|
data/lib/osc_ruby/connect.rb
CHANGED
@@ -2,7 +2,6 @@ require 'osc_ruby/client'
|
|
2
2
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'openssl'
|
5
|
-
require 'json'
|
6
5
|
require 'uri'
|
7
6
|
|
8
7
|
module OSCRuby
|
@@ -11,13 +10,7 @@ module OSCRuby
|
|
11
10
|
|
12
11
|
def self.get(client,resource_url = nil)
|
13
12
|
|
14
|
-
|
15
|
-
raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
|
16
|
-
elsif !resource_url.nil?
|
17
|
-
@final_config = generate_url_and_config(client,resource_url)
|
18
|
-
else
|
19
|
-
@final_config = generate_url_and_config(client,nil)
|
20
|
-
end
|
13
|
+
@final_config = get_check(client,resource_url)
|
21
14
|
|
22
15
|
@uri = @final_config['site_url']
|
23
16
|
@username = @final_config['username']
|
@@ -28,10 +21,38 @@ module OSCRuby
|
|
28
21
|
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
29
22
|
|
30
23
|
request = Net::HTTP::Get.new @uri.request_uri
|
24
|
+
|
25
|
+
request.add_field('Content-Type', 'application/x-www-form-urlencoded')
|
26
|
+
|
31
27
|
request.basic_auth @username, @password
|
32
28
|
|
33
29
|
response = http.request request # Net::HTTPResponse object
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.post(client,resource_url = nil, json_content = nil)
|
36
|
+
|
37
|
+
@final_config = post_check(client,resource_url, json_content)
|
38
|
+
|
39
|
+
@uri = @final_config['site_url']
|
40
|
+
@username = @final_config['username']
|
41
|
+
@password = @final_config['password']
|
42
|
+
|
43
|
+
Net::HTTP.start(@uri.host, @uri.port,
|
44
|
+
:use_ssl => true,
|
45
|
+
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
46
|
+
|
47
|
+
request = Net::HTTP::Post.new @uri.request_uri
|
48
|
+
request.basic_auth @username, @password
|
49
|
+
request.content_type = "application/json"
|
50
|
+
request.body = JSON.dump(json_content)
|
51
|
+
|
52
|
+
response = http.request request # Net::HTTPResponse object
|
53
|
+
|
34
54
|
end
|
55
|
+
|
35
56
|
end
|
36
57
|
|
37
58
|
private
|
@@ -74,5 +95,31 @@ module OSCRuby
|
|
74
95
|
|
75
96
|
end
|
76
97
|
|
98
|
+
def self.get_check(client,resource_url = nil)
|
99
|
+
|
100
|
+
if client.nil?
|
101
|
+
raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
|
102
|
+
elsif !resource_url.nil?
|
103
|
+
@final_config = generate_url_and_config(client,resource_url)
|
104
|
+
else
|
105
|
+
@final_config = generate_url_and_config(client,nil)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.post_check(client,resource_url = nil, json_content = nil)
|
111
|
+
|
112
|
+
if client.nil?
|
113
|
+
raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
|
114
|
+
elsif resource_url.nil?
|
115
|
+
raise ArgumentError, "There is no URL resource provided; please specify a URL resource that you would like to send a POST request to"
|
116
|
+
elsif json_content.nil?
|
117
|
+
raise ArgumentError, "There is no json content provided; please specify json content that you would like to send a POST request with"
|
118
|
+
else
|
119
|
+
@final_config = generate_url_and_config(client,resource_url)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
77
124
|
end
|
78
125
|
end
|
data/lib/osc_ruby/version.rb
CHANGED
data/spec/core/connect_spec.rb
CHANGED
@@ -36,18 +36,18 @@ describe OSCRuby::Connect do
|
|
36
36
|
|
37
37
|
expect do
|
38
38
|
|
39
|
-
OSCRuby::Connect.generate_url_and_config(client, '
|
39
|
+
OSCRuby::Connect.generate_url_and_config(client, 'serviceProducts')
|
40
40
|
|
41
41
|
end.not_to raise_error
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should change the final configured url if the resource_url parameter is specified' do
|
45
45
|
|
46
|
-
test = OSCRuby::Connect.generate_url_and_config(client, '
|
46
|
+
test = OSCRuby::Connect.generate_url_and_config(client, 'serviceProducts')
|
47
47
|
|
48
48
|
interface = client.config.interface
|
49
49
|
|
50
|
-
expect(test['site_url']).to eq(URI("https://#{interface}.custhelp.com/services/rest/connect/v1.3/
|
50
|
+
expect(test['site_url']).to eq(URI("https://#{interface}.custhelp.com/services/rest/connect/v1.3/serviceProducts"))
|
51
51
|
|
52
52
|
expect(test['site_url']).to be_an(URI::HTTPS)
|
53
53
|
end
|
@@ -172,11 +172,90 @@ describe OSCRuby::Connect do
|
|
172
172
|
|
173
173
|
it 'should produce a JSON Response form the response body' do
|
174
174
|
|
175
|
-
expect
|
176
|
-
test.body.should_be a('String')
|
177
|
-
end
|
175
|
+
expect(test.body).to be_an(String)
|
178
176
|
|
179
177
|
expect{JSON.parse(test.body)}.not_to raise_error
|
180
178
|
end
|
179
|
+
|
180
|
+
let(:json_content){
|
181
|
+
{:test => 'content'}
|
182
|
+
}
|
183
|
+
|
184
|
+
context '#post' do
|
185
|
+
|
186
|
+
it 'should take at least a config parameter that is an instance of an OSCRuby::Client' do
|
187
|
+
|
188
|
+
expect(client).to be_an(OSCRuby::Client)
|
189
|
+
|
190
|
+
expect do
|
191
|
+
|
192
|
+
OSCRuby::Connect.post(client,'serviceProducts',json_content)
|
193
|
+
|
194
|
+
end.not_to raise_error
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should raise an error if client is nil' do
|
198
|
+
|
199
|
+
expect do
|
200
|
+
|
201
|
+
client = nil
|
202
|
+
|
203
|
+
OSCRuby::Connect.post(client,'serviceProducts',json_content)
|
204
|
+
|
205
|
+
end.to raise_error("Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings")
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'should raise an error if resource_url is nil' do
|
210
|
+
|
211
|
+
expect do
|
212
|
+
|
213
|
+
OSCRuby::Connect.post(client,'serviceProducts')
|
214
|
+
|
215
|
+
end.to raise_error("There is no json content provided; please specify json content that you would like to send a POST request with")
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should produce a Net::HTTPResponse, should produce a 201 response code, and should produce a JSON Response form the response body' do
|
220
|
+
|
221
|
+
names = []
|
222
|
+
|
223
|
+
names[0] = {:labelText => 'QTH45-test', :language => {:id => 1}}
|
224
|
+
names[1] = {:labelText => 'QTH45-test', :language => {:id => 11}}
|
225
|
+
|
226
|
+
parent = {:id => 102}
|
227
|
+
|
228
|
+
displayOrder = {:id => 4}
|
229
|
+
|
230
|
+
admin_user_visible_interfaces = []
|
231
|
+
admin_user_visible_interfaces[0] = {:id => 1}
|
232
|
+
|
233
|
+
end_user_visible_interfaces = []
|
234
|
+
end_user_visible_interfaces[0] = {:id => 1}
|
235
|
+
|
236
|
+
new_prod = []
|
237
|
+
new_prod[0] = {:names => names,
|
238
|
+
:parent => parent,
|
239
|
+
:adminVisibleInterfaces => admin_user_visible_interfaces,
|
240
|
+
:endUserVisibleInterfaces => end_user_visible_interfaces}
|
241
|
+
|
242
|
+
test = OSCRuby::Connect.post(client,'serviceProducts',new_prod[0])
|
243
|
+
|
244
|
+
expect(test).to be_an(Net::HTTPResponse)
|
245
|
+
|
246
|
+
expect(test.code).to eq("201")
|
247
|
+
|
248
|
+
expect(test.body).to be_an(String)
|
249
|
+
|
250
|
+
expect{JSON.parse(test.body)}.not_to raise_error
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
context '#patch'
|
257
|
+
|
258
|
+
|
259
|
+
end
|
181
260
|
end
|
182
261
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: osc_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rajan Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,7 +69,6 @@ files:
|
|
69
69
|
- LICENSE.txt
|
70
70
|
- README.md
|
71
71
|
- Rakefile
|
72
|
-
- example.rb
|
73
72
|
- lib/osc_ruby.rb
|
74
73
|
- lib/osc_ruby/client.rb
|
75
74
|
- lib/osc_ruby/configuration.rb
|
data/example.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
# Client class to initiate generic requests
|
2
|
-
|
3
|
-
# => hosts Net::HTTP Class
|
4
|
-
# => returns the response
|
5
|
-
|
6
|
-
# => CREATE
|
7
|
-
|
8
|
-
# => POST to end point
|
9
|
-
|
10
|
-
# => READ
|
11
|
-
# => SHOW Example
|
12
|
-
# Net::HTTP.start(uri.host, uri.port,
|
13
|
-
# :use_ssl => uri.scheme == 'https',
|
14
|
-
# :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
15
|
-
|
16
|
-
# request = Net::HTTP::Get.new uri.request_uri
|
17
|
-
# request.basic_auth username, password
|
18
|
-
|
19
|
-
# response = http.request request # Net::HTTPResponse object
|
20
|
-
|
21
|
-
# json_response = JSON.parse(response.body)
|
22
|
-
|
23
|
-
# end
|
24
|
-
|
25
|
-
# Configuration class to collect client values
|
26
|
-
# => username
|
27
|
-
# => password
|
28
|
-
# => interface
|
29
|
-
|
30
|
-
# ServiceProduct class
|
31
|
-
|
32
|
-
require 'net/http'
|
33
|
-
require 'openssl'
|
34
|
-
require 'json'
|
35
|
-
require 'uri'
|
36
|
-
|
37
|
-
interface = ENV['OSC_TEST_SITE']
|
38
|
-
username = ENV['OSC_ADMIN']
|
39
|
-
password = ENV['OSC_PASSWORD']
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
products_query = 'select id,lookupname,parent.id,displayorder from serviceproducts'
|
44
|
-
interface_query = 'select id,name,language from siteinterfaces'
|
45
|
-
final_query = products_query+';'+interface_query
|
46
|
-
uri = URI.encode("https://#{interface}.custhelp.com/services/rest/connect/v1.3/queryResults?query=#{final_query};")
|
47
|
-
uri = URI.parse(uri)
|
48
|
-
puts uri
|
49
|
-
|
50
|
-
|
51
|
-
Net::HTTP.start(uri.host, uri.port,
|
52
|
-
:use_ssl => uri.scheme == 'https',
|
53
|
-
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
54
|
-
|
55
|
-
request = Net::HTTP::Get.new uri.request_uri
|
56
|
-
request.add_field('Content-Type', 'application/x-www-form-urlencoded')
|
57
|
-
request.basic_auth username, password
|
58
|
-
|
59
|
-
response = http.request request # Net::HTTPResponse object
|
60
|
-
|
61
|
-
json_response = JSON.parse(response.body)
|
62
|
-
|
63
|
-
puts JSON.pretty_generate(json_response)
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
# names = []
|
68
|
-
|
69
|
-
# names[0] = {:labelText => 'QTH45', :language => {:id => 1}}
|
70
|
-
# names[1] = {:labelText => 'QTH45', :language => {:id => 11}}
|
71
|
-
|
72
|
-
# parent = {:id => 102}
|
73
|
-
|
74
|
-
# displayOrder = {:id => 4}
|
75
|
-
|
76
|
-
# admin_user_visible_interfaces = []
|
77
|
-
# admin_user_visible_interfaces[0] = {:id => 1}
|
78
|
-
|
79
|
-
# end_user_visible_interfaces = []
|
80
|
-
# end_user_visible_interfaces[0] = {:id => 1}
|
81
|
-
|
82
|
-
# new_prod = []
|
83
|
-
# new_prod[0] = {:names => names,
|
84
|
-
# :parent => parent,
|
85
|
-
# :adminVisibleInterfaces => admin_user_visible_interfaces,
|
86
|
-
# :endUserVisibleInterfaces => end_user_visible_interfaces}
|
87
|
-
|
88
|
-
# Net::HTTP.start(uri.host, uri.port,
|
89
|
-
# :use_ssl => uri.scheme == 'https',
|
90
|
-
# :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
|
91
|
-
|
92
|
-
# request = Net::HTTP::Post.new uri.request_uri
|
93
|
-
# request.basic_auth username, password
|
94
|
-
# request.content_type = "application/json"
|
95
|
-
# request.body = JSON.dump(new_prod)
|
96
|
-
|
97
|
-
# response = http.request request # Net::HTTPResponse object
|
98
|
-
|
99
|
-
# json_response = JSON.parse(response.body)
|
100
|
-
|
101
|
-
# puts JSON.pretty_generate(json_response)
|
102
|
-
# end
|