player_set_history 1.0.1

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: '08ca66397eb17680624fc78c7cd559ee1b50fd50f7fede9599d2780f046635e1'
4
+ data.tar.gz: 62874c3af600e447662f7e2fdee5770881e66c34d0af4fbb3a3be07cb472817e
5
+ SHA512:
6
+ metadata.gz: ab731576ed3eaec03d756354f649b9dee10e2d8794b3aed6bb16b9dc62f0e9b01770c50270802bb4169b86c66f8d8cc680ded06abea9dc36cd3a907ea14decf5
7
+ data.tar.gz: 0aaff2e6e5aec3ea612b3c02767b787bd670e849cc4278a3a86fc83c38c187be6c6ca4763a45b4dce3c1c18312b3d740fe434c6763ee977598da005c8aae7a2a
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at 'jthen93@gmail.com'. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in player_set_history.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ player_set_history (1.0.1)
5
+ httparty
6
+ pry
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.3)
12
+ httparty (0.18.1)
13
+ mime-types (~> 3.0)
14
+ multi_xml (>= 0.5.2)
15
+ method_source (1.0.0)
16
+ mime-types (3.3.1)
17
+ mime-types-data (~> 3.2015)
18
+ mime-types-data (3.2021.0225)
19
+ multi_xml (0.6.0)
20
+ pry (0.14.0)
21
+ coderay (~> 1.1)
22
+ method_source (~> 1.0)
23
+ rake (10.5.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 2.0)
30
+ player_set_history!
31
+ rake (~> 10.0)
32
+
33
+ BUNDLED WITH
34
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 'Jouse then'
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # PlayerSetHistory
2
+
3
+ Welcome! This gem will provide a CLI interface to the smash.gg API for the purpose of pulling a player's set history as well as provide basic profile information.
4
+
5
+ ## Getting Started
6
+
7
+ These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
8
+
9
+ ### Prerequisites
10
+
11
+ Before starting you will need.
12
+
13
+
14
+ ```
15
+ - Smash.GG API Key. It's free!
16
+ - Basic Knowledge of smash.gg
17
+ ```
18
+
19
+ ### Installing
20
+
21
+ A step by step series of examples that tell you how to get a development env running
22
+
23
+ Clone this repository and modify bin/player_set_history so that your API key gets passed to the call
24
+
25
+ ```
26
+ PlayerSetHistory::CLIManager.new(api_key: "832djsadjahde838392482sd23").call
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Afterwards, run bin/player_set_history to kick off the app.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/'sway'/player_set_history. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the PlayerSetHistory project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/'sway'/player_set_history/blob/master/CODE_OF_CONDUCT.md).
46
+
47
+
48
+ ## Acknowledgments
49
+
50
+ Thank you Anbi for giving me the idea and also helping a bit with the GraphQL queries :)
51
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "player_set_history"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/environment'
3
+
4
+
5
+ PlayerSetHistory::CLIManager.new(api_key: "").call
6
+
7
+
8
+
9
+
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,13 @@
1
+ require_relative "./player_set_history/version"
2
+ require_relative "./player_set_history/climanager"
3
+ require_relative "./player_set_history/importer"
4
+ require_relative "./player_set_history/player"
5
+ require_relative "./player_set_history/set"
6
+ require_relative "./player_set_history/tournament"
7
+
8
+ require 'pry'
9
+ require 'httparty'
10
+
11
+ module PlayerSetHistory
12
+ class Error < StandardError; end
13
+ end
@@ -0,0 +1,151 @@
1
+ class PlayerSetHistory::CLIManager
2
+ attr_accessor :api_key, :api_url
3
+
4
+ def initialize(api_url: "https://api.smash.gg/gql/alpha", api_key:)
5
+ @api_key = api_key
6
+ @api_url = api_url
7
+ end
8
+
9
+ def call
10
+ input = ""
11
+ puts "Welcome! Please Choose the number game we will be pulling sets from"
12
+ puts "1) Street Fighter V: Champion Edition"
13
+ puts "2) Guilty Gear Accent Core Plus R"
14
+ puts "3) Guilty Gear Xrd Rev 2"
15
+ puts "4) Guilty Gear Strive"
16
+ puts "5) Tekken 7"
17
+ puts "6) Smash Ultimate"
18
+ puts "7) Mortal Kombat 11"
19
+
20
+
21
+
22
+ until input.to_i.between?(1,7) do
23
+ puts "The input must be a valid number"
24
+ input = gets.chomp
25
+ end
26
+
27
+ game_id = get_game_id(input)
28
+ puts `clear`
29
+
30
+ input = ""
31
+ puts "Please enter the players slug: \n\n"
32
+ puts "*To find the player slug, go to their smash.gg profile. You can pull it from the page itself or the url*: \n\nSample: Smash.gg/user/[slug]"
33
+
34
+ until input != "" do
35
+ input = gets.chomp
36
+ end
37
+ puts "Loading..."
38
+
39
+
40
+ importer = PlayerSetHistory::Importer.new(@api_url, @api_key, game_id)
41
+ player = PlayerSetHistory::Player.find_or_create_from_slug(input, importer)
42
+ display_player_profile(player)
43
+
44
+ until input == "4"
45
+ input = ""
46
+ puts "\n\nWhat would you like to do?"
47
+ puts "1) Retrieve set history for player"
48
+ puts "2) Retrieve head-to-head set history between players"
49
+ puts "3) Search for another player"
50
+ puts "4) Exit"
51
+
52
+
53
+ until input.to_i.between?(1,4) do
54
+ input = gets.chomp
55
+ end
56
+
57
+ puts `clear`
58
+ puts "Loading..."
59
+
60
+ if input == "1"
61
+ importer.import_sets_from_sgg(player.slug, player.player_id)
62
+
63
+ sets = player.get_all_sets
64
+ sets.each do |set|
65
+ puts set.score
66
+ puts set.tournament.name
67
+ puts set.tournament.date
68
+ puts "\n"
69
+ end
70
+
71
+ elsif input == "2"
72
+ input =""
73
+ importer.import_sets_from_sgg(player.slug, player.player_id)
74
+ puts `clear`
75
+ puts "Enter the opponent's tag: "
76
+
77
+ until input != "" do
78
+ input = gets.chomp
79
+ end
80
+
81
+ puts `clear`
82
+ puts "Loading..."
83
+
84
+ sets = player.get_all_sets_vs_player(input)
85
+
86
+ if sets.length == 0
87
+ puts "No sets found between #{player.tag} and #{input}. \n"
88
+ else
89
+ sets.each do |set|
90
+ puts set.score
91
+ puts set.tournament.name
92
+ puts set.tournament.date
93
+ puts "\n"
94
+ end
95
+ end
96
+
97
+ elsif input == "3"
98
+ input = ""
99
+ puts `clear`
100
+ puts "Please enter the players slug: \n\n"
101
+ puts "*To find the player slug, go to their smash.gg profile. You can pull it from the page itself or the url*: \n\nSample: Smash.gg/user/[slug]"
102
+
103
+ until input != "" do
104
+ input = gets.chomp
105
+ end
106
+ puts "Loading..."
107
+
108
+ player = PlayerSetHistory::Player.find_or_create_from_slug(input, importer)
109
+ display_player_profile(player)
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+
116
+ def get_game_id (num)
117
+ case num
118
+ when "1"
119
+ return "33990"
120
+ when "2"
121
+ return "22406"
122
+ when "3"
123
+ return "36"
124
+ when "4"
125
+ return "33945"
126
+ when "5"
127
+ return "17"
128
+ when "6"
129
+ return "1386"
130
+ when "7"
131
+ return "3200"
132
+ end
133
+ end
134
+
135
+ def display_player_profile (player)
136
+ puts `clear`
137
+ puts "----------------------"
138
+ puts "| Player Profile |"
139
+ puts "----------------------"
140
+ puts "\n"
141
+ puts "Sponsor: #{player.prefix}"
142
+ puts "Tag: #{player.tag}"
143
+ puts "Pronouns: #{player.pronoun}"
144
+ puts "Location: #{player.state}, #{player.country}"
145
+ puts "Twitter: #{player.twitter}"
146
+ puts "Discord: #{player.discord}"
147
+ puts "Twitch: #{player.twitch}"
148
+ end
149
+
150
+ end
151
+
@@ -0,0 +1,95 @@
1
+ class PlayerSetHistory::Importer
2
+ attr_accessor :url, :token
3
+
4
+ def initialize(url,token, game_id = "22406")
5
+ @url = url
6
+ @token = token
7
+ @game_id = game_id
8
+ end
9
+
10
+ def user_query()
11
+ return %{
12
+ query Users($slug: String) {
13
+ user(slug: $slug) {
14
+ genderPronoun
15
+ discriminator
16
+ location {
17
+ state
18
+ country
19
+ }
20
+ authorizations(types: [TWITCH, TWITTER, DISCORD]) {url}
21
+
22
+ player {
23
+ id
24
+ gamerTag
25
+ prefix
26
+ }
27
+ }
28
+ }
29
+ }
30
+ end
31
+
32
+ def set_query()
33
+ return %{
34
+ query Users($slug: String, $pid: ID) {
35
+ user(slug: $slug) {
36
+ discriminator
37
+ events(query: { page: 1, perPage: 100, filter: { videogameId: #{@game_id} } }) {
38
+ nodes {
39
+ tournament{
40
+ name
41
+ startAt
42
+ }
43
+ sets(filters: { playerIds: [$pid] }) {
44
+ nodes {
45
+ id
46
+ displayScore
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ end
55
+
56
+ def import_user_from_sgg(slug_str)
57
+ q = user_query
58
+ variables = {slug: slug_str}
59
+ result = HTTParty.post(
60
+ @url,
61
+ headers: {
62
+ 'Content-Type' => 'application/json',
63
+ 'Authorization' => "Bearer #{@token}"
64
+ },
65
+ body: {
66
+ query: q,
67
+ variables: variables
68
+ }.to_json
69
+ )
70
+
71
+ return JSON.parse(result.response.body)["data"]["user"]
72
+ end
73
+
74
+ def import_sets_from_sgg(slug_str, pid_str)
75
+ q = set_query
76
+ variables = {
77
+ slug: slug_str,
78
+ pid: pid_str
79
+ }
80
+ result = HTTParty.post(
81
+ @url,
82
+ headers: {
83
+ 'Content-Type' => 'application/json',
84
+ 'Authorization' => "Bearer #{@token}"
85
+ },
86
+ body: {
87
+ query: q,
88
+ variables: variables
89
+ }.to_json
90
+ )
91
+
92
+ event_hash = JSON.parse(result.response.body)["data"]["user"]
93
+ PlayerSetHistory::Set.create_sets_from_player(event_hash, self)
94
+ end
95
+ end
@@ -0,0 +1,97 @@
1
+ class PlayerSetHistory::Player
2
+ attr_accessor :slug, :tag, :twitter, :discord, :twitch, :pronoun, :state, :country, :player_id, :prefix, :sets
3
+ @@all = []
4
+
5
+ def initialize(attributes)
6
+ attributes.each {|key, value| self.send(("#{key}="), value)}
7
+ @@all << self
8
+ end
9
+
10
+ def self.all
11
+ @@all
12
+ end
13
+
14
+ def add_player_attributes(attributes)
15
+ attributes.each {|key, value| self.send(("#{key}="), value)}
16
+ end
17
+
18
+ def self.create_from_json(user_hash)
19
+ attributes = {
20
+ :pronoun => user_hash["genderPronoun"],
21
+ :state => user_hash["location"]["state"],
22
+ :country => user_hash["location"]["country"],
23
+ :slug => user_hash["discriminator"],
24
+ :player_id => user_hash["player"]["id"],
25
+ :tag => user_hash["player"]["gamerTag"],
26
+ :prefix => user_hash["player"]["prefix"],
27
+ }
28
+ # Links
29
+ unless user_hash["authorizations"] == nil
30
+ user_hash["authorizations"].each do |url|
31
+
32
+ social = ""
33
+ social = url["url"]
34
+
35
+ if social != nil
36
+ if social.include?("twitter")
37
+ attributes[:twitter] = social
38
+ elsif social.include?("discord")
39
+ attributes[:discord] = social
40
+ elsif social.include?("twitch")
41
+ attributes[:twitch] = social
42
+ end
43
+ end
44
+ end
45
+ end
46
+ player = PlayerSetHistory::Player.new(attributes)
47
+ return player
48
+ end
49
+
50
+ def self.create_from_tag(prefix: "", tag:)
51
+ attributes = {:prefix => prefix, :tag => tag}
52
+ player = PlayerSetHistory::Player.new(attributes)
53
+ return player
54
+ end
55
+
56
+ def self.find_or_create_from_tag(tag: , prefix: "")
57
+ player_index = self.all.index {|x| x.tag.downcase == tag.downcase}
58
+
59
+ if player_index == nil
60
+ player = PlayerSetHistory::Player.create_from_tag(tag: tag, prefix: prefix)
61
+ else
62
+ player = self.all[player_index]
63
+ end
64
+
65
+ return player
66
+ end
67
+
68
+ def self.find_or_create_from_slug(slug, importer)
69
+ player_index = self.all.index {|x| x.slug == slug}
70
+
71
+ if player_index == nil
72
+ r_player = importer.import_user_from_sgg(slug)
73
+ player = PlayerSetHistory::Player.create_from_json(r_player)
74
+ else
75
+ player = self.all[player_index]
76
+ end
77
+
78
+ return player
79
+ end
80
+
81
+ def get_all_sets
82
+ sets = PlayerSetHistory::Set.all.select do |set|
83
+ set.players.include?(self)
84
+ end
85
+ return sets
86
+ end
87
+
88
+ def get_all_sets_vs_player (player_tag)
89
+
90
+ sets = self.get_all_sets.select do |set|
91
+ set.score.downcase.include?(player_tag.downcase)
92
+ end
93
+ return sets
94
+ end
95
+
96
+
97
+ end
@@ -0,0 +1,78 @@
1
+ class PlayerSetHistory::Set
2
+ attr_accessor :players, :tournament, :score, :winner, :id
3
+ @@all = []
4
+
5
+ def initialize(attributes)
6
+ attributes.each {|key, value| self.send(("#{key}="), value)}
7
+ @@all << self
8
+ end
9
+
10
+ def self.all
11
+ @@all
12
+ end
13
+
14
+ def self.create_sets_from_player(event_hash, importer)
15
+ #Get one of the players
16
+ player_1 = PlayerSetHistory::Player.find_or_create_from_slug(event_hash["discriminator"], importer)
17
+
18
+ event_hash["events"]["nodes"].each do |event|
19
+ # Find or create tournament
20
+ tourny = PlayerSetHistory::Tournament.find_or_create_from_name(
21
+ event["tournament"]["name"],
22
+ event["tournament"]["startAt"]
23
+ )
24
+
25
+ # create sets
26
+ if event["sets"]["nodes"] != nil # Prevents error when event is nil
27
+ event["sets"]["nodes"].each do |set|
28
+ score = set["displayScore"]
29
+ id = set["id"]
30
+ player_2 = nil
31
+ winner_score = 0
32
+ winner = ""
33
+
34
+ unless set_exists?(id)
35
+ score.split(" - ").each do |player|
36
+ # Parse score
37
+ if player.include?("|")
38
+ player_tag = player[0..-3].split(" | ")[1]
39
+ player_prefix = player.split(" | ")[0]
40
+ else
41
+ player_tag = player[0..-3]
42
+ player_prefix = ""
43
+ end
44
+
45
+ # create player_2 if neccessary
46
+ if player_tag != player_1.tag
47
+ player_2 = PlayerSetHistory::Player.find_or_create_from_tag(tag: player_tag, prefix: player_prefix)
48
+ end
49
+
50
+ # Find winner
51
+ if player[-1].to_i > winner_score
52
+ winner_score = player[-1].to_i
53
+ winner = player_tag
54
+ end
55
+ end
56
+
57
+
58
+ set_attributes = {players: [player_1, player_2],
59
+ score: score,
60
+ id: id,
61
+ winner: winner,
62
+ tournament: tourny
63
+ }
64
+
65
+ new_set = PlayerSetHistory::Set.new(set_attributes)
66
+ tourny.add_set(new_set)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def self.set_exists? (set_id)
74
+ sets = self.all.any? do |set|
75
+ set.id == set_id
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,34 @@
1
+ require 'date'
2
+
3
+ class PlayerSetHistory::Tournament
4
+ attr_accessor :sets, :date, :name, :winner
5
+ @@all = []
6
+
7
+ def initialize (name, date)
8
+ @name = name
9
+ @date = DateTime.strptime(date.to_s,'%s').to_s[0..9]
10
+ @@all << self
11
+ @sets = []
12
+ end
13
+
14
+ def self.all
15
+ @@all
16
+ end
17
+
18
+ def add_set(set)
19
+ @sets << set
20
+ end
21
+
22
+ def self.find_or_create_from_name (name, date)
23
+ tourny_index = self.all.index {|x| x.name == name}
24
+
25
+ if tourny_index == nil
26
+ tourny = PlayerSetHistory::Tournament.new(name, date)
27
+ else
28
+ tourny = self.all[tourny_index]
29
+ end
30
+
31
+ return tourny
32
+ end
33
+
34
+ end
@@ -0,0 +1,3 @@
1
+ module PlayerSetHistory
2
+ VERSION = "1.0.1"
3
+ end
data/notes.md ADDED
@@ -0,0 +1,131 @@
1
+ # Made this before the project started.
2
+
3
+ Classes (Potentially)
4
+
5
+ Player
6
+ - Belongs to a Set
7
+ - Belongs to a Tournament
8
+ - #Set_History
9
+ - #Tournaments_Won
10
+ - .Best_Record
11
+ - Attributes: Slug, GamerTag, Twitter, Discord, Twitch, Pronoun, State, Country, Player_ID
12
+
13
+
14
+ Sets
15
+ - Belongs to Tournament
16
+ - Player_1 and Player_2
17
+ - #Winner
18
+ - #Tournament
19
+
20
+
21
+ Tournament
22
+ - #Name
23
+ - #Date
24
+ - #Sets
25
+
26
+ CLIManager
27
+
28
+ SggApi
29
+ - #get_user
30
+ - #get_users_in_tournament
31
+ -
32
+
33
+ SAMPLE QUERY
34
+
35
+ @url = 'https://api.smash.gg/gql/alpha'
36
+ @token = '97db6a94b20d4004ba9ad54d37d6a290'
37
+
38
+ query = %{
39
+ query Users($slug: String) {
40
+ user(slug: $slug) {
41
+ genderPronoun
42
+ location {
43
+ state
44
+ country
45
+ }
46
+ authorizations(types: [TWITCH, TWITTER, DISCORD]) {url}
47
+
48
+ player {
49
+ id
50
+ gamerTag
51
+ sets(perPage: 1, page: 1) {
52
+ nodes {
53
+ displayScore
54
+ fullRoundText
55
+ event {videogame {displayName}
56
+ tournament {name}
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }}
63
+
64
+ variables = {
65
+ slug: "356d0e24"
66
+ }
67
+
68
+
69
+ result = HTTParty.post(
70
+ @url,
71
+ headers: {
72
+ 'Content-Type' => 'application/json',
73
+ 'Authorization' => "Bearer #{@token}"
74
+ },
75
+ body: {
76
+ query: query,
77
+ variables: variables
78
+ }.to_json
79
+ )
80
+
81
+ puts "#{result}"
82
+
83
+
84
+
85
+ SAMPLE RESULTS
86
+ {"genderPronoun"=>nil, "location"=>{"state"=>"CA", "country"=>"United States"},"authorizations"=>[{"url"=>"https://twitter.com/Kizzie_Kay310"}, {"url"=>"https://twitch.tv/Kizziekay310"}], "player"=>{"id"=>57141, "gamerTag"=>"Kizzie Kay"}}
87
+
88
+
89
+
90
+ just player info
91
+ query Users($slug: String) {
92
+ user(slug: $slug) {
93
+ genderPronoun
94
+ location {
95
+ state
96
+ country
97
+ }
98
+ authorizations(types: [TWITCH, TWITTER, DISCORD]) {url}
99
+
100
+ player {
101
+ id
102
+ gamerTag
103
+ }
104
+ }
105
+ }
106
+
107
+ GET ALL SETS FROM USER
108
+
109
+ query Users($slug: String, $pid: ID) {
110
+ user(slug: $slug) {
111
+ events(query: { page: 1, perPage: 100, filter: { videogameId: 22406 } }) {
112
+ nodes {
113
+ tournament{
114
+ name
115
+ startAt
116
+ }
117
+ sets(filters: { playerIds: [$pid] }) {
118
+ nodes {
119
+ displayScore
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+
127
+
128
+ {
129
+ "slug": "08e32f96",
130
+ "pid": "15866"
131
+ }
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "player_set_history/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "player_set_history"
8
+ spec.version = PlayerSetHistory::VERSION
9
+ spec.authors = ["'Jouse Then'"]
10
+ spec.email = ["'jthen93@gmail.com'"]
11
+
12
+ spec.summary = %q{"Retrieves player set history"}
13
+ spec.description = %q{"Retrieves a player's smash.gg set history and displays it in a CLI. On the back-end, it creates player, sets, tournament objects which can be referenced for more information in the future"}
14
+ spec.homepage = "https://github.com/jousethen/player_set_history"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+
21
+ spec.metadata['allowed_push_host'] = "https://rubygems.org/"
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_development_dependency "bundler", "~> 2.0"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_dependency "pry"
41
+ spec.add_dependency "httparty"
42
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: player_set_history
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - "'Jouse Then'"
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-22 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.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.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: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
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
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: '"Retrieves a player''s smash.gg set history and displays it in a CLI.
70
+ On the back-end, it creates player, sets, tournament objects which can be referenced
71
+ for more information in the future"'
72
+ email:
73
+ - "'jthen93@gmail.com'"
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/player_set_history
87
+ - bin/setup
88
+ - lib/environment.rb
89
+ - lib/player_set_history/climanager.rb
90
+ - lib/player_set_history/importer.rb
91
+ - lib/player_set_history/player.rb
92
+ - lib/player_set_history/set.rb
93
+ - lib/player_set_history/tournament.rb
94
+ - lib/player_set_history/version.rb
95
+ - notes.md
96
+ - player_set_history.gemspec
97
+ homepage: https://github.com/jousethen/player_set_history
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ allowed_push_host: https://rubygems.org/
102
+ homepage_uri: https://github.com/jousethen/player_set_history
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.0.3
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: '"Retrieves player set history"'
122
+ test_files: []