osc_ruby 0.1.0 → 0.1.1

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: 8037699e524a610096534990ff8c2a5c6b675375
4
- data.tar.gz: de4304b8f05ed89f3226d67ab8b310d6c9ce430f
3
+ metadata.gz: bf379c1f203bbe3a5a5f77bde85d2618a0115158
4
+ data.tar.gz: a4d27cee02b3451ce580283ad09b3a41137ac320
5
5
  SHA512:
6
- metadata.gz: eceab49e9e22cd4965d9e386c1f78fe2dccbe1676ddf48d4a47818c4cf039d8903c67b06aaf3717bf87783f7054f1cadb118202912ae8c2acf6cf85e9b6b6b6a
7
- data.tar.gz: 202c440ec8081ddce1542131e1624dd97c7b1b0229fbd8efe64f99b404558778407446d7196ab10f6a0be88680c0e9fd173cbda80bb4b00db6ccbc06ae563a7d
6
+ metadata.gz: 9b4a750e171d4f02b355511a9de8643314182d744ee53f4e72bf2e5b3300c4585417ee390adcf43266f392fbf84aa11652f2683ce831d25256902644d4861e15
7
+ data.tar.gz: 4627953fdbd006c4ace517f8239d1a1a41f4078f08e54cefd4da100039814bda45a0927ba2d5c5d5dc40d3b0a67cdde7b79bb65d85b60ba5e21564d7207cdb6f
data/README.md CHANGED
@@ -4,57 +4,76 @@
4
4
 
