osc_ruby 0.1.13 → 0.2.0

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.
@@ -0,0 +1,94 @@
1
+ require 'osc_ruby/connect'
2
+ require 'json'
3
+
4
+ module OSCRuby
5
+
6
+ module ValidationsModule
7
+
8
+ class << self
9
+
10
+ def extract_attributes(obj)
11
+
12
+ empty_arr = [{}]
13
+
14
+ obj_vars = obj.instance_variables
15
+
16
+ obj_vars.each do |var|
17
+
18
+ obj_attr = var.to_s.delete("@")
19
+
20
+ obj_attr_val = obj.instance_variable_get(var)
21
+
22
+ empty_arr[0][obj_attr] = obj_attr_val
23
+
24
+ end
25
+
26
+ empty_arr
27
+
28
+ end
29
+
30
+ def check_for_id(id)
31
+
32
+ if id.nil? == true
33
+
34
+ raise ArgumentError, 'ID cannot be nil'
35
+
36
+ elsif id.class != Fixnum
37
+
38
+ raise ArgumentError, 'ID must be an integer'
39
+
40
+ end
41
+
42
+ end
43
+
44
+ def check_object_for_id(obj,class_name)
45
+
46
+ if obj.id.nil?
47
+
48
+ raise ArgumentError, "#{class_name} must have a valid ID set"
49
+
50
+ end
51
+
52
+ end
53
+
54
+ def check_attributes(attributes)
55
+
56
+ if attributes.class != Hash
57
+
58
+ raise ArgumentError, "Attributes must be a hash; please use the appropriate data structure"
59
+
60
+ end
61
+
62
+ end
63
+
64
+ def check_query(query)
65
+
66
+ if query.empty?
67
+
68
+ raise ArgumentError, 'A query must be specified when using the "where" method'
69
+
70
+ end
71
+
72
+ end
73
+
74
+ def check_client(client)
75
+
76
+ if client.class != OSCRuby::Client || client.nil?
77
+
78
+ raise ArgumentError, "Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings"
79
+
80
+ end
81
+
82
+ end
83
+
84
+ def attr_hash_exists_and_is_type_of(obj,key,val,class_of_value)
85
+
86
+ return obj[0][key][val].nil? || obj[0][key][val].class != class_of_value
87
+
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+
94
+ end
@@ -1,3 +1,3 @@
1
1
  module OSCRuby
