osc_ruby 1.2.0 → 1.2.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: '092bf8f94c945604c55401ccc25290289a330bb5'
4
- data.tar.gz: b93990c2ad72a2b09aa350ad49eaf842e70088d7
3
+ metadata.gz: 0445ee6723c74419476e60d6c70dde19cf0dca7d
4
+ data.tar.gz: aae32a58af79823e0970c7f19d720d5375dfdaab
5
5
  SHA512:
6
- metadata.gz: 155dc9b479a66e823ad6aedbb563021ca2a875184623d3af3a7b69a243a31c0fa34d06717a9a4f9e892ae211c853d865cb96b24131868a64d5926a2d192a0b11
7
- data.tar.gz: 2433bff4ab9edbf81e37d7f3bde8c413a397152737e7d75854e551b6f4442faf887d284694babcaa909521aac4415cc35ea64c2566dc5db5461879eda557bf6a
6
+ metadata.gz: 78d2397aaef603036464facd1380ca8893d28114ddffb319eeaf2b8a21ca4d0b12f8d33286e2fa627b33369950ba27df0c20a9fd4128c36e59c0fd1c96b9d453
7
+ data.tar.gz: 8ab64d7ed2f04d5f89c07f32b6be1eebdf4e9d07c97bc34d61e2b70d642fefa2e6b37d48e20f43e3d5973ae6ff2768e8e5718f0ee3386cabcd65b7ee086acddd
@@ -0,0 +1,77 @@
1
+ require 'osc_ruby/modules/validations_module'
2
+ require 'osc_ruby/modules/normalize_module'
3
+ require 'json'
4
+
5
+ module OSCRuby
6
+
7
+ class AnalyticsReportResults
8
+
9
+ include NormalizeModule
10
+ include ValidationsModule
11
+
12
+ attr_accessor :lookupName,:id, :filters
13
+
14
+ def initialize(**args)
15
+ @lookupName = args[:lookupName]
16
+ @id = args[:id]
17
+ @filters = []
18
+ end
19
+
20
+
21
+
22
+ def run(client)
23
+
24
+ json_data = convert_to_json(self)
25
+
26
+ ValidationsModule::check_client(client)
27
+
28
+ response = OSCRuby::Connect.post_or_patch(client,'analyticsReportResults',json_data)
29
+
30
+ check_and_parse_response(response)
31
+
32
+ end
33
+
34
+
35
+ private
36
+
37
+ def convert_to_json(s)
38
+ json_data = {}
39
+ check_for_id_and_name(s)
40
+ s.instance_variables.each do|iv|
41
+ key = iv.to_s.gsub("@",'')
42
+ value = instance_variable_get iv
43
+ json_data[key] = value unless value.nil?
44
+ end
45
+ json_data
46
+ end
47
+
48
+ def check_for_id_and_name(s)
49
+ if s.lookupName.nil? && s.id.nil?
50
+ raise ArgumentError, "AnalyticsReportResults must have an id or lookupName set"
51
+ end
52
+ end
53
+
54
+ def check_and_parse_response(response)
55
+ if response.code.to_i != 200
56
+ puts JSON.pretty_generate(response.body)
57
+ response.body
58
+ else
59
+ body = JSON.parse(response.body)
60
+ final_json = []
61
+ body['rows'].each_with_index do |r,j|
62
+
63
+ hash = {}
64
+
65
+ body['columnNames'].each_with_index do |cn,i|
66
+ hash[cn] = if !r[i].nil? && r[i].is_i? == true then r[i].to_i else r[i] end
67
+ end
68
+
69
+ final_json << hash
70
+ end
71
+ final_json
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -1,3 +1,3 @@
1
1
  module OSCRuby
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -0,0 +1,86 @@
1
+ require 'core/spec_helper'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ describe OSCRuby::AnalyticsReportResults do
6
+
7
+ let(:client) {
8
+
9
+ OSCRuby::Client.new do |config|
10
+
11
+ config.interface = ENV['OSC_SITE']
12
+
13
+ config.username = ENV['OSC_ADMIN']
14
+
15
+ config.password = ENV['OSC_PASSWORD']
16
+
17
+ config.demo_site = true
18
+
19
+ end
20
+ }
21
+
22
+ let(:last_updated){
23
+ OSCRuby::AnalyticsReportResults.new(lookupName: "Last Updated By Status")
24
+ }
25
+
26
+ let(:answers_search){
27
+ OSCRuby::AnalyticsReportResults.new(id: 176)
28
+ }
29
+
30
+ let(:error_example){
31
+ OSCRuby::AnalyticsReportResults.new
32
+ }
33
+
34
+
35
+ context "#initialize" do
36
+
37
+ it "should expect an id or a lookupName for a report" do
38
+
39
+ expect(last_updated).to be_an(OSCRuby::AnalyticsReportResults)
40
+
41
+ expect(last_updated.lookupName).to eq("Last Updated By Status")
42
+
43
+ expect(answers_search).to be_an(OSCRuby::AnalyticsReportResults)
44
+
45
+ expect(answers_search.id).to eq(176)
46
+
47
+ end
48
+
49
+
50
+
51
+ end
52
+
53
+ context "#run" do
54
+ it 'should expect client is an instance of OSCRuby::Client class and raise an error if does not' do
55
+
56
+ expect(client).to be_an(OSCRuby::Client)
57
+
58
+ client = nil
59
+
60
+ expect{answers_search.run(client)}.to raise_error('Client must have some configuration set; please create an instance of OSCRuby::Client with configuration settings')
61
+
62
+ end
63
+
64
+ it 'should throw an error if there is no id or no lookupName assigned',:vcr do
65
+ expect{error_example.run(client)}.to raise_error('AnalyticsReportResults must have an id or lookupName set')
66
+ error_example.id = 176
67
+ expect(error_example.run(client)).to be_an(Array)
68
+ end
69
+
70
+ it 'should be able to take filters', :vcr do
71
+ keywords = arrf(name: "search_ex", values: "Maestro")
72
+ answers_search.filters << keywords
73
+
74
+ answers = answers_search.run(client)
75
+
76
+ answers.each do |answer|
77
+
78
+ expect(answer['Summary']).to be_a(String)
79
+ expect(answer['Answer ID']).to be_a(Fixnum)
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osc_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rajan Davis
@@ -159,6 +159,7 @@ files:
159
159
  - Rakefile
160
160
  - lib/ext/string.rb
161
161
  - lib/osc_ruby.rb
162
+ - lib/osc_ruby/classes/analytics_report_results.rb
162
163
  - lib/osc_ruby/classes/query_results.rb
163
164
  - lib/osc_ruby/classes/query_results_set.rb
164
165
  - lib/osc_ruby/client.rb
@@ -169,6 +170,7 @@ files:
169
170
  - lib/osc_ruby/modules/validations_module.rb
170
171
  - lib/osc_ruby/version.rb
171
172
  - osc_ruby.gemspec
173
+ - spec/core/analytics_report_results_spec.rb
172
174
  - spec/core/client_spec.rb
173
175
  - spec/core/configuration_spec.rb
174
176
  - spec/core/connect_spec.rb
@@ -201,6 +203,7 @@ signing_key:
201
203
  specification_version: 4
202
204
  summary: Making the best of opensource and enterprise technology
203
205
  test_files:
206
+ - spec/core/analytics_report_results_spec.rb
204
207
  - spec/core/client_spec.rb
205
208
  - spec/core/configuration_spec.rb
206
209
  - spec/core/connect_spec.rb