5
5
  [![Test Coverage](https://codeclimate.com/github/rajangdavis/osc_ruby/badges/coverage.svg)](https://codeclimate.com/github/rajangdavis/osc_ruby/coverage)
6
6
 
7
+
8
+
7
9
  An (under development) Ruby ORM for using Oracle Service Cloud influenced by the ConnectPHP API and ActiveRecord Gem
8
10
 
9
11
  ## Example (still coding this out, but trying to get this pretty simple)
10
12
 
11
- # Product Fetch example
13
+ # Configuration is as simple as requiring the gem
14
+ # and adding a config block (Completed 12/2016)
12
15
 
13
- client = OSCRuby::Client.new do |config|
14
- config.interface = ENV['OSC_TEST_SITE']
16
+ require 'osc_ruby'
17
+
18
+ rn_client = OSCRuby::Client.new do |config|
15
19
  config.username = ENV['OSC_ADMIN']
16
20
  config.password = ENV['OSC_PASSWORD']
21
+ config.interface = ENV['OSC_TEST_SITE']
17
22
  end
18
23
 
19
- product = OSCRuby::ServiceProduct.fetch(1)
20
24
 
21
- # returns OSCRuby::ServiceProduct object with id of 1
25
+ # ServiceProduct fetch example (Completed 12/28/2016)
22
26
 
23
- puts product.name
27
+ product = ServiceProduct.find(rn_client,100)
24
28
 
25
- # =>'Product Lookup Name'
29
+ puts product
30
+ # => #<ServiceProduct:0x007fd0fa87e588>
26
31
 
27
- puts product.displayOrder
32
+ puts product.name
33
+ # => QR404
28
34
 
29
- # => 64
35
+ puts product.displayOrder
36
+ # => 3
30
37
 
38
+ # ServiceProduct fetch all example
31
39
 
40
+ products = OSCRuby::ServiceProduct.all(rn_client)
32
41
 
42
+ products.each do |p|
33
43
 
34
- # Product Creation example
44
+ puts p.name
35
45
 
36
- new_product = OSCRuby::ServiceProduct.new
46
+ end
37
47
 
38
- # use Ruby hashes to set field information
48
+ # => Unsure
49
+ # => DVR/NVR
50
+ # => QC Series
51
+ # => QR Series
52
+ # => QR404
53
+ # => QS Series
54
+ # => QT Series
39
55
 
40
- new_product.names[0] = {:labelText => 'QTH45-test', :language => {:id => 1}}
41
- new_product.names[1] = {:labelText => 'QTH45-test', :language => {:id => 11}}
56
+ # Product Creation example
42
57
 
43
- new_product.parent = {:id => 102}
58
+ new_product = OSCRuby::ServiceProduct.new
44
59
 
45
- new_product.displayOrder = {:id => 4}
60
+ # use Ruby hashes to set field information
46
61
 
47
- new_product.adminUserVisibleInterfaces[0] = {:id => 1}
62
+ new_product.names[0] = {'labelText' => 'QTH45-test', 'language' => {'id' => 1}}
63
+ new_product.names[1] = {'labelText' => 'QTH45-test', 'language' => {'id' => 11}}
48
64
 
49
- new_product.endUserVisibleInterfaces[0] = {:id => 1}
65
+ new_product.parent = {'id' => 102}
50
66
 
51
- new_product.save(client)
67
+ new_product.displayOrder = 4
52
68
 
53
- # callback with JSON details
69
+ new_product.adminVisibleInterfaces[0] = {'id' => 1}
54
70
 
71
+ new_product.endUserVisibleInterfaces[0] = {'id' => 1}
55
72
 
73
+ new_product.save(client)
74
+
75
+ # callback with JSON details
56
76
 
57
-
58
77
 
59
78
  ## To do list
60
79
 
@@ -90,9 +109,27 @@ An (under development) Ruby ORM for using Oracle Service Cloud influenced by the
90
109
 
91
110
  - [x] Make a delete method
92
111
 
93
- - [ ] Create a OSCRuby::ServiceProduct class
112
+ - [x] Create a OSCRuby::ServiceProduct class
113
+
114
+ - [x] Build a QueryModule Module with the following query methods to be shared between all classes:
115
+
116
+ - [x] find
117
+
118
+ - [ ] take
119
+
120
+ - [ ] first
121
+
122
+ - [ ] last
123
+
124
+ - [ ] order
125
+
126
+ - [ ] find_by
127
+
128
+ - [ ] where
129
+
130
+ - [ ] all
94
131
 
95
- - [ ] I might need to do a transformation class that converts JSON response into a Ruby Hash
132
+ - [x] QueryModel converts JSON response into a Ruby Hash => new instance of the object being queried
96
133
 
97
134
  - [ ] Figure out how to do RDoc/Yardoc documentation or best in class documentation for using this Ruby Wrapper
98
135
 
data/example.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'osc_ruby'
2
+
3
+ rn_client = OSCRuby::Client.new do |config|
4
+ config.username = ENV['OSC_ADMIN']
5
+ config.password = ENV['OSC_PASSWORD']
6
+ config.interface = ENV['OSC_TEST_SITE']
7
+ end
8
+
9
+
10
+ # ServiceProduct fetch example
11
+
12
+ product = ServiceProduct.find(rn_client,100)
13
+
14
+ puts product
15
+
16
+ # => #<ServiceProduct:0x007fd0fa87e588>
17
+
18
+ puts product.name
19
+
20
+ # => QR404
21
+
22
+ puts product.displayOrder
23
+
24
+ # => 3
25
+
26
+ # ServiceProduct fetch all example
27
+
28
+ products = OSCRuby::ServiceProduct.all(rn_client)
29
+
30
+ products.each do |p|
31
+
32
+ puts p.name
33
+
34
+ end
35
+
36
+ # => Unsure
37
+ # => DVR/NVR
38
+ # => QC Series
39
+ # => QR Series
40
+ # => QR404
41
+ # => QS Series
42
+ # => QT Series
data/lib/ext/string.rb ADDED
@@ -0,0 +1,5 @@
1
+ class String
2
+ def is_i?
3
+ /\A[-+]?\d+\z/ === self
4
+ end
5
+ end
@@ -4,7 +4,6 @@ require 'osc_ruby/configuration'
4
4
 
5
5
  module OSCRuby
6
6
 
7
-
8
7
  class Client
9
8
  # The top-level class that handles configuration and connection to the Oracle Service Cloud REST API.
10
9
 
@@ -1,10 +1,11 @@
1
1
  module OSCRuby
2
+
2
3
  class Configuration
4
+ # A holder class that holds the configuration information for the OSCRuby::Client block
3
5
 
4
- attr_accessor :interface,:username,:password,:resource
6
+ attr_accessor :interface,:username,:password
5
7
 
6
8
  def initialize
7
- @resource = ''
8
9
  end
9
10
  end
10
11
  end
@@ -7,6 +7,7 @@ require 'uri'
7
7
  module OSCRuby
8
8
 
9
9
  class Connect
10
+ # This class is purely to provide the underlying methods for CRUD functionality using Net::HTTP, URI, and OpenSSL
10
11
 
11
12
  def self.get(client,resource_url = nil)
12
13
 
@@ -0,0 +1,72 @@
1
+ require 'osc_ruby/connect'
2
+ require_relative '../ext/string'
3
+
4
+ require 'json'
5
+
6
+ module OSCRuby
7
+
8
+ module QueryModule
9
+
10
+ def self.find(rn_client,resource)
11
+
12
+ obj_to_find = OSCRuby::Connect.get(rn_client,resource)
13
+
14
+ check_obj_for_errors(obj_to_find)
15
+
16
+ obj_info = normalize(obj_to_find)
17
+
18
+ end
19
+
20
+ def self.create(rn_client,resource,json_content)
21
+
22
+ obj_to_find = OSCRuby::Connect.post_or_patch(rn_client,resource,json_content)
23
+
24
+ obj_to_find.body
25
+
26
+ end
27
+
28
+ def self.normalize(input)
29
+
30
+ if input.code.to_i == 404
31
+
32
+ input.body
33
+
34
+ else
35
+
36
+ _json = JSON.parse(input.body)
37
+
38
+ final_hash = []
39
+
40
+ _json['items'][0]['rows'].each do |row|
41
+
42
+ obj_hash = {}
43
+
44
+ _json['items'][0]['columnNames'].each_with_index do |column,i|
45
+ obj_hash[column] = if !row[i].nil? && row[i].is_i? == true then row[i].to_i else row[i] end
46
+ end
47
+
48
+ final_hash.push(obj_hash)
49
+
50
+ end
51
+
52
+ final_hash.to_json
53
+
54
+ end
55
+
56
+ end
57
+
58
+ def self.check_obj_for_errors(obj_to_check)
59
+
60
+ _json = JSON.parse(obj_to_check.body)
61
+
62
+ if _json['items'][0]['rows'].count == 0
63
+
64
+ raise ArgumentError, 'There were no objects matching your query; please try again.'
65
+
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,130 @@
1
+ require 'osc_ruby/client'
2
+ require 'osc_ruby/query_module'
3
+ require 'json'
4
+ require 'uri'
5
+
6
+ module OSCRuby
7
+
8
+ class ServiceProduct
9
+
10
+ include QueryModule
11
+
12
+ attr_reader :id, :lookupName, :createdTime, :updatedTime, :name
13
+
14
+ attr_accessor :names, :parent, :displayOrder, :adminVisibleInterfaces, :endUserVisibleInterfaces
15
+
16
+ def initialize(attributes = nil)
17
+
18
+ if attributes.nil?
19
+
20
+ @names = []
21
+
22
+ @parent = {}
23
+
24
+ @displayOrder = 1
25
+
26
+ @adminVisibleInterfaces = []
27
+
28
+ @endUserVisibleInterfaces = []
29
+
30
+ else
31
+
32
+ @id = attributes["id"]
33
+
34
+ @lookupName = attributes["lookupName"]
35
+
36
+ @createdTime = attributes["createdTime"]
37
+
38
+ @updatedTime = attributes["updatedTime"]
39
+
40
+ @displayOrder = attributes["displayOrder"]
41
+
42
+ @name = attributes["name"]
43
+
44
+ @parent = attributes["parent"]
45
+
46
+ end
47
+
48
+ end
49
+
50
+ def self.find(client,id = nil)
51
+
52
+ check_client(client)
53
+
54
+ if id.nil? == true
55
+ raise ArgumentError, 'ID cannot be nil'
56
+ elsif id.class != Fixnum
57
+ raise ArgumentError, 'ID must be an integer'
58
+ end
59
+
60
+ resource = URI.escape("queryResults/?query=select * from serviceproducts where id = #{id}")
61
+
62
+ service_product_json = QueryModule::find(client,resource)
63
+
64
+ service_product_json_final = JSON.parse(service_product_json)
65
+
66
+ new_from_fetch(service_product_json_final[0])
67
+
68
+ end
69
+
70
+ # def self.all(client)
71
+
72
+ # resource = URI.escape("queryResults/?query=select * from serviceproducts")
73
+
74
+ # service_product_json = QueryModule::find(client,resource)
75
+
76
+ # service_product_json_final = JSON.parse(service_product_json)
77
+
78
+ # service_product_json_final.map { |attributes| new_from_fetch(attributes) }
79
+
80
+ # end
81
+
82
+ # def create(client)
83
+
84
+ # new_product = self
85
+
86
+ # empty_arr = []
87
+
88
+ # json_content = {}
89
+
90
+ # new_product.instance_variables.each {|var| json_content[var.to_s.delete("@")] = new_product.instance_variable_get(var)}
91
+
92
+ # empty_arr[0] = json_content
93
+
94
+ # puts JSON.pretty_generate(empty_arr)
95
+
96
+ # resource = URI.escape("/serviceProducts")
97
+
98
+ # service_product_json = QueryModule::create(client,resource,empty_arr[0])
99
+
100
+ # end
101
+
102
+ def self.new_from_fetch(attributes)
103
+
104
+ check_attributes(attributes)
105
+
106
+ OSCRuby::ServiceProduct.new(attributes)
107
+
108
+ end
109
+
110
+ def self.check_attributes(attributes)
111
+
112
+ if attributes.class != Hash
113
+
114
+ raise ArgumentError, "Attributes must be a hash; please use the appropriate data structure"
115
+
116
+ end
117
+
118
+ end
119
+
120
+ def self.check_client(client)
121
+
122
+ if client.class != OSCRuby::Client || client.nil?
123
+ raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
124
+ end
125
+
126
+ end
127
+
128
+ end
129
+
130
+ end
@@ -1,3 +1,3 @@
1
1
  module OSCRuby
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/osc_ruby.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module OSCRuby; end
2
2
 
3
3
  require 'osc_ruby/client'
4
- require 'osc_ruby/connect'
4
+ require 'osc_ruby/connect'
5
+ require 'osc_ruby/service_product'
@@ -0,0 +1,152 @@
1
+ require 'core/spec_helper'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ describe OSCRuby::ServiceProduct do
6
+
7
+ let(:service_product){
8
+
9
+ OSCRuby::ServiceProduct.new
10
+
11
+ }
12
+
13
+ context '#initialize' do
14
+
15
+ it 'should not throw an error when initialized' do
16
+
17
+ expect{service_product}.not_to raise_error
18
+
19
+ end
20
+
21
+ it 'should initialize with names being an array; parent is an empty hash;
22
+ displayOrder is 1; adminVisibleInterfaces is an empty array; and endUserVisibleInterfaces is an empty array' do
23
+
24
+ expect(service_product.names).to eq([])
25
+
26
+ expect(service_product.parent).to eq({})
27
+
28
+ expect(service_product.displayOrder).to eq(1)
29
+
30
+ expect(service_product.adminVisibleInterfaces).to eq([])
31
+
32
+ expect(service_product.endUserVisibleInterfaces).to eq([])
33
+
34
+ end
35
+
36
+ end
37
+
38
+ let(:attributes){
39
+ {'id' => 1,
40
+ 'lookupName' => 'Test Product Lookup Name',
41
+ 'createdTime'=>nil,
42
+ 'updatedTime'=>nil,
43
+ 'displayOrder'=>1,
44
+ 'name'=>'Test Product Lookup Name',
45
+ 'parent' => nil
46
+ }
47
+ }
48
+
49
+ context '#new_from_fetch' do
50
+
51
+ it 'should accept an attributes as a hash' do
52
+
53
+ expect do
54
+
55
+ attributes = []
56
+
57
+ OSCRuby::ServiceProduct.new_from_fetch(attributes)
58
+
59
+ end.to raise_error("Attributes must be a hash; please use the appropriate data structure")
60
+
61
+ expect do
62
+
63
+ OSCRuby::ServiceProduct.new_from_fetch(attributes)
64
+
65
+ end.not_to raise_error
66
+
67
+ end
68
+
69
+ it 'should instantiate an id, lookupName, createdTime, updatedTime, displayOrder, name, and parent with the correct values' do
70
+
71
+ test = OSCRuby::ServiceProduct.new_from_fetch(attributes)
72
+
73
+ expect(test.id).to eq(1)
74
+
75
+ expect(test.lookupName).to eq('Test Product Lookup Name')
76
+
77
+ expect(test.createdTime).to eq(nil)
78
+
79
+ expect(test.updatedTime).to eq(nil)
80
+
81
+ expect(test.displayOrder).to eq(1)
82
+
83
+ expect(test.name).to eq('Test Product Lookup Name')
84
+
85
+ expect(test.name).to eq(test.lookupName)
86
+
87
+ expect(test.parent).to eq(nil)
88
+
89
+ end
90
+
91
+ end
92
+
93
+ let(:client) {
94
+
95
+ OSCRuby::Client.new do |config|
96
+
97
+ config.interface = ENV['OSC_TEST_SITE']
98
+
99
+ config.username = ENV['OSC_ADMIN']
100
+
101
+ config.password = ENV['OSC_PASSWORD']
102
+
103
+ end
104
+ }
105
+
106
+ context '#find' do
107
+
108
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
109
+
110
+ expect(client).to be_an(OSCRuby::Client)
111
+
112
+ client = nil
113
+
114
+ expect{OSCRuby::ServiceProduct.find(client,100)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
115
+
116
+ end
117
+
118
+ it 'should raise an error if ID is undefined' do
119
+
120
+ expect{OSCRuby::ServiceProduct.find(client)}.to raise_error('ID cannot be nil')
121
+
122
+ end
123
+
124
+ it 'should raise an error if ID is not an integer' do
125
+
126
+ expect{OSCRuby::ServiceProduct.find(client, 'a')}.to raise_error('ID must be an integer')
127
+
128
+ end
129
+
130
+ it 'should return a warning if empty/no instances of the object can be found' do
131
+
132
+ expect{OSCRuby::ServiceProduct.find(client, 1)}.to raise_error('There were no objects matching your query; please try again.')
133
+
134
+ end
135
+
136
+ let(:known_working_product){
137
+ OSCRuby::ServiceProduct.find(client, 100)
138
+ }
139
+
140
+ it 'should return an instance of a new OSC::ServiceProduct object with at least a name and displayOrder' do
141
+
142
+ expect(known_working_product).to be_an(OSCRuby::ServiceProduct)
143
+
144
+ expect(known_working_product.name).to eq('QR404')
145
+
146
+ expect(known_working_product.displayOrder).to eq(3)
147
+
148
+ end
149
+
150
+ end
151
+
152
+ 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.1.0
4
+ version: 0.1.1
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-24 00:00:00.000000000 Z
11
+ date: 2016-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,15 +69,20 @@ files:
69
69
  - LICENSE.txt
70
70
  - README.md
71
71
  - Rakefile
72
+ - example.rb
73
+ - lib/ext/string.rb
72
74
  - lib/osc_ruby.rb
73
75
  - lib/osc_ruby/client.rb
74
76
  - lib/osc_ruby/configuration.rb
75
77
  - lib/osc_ruby/connect.rb
78
+ - lib/osc_ruby/query_module.rb
79
+ - lib/osc_ruby/service_product.rb
76
80
  - lib/osc_ruby/version.rb
77
81
  - osc_ruby.gemspec
78
82
  - spec/core/client_spec.rb
79
83
  - spec/core/configuration_spec.rb
80
84
  - spec/core/connect_spec.rb
85
+ - spec/core/service_product_spec.rb
81
86
  - spec/core/spec_helper.rb
82
87
  - tasks/rspec.rake
83
88
  homepage: https://github.com/rajangdavis/osc_ruby
@@ -108,4 +113,5 @@ test_files:
108
113
  - spec/core/client_spec.rb
109
114
  - spec/core/configuration_spec.rb
110
115
  - spec/core/connect_spec.rb
116
+ - spec/core/service_product_spec.rb
111
117
  - spec/core/spec_helper.rb