class PlayerSetHistory::Importer
Attributes
token[RW]
url[RW]
Public Class Methods
new(url,token, game_id = "22406")
click to toggle source
# File lib/player_set_history/importer.rb, line 4 def initialize(url,token, game_id = "22406") @url = url @token = token @game_id = game_id end
Public Instance Methods
import_sets_from_sgg(slug_str, pid_str)
click to toggle source
# File lib/player_set_history/importer.rb, line 74 def import_sets_from_sgg(slug_str, pid_str) q = set_query variables = { slug: slug_str, pid: pid_str } result = HTTParty.post( @url, headers: { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@token}" }, body: { query: q, variables: variables }.to_json ) event_hash = JSON.parse(result.response.body)["data"]["user"] if event_hash["events"]["nodes"] == nil puts "This player does not play this game" else PlayerSetHistory::Set.create_sets_from_player(event_hash, self) end end
import_user_from_sgg(slug_str)
click to toggle source
# File lib/player_set_history/importer.rb, line 56 def import_user_from_sgg(slug_str) q = user_query variables = {slug: slug_str} result = HTTParty.post( @url, headers: { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@token}" }, body: { query: q, variables: variables }.to_json ) return JSON.parse(result.response.body)["data"]["user"] end
set_query()
click to toggle source
# File lib/player_set_history/importer.rb, line 32 def set_query() return %{ query Users($slug: String, $pid: ID) { user(slug: $slug) { discriminator events(query: { page: 1, perPage: 100, filter: { videogameId: #{@game_id} } }) { nodes { tournament{ name startAt } sets(filters: { playerIds: [$pid] }) { nodes { id displayScore } } } } } } } end
user_query()
click to toggle source
# File lib/player_set_history/importer.rb, line 10 def user_query() return %{ query Users($slug: String) { user(slug: $slug) { genderPronoun discriminator location { state country } authorizations(types: [TWITCH, TWITTER, DISCORD]) {url} player { id gamerTag prefix } } } } end