Skip to content

Commit 719e464

Browse files
committed
Adding filter and Game Precision
1 parent 8346640 commit 719e464

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

app/providers/smash_gg/get_tournaments_by_country.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class SmashGg::GetTournamentsByCountry
88
TournamentsQuery = GraphClient.parse <<-'GRAPHQL'
99
query($cCode: String!, $perPage: Int!) {
1010
tournaments(query: { perPage: $perPage,
11-
filter: { countryCode: $cCode, upcoming: true },
11+
filter: { countryCode: $cCode, upcoming: true, videogameIds: [1, 1386] },
1212
sortBy: "startAt" })
1313
{
1414
nodes {
@@ -24,7 +24,6 @@ class SmashGg::GetTournamentsByCountry
2424
venueName
2525
events {
2626
videogame {
27-
id
2827
name
2928
}
3029
}
@@ -39,7 +38,7 @@ def self.call(country: "FR", page_size: 25)
3938
end
4039

4140
def self.videogames(hash)
42-
hash['events'].map{|e| e.dig('name')}.uniq
41+
hash['events'].map{|e| e.dig('videogame', 'name')}.uniq
4342
end
4443

4544
def self.format(results)
@@ -53,6 +52,7 @@ def self.format(results)
5352
new_hash[:address] = new_hash.delete('venueAddress')
5453
new_hash[:google_place_id] = new_hash.delete('mapsPlaceId')
5554
new_hash[:games] = videogames(hash)
55+
new_hash.delete('events')
5656
new_hash.with_indifferent_access
5757
end
5858
end

app/services/tournaments/check_new_tournaments.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Tournaments::CheckNewTournaments < ::BaseService
55

66
def compute(input)
77
remote_ids = Tournament.all.pluck(:remote_id)
8-
input[:remote_tournaments] = SmashGg::GetTournamentsByCountry.()
8+
input[:remote_tournaments] = SmashGg::GetTournamentsByCountry.(page_size: 50)
99

1010
input[:remote_tournaments].delete_if {|t| remote_ids.include?(t[:remote_id].to_s)}
1111
end
@@ -17,7 +17,7 @@ def persist(input)
1717
def notify(input)
1818
input[:remote_tournaments].each do |tournament|
1919
notify_discord(tournament)
20-
notify_twitter(tournament)
20+
notify_twitter(tournament) if Rails.env.production?
2121
sleep 0.5
2222
end
2323
end
@@ -27,7 +27,7 @@ def notify(input)
2727
def notify_discord(tournament)
2828
start_at = I18n.l(tournament[:start_at], format: :long)
2929
ClientDiscord.execute do |builder|
30-
builder.content = 'Un nouveau tournoi just appeared'
30+
builder.content = "Un nouveau tournoi just appeared sur #{tournament[:games].join(' et ')}"
3131
builder.add_embed do |embed|
3232
embed.title = tournament[:name]
3333
embed.description = "#{tournament[:city]}\nLien: https://smash.gg/#{tournament[:slug]}\n Le: #{start_at}"
@@ -38,7 +38,7 @@ def notify_discord(tournament)
3838

3939
def notify_twitter(tournament)
4040
start_at = I18n.l(tournament[:start_at], format: :long)
41-
tweet = "Un nouveau tournoi à #{tournament[:city]}\n#{tournament[:name]}\nDebute le #{start_at}\nhttps://smash.gg/#{tournament[:slug]}\nLieu: #{tournament[:venue_name]} #{tournament[:address]}"
41+
tweet = "Un nouveau tournoi à #{tournament[:city]} sur #{tournament[:games].join(' et ')}\n#{tournament[:name]}\nDebute le #{start_at}\nhttps://smash.gg/#{tournament[:slug]}\nLieu: #{tournament[:venue_name]} #{tournament[:address]}"
4242
TwitterClient.update(tweet[0, 280])
4343
end
4444
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class AddGamesToTounaments < ActiveRecord::Migration[5.2]
2+
def change
3+
add_column :tournaments, :games, :string, array: true
4+
add_index :tournaments, :games, using: :gin
5+
end
6+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2019_03_13_191339) do
13+
ActiveRecord::Schema.define(version: 2019_03_18_223805) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -54,6 +54,8 @@
5454
t.datetime "end_at"
5555
t.datetime "created_at", null: false
5656
t.datetime "updated_at", null: false
57+
t.string "games", array: true
58+
t.index ["games"], name: "index_tournaments_on_games", using: :gin
5759
end
5860

5961
end

0 commit comments

Comments
 (0)