-
Notifications
You must be signed in to change notification settings - Fork 28
A lot of improvements #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexWayfer
wants to merge
16
commits into
bhaberer:master
Choose a base branch
from
AlexWayfer:a_lot_of_improvements
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e1bb3df
Enable RSpec `--only-fail` feature
AlexWayfer d239be4
Improve RSpec configuration
AlexWayfer 65e0c67
Add `frozen_string_literal` tech comment
AlexWayfer 051c92e
Rename some spec files
AlexWayfer 3d8fcfc
Remove `require 'spec_helper'` since it's in the RSpec config
AlexWayfer f8019ff
Improve code style
AlexWayfer e41d47b
Move `Hash` monkey-patching under our namespace
AlexWayfer 3a98b07
Require lib for specs relatively
AlexWayfer 4af7764
Specify required Ruby version in gemspec
AlexWayfer fe78c73
Add EditorConfig file
AlexWayfer 8ce67bc
Use `require_relative` where necessary
AlexWayfer 505c28b
Get rid of `Helpers` in the `Kernel`
AlexWayfer cbb31d1
Improve code for `Steam.apikey`
AlexWayfer c85288a
Add RuboCop development dependencies and resolve offenses
AlexWayfer f6a0cb7
Add suggested RuboCop plugins
AlexWayfer f6f279a
Update Faraday dependency to v2
AlexWayfer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| indent_style = space | ||
| indent_size = 2 | ||
| end_of_line = lf | ||
| charset = utf-8 | ||
| trim_trailing_whitespace = true | ||
| insert_final_newline = true | ||
| max_line_length = 100 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,3 +16,4 @@ spec/secret.rb | |
| test/tmp | ||
| test/version_tmp | ||
| tmp | ||
| spec/examples.txt | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| -f d -c --warning | ||
| --require spec_helper | ||
| --format doc | ||
| --color | ||
| --warning |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| require: | ||
| - rubocop-rake | ||
| - rubocop-rspec | ||
|
|
||
| AllCops: | ||
| NewCops: enable | ||
| TargetRubyVersion: 2.4 | ||
|
|
||
| Layout/LineLength: | ||
| Max: 100 | ||
|
|
||
| Metrics/BlockLength: | ||
| Exclude: | ||
| - spec/**/*.rb | ||
|
|
||
| Naming/FileName: | ||
| Exclude: | ||
| - lib/steam-api.rb | ||
| Naming/AccessorMethodName: | ||
| Exclude: | ||
| - lib/steam-api/steam/**/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'bundler/gem_tasks' | ||
| require 'rspec/core/rake_task' | ||
|
|
||
| RSpec::Core::RakeTask.new | ||
|
|
||
| task default: :spec | ||
|
|
||
| desc 'Alias for spec task' | ||
| task test: :spec |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,39 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Steam | ||
| # Since the steam responses are so randomly inconsistant we're making a new | ||
| # class to manage the responses. | ||
| # FIXME: move all hash extensions here once the gem is finished and make | ||
| class Response < Hash | ||
| # def parse_key(key) | ||
| # fail Steam::JSONError unless self.key?(key) | ||
| # self[key] | ||
| # end | ||
| end | ||
| end | ||
| def initialize(raw_response) | ||
| super() | ||
|
|
||
| class Hash | ||
| # Simple method to access a nested field, since Valve seems to like | ||
| # nesting their json a few levels on every request. | ||
| # @param [String] key The key to extract from the hash | ||
| def parse_key(key) | ||
| raise Steam::JSONError unless key?(key) | ||
| raw_response.each do |key, value| | ||
| self[key] = | ||
| case value | ||
| when Hash then self.class.new(value) | ||
| else value | ||
| end | ||
| end | ||
| end | ||
|
|
||
| self[key] | ||
| end | ||
| # Simple method to access a nested field, since Valve seems to like | ||
| # nesting their json a few levels on every request. | ||
| # @param [String] key The key to extract from the hash | ||
| def parse_key(key) | ||
| raise Steam::JSONError unless key?(key) | ||
|
|
||
| self[key] | ||
| end | ||
|
|
||
| # Many responses from the apis (but not all) include a success | ||
| # field, so this allows us to check it wiht minimal fuss. | ||
| # @param [String] success_condition what the success condition should be | ||
| # @return [Boolean] Returns true or raises an exception. | ||
| def check_success(success_condition: true) | ||
| success = parse_key('success') | ||
| raise Steam::SteamError unless success == success_condition | ||
| # Many responses from the apis (but not all) include a success | ||
| # field, so this allows us to check it wiht minimal fuss. | ||
| # @param [String] success_condition what the success condition should be | ||
| # @return [Boolean] Returns true or raises an exception. | ||
| def check_success(success_condition: true) | ||
| success = parse_key('success') | ||
| raise Steam::SteamError unless success == success_condition | ||
|
|
||
| true | ||
| true | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,16 @@ | ||
| # Base class def | ||
| # frozen_string_literal: true | ||
|
|
||
| # Base class definition | ||
| module Steam | ||
| @apikey = ENV['STEAM_API_KEY'] | ||
| class << self | ||
| attr_writer :apikey | ||
|
|
||
| def self.apikey | ||
| if @apikey.nil? | ||
| unless ENV.key?('STEAM_API_KEY') | ||
| raise ArgumentError, 'Please set your Steam API key.' | ||
| end | ||
| def apikey | ||
| return @apikey if @apikey | ||
|
|
||
| @apikey = ENV['STEAM_API_KEY'] | ||
| end | ||
| @apikey | ||
| end | ||
| raise ArgumentError, 'Please set your Steam API key.' unless ENV.key?('STEAM_API_KEY') | ||
|
|
||
| def self.apikey=(key) | ||
| @apikey = key | ||
| @apikey = ENV.fetch('STEAM_API_KEY') | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,50 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Steam | ||
| # A Ruby DSL for communicating with the Apps portion of the Steam Web API. | ||
| # @see https://developer.valvesoftware.com/wiki/Steam_Web_API | ||
| # @since 1.0.0 | ||
| module Apps | ||
| # Get Steam Applications | ||
| # @return [Hash] A list of objects containing the title and app ID of | ||
| # each program available in the store. | ||
| # @see http://wiki.teamfortress.com/wiki/WebAPI/GetAppList | ||
| def self.get_all | ||
| response = client.get('GetApplist/v2') | ||
| .parse_key('applist') | ||
| .parse_key('apps') | ||
| response | ||
| end | ||
| class << self | ||
| # Get Steam Applications | ||
| # @return [Hash] A list of objects containing the title and app ID of | ||
| # each program available in the store. | ||
| # @see http://wiki.teamfortress.com/wiki/WebAPI/GetAppList | ||
| def get_all | ||
| client.get('GetApplist/v2').parse_key('applist').parse_key('apps') | ||
| end | ||
|
|
||
| # Get Servers at Address | ||
| # @param [String] addr IP or IP:queryport to list | ||
| # @return [Hash] A hash containing the API response | ||
| # @see http://wiki.teamfortress.com/wiki/WebAPI/GetServersAtAddress | ||
| def self.get_servers(addr: nil, api_version: 'v1') | ||
| response = client.get "GetServersAtAddress/#{api_version}", | ||
| params: { addr: ERB::Util.url_encode(addr) } | ||
| response = response.parse_key('response') | ||
| response.check_success | ||
| response.parse_key('servers') | ||
| end | ||
| # Get Servers at Address | ||
| # @param [String] addr IP or IP:queryport to list | ||
| # @return [Hash] A hash containing the API response | ||
| # @see http://wiki.teamfortress.com/wiki/WebAPI/GetServersAtAddress | ||
| def get_servers(addr: nil, api_version: 'v1') | ||
| response = client.get( | ||
| "GetServersAtAddress/#{api_version}", params: { addr: ERB::Util.url_encode(addr) } | ||
| ) | ||
| response = response.parse_key('response') | ||
| response.check_success | ||
| response.parse_key('servers') | ||
| end | ||
|
|
||
| # Check if a given version of an App is current | ||
| # @param [Fixnum] appid AppID of game | ||
| # @param [Fixnum] version The installed version of the game | ||
| # @return [Hash] A hash containing the API response | ||
| # @see http://wiki.teamfortress.com/wiki/WebAPI/UpToDateCheck | ||
| def self.up_to_date(appid: nil, version: 'v1', api_version: 'v1') | ||
| response = client.get "UpToDateCheck/#{api_version}", | ||
| params: { appid: appid, version: version } | ||
| response = response.parse_key('response') | ||
| response.check_success | ||
| response.delete('success') | ||
| response | ||
| end | ||
| # Check if a given version of an App is current | ||
| # @param [Fixnum] appid AppID of game | ||
| # @param [Fixnum] version The installed version of the game | ||
| # @return [Hash] A hash containing the API response | ||
| # @see http://wiki.teamfortress.com/wiki/WebAPI/UpToDateCheck | ||
| def up_to_date(appid: nil, version: 'v1', api_version: 'v1') | ||
| response = client.get( | ||
| "UpToDateCheck/#{api_version}", params: { appid: appid, version: version } | ||
| ) | ||
| response = response.parse_key('response') | ||
| response.check_success | ||
| response.delete('success') | ||
| response | ||
| end | ||
|
|
||
| def self.client | ||
| build_client 'ISteamApps' | ||
| def client | ||
| Steam::Client.new 'ISteamApps' | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little resistant to adding personal editor settings to the repo, even mine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, there are different levels of "editor settings" (convention): "team" (it can have several projects), "projects" (where we're), "personal".
And I respect any level of preferences, but was trying to introduce project-wide convention. To keep project's source code in one style (not to mix space-indentation with tabs, etc.)
If you're against it — I can remove. But in my practice it helps, not to specific maintainers or contributors, but to a project, and all its members (how to write code for the specific project despite personal preferences).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like an additional example:
I have personal taste in tab-indentation. Even in Ruby. But I don't enforce it. And I have a code editor plugin, which toggles my settings (indentation, line length / wrapping, encoding, etc.) to the specific open project.
I wish similar to everyone. You can write as you want, but in a single project we're all should stick together, with chosen rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexWayfer fair points; how about this, fine with leaving it if we bump the
.editorconfig/ rubocop line length to the current rubocop default of 120, everything else seems fairly reasonable for what I'd expect from a ruby ide.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "ruby ide"? I've been using Atom Editor, now I use Pulsar Editor. I can use VS Code — whatever.
You can open EditorConfig's site: https://editorconfig.org/#pre-installed
Some editors work with it "out-of-box", some requires (simple) plugins. Even RubyMine, Sublime, etc.
Again: if I have editor's setting for tab-indentation — I'd have problems with this project with 2-spaces indentation. Which I'm not against, this config is just a kind of automatization for project-to-project work.
The same for end-of-line chars between UNIX and Windows users on the same projects, etc. Nobody against Windows users or their end-line chars, we just should keep the same chars along the project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexWayfer a Ruby IDE, a Integrated development environment is any feature rich software development application. Basically, I'd expect something like VS code, etc to default to most of those settings (other than the line length).
Rubocop's LineLength Cop defaults to 120 so I'd want to keep to that value.