huginn_activision_games_status_agent 0.1.10

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bb83a1b71b6b2df1cf4cbe41136d69384d6f4124eeb43814239bf3478f65883b
4
+ data.tar.gz: 8962a8c4afe6e8f865572cc775dfed874d2f401827ae63a745419cfe504bc7bf
5
+ SHA512:
6
+ metadata.gz: 6d662ec8543ad2e04cf2a99a901371bf7d452336073f90adbd13eef8efbad603f3b0340c0d0cadd2991d6af3a677f7fc24edb723249c6db9b739da2d1b5def34
7
+ data.tar.gz: b8fbeb48313912eab5fd181ac82ffe29ccd38451e98cf04dff18d292f4b4651a8122890f381e5fd0cac7d9e39e59edf5849e6ee5fbb6ff6e02763bdd258f51d9
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2020 Nicolas Germain
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,197 @@
1
+ module Agents
2
+ class ActivisionGamesStatusAgent < Agent
3
+ include FormConfigurable
4
+
5
+ can_dry_run!
6
+ no_bulk_receive!
7
+ default_schedule "5m"
8
+
9
+ description do
10
+ <<-MD
11
+ The Activision games status agent fetches servers's status about Activision's games.
12
+
13
+ `changes_only` is only used to emit event about a game's status change.
14
+
15
+ `all` is only used to filtering only event for All platforms.
16
+
17
+ `windows` is only used to filtering only event for Windows's platform.
18
+
19
+ `switch` is only used to filtering only event for Switch's platform.
20
+
21
+ `xbox1` is only used to filtering only event for Xbox one's platform.
22
+
23
+ `play4` is only used to filtering only event for Playstation 4's platform.
24
+
25
+ `mac` is only used to filtering only event for Mac's platform.
26
+
27
+ `xbox360` is only used to filtering only event for Xbox 360's platform.
28
+
29
+ `play3` is only used to filtering only event for Playstation 3's platform.
30
+
31
+ `wii` is only used to filtering only event for Wii's platform.
32
+
33
+ `ios` is only used to filtering only event for IOs's platform.
34
+
35
+ `expected_receive_period_in_days` is used to determine if the Agent is working. Set it to the maximum number of days
36
+ that you anticipate passing without this Agent receiving an incoming Event.
37
+ MD
38
+ end
39
+
40
+ event_description <<-MD
41
+ Events look like this:
42
+
43
+ {
44
+ "status": "ok",
45
+ "platform": "All platforms",
46
+ "gameTitle": "Call of Duty: Modern Warfare",
47
+ "eventId": "9531",
48
+ "alertId": "a0i4P00000TVnMVQA1"
49
+ }
50
+ MD
51
+
52
+ def default_options
53
+ {
54
+ # 'game_filter' => {},
55
+ 'expected_receive_period_in_days' => '2',
56
+ 'changes_only' => 'true',
57
+ 'all' => 'true',
58
+ 'windows' => 'true',
59
+ 'switch' => 'false',
60
+ 'xbox1' => 'false',
61
+ 'play4' => 'false',
62
+ 'mac' => 'false',
63
+ 'xbox360' => 'false',
64
+ 'play3' => 'false',
65
+ 'wii' => 'false',
66
+ 'ios' => 'false'
67
+ }
68
+ end
69
+
70
+ form_configurable :changes_only, type: :boolean
71
+ form_configurable :all, type: :boolean
72
+ form_configurable :switch, type: :boolean
73
+ form_configurable :xbox1, type: :boolean
74
+ form_configurable :play4, type: :boolean
75
+ form_configurable :mac, type: :boolean
76
+ form_configurable :windows, type: :boolean
77
+ form_configurable :xbox360, type: :boolean
78
+ form_configurable :play3, type: :boolean
79
+ form_configurable :wii, type: :boolean
80
+ form_configurable :ios, type: :boolean
81
+ form_configurable :expected_receive_period_in_days, type: :string
82
+
83
+ def validate_options
84
+
85
+ if options.has_key?('changes_only') && boolify(options['changes_only']).nil?
86
+ errors.add(:base, "if provided, changes_only must be true or false")
87
+ end
88
+
89
+ unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
90
+ errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
91
+ end
92
+ end
93
+
94
+ def working?
95
+ event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
96
+ end
97
+
98
+ def check
99
+ parse
100
+ end
101
+
102
+ private
103
+
104
+ def filter(status)
105
+ create_event = false
106
+ case "#{status['platform']}"
107
+ when "All platforms"
108
+ if interpolated['all'] == 'true'
109
+ create_event = true
110
+ end
111
+ when "Nintendo Switch"
112
+ if interpolated['switch'] == 'true'
113
+ create_event = true
114
+ end
115
+ when "Xbox One"
116
+ if interpolated['xbox1'] == 'true'
117
+ create_event = true
118
+ end
119
+ when "PlayStation 4"
120
+ if interpolated['play4'] == 'true'
121
+ create_event = true
122
+ end
123
+ when "Mac"
124
+ if interpolated['mac'] == 'true'
125
+ create_event = true
126
+ end
127
+ when "Windows"
128
+ if interpolated['windows'] == 'true'
129
+ create_event = true
130
+ end
131
+ when "Xbox 360"
132
+ if interpolated['xbox360'] == 'true'
133
+ create_event = true
134
+ end
135
+ when "PlayStation 3"
136
+ if interpolated['play3'] == 'true'
137
+ create_event = true
138
+ end
139
+ when "Wii U"
140
+ if interpolated['wii'] == 'true'
141
+ create_event = true
142
+ end
143
+ when "iOS"
144
+ if interpolated['ios'] == 'true'
145
+ create_event = true
146
+ end
147
+ end
148
+ if "#{create_event}" == 'true'
149
+ # if create_event == 'true' && game_filter.empty?
150
+ create_event payload: status
151
+ # else
152
+ # event_per_filter(status)
153
+ end
154
+ end
155
+
156
+ def parse
157
+ uri = URI.parse("https://support.activision.com/data/online-status-feed.js")
158
+ response = Net::HTTP.get_response(uri)
159
+
160
+ log "request status : #{response.code}"
161
+ payload = response.body
162
+ payload = payload.gsub(":null", ": \"ok\"")
163
+ payload = JSON.parse(payload)
164
+
165
+ if interpolated['changes_only'] == 'true'
166
+ if payload['serverStatuses'].to_s != memory['last_status']
167
+ if "#{memory['last_status']}" == ''
168
+ payload['serverStatuses'].each do |status|
169
+ filter(status)
170
+ end
171
+ else
172
+ last_status = memory['last_status'].gsub("=>", ": ").gsub(": nil", ": null")
173
+ last_status = JSON.parse(last_status)
174
+ payload['serverStatuses'].each do |status|
175
+ found = false
176
+ last_status.each do |statusbis|
177
+ if status == statusbis
178
+ found = true
179
+ end
180
+ end
181
+ if found == false
182
+ filter(status)
183
+ # create_event payload: status
184
+ end
185
+ end
186
+ end
187
+ memory['last_status'] = payload['serverStatuses'].to_s
188
+ end
189
+ else
190
+ create_event payload: payload
191
+ if payload['serverStatuses'].to_s != memory['last_status']
192
+ memory['last_status'] = payload['serverStatuses'].to_s
193
+ end
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,4 @@
1
+ require 'huginn_agent'
2
+
3
+ #HuginnAgent.load 'huginn_activision_games_status_agent/concerns/my_agent_concern'
4
+ HuginnAgent.register 'huginn_activision_games_status_agent/activision_games_status_agent'
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+ require 'huginn_agent/spec_helper'
3
+
4
+ describe Agents::ActivisionGamesStatusAgent do
5
+ before(:each) do
6
+ @valid_options = Agents::ActivisionGamesStatusAgent.new.default_options
7
+ @checker = Agents::ActivisionGamesStatusAgent.new(:name => "ActivisionGamesStatusAgent", :options => @valid_options)
8
+ @checker.user = users(:bob)
9
+ @checker.save!
10
+ end
11
+
12
+ pending "add specs here"
13
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: huginn_activision_games_status_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.10
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Germain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.3
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: huginn_agent
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Write a longer description or delete this line.
56
+ email:
57
+ - ngermain@hihouhou.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE.txt
63
+ - lib/huginn_activision_games_status_agent.rb
64
+ - lib/huginn_activision_games_status_agent/activision_games_status_agent.rb
65
+ - spec/activision_games_status_agent_spec.rb
66
+ homepage: https://github.com/hihouhou/huginn_activision_games_status_agent
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.3.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Write a short summary, because Rubygems requires one.
89
+ test_files:
90
+ - spec/activision_games_status_agent_spec.rb