huginn_epic_store_new_free_game_agent 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eff17a68e69d26712b938316e8ad64950d5b35532dfe5a159d3fc5d640c417b7
4
+ data.tar.gz: 14d3c309d6e366403d5ad92b2b061a1b904cff33a77d6c8bcd55cf6bdb415c44
5
+ SHA512:
6
+ metadata.gz: 82ecb66aa5f230143c6d31744527baa9e45a79127e5be3dec15ce784de090af7aaf28feb529b07c8c649cae08f6ef848db34004460babf5a2000c64c0947acd4
7
+ data.tar.gz: ce7718132b0d66e49124a8a2f9b2fe8c58cf53bdc22823e35b28534bc9344a92a35d7a256cdedb02e42332b1ce1024069c58700be50544884a0887e385fe38d0
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,327 @@
1
+ module Agents
2
+ class EpicStoreNewFreeGameAgent < 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 Epic Store new Free Game agent creates an event if a free game is available actually.
11
+
12
+ `debug` is used to verbose mode.
13
+
14
+ `expected_receive_period_in_days` is used to determine if the Agent is working. Set it to the maximum number of days
15
+ that you anticipate passing without this Agent receiving an incoming Event.
16
+ MD
17
+ end
18
+
19
+ event_description <<-MD
20
+ Events look like this:
21
+
22
+ {
23
+ "title": "RollerCoaster Tycoon® 3: Complete Edition",
24
+ "id": "4ec50a302f1449b3bf706a199c333ab8",
25
+ "namespace": "f01b3e0178d448f0b93911e292d8e614",
26
+ "description": "RollerCoaster Tycoon® 3: Complete Edition",
27
+ "effectiveDate": "2020-09-24T15:00:00.000Z",
28
+ "keyImages": [
29
+ {
30
+ "type": "OfferImageWide",
31
+ "url": "https://cdn1.epicgames.com/f01b3e0178d448f0b93911e292d8e614/offer/EGS_RollerCoasterTycoon3CompleteEdition_FrontierDevelopments_S5-1920x1080-689d96ca4d5a4e8de183b7a928960c87.jpg"
32
+ },
33
+ {
34
+ "type": "OfferImageTall",
35
+ "url": "https://cdn1.epicgames.com/f01b3e0178d448f0b93911e292d8e614/offer/EGS_RollerCoasterTycoon3CompleteEdition_FrontierDevelopments_S6-1200x1600-591ca93f3bee7bc55a90b77ccc36eb84.jpg"
36
+ },
37
+ {
38
+ "type": "DieselStoreFrontWide",
39
+ "url": "https://cdn1.epicgames.com/f01b3e0178d448f0b93911e292d8e614/offer/EGS_RollerCoasterTycoon3CompleteEdition_FrontierDevelopments_S5-1920x1080-689d96ca4d5a4e8de183b7a928960c87.jpg"
40
+ },
41
+ {
42
+ "type": "DieselStoreFrontTall",
43
+ "url": "https://cdn1.epicgames.com/f01b3e0178d448f0b93911e292d8e614/offer/EGS_RollerCoasterTycoon3CompleteEdition_FrontierDevelopments_S6-1200x1600-591ca93f3bee7bc55a90b77ccc36eb84.jpg"
44
+ },
45
+ {
46
+ "type": "Thumbnail",
47
+ "url": "https://cdn1.epicgames.com/f01b3e0178d448f0b93911e292d8e614/offer/EGS_RollerCoasterTycoon3CompleteEdition_FrontierDevelopments_S6-1200x1600-591ca93f3bee7bc55a90b77ccc36eb84.jpg"
48
+ },
49
+ {
50
+ "type": "CodeRedemption_340x440",
51
+ "url": "https://cdn1.epicgames.com/f01b3e0178d448f0b93911e292d8e614/offer/EGS_RollerCoasterTycoon3CompleteEdition_FrontierDevelopments_S6-1200x1600-591ca93f3bee7bc55a90b77ccc36eb84.jpg"
52
+ }
53
+ ],
54
+ "seller": {
55
+ "id": "o-mlnjydnrxlmer2ducb6u6ngznq25mx",
56
+ "name": "Frontier Developments"
57
+ },
58
+ "productSlug": "rollercoaster-tycoon-3-complete-edition/home",
59
+ "urlSlug": "mainegeneralaudience",
60
+ "url": null,
61
+ "items": [
62
+ {
63
+ "id": "d666b5e22c58413ebcf10a028d2364ee",
64
+ "namespace": "f01b3e0178d448f0b93911e292d8e614"
65
+ }
66
+ ],
67
+ "customAttributes": [
68
+ {
69
+ "key": "com.epicgames.app.blacklist",
70
+ "value": "[]"
71
+ },
72
+ {
73
+ "key": "publisherName",
74
+ "value": "Frontier Foundry"
75
+ },
76
+ {
77
+ "key": "developerName",
78
+ "value": "Frontier Developments"
79
+ },
80
+ {
81
+ "key": "com.epicgames.app.productSlug",
82
+ "value": "rollercoaster-tycoon-3-complete-edition/home"
83
+ }
84
+ ],
85
+ "categories": [
86
+ {
87
+ "path": "freegames"
88
+ },
89
+ {
90
+ "path": "games"
91
+ },
92
+ {
93
+ "path": "games/edition/base"
94
+ },
95
+ {
96
+ "path": "games/edition"
97
+ },
98
+ {
99
+ "path": "applications"
100
+ }
101
+ ],
102
+ "tags": [
103
+ {
104
+ "id": "1393"
105
+ },
106
+ {
107
+ "id": "1115"
108
+ },
109
+ {
110
+ "id": "9547"
111
+ }
112
+ ],
113
+ "price": {
114
+ "totalPrice": {
115
+ "discountPrice": 0,
116
+ "originalPrice": 1999,
117
+ "voucherDiscount": 0,
118
+ "discount": 1999,
119
+ "currencyCode": "EUR",
120
+ "currencyInfo": {
121
+ "decimals": 2
122
+ },
123
+ "fmtPrice": {
124
+ "originalPrice": "19,99 €",
125
+ "discountPrice": "0",
126
+ "intermediatePrice": "0"
127
+ }
128
+ },
129
+ "lineOffers": [
130
+ {
131
+ "appliedRules": [
132
+ {
133
+ "id": "cbda333590a14a55a8e1edbf6b7b6b1b",
134
+ "endDate": "2020-10-01T15:00:00.000Z",
135
+ "discountSetting": {
136
+ "discountType": "PERCENTAGE"
137
+ }
138
+ }
139
+ ]
140
+ }
141
+ ]
142
+ },
143
+ "promotions": {
144
+ "promotionalOffers": [
145
+ {
146
+ "promotionalOffers": [
147
+ {
148
+ "startDate": "2020-09-24T15:00:00.000Z",
149
+ "endDate": "2020-10-01T15:00:00.000Z",
150
+ "discountSetting": {
151
+ "discountType": "PERCENTAGE",
152
+ "discountPercentage": 0
153
+ }
154
+ }
155
+ ]
156
+ }
157
+ ],
158
+ "upcomingPromotionalOffers": [
159
+
160
+ ]
161
+ }
162
+ }
163
+ MD
164
+
165
+ def default_options
166
+ {
167
+ 'debug' => 'false',
168
+ 'expected_receive_period_in_days' => '2',
169
+ 'changes_only' => 'true'
170
+ }
171
+ end
172
+
173
+ form_configurable :expected_receive_period_in_days, type: :string
174
+ form_configurable :changes_only, type: :boolean
175
+ form_configurable :debug, type: :boolean
176
+
177
+ def validate_options
178
+
179
+ if options.has_key?('changes_only') && boolify(options['changes_only']).nil?
180
+ errors.add(:base, "if provided, changes_only must be true or false")
181
+ end
182
+
183
+ if options.has_key?('debug') && boolify(options['debug']).nil?
184
+ errors.add(:base, "if provided, debug must be true or false")
185
+ end
186
+
187
+ unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
188
+ 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")
189
+ end
190
+ end
191
+
192
+ def working?
193
+ event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
194
+ end
195
+
196
+ def check
197
+ fetch
198
+ end
199
+
200
+ private
201
+
202
+ def log_curl_output(code,body)
203
+
204
+ log "request status : #{code}"
205
+
206
+ if interpolated['debug'] == 'true'
207
+ log "body"
208
+ log body
209
+ end
210
+
211
+ end
212
+
213
+ def fetch
214
+ uri = URI.parse("https://store-site-backend-static.ak.epicgames.com/freeGamesPromotions?locale=fr&country=FR&allowCountries=FR")
215
+ request = Net::HTTP::Get.new(uri)
216
+ request["Authority"] = "store-site-backend-static.ak.epicgames.com"
217
+ request["Accept"] = "application/json, text/plain, */*"
218
+ request["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
219
+ request["X-Requested-With"] = "XMLHttpRequest"
220
+ request["Origin"] = "https://www.epicgames.com"
221
+ request["Sec-Fetch-Site"] = "same-site"
222
+ request["Sec-Fetch-Mode"] = "cors"
223
+ request["Sec-Fetch-Dest"] = "empty"
224
+ request["Referer"] = "https://www.epicgames.com/"
225
+ request["Accept-Language"] = "fr,en-US;q=0.9,en;q=0.8"
226
+
227
+ req_options = {
228
+ use_ssl: uri.scheme == "https",
229
+ }
230
+
231
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
232
+ http.request(request)
233
+ end
234
+
235
+ log_curl_output(response.code, response.body)
236
+
237
+ payload = JSON.parse(response.body)
238
+
239
+ if !memory['triggered'].present?
240
+ memory['triggered'] = []
241
+ end
242
+
243
+ if interpolated['changes_only'] == 'true'
244
+ if payload != memory['last_status']
245
+ if "#{memory['last_status']}" == ''
246
+ payload['data']['Catalog']['searchStore']['elements'].each do |item|
247
+ if interpolated['debug'] == 'true'
248
+ log item
249
+ end
250
+ if !item['promotions'].nil?
251
+ if !item['promotions']['promotionalOffers'].nil?
252
+ if !item['promotions']['promotionalOffers'].empty?
253
+ if !item['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate'].nil?
254
+ start_date = item['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate']
255
+ end
256
+ if !item['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['endDate'].nil?
257
+ end_date = item['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['endDate']
258
+ end
259
+ if !start_date.nil? && !end_date.nil? && Time.now.to_i.between?(Time.parse(start_date).to_i, Time.parse(end_date).to_i) && item['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['discountSetting']['discountPercentage'] == 0
260
+ create_event payload: item
261
+ memory['triggered'] << item['id']
262
+ end
263
+ end
264
+ end
265
+ end
266
+ end
267
+ else
268
+ last_status = memory['last_status']
269
+ payload['data']['Catalog']['searchStore']['elements'].each do | item |
270
+ found = false
271
+ if interpolated['debug'] == 'true'
272
+ log item
273
+ log "found is #{found}"
274
+ end
275
+ if !item['promotions'].nil?
276
+ if !item['promotions']['promotionalOffers'].nil?
277
+ if !item['promotions']['promotionalOffers'].empty?
278
+ if !item['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate'].nil?
279
+ start_date = item['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['startDate']
280
+ end
281
+ if !item['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['endDate'].nil?
282
+ end_date = item['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['endDate']
283
+ end
284
+ last_status['data']['Catalog']['searchStore']['elements'].each do | itembis|
285
+ if item['id'] == itembis['id'] && memory['triggered'].include?(item['id'])
286
+ found = true
287
+ end
288
+ if interpolated['debug'] == 'true'
289
+ log "found is #{found}"
290
+ end
291
+ end
292
+ if found == false && !start_date.nil? && !end_date.nil? && Time.now.to_i.between?(Time.parse(start_date).to_i, Time.parse(end_date).to_i) && item['promotions']['promotionalOffers'][0]['promotionalOffers'][0]['discountSetting']['discountPercentage'] == 0
293
+ create_event payload: item
294
+ if interpolated['debug'] == 'true'
295
+ log "adding #{item['id']} to triggered list"
296
+ end
297
+ memory['triggered'] << item['id']
298
+ log "event created"
299
+ else
300
+ if interpolated['debug'] == 'true'
301
+ log "event not created"
302
+ end
303
+ end
304
+ if !Time.now.to_i.between?(Time.parse(start_date).to_i, Time.parse(end_date).to_i)
305
+ if interpolated['debug'] == 'true'
306
+ log "removing #{item['id']} to triggered list"
307
+ end
308
+ memory['triggered'].delete(item['id'])
309
+ end
310
+ end
311
+ end
312
+ end
313
+ end
314
+ end
315
+ memory['last_status'] = payload
316
+ end
317
+ else
318
+ if payload != memory['last_status']
319
+ memory['last_status']= payload
320
+ end
321
+ payload['data']['Catalog']['searchStore']['elements'].each do |item|
322
+ create_event payload: item
323
+ end
324
+ end
325
+ end
326
+ end
327
+ end
@@ -0,0 +1,4 @@
1
+ require 'huginn_agent'
2
+
3
+ #HuginnAgent.load 'huginn_epic_store_new_free_game_agent/concerns/my_agent_concern'
4
+ HuginnAgent.register 'huginn_epic_store_new_free_game_agent/epic_store_new_free_game_agent'
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+ require 'huginn_agent/spec_helper'
3
+
4
+ describe Agents::EpicStoreNewFreeGameAgent do
5
+ before(:each) do
6
+ @valid_options = Agents::EpicStoreNewFreeGameAgent.new.default_options
7
+ @checker = Agents::EpicStoreNewFreeGameAgent.new(:name => "EpicStoreNewFreeGameAgent", :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_epic_store_new_free_game_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Germain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-11-09 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_epic_store_new_free_game_agent.rb
64
+ - lib/huginn_epic_store_new_free_game_agent/epic_store_new_free_game_agent.rb
65
+ - spec/epic_store_new_free_game_agent_spec.rb
66
+ homepage: https://github.com/hihouhou/huginn_epic_store_new_free_game_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/epic_store_new_free_game_agent_spec.rb