huginn_battlenet_version_checker_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: ee546189db3549b2dc875af8b9c71a7794d96ab4867d30e339e86f66678d8f70
4
+ data.tar.gz: aecc685786e3dc23e9b2a64d5766f08b6aeacc340d64ecf927f0593a922fdde8
5
+ SHA512:
6
+ metadata.gz: aba21ba915827b56a1bfba833505d9afd13d0efbb634d81d2dac41e5f23abd719d7d0c251eece481f6e40d0638b9dba2a919e23d947aa9a48e98b0f2a75a334e
7
+ data.tar.gz: 908e235b41f3dd0e26eae86323a9b899917dc7d7d93bd7b899fc617b3b567b918f2cd15d61a0b177116b593bf00390ffa5328106d40b83bbb5ad5d266ffa944e
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2023 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,195 @@
1
+ module Agents
2
+ class BattlenetVersionCheckerAgent < Agent
3
+ include FormConfigurable
4
+ can_dry_run!
5
+ no_bulk_receive!
6
+ default_schedule 'every_1h'
7
+
8
+ description do
9
+ <<-MD
10
+ The Battlenet Version Checker Agent checks if a new version is available for games and creates an event if found.
11
+
12
+ `debug` is used for verbose mode.
13
+
14
+ `diablo4` can be enabled to monitore new releases about this game.
15
+
16
+ `cod_mw2_wz2` can be enabled to monitore new releases about this game.
17
+
18
+ `agent` can be enabled to monitore new releases about this game.
19
+
20
+ `region` can be eu, us or kr.
21
+
22
+ `expected_receive_period_in_days` is used to determine if the Agent is working. Set it to the maximum number of days
23
+ that you anticipate passing without this Agent receiving an incoming Event.
24
+ MD
25
+ end
26
+
27
+ event_description <<-MD
28
+ Events look like this:
29
+
30
+ {
31
+ "Region": "eu",
32
+ "BuildConfig": "849b3cbba08ee5a78173a8bed156909e",
33
+ "CDNConfig": "cf3e51475b3258e18fc53c115021381b",
34
+ "KeyRing": "",
35
+ "BuildId": "42016",
36
+ "VersionName": "1.0.2.42016",
37
+ "ProductConfig": "bb943b96ed03cafe783d31dc3d5ee155",
38
+ "Game": "Diablo IV"
39
+ }
40
+ MD
41
+
42
+ def default_options
43
+ {
44
+ 'debug' => 'false',
45
+ 'diablo4' => 'true',
46
+ 'cod_mw2_wz2' => 'true',
47
+ 'agent' => 'true',
48
+ 'expected_receive_period_in_days' => '15',
49
+ }
50
+ end
51
+
52
+ form_configurable :debug, type: :boolean
53
+ form_configurable :diablo4, type: :boolean
54
+ form_configurable :cod_mw2_wz2, type: :boolean
55
+ form_configurable :agent, type: :boolean
56
+ form_configurable :expected_receive_period_in_days, type: :string
57
+ form_configurable :region, type: :array, values: ['eu', 'us', 'kr']
58
+ def validate_options
59
+ errors.add(:base, "region has invalid value: should be 'eu', 'us', 'kr'") if interpolated['type'].present? && !%w(en us kr).include?(interpolated['region'])
60
+
61
+ if options.has_key?('diablo4') && boolify(options['diablo4']).nil?
62
+ errors.add(:base, "if provided, diablo4 must be true or false")
63
+ end
64
+
65
+ if options.has_key?('cod_mw2_wz2') && boolify(options['cod_mw2_wz2']).nil?
66
+ errors.add(:base, "if provided, cod_mw2_wz2 must be true or false")
67
+ end
68
+
69
+ if options.has_key?('agent') && boolify(options['agent']).nil?
70
+ errors.add(:base, "if provided, agent must be true or false")
71
+ end
72
+
73
+ if options.has_key?('debug') && boolify(options['debug']).nil?
74
+ errors.add(:base, "if provided, debug must be true or false")
75
+ end
76
+
77
+ unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
78
+ 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")
79
+ end
80
+ end
81
+
82
+ def working?
83
+ event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
84
+ end
85
+
86
+ def check
87
+ trigger_action
88
+ end
89
+
90
+ private
91
+
92
+ def log_curl_output(code,body)
93
+
94
+ log "request status : #{code}"
95
+
96
+ if interpolated['debug'] == 'true'
97
+ log "body"
98
+ log body
99
+ end
100
+
101
+ end
102
+
103
+ def compare(payload,game)
104
+
105
+ payload = JSON.parse(payload)
106
+ if !memory[game]
107
+ payload.each do |result|
108
+ if result["Region"] == interpolated['region']
109
+ create_event payload: result
110
+ end
111
+ end
112
+ memory[game] = payload
113
+ else
114
+ result = payload.select { |entry| entry['Region'] == interpolated['region'] }
115
+ result_memory = memory[game].select { |entry| entry['Region'] == interpolated['region'] }
116
+ if result != result_memory
117
+ create_event payload: result[0]
118
+ memory[game] = payload
119
+ else
120
+ if interpolated['debug'] == 'true'
121
+ log "nothing to compare because same value"
122
+ end
123
+ end
124
+ end
125
+
126
+ end
127
+
128
+ def get_version(game,real_name)
129
+
130
+ url = URI.parse("http://eu.patch.battle.net:1119/#{game}/versions")
131
+
132
+ response = Net::HTTP.get_response(url)
133
+
134
+ log_curl_output(response.code,response.body)
135
+
136
+ lines = response.body.split("\n")
137
+ results = []
138
+
139
+ lines.each do |line|
140
+ next if line.start_with?("Region")
141
+ next if line.start_with?("## seqn")
142
+
143
+ parts = line.split("|")
144
+ region = parts[0]
145
+ build_config = parts[1]
146
+ cdn_config = parts[2]
147
+ key_ring = parts[3]
148
+ build_id = parts[4]
149
+ version_name = parts[5]
150
+ product_config = parts[6]
151
+
152
+ result = {
153
+ "Region" => region,
154
+ "BuildConfig" => build_config,
155
+ "CDNConfig" => cdn_config,
156
+ "KeyRing" => key_ring,
157
+ "BuildId" => build_id,
158
+ "VersionName" => version_name,
159
+ "ProductConfig" => product_config,
160
+ "Game" => real_name
161
+ }
162
+
163
+ results << result
164
+ end
165
+
166
+ json_data = results.to_json
167
+
168
+ if interpolated['debug'] == 'true'
169
+ log json_data
170
+ end
171
+
172
+ compare(json_data,game)
173
+
174
+ end
175
+
176
+ def trigger_action
177
+
178
+ if interpolated['diablo4'] == 'true'
179
+ product_code = "fenris"
180
+ real_name = "Diablo IV"
181
+ get_version(product_code,real_name)
182
+ end
183
+ if interpolated['cod_mw2_wz2'] == 'true'
184
+ product_code = "auks"
185
+ real_name = "Call of Duty: MWII | WZ2.0"
186
+ get_version(product_code,real_name)
187
+ end
188
+ if interpolated['agent'] == 'true'
189
+ product_code = "agent"
190
+ real_name = "Battle.net Agent"
191
+ get_version(product_code,real_name)
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,4 @@
1
+ require 'huginn_agent'
2
+
3
+ #HuginnAgent.load 'huginn_battlenet_version_checker_agent/concerns/my_agent_concern'
4
+ HuginnAgent.register 'huginn_battlenet_version_checker_agent/battlenet_version_checker_agent'
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+ require 'huginn_agent/spec_helper'
3
+
4
+ describe Agents::BattlenetVersionCheckerAgent do
5
+ before(:each) do
6
+ @valid_options = Agents::BattlenetVersionCheckerAgent.new.default_options
7
+ @checker = Agents::BattlenetVersionCheckerAgent.new(:name => "BattlenetVersionCheckerAgent", :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_battlenet_version_checker_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_battlenet_version_checker_agent.rb
64
+ - lib/huginn_battlenet_version_checker_agent/battlenet_version_checker_agent.rb
65
+ - spec/battlenet_version_checker_agent_spec.rb
66
+ homepage: https://github.com/hihouhou/huginn_battlenet_version_checker_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/battlenet_version_checker_agent_spec.rb