osc_ruby 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b8d71f6076e1f7227e4677c44199d028aacec67
4
- data.tar.gz: 1c8bab16bfce033bfa3610552fd6acfd0b52c965
3
+ metadata.gz: 942ee89662b0b209dd45a335444a2d111500bfd1
4
+ data.tar.gz: dd643b88f840af731ebde064ef83c02ef563d702
5
5
  SHA512:
6
- metadata.gz: 6d45bd2c316d5f62078017f02f60e8bc4426c7d7ce7561a7579c7ba87b15b06f2679dd985a34cc3bbd18f47140cb48013fd172796c86bd0c203b5949b77a1454
7
- data.tar.gz: 6de4026da3243b24b46f9174c980d2487ea13529b851356534620e4fbc0267da29dbd9236ed48125958d2e5b8f884e7e61d2f2440fbf0efc9fe131dcef725b13
6
+ metadata.gz: 38a462edfb97c8d90517510f042922c91fdeba3e72eaabb119c75b861218107884f9d5837a5f4d1d22e9ab1dccce12d407b6e169c10f18759215a44d16892b1b
7
+ data.tar.gz: 46de252b73802e45d236a4015c84bca4cf824a84be99e9cac87d342e3c258e710f7ca7f3676b17dce98ce7909dc3aceb641e1125894c5514fedc6ff2c0ee150e
@@ -0,0 +1,102 @@
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 = 'qsee--tst'
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
@@ -4,46 +4,53 @@ require 'openssl'
4
4
  require 'osc_ruby/version'
5
5
  require 'osc_ruby/configuration'
6
6
 
7
+
7
8
  module OSCRuby
9
+
8
10
 
9
11
  class Client
10
- # The top-level class that handles configuration and connection to the Oracle Service Cloud REST API.
12
+ # The top-level class that handles configuration and connection to the Oracle Service Cloud REST API.
13
+
14
+ attr_accessor :config
11
15
 
12
- # @return [Configuration] Config instance
13
- attr_reader :config
14
-
15
16
  def initialize
16
17
  raise ArgumentError, "block not given" unless block_given?
18
+ self.config ||= OSCRuby::Configuration.new
19
+ yield(config)
17
20
 
18
- @config = OSCRuby::Configuration.new
19
- yield config
20
-
21
- uri = basic_auth(config)
22
-
23
- connect(config,uri)
21
+ check_config
22
+ end
24
23
 
24
+ def check_config
25
+ if config.interface ==''
26
+ raise ArgumentError, "Interface cannot be nil or blank"
27
+ elsif config.username ==''
28
+ raise ArgumentError, "Username cannot be nil or blank"
29
+ elsif config.password ==''
30
+ raise ArgumentError, "Password cannot be nil or blank"
31
+ end
25
32
  end
26
33
 
27
- def basic_auth(config)
28
- uri = URI(service_cloud_interface(config))
29
- end
34
+ # def basic_auth(config)
35
+ # uri = URI(service_cloud_interface(config))
36
+ # end
30
37
 
31
- def service_cloud_interface(config)
32
- @url = 'https://' + config.interface + '/services/rest/connect/v1.3/'
33
- end
38
+ # def service_cloud_interface(config)
39
+ # @url = 'https://' + config.interface + '/services/rest/connect/v1.3/'
40
+ # end
34
41
 
35
- def connect(config,uri)
36
- Net::HTTP.start(uri.host, uri.port,
37
- :use_ssl => uri.scheme == 'https') do |http|
42
+ # def connect(config,uri)
43
+ # Net::HTTP.start(uri.host, uri.port,
44
+ # :use_ssl => uri.scheme == 'https') do |http|
38
45
 
39
- request = Net::HTTP::Get.new uri.request_uri
40
- request.basic_auth config.username, config.password
46
+ # request = Net::HTTP::Get.new uri.request_uri
47
+ # request.basic_auth config.username, config.password
41
48
 
42
- response = http.request request # Net::HTTPResponse object
49
+ # response = http.request request # Net::HTTPResponse object
43
50
 
44
- puts response
45
- puts response.body
46
- end
47
- end
51
+ # puts response
52
+ # puts response.body
53
+ # end
54
+ # end
48
55
  end
49
56
  end
@@ -1,21 +1,10 @@
1
1
  module OSCRuby
2
2
  class Configuration
3
- # takes config values for connecting to the REST API
4
-
5
- # @return [String] The basic auth username.
6
- attr_accessor :username
7
-
8
- # @return [String] The basic auth password.
9
- attr_accessor :password
10
-
11
- # @return [String] The site interface to connect to.
12
- attr_accessor :interface
13
-
14
- # @return [String] The resource that is being connected to .
15
- attr_accessor :resource
3
+
4
+ attr_accessor :interface,:username,:password,:resource
16
5
 
17
6
  def initialize
18
- @client_options = {}
7
+ @resource = ''
19
8
  end
20
9
  end
21
10
  end
@@ -1,3 +1,3 @@
1
1
  module OSCRuby
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -13,23 +13,45 @@ describe OSCRuby::Client do
13
13
  OSCRuby::Client.new do |config|
14
14
  config.interface = ''
15
15
  end
16
- end.to raise_error(NameError)
16
+ end.to raise_error("Interface cannot be nil or blank")
17
17
  end
18
18
 
19
19
  it 'should raise exception if username is blank' do
20
20
  expect do
21
21
  OSCRuby::Client.new do |config|
22
+ config.interface = 'test'
22
23
  config.username = ''
23
24
  end
24
- end.to raise_error(NameError)
25
+ end.to raise_error("Username cannot be nil or blank")
25
26
  end
26
27
 
27
28
  it 'should raise exception if password is blank' do
28
29
  expect do
29
30
  OSCRuby::Client.new do |config|
31
+ config.interface = 'test'
32
+ config.username = 'test_username'
30
33
  config.password = ''
31
34
  end
32
- end.to raise_error(NameError)
35
+ end.to raise_error("Password cannot be nil or blank")
36
+ end
37
+
38
+ it 'should create a configuration object' do
39
+ expect do
40
+ client = OSCRuby::Client.new do |config|
41
+ config.interface = 'test'
42
+ config.username = 'test_username'
43
+ config.password = 'test_password'
44
+ end
45
+
46
+ client.config.interface.should eq('test')
47
+ client.config.interface.should !='test1'
48
+
49
+ client.config.username.should eq('test_username')
50
+ client.config.username.should !='test1_username'
51
+
52
+ client.config.interface.should eq('test_password')
53
+ client.config.interface.should !='test1_password'
54
+ end
33
55
  end
34
56
  end
35
57
  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
4
+ version: 0.0.5
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-09 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,7 @@ files:
66
66
  - LICENSE.txt
67
67
  - README.md
68
68
  - Rakefile
69
+ - example.rb
69
70
  - lib/osc_ruby.rb
70
71
  - lib/osc_ruby/client.rb
71
72
  - lib/osc_ruby/configuration.rb