2
- VERSION = "0.1.13"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -4,21 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'osc_ruby/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "osc_ruby"
8
- spec.version = OSCRuby::VERSION
9
- spec.authors = ["Rajan Davis"]
10
- spec.email = ["rajangdavis@gmail.com"]
11
- spec.summary = %q{Making the best of opensource and enterprise technology}
12
- spec.description = %q{An unofficial Ruby ORM on top of the Oracle Cloud Services (fka RightNow Technologies) REST API}
13
- spec.homepage = %q{https://github.com/rajangdavis/osc_ruby}
14
- spec.license = "MIT"
7
+ spec.name = "osc_ruby"
8
+ spec.version = OSCRuby::VERSION
9
+ spec.authors = ["Rajan Davis"]
10
+ spec.email = ["rajangdavis@gmail.com"]
11
+ spec.summary = %q{Making the best of opensource and enterprise technology}
12
+ spec.description = %q{An unofficial Ruby ORM on top of the Oracle Cloud Services (fka RightNow Technologies) REST API}
13
+ spec.homepage = %q{https://github.com/rajangdavis/osc_ruby}
14
+ spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec", "~> 3.2.0"
24
- end
21
+ spec.add_development_dependency "simplecov"
22
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.2.0"
26
+ spec.add_development_dependency "vcr", "~> 3.0.3"
27
+ spec.add_development_dependency "fakeweb"
28
+
29
+ spec.add_dependency 'yard'
30
+ end
@@ -0,0 +1,496 @@
1
+ require 'core/spec_helper'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ describe OSCRuby::Answer do
6
+
7
+ let(:answer){
8
+
9
+ OSCRuby::Answer.new
10
+
11
+ }
12
+
13
+ context '#initialize' do
14
+
15
+ it 'should not throw an error when initialized' do
16
+
17
+ expect{answer}.not_to raise_error
18
+
19
+ end
20
+
21
+ it 'should initialize with answerType as a hash, language as a hash, and summary as a string' do
22
+
23
+ expect(answer.answerType).to eq({})
24
+
25
+ expect(answer.language).to eq({})
26
+
27
+ expect(answer.summary).to eq('Answer summary text')
28
+
29
+ end
30
+
31
+ end
32
+
33
+ # let(:attributes){
34
+ # {
35
+ # "id"=> 2222,
36
+ # "lookupName"=> 2222,
37
+ # "createdTime"=> "2014-02-05T23:42:28Z",
38
+ # "updatedTime"=> "2016-12-13T09:55:45Z",
39
+ # "accessLevels"=> 3,
40
+ # "adminLastAccessTime"=> "2016-11-23T22:54:26Z",
41
+ # "answerType"=> 1,
42
+ # "expiresDate"=> nil,
43
+ # "guidedAssistance"=> nil,
44
+ # "keywords"=> "AbCbEbAb",
45
+ # "language"=> 1,
46
+ # "lastAccessTime"=> "2016-12-10T07:27:37Z",
47
+ # "lastNotificationTime"=> nil,
48
+ # "name"=> 2222,
49
+ # "nextNotificationTime"=> nil,
50
+ # "originalReferenceNumber"=> nil,
51
+ # "positionInList"=> 1,
52
+ # "publishOnDate"=> nil,
53
+ # "question"=> nil,
54
+ # "solution"=> "<p ></iframe></p>\n<ol>\n<li>\n<div class=\"MsoNormal\" >The following video will show you how to view your DVR using the QT view app or through a Browser using the Q-See Scan n View P2P technology.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step1.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >P2P equals Peer to Peer. This concept has been around for a long time.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step2.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >P2P equals Peer to Peer. In a peer to peer network, tasks (such as searching for files or streaming audio/video) are shared amongst multiple interconnected peers who each make a portion of their resources (such as processing power, Disk Storage or network bandwidth) directly available to other Network participants, without the need for centralized coordination by servers.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step3.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Q-See's application is to take the Port Forwarding process out of the hands of the End User.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step4.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Next, you will need to install your QT View app via the Apple App Store or the Google Play Store.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step5.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Once the DVR is connected and is powered up, you will go through the wizard.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6a.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6b.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6c.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >While going through the wizard you will need to select your device to fit the the QR Code.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6d.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6e.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Then go to your QT View and tap on the QR code image.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step7.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Now, your scanner will come up, then scan the QR code.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step8.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >The MAC address will appear, then enter the DVR's user name and password.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step9.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Then Tap Login.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step10.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >After a few moments you will then be able to see the cameras without having to access the router.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step11.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >How to access it for PC/MAC.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step12.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Open Browser. Enter qtview.com, Push enter. NOTE: YOU WILL STILL NEED TO ADD IN THE ACTIVE X OR IE PLUG IN FOR YOUR BROWSER.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step13.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Enter the MAC address, User name, and Password, then click LOGIN.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step14.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Then you will be able to see your system.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step15.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Q-See Scan n View.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step16.png\" /></p>\n</li>\n</ol>",
55
+ # "summary"=> "QT Series: (VIDEO) Scan 'N View Setup",
56
+ # "updatedByAccount"=> 47,
57
+ # "uRL"=> nil
58
+ # }
59
+ # }
60
+
61
+ # context '#new_from_fetch' do
62
+
63
+ # it 'should accept an attributes as a hash' do
64
+
65
+ # expect do
66
+
67
+ # attributes = []
68
+
69
+ # OSCRuby::Answer.new_from_fetch(attributes)
70
+
71
+ # end.to raise_error("Attributes must be a hash; please use the appropriate data structure")
72
+
73
+ # expect do
74
+
75
+ # OSCRuby::Answer.new_from_fetch(attributes)
76
+
77
+ # end.not_to raise_error
78
+
79
+ # end
80
+
81
+ # it 'should instantiate an id, lookupName, createdTime, updatedTime, accessLevels, adminLastAccessTime, answerType, expiresDate, guidedAssistance, keywords, language, lastAccessTime, lastNotificationTime, name, nextNotificationTime, originalReferenceNumber, positionInList, publishOnDate, question, solution, summary, updatedByAccount, uRL with the correct values' do
82
+
83
+ # test = OSCRuby::Answer.new_from_fetch(attributes)
84
+
85
+ # expect(test.id).to eq(2222)
86
+ # expect(test.lookupName).to eq(2222)
87
+ # expect(test.createdTime).to eq("2014-02-05T23:42:28Z")
88
+ # expect(test.updatedTime).to eq("2016-12-13T09:55:45Z")
89
+ # expect(test.accessLevels).to eq(3)
90
+ # expect(test.adminLastAccessTime).to eq("2016-11-23T22:54:26Z")
91
+ # expect(test.answerType).to eq(1)
92
+ # expect(test.expiresDate).to eq(nil)
93
+ # expect(test.guidedAssistance).to eq(nil)
94
+ # expect(test.keywords).to eq("AbCbEbAb")
95
+ # expect(test.language).to eq(1)
96
+ # expect(test.lastAccessTime).to eq("2016-12-10T07:27:37Z")
97
+ # expect(test.lastNotificationTime).to eq(nil)
98
+ # expect(test.name).to eq(2222)
99
+ # expect(test.nextNotificationTime).to eq(nil)
100
+ # expect(test.originalReferenceNumber).to eq(nil)
101
+ # expect(test.positionInList).to eq(1)
102
+ # expect(test.publishOnDate).to eq(nil)
103
+ # expect(test.question).to eq(nil)
104
+ # expect(test.solution).to eq("<p ></iframe></p>\n<ol>\n<li>\n<div class=\"MsoNormal\" >The following video will show you how to view your DVR using the QT view app or through a Browser using the Q-See Scan n View P2P technology.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step1.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >P2P equals Peer to Peer. This concept has been around for a long time.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step2.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >P2P equals Peer to Peer. In a peer to peer network, tasks (such as searching for files or streaming audio/video) are shared amongst multiple interconnected peers who each make a portion of their resources (such as processing power, Disk Storage or network bandwidth) directly available to other Network participants, without the need for centralized coordination by servers.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step3.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Q-See's application is to take the Port Forwarding process out of the hands of the End User.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step4.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Next, you will need to install your QT View app via the Apple App Store or the Google Play Store.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step5.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Once the DVR is connected and is powered up, you will go through the wizard.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6a.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6b.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6c.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >While going through the wizard you will need to select your device to fit the the QR Code.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6d.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6e.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Then go to your QT View and tap on the QR code image.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step7.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Now, your scanner will come up, then scan the QR code.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step8.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >The MAC address will appear, then enter the DVR's user name and password.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step9.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Then Tap Login.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step10.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >After a few moments you will then be able to see the cameras without having to access the router.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step11.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >How to access it for PC/MAC.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step12.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Open Browser. Enter qtview.com, Push enter. NOTE: YOU WILL STILL NEED TO ADD IN THE ACTIVE X OR IE PLUG IN FOR YOUR BROWSER.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step13.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Enter the MAC address, User name, and Password, then click LOGIN.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step14.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Then you will be able to see your system.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step15.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Q-See Scan n View.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step16.png\" /></p>\n</li>\n</ol>")
105
+ # expect(test.summary).to eq("QT Series: (VIDEO) Scan 'N View Setup")
106
+ # expect(test.updatedByAccount).to eq(47)
107
+ # expect(test.uRL).to eq(nil)
108
+
109
+ # end
110
+
111
+ # end
112
+
113
+ let(:client) {
114
+
115
+ OSCRuby::Client.new do |config|
116
+
117
+ config.interface = ENV['OSC_TEST_SITE']
118
+
119
+ config.username = ENV['OSC_ADMIN']
120
+
121
+ config.password = ENV['OSC_PASSWORD']
122
+
123
+ end
124
+ }
125
+
126
+ let(:new_answer){
127
+ OSCRuby::Answer.new
128
+ }
129
+
130
+ context '#create' do
131
+
132
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
133
+
134
+ expect(client).to be_an(OSCRuby::Client)
135
+
136
+ client = nil
137
+
138
+ expect{new_answer.create(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
139
+
140
+ end
141
+
142
+ it 'should check the object and make sure that it at least has a language, answerType, and summary set', :vcr do
143
+
144
+ expect{new_answer.create(client)}.to raise_error('Answer should at least the language, answerType, and summary set (new_answer.language = {"id" => 1}; new_answer.answerType = {"id" => 1}}; new_answer.summary = "This is the Answer Title")')
145
+
146
+ new_answer.language['id'] = 1
147
+
148
+ expect{new_answer.create(client)}.to raise_error('Answer should at least the language, answerType, and summary set (new_answer.language = {"id" => 1}; new_answer.answerType = {"id" => 1}}; new_answer.summary = "This is the Answer Title")')
149
+
150
+ new_answer.answerType['id'] = 1
151
+
152
+ # the Answer summary is defaulted to "Answer summary text" so it should pass here
153
+
154
+ expect{new_answer.create(client)}.to_not raise_error
155
+
156
+ end
157
+
158
+ it 'should expect the language as a hash with an id as a key with a value of a number' do
159
+
160
+ new_answer.language['id'] = "new answer name"
161
+ new_answer.answerType['id'] = 1
162
+
163
+ expect{new_answer.create(client)}.to raise_error('Answer should at least the language, answerType, and summary set (new_answer.language = {"id" => 1}; new_answer.answerType = {"id" => 1}}; new_answer.summary = "This is the Answer Title")')
164
+
165
+ end
166
+
167
+ it 'should expect the answerType as a hash with an id as a key with a value of a number' do
168
+
169
+ new_answer.language['id'] = 1
170
+ new_answer.answerType['id'] = "new answer name"
171
+
172
+ expect{new_answer.create(client)}.to raise_error('Answer should at least the language, answerType, and summary set (new_answer.language = {"id" => 1}; new_answer.answerType = {"id" => 1}}; new_answer.summary = "This is the Answer Title")')
173
+
174
+ end
175
+
176
+ it 'should expect the answerType as a hash with an lookupName as a key with a value of "HTML","URL", or "File Attachment"', :vcr do
177
+
178
+ new_answer.language['id'] = 1
179
+ new_answer.answerType['lookupName'] = "HTML"
180
+
181
+ expect{new_answer.create(client)}.not_to raise_error
182
+
183
+ end
184
+
185
+ it 'should return an instance of an OSCRuby::Answer if the json_response param is set to false (which it is by default)', :vcr do
186
+
187
+ new_answer.language['id'] = 1
188
+ new_answer.answerType['lookupName'] = "HTML"
189
+
190
+ new_answer.create(client)
191
+
192
+ expect(new_answer).to be_a(OSCRuby::Answer)
193
+
194
+ expect(new_answer.summary).to eq("Answer summary text")
195
+
196
+ expect(new_answer.language).to eq({"id"=>1, "lookupName"=>"en_US"})
197
+
198
+ end
199
+
200
+
201
+ it 'should return the body object if the json_response param is set to true', :vcr do
202
+
203
+ new_answer.language['id'] = 1
204
+ new_answer.answerType['lookupName'] = "HTML"
205
+
206
+ expect(new_answer.create(client,true)).to be_a(String)
207
+
208
+ end
209
+
210
+ end
211
+
212
+ context '#find' do
213
+
214
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
215
+
216
+ expect(client).to be_an(OSCRuby::Client)
217
+
218
+ client = nil
219
+
220
+ expect{OSCRuby::Answer.find(client,100)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
221
+
222
+ end
223
+
224
+ it 'should raise an error if ID is undefined' do
225
+
226
+ expect{OSCRuby::Answer.find(client)}.to raise_error('ID cannot be nil')
227
+
228
+ end
229
+
230
+ it 'should raise an error if ID is not an integer' do
231
+
232
+ expect{OSCRuby::Answer.find(client, 'a')}.to raise_error('ID must be an integer')
233
+
234
+ end
235
+
236
+ it 'should return a warning if empty/no instances of the object can be found', :vcr do
237
+
238
+ expect{OSCRuby::Answer.find(client, 100)}.to raise_error('There were no objects matching your query; please try again.')
239
+
240
+ end
241
+
242
+
243
+ it 'should return an instance of a new OSCRuby::Answer object with at least a name and displayOrder', :vcr do
244
+
245
+ known_working_answer = OSCRuby::Answer.find(client, 2222)
246
+
247
+ expect(known_working_answer).to be_an(OSCRuby::Answer)
248
+ expect(known_working_answer.id).to eq(2222)
249
+ expect(known_working_answer.lookupName).to eq(2222)
250
+ expect(known_working_answer.createdTime).to eq("2014-02-05T23:42:28Z")
251
+ expect(known_working_answer.updatedTime).to eq("2016-12-13T09:55:45Z")
252
+ expect(known_working_answer.accessLevels).to eq(3)
253
+ expect(known_working_answer.adminLastAccessTime).to eq("2016-11-23T22:54:26Z")
254
+ expect(known_working_answer.answerType).to eq(1)
255
+ expect(known_working_answer.expiresDate).to eq(nil)
256
+ expect(known_working_answer.guidedAssistance).to eq(nil)
257
+ expect(known_working_answer.keywords).to eq("AbCbEbAb")
258
+ expect(known_working_answer.language).to eq(1)
259
+ expect(known_working_answer.lastAccessTime).to eq("2016-12-10T07:27:37Z")
260
+ expect(known_working_answer.lastNotificationTime).to eq(nil)
261
+ expect(known_working_answer.name).to eq(2222)
262
+ expect(known_working_answer.nextNotificationTime).to eq(nil)
263
+ expect(known_working_answer.originalReferenceNumber).to eq(nil)
264
+ expect(known_working_answer.positionInList).to eq(1)
265
+ expect(known_working_answer.publishOnDate).to eq(nil)
266
+ expect(known_working_answer.question).to eq(nil)
267
+ expect(known_working_answer.solution).to eq("<p ></iframe></p>\n<ol>\n<li>\n<div class=\"MsoNormal\" >The following video will show you how to view your DVR using the QT view app or through a Browser using the Q-See Scan n View P2P technology.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step1.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >P2P equals Peer to Peer. This concept has been around for a long time.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step2.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >P2P equals Peer to Peer. In a peer to peer network, tasks (such as searching for files or streaming audio/video) are shared amongst multiple interconnected peers who each make a portion of their resources (such as processing power, Disk Storage or network bandwidth) directly available to other Network participants, without the need for centralized coordination by servers.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step3.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Q-See's application is to take the Port Forwarding process out of the hands of the End User.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step4.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Next, you will need to install your QT View app via the Apple App Store or the Google Play Store.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step5.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Once the DVR is connected and is powered up, you will go through the wizard.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6a.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6b.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6c.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >While going through the wizard you will need to select your device to fit the the QR Code.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6d.png\" /></p>\n<div class=\"MsoNormal\" ></div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step6e.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Then go to your QT View and tap on the QR code image.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step7.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Now, your scanner will come up, then scan the QR code.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step8.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >The MAC address will appear, then enter the DVR's user name and password.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step9.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Then Tap Login.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step10.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >After a few moments you will then be able to see the cameras without having to access the router.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step11.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >How to access it for PC/MAC.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step12.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Open Browser. Enter qtview.com, Push enter. NOTE: YOU WILL STILL NEED TO ADD IN THE ACTIVE X OR IE PLUG IN FOR YOUR BROWSER.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step13.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Enter the MAC address, User name, and Password, then click LOGIN.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step14.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Then you will be able to see your system.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step15.png\" /></p>\n</li>\n<li>\n<div class=\"MsoNormal\" >Q-See Scan n View.</div>\n<p align=\"center\"><img border=\"0\" alt=\"Image\" src=\"//q-see.s3.amazonaws.com/content/files/HowToFiles/p2pimages/Step16.png\" /></p>\n</li>\n</ol>")
268
+ expect(known_working_answer.summary).to eq("QT Series: (VIDEO) Scan 'N View Setup")
269
+ expect(known_working_answer.updatedByAccount).to eq(47)
270
+ expect(known_working_answer.uRL).to eq(nil)
271
+
272
+ end
273
+
274
+ it 'should return the raw json response if the return_json parameter is set to true', :vcr do
275
+
276
+ known_working_answer_in_json = OSCRuby::Answer.find(client, 2222, true)
277
+
278
+ expect(known_working_answer_in_json).to be_an(String)
279
+
280
+ end
281
+
282
+ end
283
+
284
+ context '#all' do
285
+
286
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
287
+
288
+ expect(client).to be_an(OSCRuby::Client)
289
+
290
+ client = nil
291
+
292
+ expect{OSCRuby::Answer.all(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
293
+
294
+ end
295
+
296
+ it 'should return multiple instances of OSCRuby::Answer', :vcr do
297
+
298
+ answers = OSCRuby::Answer.all(client)
299
+
300
+ expect(answers.size).to be > 0
301
+
302
+ # puts "Checking if OSCRuby::Answer.all produces multiple instances of answers"
303
+
304
+ answers.each_with_index do |p,i|
305
+
306
+ if i < 10
307
+
308
+ expect(p).to be_an(OSCRuby::Answer)
309
+
310
+ # puts p.name
311
+
312
+ end
313
+
314
+ end
315
+
316
+ end
317
+
318
+ it 'should just return JSON if the return_json parameter is set to true', :vcr do
319
+
320
+ expect(OSCRuby::Answer.all(client,true)).to be_a(String)
321
+
322
+ end
323
+
324
+ end
325
+
326
+ context '#where' do
327
+
328
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
329
+
330
+ expect(client).to be_an(OSCRuby::Client)
331
+
332
+ client = nil
333
+
334
+ expect{OSCRuby::Answer.where(client,'query')}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
335
+
336
+ end
337
+
338
+ it 'should raise an error if there is no query' do
339
+
340
+ expect{OSCRuby::Answer.where(client)}.to raise_error('A query must be specified when using the "where" method')
341
+
342
+ end
343
+
344
+ it 'should take a query and return results', :vcr do
345
+
346
+ answers_lvl_1 = OSCRuby::Answer.where(client,"language.id = 11")
347
+
348
+ expect(answers_lvl_1.count).to be > 0
349
+
350
+ answers_lvl_1.each_with_index do |p,i|
351
+
352
+ if i < 10
353
+
354
+ expect(p).to be_an(OSCRuby::Answer)
355
+
356
+ # puts p.name
357
+
358
+ end
359
+
360
+ end
361
+
362
+ end
363
+
364
+ it 'should raise an error if the query returns 0 results', :vcr do
365
+
366
+ expect{OSCRuby::Answer.where(client,"id = 6546546546546")}.to raise_error('There were no objects matching your query; please try again.')
367
+
368
+ end
369
+
370
+ it 'should just return JSON if the return_json parameter is set to true', :vcr do
371
+
372
+ parents = OSCRuby::Answer.where(client,"parent is null and lookupname not like 'Unsure'",true)
373
+
374
+ expect(parents).to be_a(String)
375
+
376
+ # puts parents
377
+
378
+ end
379
+
380
+ end
381
+
382
+ context '#update' do
383
+
384
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not', :vcr do
385
+
386
+ known_working_answer = OSCRuby::Answer.find(client, 2222)
387
+
388
+ expect(client).to be_an(OSCRuby::Client)
389
+
390
+ client = nil
391
+
392
+ expect{known_working_answer.update(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
393
+
394
+ end
395
+
396
+ it 'should expect that the Answer is an instance of a OSCRuby::Answer', :vcr do
397
+
398
+ known_working_answer = OSCRuby::Answer.find(client, 2222)
399
+
400
+ expect(known_working_answer).to be_an(OSCRuby::Answer)
401
+
402
+ end
403
+
404
+ it 'should expect that the answer has an ID and spit out an error if it does not', :vcr do
405
+
406
+ known_working_answer = OSCRuby::Answer.find(client, 2222)
407
+
408
+ known_working_answer.id = nil
409
+
410
+ expect{known_working_answer.update(client)}.to raise_error('OSCRuby::Answer must have a valid ID set')
411
+
412
+ end
413
+
414
+ # it 'should update name when the names is updated', :vcr do
415
+
416
+ # test_answers = OSCRuby::Answer.where(client,"language.id = 11")
417
+ # first_prod = test_answers[0]
418
+
419
+ # first_prod.names[0] = {"labelText" => "TEST-answer-UPDATED", "language" => {"id" => 1}}
420
+
421
+ # first_prod.update(client)
422
+
423
+ # expect(first_prod.name).to eq('TEST-answer-UPDATED')
424
+
425
+ # end
426
+
427
+ it 'should just return JSON if the return_json parameter is set to true', :vcr do
428
+
429
+ known_working_answer = OSCRuby::Answer.find(client, 2222)
430
+
431
+ test = known_working_answer.update(client,true)
432
+
433
+ expect(test).to be_a(String)
434
+
435
+ end
436
+
437
+ end
438
+
439
+ context '#destroy' do
440
+
441
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not', :vcr do
442
+
443
+ test_answers = OSCRuby::Answer.where(client,"summary like '%Answer summary text%'")
444
+ answer_to_delete = test_answers[0]
445
+
446
+ expect(client).to be_an(OSCRuby::Client)
447
+
448
+ client = nil
449
+
450
+ expect{answer_to_delete.destroy(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
451
+
452
+ end
453
+
454
+ it 'should expect that the Service answer is an instance of a OSCRuby::Answer', :vcr do
455
+
456
+ test_answers = OSCRuby::Answer.where(client,"summary like '%Answer summary text%'")
457
+ answer_to_delete = test_answers[0]
458
+
459
+ expect(answer_to_delete).to be_an(OSCRuby::Answer)
460
+
461
+ end
462
+
463
+ it 'should expect that the answer has an ID and spit out an error if it does not', :vcr do
464
+
465
+ test_answers = OSCRuby::Answer.where(client,"summary like '%Answer summary text%'")
466
+ answer_to_delete = test_answers[0]
467
+
468
+ answer_to_delete.id = nil
469
+
470
+ expect{answer_to_delete.destroy(client)}.to raise_error('OSCRuby::Answer must have a valid ID set')
471
+
472
+ end
473
+
474
+ it 'should delete the answer', :vcr do
475
+
476
+ test_answers = OSCRuby::Answer.where(client,"summary like '%Answer summary text%'")
477
+
478
+ answer_to_delete = test_answers[0]
479
+
480
+ id_to_find = answer_to_delete.id
481
+
482
+ test_answers.each do |answer|
483
+
484
+ puts answer.id
485
+
486
+ answer.destroy(client)
487
+
488
+ end
489
+
490
+ expect{OSCRuby::Answer.find(client, id_to_find)}.to raise_error('There were no objects matching your query; please try again.')
491
+
492
+ end
493
+
494
+ end
495
+
496
+ end