pdga_api 0.1.0

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: 1076fb2bf9d835886a8242dfd829eeb1f5406b462e51314d8f67516c726a73d6
4
+ data.tar.gz: a7c712f9530888dd7ca7b6a387485a4048ce8576802cba57ebf15e671955a628
5
+ SHA512:
6
+ metadata.gz: b442e7f2e99a00fd56d14b2d30d889715bce26e6a50d8a9adbae457fe4226f4f04632dad4ea0bcd1b55b2b1b5f07a7945392cb949160301f8a35ec0de429621a
7
+ data.tar.gz: 2c5a79af6766bec5db9f452f7582887f9911c3c55df1560e02cc4ceb8f98cd69bba25ea8899660844609b3f02e7f6a97a8977c728e61d1098de770ad97b1dd05
data/.env.template ADDED
@@ -0,0 +1,3 @@
1
+ SESSID=SESSID
2
+ SESSION_NAME=SESSION_NAME
3
+ TOKEN=TOKEN
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /secret.env
10
+ /.env
data/.rubocop.yml ADDED
@@ -0,0 +1,10 @@
1
+ Style/StringLiterals:
2
+ Enabled: true
3
+ EnforcedStyle: double_quotes
4
+
5
+ Style/StringLiteralsInInterpolation:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Layout/LineLength:
10
+ Max: 120
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in pdga_api.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 0.80"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 TODO: Write your name
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,55 @@
1
+ # PdgaApi
2
+ PDGA API Wrapper
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'pdga_api'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle install
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install pdga_api
19
+ ## Starting steps
20
+
21
+ Out of the box there are some ENV vars that are needed in order to make this gem work (also assumes you already have PDGA API access)
22
+ First in the root directory there are 2 template .env files you can look at for setting up the ENV vars. You can run this with just a secret.env that contains your PDGA username and password
23
+ If you run the login method it will write out a .env with additional information the API needs to make calls. (session id, session name, and token)
24
+
25
+ ## Usage
26
+
27
+ Expected responses can all be found here https://www.pdga.com/dev/api/rest/v1/auth
28
+
29
+ There are 4 types of actions that this gem allows you to perform.
30
+ 1. Authentication
31
+ 1. login Pdga::Client.login({ username: ENV["USERNAME"], password: ENV["PASSWORD"] }) (Could pass the actual username/password)
32
+ 2. connection status Pdga::Client.connect
33
+ 3. logout Pdga::Client.logout
34
+ 2. Player information which takes a hash of various search params that are listed on the PDGA site (default 10 returned with a max of 200)
35
+ 1. player search Pdga::Client.players({ pdga_number: "15857" })
36
+ 2. player statistics search Pdga::Client.player_statistics({ pdga_number: "15857", year: "2022" })
37
+ 3. Event information which takes a hash of various search params that are listed on the PDGA site (default 10 returned with a max of 200)
38
+ 1. event search Pdga::Client.events({ tournament_id: "47877" })
39
+ 4. Course information which takes a hash of various search params that are listed on the PDGA site (default 10 returned with a max of 200)
40
+ 1. course search Pdga::Client.courses({ course_id: "2146" })
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
45
+
46
+ ## Code of Conduct
47
+
48
+ Everyone interacting in the PdgaApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/relia1/pdga_api/blob/master/CODE_OF_CONDUCT.md).
49
+
50
+ ## Todos
51
+
52
+ 1. Mock the tests!
53
+ 2. Figure out something better for the ENV vars
54
+ 3. Add response error handling from the API
55
+ 4. Refactor duplicated code in client.rb
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "pdga_api"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
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,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "json"
5
+ require "oj"
6
+ require "dotenv"
7
+
8
+ module Pdga
9
+ # API Client for PDGA
10
+ class Client
11
+ API_ENDPOINT = "https://api.pdga.com"
12
+
13
+ def self.players(options)
14
+ params = build_params(options)
15
+ response = build_request("get", "services/json/players?#{params}")
16
+ JSON.parse(response.body)
17
+ end
18
+
19
+ def self.player_statistics(options)
20
+ params = build_params(options)
21
+ response = build_request("get", "services/json/player-statistics?#{params}")
22
+ JSON.parse(response.body)
23
+ end
24
+
25
+ def self.events(options)
26
+ params = build_params(options)
27
+ response = build_request("get", "services/json/event?#{params}")
28
+ JSON.parse(response.body)
29
+ end
30
+
31
+ def self.courses(options)
32
+ params = build_params(options)
33
+ response = build_request("get", "services/json/course?#{params}")
34
+ JSON.parse(response.body)
35
+ end
36
+
37
+ def self.login(options)
38
+ response = build_request("post", "services/json/user/login", options)
39
+ update_envs(JSON.parse(response.body))
40
+ JSON.parse(response.body)
41
+ end
42
+
43
+ def self.connect
44
+ response = build_request("post", "services/json/system/connect")
45
+ JSON.parse(response.body)
46
+ end
47
+
48
+ def self.logout
49
+ response = build_request("post", "services/json/user/logout")
50
+ clear_env
51
+ JSON.parse(response.body)
52
+ end
53
+
54
+ def self.client
55
+ @client ||= Faraday.new(API_ENDPOINT) do |client|
56
+ client.use Faraday::Response::RaiseError
57
+ client.request :url_encoded
58
+ client.adapter Faraday.default_adapter
59
+ client.headers["Cookie"] = "#{ENV["SESSION_NAME"]}=#{ENV["SESSID"]}"
60
+ client.headers["X-CSRF-Token"] = ENV["TOKEN"]
61
+ end
62
+ end
63
+
64
+ def self.request(http_method:, endpoint:, body: {})
65
+ client.public_send(http_method, endpoint, body)
66
+ end
67
+
68
+ def self.build_params(options)
69
+ params = ""
70
+ options.each do |key, value|
71
+ params += "#{key}=#{value}&"
72
+ end
73
+ params.chomp!("&")
74
+ end
75
+
76
+ def self.build_request(http_method, endpoint, options = {})
77
+ request(
78
+ http_method: http_method.to_sym,
79
+ endpoint: endpoint,
80
+ body: options
81
+ )
82
+ end
83
+
84
+ def self.update_envs(response)
85
+ f = File.new(".env", "w")
86
+ f.write("SESSID=#{response["sessid"]}\nSESSION_NAME=#{response["session_name"]}\nTOKEN=#{response["token"]}")
87
+ f.close
88
+ ENV["SESSID"] = response["sessid"]
89
+ ENV["SESSION_NAME"] = response["session_name"]
90
+ ENV["TOKEN"] = response["token"]
91
+ end
92
+
93
+ def self.clear_env
94
+ f = File.new(".env", "w")
95
+ f.write("SESSID=\nSESSION_NAME=\nTOKEN=")
96
+ f.close
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PdgaApi
4
+ VERSION = "0.1.0"
5
+ end
data/lib/pdga_api.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pdga_api/version"
4
+ require_relative "pdga_api/client"
5
+ require "dotenv"
6
+
7
+ module PdgaApi
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ Dotenv.load(".env", "secret.env")
11
+ end
data/pdga_api.gemspec ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/pdga_api/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "pdga_api"
7
+ spec.version = PdgaApi::VERSION
8
+ spec.authors = ["Robert Elia"]
9
+ spec.email = ["relia1@pdx.edu"]
10
+
11
+ spec.summary = "Gem to wrap the PDGA API."
12
+ spec.description = "Gem to wrap the PDGA API."
13
+ spec.homepage = "https://github.com/relia1/pdga_api"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
+
19
+ # spec.metadata["homepage_uri"] = spec.homepage
20
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+ spec.add_development_dependency "minitest"
35
+ spec.add_development_dependency "vcr"
36
+ spec.add_development_dependency "webmock"
37
+
38
+ spec.add_dependency "dotenv"
39
+ spec.add_dependency "faraday"
40
+ spec.add_dependency "json"
41
+ spec.add_dependency "oj"
42
+
43
+ # For more information and examples about making a new gem, checkout our
44
+ # guide at: https://bundler.io/guides/creating_gem.html
45
+ end
@@ -0,0 +1,2 @@
1
+ USERNAME=USERNAME
2
+ PASSWORD=PASSWORD
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdga_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Elia
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: vcr
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: dotenv
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
+ - !ruby/object:Gem::Dependency
70
+ name: faraday
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: oj
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Gem to wrap the PDGA API.
112
+ email:
113
+ - relia1@pdx.edu
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".env.template"
119
+ - ".gitignore"
120
+ - ".rubocop.yml"
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/pdga_api.rb
129
+ - lib/pdga_api/client.rb
130
+ - lib/pdga_api/version.rb
131
+ - pdga_api.gemspec
132
+ - secret.env.template
133
+ homepage: https://github.com/relia1/pdga_api
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.4.0
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubygems_version: 3.2.3
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Gem to wrap the PDGA API.
156
+ test_files: []