huginn_steam_news_app_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: a353ffbf4f0ca25525964a5b1a4dabf6257fe93643b087fd7423f36b11abd589
4
+ data.tar.gz: d3f5ba4513458827c56e5c72f873b8173f2b08ac40ec6f973b0f9a374efcddd9
5
+ SHA512:
6
+ metadata.gz: 5e06eaeabdf933ff3e0d4c25fbffa4fa7a4f10d4d2ff7cba40a889f7a4f4b345944c80e5da901df9956ca4f3e549240198b662bfab1a8481a04ec7ce38927347
7
+ data.tar.gz: ab980c296b54a435a0933b27223a90ac6b51ccc5b9c3095b8b9ee87599ea6c9ac456a0f2711d7611f4e4f83dc713a8aa8c4b8f3516492988286680576775f44e
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,170 @@
1
+ module Agents
2
+ class SteamNewsAppAgent < Agent
3
+ include FormConfigurable
4
+ can_dry_run!
5
+ no_bulk_receive!
6
+ default_schedule 'every_1h'
7
+
8
+ description <<-MD
9
+ The Steam News App Agent interacts with the API from Callisto for checking news from an app.
10
+
11
+ The `debug` option is for adding.
12
+
13
+ The `app_id` option the id of the app.
14
+
15
+ The `limit` options is for limiting the results.
16
+
17
+ The `max_length` options is for limiting the length.
18
+
19
+ Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent.
20
+
21
+ MD
22
+
23
+ event_description <<-MD
24
+ Events look like this:
25
+
26
+ {
27
+ "gid": "5623338145768332949",
28
+ "title": "Patch 0.212.9",
29
+ "url": "https://steamstore-a.akamaihd.net/news/externalpost/steam_community_announcements/5623338145768332949",
30
+ "is_external_url": true,
31
+ "author": "IronMontilyet",
32
+ "contents": "Before the holiday season truly kicks off we have a few more bugs that we wanted to address! In this patch you can expect some adjustments to various crafting recipes, further fishing fixes, as well as tweaks to several Mistlands enemies. We also found a way to optimise the game to make your RAM a w...",
33
+ "feedlabel": "Community Announcements",
34
+ "date": 1671526854,
35
+ "feedname": "steam_community_announcements",
36
+ "feed_type": 1,
37
+ "appid": 892970,
38
+ "tags": [
39
+ "patchnotes"
40
+ ]
41
+ }
42
+ MD
43
+
44
+ def default_options
45
+ {
46
+ 'debug' => 'false',
47
+ 'expected_receive_period_in_days' => '2',
48
+ 'app_id' => '',
49
+ 'language' => 'en',
50
+ 'limit' => '',
51
+ 'max_length' => '',
52
+ 'community_announcements_only' => 'true',
53
+ 'patchnotes_only' => 'true'
54
+ }
55
+ end
56
+
57
+ form_configurable :debug, type: :boolean
58
+ form_configurable :expected_receive_period_in_days, type: :string
59
+ form_configurable :app_id, type: :string
60
+ form_configurable :language, type: :string
61
+ form_configurable :limit, type: :string
62
+ form_configurable :max_length, type: :string
63
+ form_configurable :patchnotes_only, type: :boolean
64
+ form_configurable :community_announcements_only, type: :boolean
65
+ def validate_options
66
+ unless options['app_id'].present?
67
+ errors.add(:base, "app_id is a required field")
68
+ end
69
+ unless options['language'].present?
70
+ errors.add(:base, "language is a required field")
71
+ end
72
+ unless options['limit'].present?
73
+ errors.add(:base, "limit is a required field")
74
+ end
75
+ unless options['max_length'].present?
76
+ errors.add(:base, "max_length is a required field")
77
+ end
78
+ if options.has_key?('patchnotes_only') && boolify(options['patchnotes_only']).nil?
79
+ errors.add(:base, "if provided, patchnotes_only must be true or false")
80
+ end
81
+
82
+ if options.has_key?('community_announcements_only') && boolify(options['community_announcements_only']).nil?
83
+ errors.add(:base, "if provided, community_announcements_only must be true or false")
84
+ end
85
+
86
+ if options.has_key?('debug') && boolify(options['debug']).nil?
87
+ errors.add(:base, "if provided, debug must be true or false")
88
+ end
89
+
90
+ unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
91
+ 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")
92
+ end
93
+ end
94
+
95
+ def working?
96
+ event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
97
+ end
98
+
99
+ def check
100
+ query_steam
101
+ end
102
+
103
+ private
104
+
105
+ def log_curl_output(code,body)
106
+
107
+ log "request status : #{code}"
108
+
109
+ if interpolated['debug'] == 'true'
110
+ log "body"
111
+ log body
112
+ end
113
+
114
+ end
115
+
116
+ def query_steam()
117
+ url = URI("https://api.steampowered.com/ISteamNews/GetNewsForApp/v2/")
118
+ params = { :appid => interpolated['app_id'], :count => interpolated['limit'], :maxlength => interpolated['max_length'] , :language => interpolated['language']}
119
+ url.query = URI.encode_www_form(params)
120
+
121
+ http = Net::HTTP.new(url.host, url.port)
122
+ http.use_ssl = true
123
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
124
+
125
+ request = Net::HTTP::Get.new(url)
126
+ response = http.request(request)
127
+
128
+ log_curl_output(response.code,response.body)
129
+
130
+ payload = JSON.parse(response.body)
131
+
132
+ if payload != memory['last_status']
133
+ payload['appnews']['newsitems'].each do | item |
134
+ found = false
135
+ if interpolated['debug'] == 'true'
136
+ log item
137
+ log "found is #{found}"
138
+ end
139
+ if !memory['last_status'].nil? and memory['last_status']['appnews']['newsitems'].present?
140
+ last_status = memory['last_status']
141
+ last_status['appnews']['newsitems'].each do | itembis|
142
+ if item == itembis
143
+ found = true
144
+ end
145
+ if interpolated['debug'] == 'true'
146
+ log "found is #{found}"
147
+ end
148
+ end
149
+ end
150
+ # if found == false && (interpolated['patchnotes_only'] == 'false' || ( !item['tags'].nil? && item['tags'].include?("patchnotes") && interpolated['patchnotes_only'] == 'true'))
151
+ if found == false && (interpolated['community_announcements_only'] == 'false' || (interpolated['community_announcements_only'] == 'true' && item['feed_type'] == 1)) && (interpolated['patchnotes_only'] == 'false' || ( !item['tags'].nil? && item['tags'].include?("patchnotes") && interpolated['patchnotes_only'] == 'true'))
152
+ if interpolated['debug'] == 'true'
153
+ log "event created"
154
+ end
155
+ create_event payload: item
156
+ else
157
+ if interpolated['debug'] == 'true'
158
+ log "event not created"
159
+ end
160
+ end
161
+ end
162
+ memory['last_status'] = payload
163
+ else
164
+ if interpolated['debug'] == 'true'
165
+ log "no diff"
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,4 @@
1
+ require 'huginn_agent'
2
+
3
+ #HuginnAgent.load 'huginn_steam_news_app_agent/concerns/my_agent_concern'
4
+ HuginnAgent.register 'huginn_steam_news_app_agent/steam_news_app_agent'
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+ require 'huginn_agent/spec_helper'
3
+
4
+ describe Agents::SteamNewsAppAgent do
5
+ before(:each) do
6
+ @valid_options = Agents::SteamNewsAppAgent.new.default_options
7
+ @checker = Agents::SteamNewsAppAgent.new(:name => "SteamNewsAppAgent", :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_steam_news_app_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-01-12 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_steam_news_app_agent.rb
64
+ - lib/huginn_steam_news_app_agent/steam_news_app_agent.rb
65
+ - spec/steam_news_app_agent_spec.rb
66
+ homepage: https://github.com/hihouhou/huginn_steam_news_app_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/steam_news_app_agent_spec.rb