steam_ladder 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.devcontainer/Dockerfile +19 -0
- data/.devcontainer/devcontainer.json +32 -0
- data/.github/workflows/gem-push.yml +44 -0
- data/.gitignore +56 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +77 -0
- data/LICENSE +21 -0
- data/README.md +178 -0
- data/bin/bundle +118 -0
- data/bin/rspec +29 -0
- data/lib/steam_ladder.rb +53 -0
- data/spec/spec_helper.rb +108 -0
- data/spec/steam_ladder_spec.rb +63 -0
- data/steam_ladder.gemspec +23 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c8ed1c0753b53024ace92b2bd23743c727e544ce252701349f7260ec7e81dc38
|
4
|
+
data.tar.gz: 1a8ca572d9dd6b09ab0c66a223a0597a08b7393084a9c8303fa260961c15fc9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b163ace523b9cf6520feb717247e58460af6a372e243d3ab31902ff41182b6384a9264e14fb2fe4aaab9c380b6bffb1b54632641908fd5f6f6a6fe2dcde4e139
|
7
|
+
data.tar.gz: a8aa296972ecd9487141d0354dcc54ad1303ef3db6b6632d1b4a54556c336e359805b934a5df289d0250bf43a4f9ff0dd7004b1fa4b0f6844b539ca3cd866dd7
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/ruby/.devcontainer/base.Dockerfile
|
2
|
+
|
3
|
+
# [Choice] Ruby version: 3, 3.0, 2, 2.7, 2.6
|
4
|
+
ARG VARIANT="3.0"
|
5
|
+
FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
|
6
|
+
|
7
|
+
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
|
8
|
+
ARG NODE_VERSION="none"
|
9
|
+
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
|
10
|
+
|
11
|
+
# [Optional] Uncomment this section to install additional OS packages.
|
12
|
+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
13
|
+
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
14
|
+
|
15
|
+
# [Optional] Uncomment this line to install additional gems.
|
16
|
+
RUN gem install rubocop
|
17
|
+
|
18
|
+
# [Optional] Uncomment this line to install global node packages.
|
19
|
+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
|
@@ -0,0 +1,32 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
|
2
|
+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/ruby
|
3
|
+
{
|
4
|
+
"name": "Ruby",
|
5
|
+
"build": {
|
6
|
+
"dockerfile": "Dockerfile",
|
7
|
+
"args": {
|
8
|
+
// Update 'VARIANT' to pick a Ruby version: 3, 3.0, 2, 2.7, 2.6
|
9
|
+
"VARIANT": "3",
|
10
|
+
// Options
|
11
|
+
"NODE_VERSION": "none"
|
12
|
+
}
|
13
|
+
},
|
14
|
+
|
15
|
+
// Set *default* container specific settings.json values on container create.
|
16
|
+
"settings": {},
|
17
|
+
|
18
|
+
// Add the IDs of extensions you want installed when the container is created.
|
19
|
+
"extensions": [
|
20
|
+
"rebornix.Ruby"
|
21
|
+
],
|
22
|
+
|
23
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
24
|
+
// "forwardPorts": [],
|
25
|
+
|
26
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
27
|
+
// "postCreateCommand": "ruby --version",
|
28
|
+
|
29
|
+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
30
|
+
"remoteUser": "vscode"
|
31
|
+
|
32
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
release:
|
5
|
+
types:
|
6
|
+
- created
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
name: Build + Publish
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
permissions:
|
13
|
+
contents: read
|
14
|
+
packages: write
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- name: Set up Ruby 2.6
|
19
|
+
uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: 2.6.x
|
22
|
+
|
23
|
+
- name: Publish to GPR
|
24
|
+
run: |
|
25
|
+
mkdir -p $HOME/.gem
|
26
|
+
touch $HOME/.gem/credentials
|
27
|
+
chmod 0600 $HOME/.gem/credentials
|
28
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
29
|
+
gem build *.gemspec
|
30
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
31
|
+
env:
|
32
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
33
|
+
OWNER: ${{ github.repository_owner }}
|
34
|
+
|
35
|
+
- name: Publish to RubyGems
|
36
|
+
run: |
|
37
|
+
mkdir -p $HOME/.gem
|
38
|
+
touch $HOME/.gem/credentials
|
39
|
+
chmod 0600 $HOME/.gem/credentials
|
40
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
41
|
+
gem build *.gemspec
|
42
|
+
gem push *.gem
|
43
|
+
env:
|
44
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
.env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.2
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
steam_ladder (1.0.0)
|
5
|
+
http (~> 5.0, >= 5.0.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.8.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
coveralls (0.8.23)
|
13
|
+
json (>= 1.8, < 3)
|
14
|
+
simplecov (~> 0.16.1)
|
15
|
+
term-ansicolor (~> 1.3)
|
16
|
+
thor (>= 0.19.4, < 2.0)
|
17
|
+
tins (~> 1.6)
|
18
|
+
diff-lcs (1.4.4)
|
19
|
+
docile (1.4.0)
|
20
|
+
domain_name (0.5.20190701)
|
21
|
+
unf (>= 0.0.5, < 1.0.0)
|
22
|
+
ffi (1.15.3)
|
23
|
+
ffi-compiler (1.0.1)
|
24
|
+
ffi (>= 1.0.0)
|
25
|
+
rake
|
26
|
+
http (5.0.1)
|
27
|
+
addressable (~> 2.3)
|
28
|
+
http-cookie (~> 1.0)
|
29
|
+
http-form_data (~> 2.2)
|
30
|
+
llhttp-ffi (~> 0.3.0)
|
31
|
+
http-cookie (1.0.4)
|
32
|
+
domain_name (~> 0.5)
|
33
|
+
http-form_data (2.3.0)
|
34
|
+
json (2.5.1)
|
35
|
+
llhttp-ffi (0.3.1)
|
36
|
+
ffi-compiler (~> 1.0)
|
37
|
+
rake (~> 13.0)
|
38
|
+
public_suffix (4.0.6)
|
39
|
+
rake (13.0.6)
|
40
|
+
rspec (3.10.0)
|
41
|
+
rspec-core (~> 3.10.0)
|
42
|
+
rspec-expectations (~> 3.10.0)
|
43
|
+
rspec-mocks (~> 3.10.0)
|
44
|
+
rspec-core (3.10.1)
|
45
|
+
rspec-support (~> 3.10.0)
|
46
|
+
rspec-expectations (3.10.1)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.10.0)
|
49
|
+
rspec-mocks (3.10.2)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.10.0)
|
52
|
+
rspec-support (3.10.2)
|
53
|
+
simplecov (0.16.1)
|
54
|
+
docile (~> 1.1)
|
55
|
+
json (>= 1.8, < 3)
|
56
|
+
simplecov-html (~> 0.10.0)
|
57
|
+
simplecov-html (0.10.2)
|
58
|
+
sync (0.5.0)
|
59
|
+
term-ansicolor (1.7.1)
|
60
|
+
tins (~> 1.0)
|
61
|
+
thor (1.1.0)
|
62
|
+
tins (1.29.1)
|
63
|
+
sync
|
64
|
+
unf (0.1.4)
|
65
|
+
unf_ext
|
66
|
+
unf_ext (0.0.7.7)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
x86_64-linux
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
coveralls (~> 0.8.23)
|
73
|
+
rspec (~> 3.5)
|
74
|
+
steam_ladder!
|
75
|
+
|
76
|
+
BUNDLED WITH
|
77
|
+
2.2.22
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Melvin
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
<img width="500px" src="https://user-images.githubusercontent.com/1312973/131711153-f8390028-8e1d-4e84-8b50-aa859dc4fef8.png" />
|
2
|
+
|
3
|
+
<b>Ruby wrapper for the <a href="https://steamladder.com/">Steam Ladder</a> API</b>.
|
4
|
+
|
5
|
+
[![Build Status](https://app.travis-ci.com/melvinsh/steam_ladder.svg?branch=main)](https://app.travis-ci.com/melvinsh/steam_ladder) [![Gem Version](https://badge.fury.io/rb/steam_ladder.svg)](https://badge.fury.io/rb/steam_ladder) [![Coverage Status](https://coveralls.io/repos/github/melvinsh/steam_ladder/badge.svg?branch=main)](https://coveralls.io/github/melvinsh/steam_ladder?branch=main)
|
6
|
+
|
7
|
+
## <a name='Tableofcontents'></a>Table of contents
|
8
|
+
|
9
|
+
<!-- vscode-markdown-toc -->
|
10
|
+
* [Installation](#Installation)
|
11
|
+
* [Usage examples](#Usageexamples)
|
12
|
+
* [Initialization](#Initialization)
|
13
|
+
* [Getting a profile](#Gettingaprofile)
|
14
|
+
* [Updating a profile](#Updatingaprofile)
|
15
|
+
* [Getting a ladder](#Gettingaladder)
|
16
|
+
* [Normal request](#Normalrequest)
|
17
|
+
* [Specifying a region or country](#Specifyingaregionorcountry)
|
18
|
+
|
19
|
+
<!-- vscode-markdown-toc-config
|
20
|
+
numbering=false
|
21
|
+
autoSave=true
|
22
|
+
/vscode-markdown-toc-config -->
|
23
|
+
<!-- /vscode-markdown-toc -->
|
24
|
+
|
25
|
+
## <a name='Installation'></a>Installation
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
```ruby
|
28
|
+
gem 'steam_ladder', '~> 1.0.0'
|
29
|
+
```
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
```bash
|
33
|
+
$ bundle
|
34
|
+
```
|
35
|
+
|
36
|
+
Or install it yourself as:
|
37
|
+
```bash
|
38
|
+
$ gem install steam_ladder
|
39
|
+
```
|
40
|
+
|
41
|
+
Inside of your Ruby program do:
|
42
|
+
```ruby
|
43
|
+
require 'steam_ladder'
|
44
|
+
```
|
45
|
+
|
46
|
+
## <a name='Usageexamples'></a>Usage examples
|
47
|
+
### <a name='Initialization'></a>Initialization
|
48
|
+
``` ruby
|
49
|
+
@steam_ladder = SteamLadder.new('API_KEY')
|
50
|
+
```
|
51
|
+
|
52
|
+
### <a name='Gettingaprofile'></a>Getting a profile
|
53
|
+
``` ruby
|
54
|
+
profile = @steam_ladder.profile('76561198029517073')
|
55
|
+
```
|
56
|
+
|
57
|
+
Will return an object like the one below (with many more attributes that have been removed from this example).
|
58
|
+
|
59
|
+
``` ruby
|
60
|
+
OpenStruct {
|
61
|
+
:steam_user => OpenStruct {
|
62
|
+
:steam_name => "Melvin",
|
63
|
+
:steam_id => "76561198029517073",
|
64
|
+
:steamladder_url => "https://steamladder.com/profile/76561198029517073/",
|
65
|
+
:steam_join_date => "2010-08-25T18:20:11",
|
66
|
+
:steam_country_code => "NL",
|
67
|
+
:is_steam_private => false
|
68
|
+
},
|
69
|
+
|
70
|
+
:steam_ladder_info => OpenStruct {
|
71
|
+
:is_staff => false,
|
72
|
+
:is_winter_18 => false,
|
73
|
+
:is_winter_19 => false,
|
74
|
+
:is_donator => false,
|
75
|
+
:is_top_donator => false,
|
76
|
+
:patreon_tier => "Platinum"
|
77
|
+
},
|
78
|
+
|
79
|
+
:steam_stats => OpenStruct {
|
80
|
+
:last_update => "2021-08-17T19:54:03.800318",
|
81
|
+
:level => 151,
|
82
|
+
:xp => 122052,
|
83
|
+
:friends => 211,
|
84
|
+
:badges => OpenStruct {
|
85
|
+
:total => 337
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
```
|
90
|
+
|
91
|
+
Objects can be accessed like:
|
92
|
+
|
93
|
+
``` ruby
|
94
|
+
profile.steam_user.steam_id # '76561198029517073'
|
95
|
+
profile.steam_user.steam_join_date # '2010-08-25T18:20:11'
|
96
|
+
profile.steam_stats.badges.total # 337
|
97
|
+
```
|
98
|
+
|
99
|
+
### <a name='Updatingaprofile'></a>Updating a profile
|
100
|
+
``` ruby
|
101
|
+
update = @steam_ladder.update_profile('76561198029517073')
|
102
|
+
```
|
103
|
+
|
104
|
+
Returns an object with a `success` attribute that can be either `true` or `false`.
|
105
|
+
If the update fails (usually due to the limit - once every four hours), the `error` attribute can be accessed.
|
106
|
+
|
107
|
+
The `last_update` attribute indicates the last update time.
|
108
|
+
|
109
|
+
Example implementation:
|
110
|
+
|
111
|
+
``` ruby
|
112
|
+
update = @api.update_profile('76561197996764410')
|
113
|
+
|
114
|
+
if update.success
|
115
|
+
puts "Yay! We did it."
|
116
|
+
else
|
117
|
+
puts "Oh no, something went wrong: #{update.error}"
|
118
|
+
puts "Last update was at #{update.last_update}, so maybe we went too fast."
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
### <a name='Gettingaladder'></a>Getting a ladder
|
123
|
+
#### <a name='Normalrequest'></a>Normal request
|
124
|
+
``` ruby
|
125
|
+
# Available types: xp, games, playtime, badges, steam_age, vac, game_ban
|
126
|
+
ladder = @steam_ladder.ladder('xp')
|
127
|
+
```
|
128
|
+
|
129
|
+
#### <a name='Specifyingaregionorcountry'></a>Specifying a region or country
|
130
|
+
``` ruby
|
131
|
+
# Available country codes: alpha-2 country codes (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
|
132
|
+
# Available regions: europe, north_america, south_america, asia, africa, oceania, antarctica
|
133
|
+
|
134
|
+
ladder = @steam_ladder.ladder('xp', 'nl')
|
135
|
+
ladder = @steam_ladder.ladder('games', 'europe')
|
136
|
+
```
|
137
|
+
|
138
|
+
Will return an object like the one below.
|
139
|
+
|
140
|
+
``` ruby
|
141
|
+
OpenStruct {
|
142
|
+
:type => "XP",
|
143
|
+
:type_url => "xp",
|
144
|
+
:country_code => nil,
|
145
|
+
:ladder => []
|
146
|
+
}
|
147
|
+
```
|
148
|
+
|
149
|
+
The `ladder` contains a maximum of `100` users and their position. Example user:
|
150
|
+
|
151
|
+
``` ruby
|
152
|
+
OpenStruct {
|
153
|
+
:pos => 0,
|
154
|
+
:steam_user => OpenStruct {
|
155
|
+
:steam_name => "St4ck",
|
156
|
+
:steam_id => "76561198023414915",
|
157
|
+
:steamladder_url => "https://steamladder.com/profile/76561198023414915/",
|
158
|
+
:steam_join_date => "2010-04-03T19:44:07",
|
159
|
+
:steam_country_code => nil,
|
160
|
+
:steam_avatar_src => "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/c4/c4cad1abe3a53c25e26a827655804bf754fbbe76_full.jpg"
|
161
|
+
},
|
162
|
+
:steam_stats => OpenStruct {
|
163
|
+
:level => 5000,
|
164
|
+
:xp => 125282351,
|
165
|
+
:badges => OpenStruct {},
|
166
|
+
:games => OpenStruct {},
|
167
|
+
:bans => OpenStruct {}
|
168
|
+
}
|
169
|
+
}
|
170
|
+
```
|
171
|
+
|
172
|
+
So if we want the Steam name of the user in the 4th place:
|
173
|
+
|
174
|
+
``` ruby
|
175
|
+
ladder = @steam_ladder.ladder('xp')
|
176
|
+
ladder[3].steam_user.steam_name # "K-miK"
|
177
|
+
```
|
178
|
+
|
data/bin/bundle
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
|
13
|
+
m = Module.new do
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def invoked_as_script?
|
17
|
+
File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def env_var_version
|
21
|
+
ENV['BUNDLER_VERSION']
|
22
|
+
end
|
23
|
+
|
24
|
+
def cli_arg_version
|
25
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
26
|
+
return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
|
27
|
+
|
28
|
+
bundler_version = nil
|
29
|
+
update_index = nil
|
30
|
+
ARGV.each_with_index do |a, i|
|
31
|
+
bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
32
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
33
|
+
|
34
|
+
bundler_version = Regexp.last_match(1)
|
35
|
+
update_index = i
|
36
|
+
end
|
37
|
+
bundler_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemfile
|
41
|
+
gemfile = ENV['BUNDLE_GEMFILE']
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
43
|
+
|
44
|
+
File.expand_path('../Gemfile', __dir__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def lockfile
|
48
|
+
lockfile =
|
49
|
+
case File.basename(gemfile)
|
50
|
+
when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
|
51
|
+
else "#{gemfile}.lock"
|
52
|
+
end
|
53
|
+
File.expand_path(lockfile)
|
54
|
+
end
|
55
|
+
|
56
|
+
def lockfile_version
|
57
|
+
return unless File.file?(lockfile)
|
58
|
+
|
59
|
+
lockfile_contents = File.read(lockfile)
|
60
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
61
|
+
|
62
|
+
Regexp.last_match(1)
|
63
|
+
end
|
64
|
+
|
65
|
+
def bundler_version
|
66
|
+
@bundler_version ||=
|
67
|
+
env_var_version || cli_arg_version ||
|
68
|
+
lockfile_version
|
69
|
+
end
|
70
|
+
|
71
|
+
def bundler_requirement
|
72
|
+
return "#{Gem::Requirement.default}.a" unless bundler_version
|
73
|
+
|
74
|
+
bundler_gem_version = Gem::Version.new(bundler_version)
|
75
|
+
|
76
|
+
requirement = bundler_gem_version.approximate_recommendation
|
77
|
+
|
78
|
+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new('2.7.0')
|
79
|
+
|
80
|
+
requirement += '.a' if bundler_gem_version.prerelease?
|
81
|
+
|
82
|
+
requirement
|
83
|
+
end
|
84
|
+
|
85
|
+
def load_bundler!
|
86
|
+
ENV['BUNDLE_GEMFILE'] ||= gemfile
|
87
|
+
|
88
|
+
activate_bundler
|
89
|
+
end
|
90
|
+
|
91
|
+
def activate_bundler
|
92
|
+
gem_error = activation_error_handling do
|
93
|
+
gem 'bundler', bundler_requirement
|
94
|
+
end
|
95
|
+
return if gem_error.nil?
|
96
|
+
|
97
|
+
require_error = activation_error_handling do
|
98
|
+
require 'bundler/version'
|
99
|
+
end
|
100
|
+
if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
101
|
+
return
|
102
|
+
end
|
103
|
+
|
104
|
+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
105
|
+
exit 42
|
106
|
+
end
|
107
|
+
|
108
|
+
def activation_error_handling
|
109
|
+
yield
|
110
|
+
nil
|
111
|
+
rescue StandardError, LoadError => e
|
112
|
+
e
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
m.load_bundler!
|
117
|
+
|
118
|
+
load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require 'pathname'
|
12
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rubygems'
|
27
|
+
require 'bundler/setup'
|
28
|
+
|
29
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
data/lib/steam_ladder.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
|
5
|
+
class SteamLadder
|
6
|
+
def initialize(key, url = 'https://steamladder.com/api/v1')
|
7
|
+
@key = key
|
8
|
+
@url = url
|
9
|
+
end
|
10
|
+
|
11
|
+
def profile(steam_id_64)
|
12
|
+
json = http_get("#{@url}/profile/#{steam_id_64}/")
|
13
|
+
JSON.parse(json, object_class: OpenStruct)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_profile(steam_id_64)
|
17
|
+
json = http_post("#{@url}/profile/#{steam_id_64}/")
|
18
|
+
response = JSON.parse(json, object_class: OpenStruct)
|
19
|
+
|
20
|
+
if response.error
|
21
|
+
OpenStruct.new(
|
22
|
+
success: false,
|
23
|
+
error: response.error,
|
24
|
+
last_update: response.last_update
|
25
|
+
)
|
26
|
+
else
|
27
|
+
OpenStruct.new(
|
28
|
+
success: true,
|
29
|
+
last_update: response.steam_stats.last_update
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def ladder(type, country = nil)
|
35
|
+
url = "#{@url}/ladder/#{type}/"
|
36
|
+
url += "#{country}/" if country
|
37
|
+
|
38
|
+
json = http_get(url)
|
39
|
+
JSON.parse(json, object_class: OpenStruct)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def http_get(url)
|
45
|
+
HTTP.headers(authorization: "Token #{@key}")
|
46
|
+
.get(url)
|
47
|
+
end
|
48
|
+
|
49
|
+
def http_post(url)
|
50
|
+
HTTP.headers(authorization: "Token #{@key}")
|
51
|
+
.post(url)
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
unless ENV['API_KEY']
|
4
|
+
raise "Please set ENV['API_KEY'] in order to run the tests."
|
5
|
+
exit 1
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'coveralls'
|
9
|
+
Coveralls.wear!
|
10
|
+
|
11
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
12
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
13
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
14
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
15
|
+
# files.
|
16
|
+
#
|
17
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
18
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
19
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
20
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
21
|
+
# a separate helper file that requires the additional dependencies and performs
|
22
|
+
# the additional setup, and require it from the spec files that actually need
|
23
|
+
# it.
|
24
|
+
#
|
25
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
26
|
+
RSpec.configure do |config|
|
27
|
+
# rspec-expectations config goes here. You can use an alternate
|
28
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
29
|
+
# assertions if you prefer.
|
30
|
+
config.expect_with :rspec do |expectations|
|
31
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
32
|
+
# and `failure_message` of custom matchers include text for helper methods
|
33
|
+
# defined using `chain`, e.g.:
|
34
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
35
|
+
# # => "be bigger than 2 and smaller than 4"
|
36
|
+
# ...rather than:
|
37
|
+
# # => "be bigger than 2"
|
38
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
39
|
+
end
|
40
|
+
|
41
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
42
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
43
|
+
config.mock_with :rspec do |mocks|
|
44
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
45
|
+
# a real object. This is generally recommended, and will default to
|
46
|
+
# `true` in RSpec 4.
|
47
|
+
mocks.verify_partial_doubles = true
|
48
|
+
end
|
49
|
+
|
50
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
51
|
+
# have no way to turn it off -- the option exists only for backwards
|
52
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
53
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
54
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
55
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
56
|
+
|
57
|
+
# The settings below are suggested to provide a good initial experience
|
58
|
+
# with RSpec, but feel free to customize to your heart's content.
|
59
|
+
# # This allows you to limit a spec run to individual examples or groups
|
60
|
+
# # you care about by tagging them with `:focus` metadata. When nothing
|
61
|
+
# # is tagged with `:focus`, all examples get run. RSpec also provides
|
62
|
+
# # aliases for `it`, `describe`, and `context` that include `:focus`
|
63
|
+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
64
|
+
# config.filter_run_when_matching :focus
|
65
|
+
#
|
66
|
+
# # Allows RSpec to persist some state between runs in order to support
|
67
|
+
# # the `--only-failures` and `--next-failure` CLI options. We recommend
|
68
|
+
# # you configure your source control system to ignore this file.
|
69
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
70
|
+
#
|
71
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
72
|
+
# # recommended. For more details, see:
|
73
|
+
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
74
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
75
|
+
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
76
|
+
# config.disable_monkey_patching!
|
77
|
+
#
|
78
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
79
|
+
# # be too noisy due to issues in dependencies.
|
80
|
+
# config.warnings = true
|
81
|
+
#
|
82
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
83
|
+
# # file, and it's useful to allow more verbose output when running an
|
84
|
+
# # individual spec file.
|
85
|
+
# if config.files_to_run.one?
|
86
|
+
# # Use the documentation formatter for detailed output,
|
87
|
+
# # unless a formatter has already been configured
|
88
|
+
# # (e.g. via a command-line flag).
|
89
|
+
# config.default_formatter = "doc"
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# # Print the 10 slowest examples and example groups at the
|
93
|
+
# # end of the spec run, to help surface which specs are running
|
94
|
+
# # particularly slow.
|
95
|
+
# config.profile_examples = 10
|
96
|
+
#
|
97
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
98
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
99
|
+
# # the seed, which is printed after each run.
|
100
|
+
# # --seed 1234
|
101
|
+
# config.order = :random
|
102
|
+
#
|
103
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
104
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
105
|
+
# # test failures related to randomization by passing the same `--seed` value
|
106
|
+
# # as the one that triggered the failure.
|
107
|
+
# Kernel.srand config.seed
|
108
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lib/steam_ladder'
|
4
|
+
|
5
|
+
describe SteamLadder do
|
6
|
+
before do
|
7
|
+
@api = SteamLadder.new(ENV['API_KEY'])
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'profile' do
|
11
|
+
it 'retrieves a Steam Ladder profile' do
|
12
|
+
profile = @api.profile('76561198029517073')
|
13
|
+
|
14
|
+
expect(profile.steam_user.steam_id).to eq('76561198029517073')
|
15
|
+
expect(profile.steam_user.steam_join_date).to eq('2010-08-25T18:20:11')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'update_profile' do
|
20
|
+
it 'updates a Steam Ladder profile' do
|
21
|
+
update = @api.update_profile('76561197996764410')
|
22
|
+
|
23
|
+
expect(update).to respond_to(:success, :last_update)
|
24
|
+
|
25
|
+
expect(update.success).to be(true).or be(false)
|
26
|
+
expect(update.last_update).to be_a(String)
|
27
|
+
|
28
|
+
unless update.success
|
29
|
+
expect(update).to respond_to(:error)
|
30
|
+
expect(update.error).to be_a(String)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'ladder' do
|
36
|
+
it 'retrieves a Steam ladder by type' do
|
37
|
+
ladder = @api.ladder('xp')
|
38
|
+
|
39
|
+
expect(ladder.type).to eq('XP')
|
40
|
+
expect(ladder.ladder).to be_an_instance_of(Array)
|
41
|
+
expect(ladder.ladder.length).to eq(100)
|
42
|
+
expect(ladder.country_code).to eq(nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'retrieves a Steam ladder by type and country' do
|
46
|
+
ladder = @api.ladder('playtime', 'nl')
|
47
|
+
|
48
|
+
expect(ladder.type).to eq('PT')
|
49
|
+
expect(ladder.ladder).to be_an_instance_of(Array)
|
50
|
+
expect(ladder.ladder.length).to eq(100)
|
51
|
+
expect(ladder.country_code).to eq('NL')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'retrieves a Steam ladder by type and region' do
|
55
|
+
ladder = @api.ladder('badges', 'europe')
|
56
|
+
|
57
|
+
expect(ladder.type).to eq('B')
|
58
|
+
expect(ladder.ladder).to be_an_instance_of(Array)
|
59
|
+
expect(ladder.ladder.length).to eq(100)
|
60
|
+
expect(ladder.country_code).to eq('EUROPE')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = 'steam_ladder'
|
5
|
+
gem.version = '1.0.1'
|
6
|
+
gem.licenses = ['MIT']
|
7
|
+
gem.summary = 'Ruby wrapper for the Steam Ladder API.'
|
8
|
+
gem.description = 'Ruby wrapper to access the Steam Ladder API at https://steamladder.com/api/.'
|
9
|
+
gem.authors = ['Melvin Lammerts']
|
10
|
+
gem.email = 'hi@melv.in'
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- spec/*`.split("\n")
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
|
16
|
+
gem.homepage = 'https://rubygems.org/gems/steam_ladder'
|
17
|
+
gem.metadata = { 'source_code_uri' => 'https://github.com/melvinsh/steam_ladder' }
|
18
|
+
|
19
|
+
gem.add_runtime_dependency 'http', '~> 5.0', '>= 5.0.1'
|
20
|
+
|
21
|
+
gem.add_development_dependency 'coveralls', '~> 0.8.23'
|
22
|
+
gem.add_development_dependency 'rspec', '~> 3.5'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: steam_ladder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Melvin Lammerts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.0.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.0.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: coveralls
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.8.23
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.8.23
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.5'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.5'
|
61
|
+
description: Ruby wrapper to access the Steam Ladder API at https://steamladder.com/api/.
|
62
|
+
email: hi@melv.in
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- ".devcontainer/Dockerfile"
|
68
|
+
- ".devcontainer/devcontainer.json"
|
69
|
+
- ".github/workflows/gem-push.yml"
|
70
|
+
- ".gitignore"
|
71
|
+
- ".rspec"
|
72
|
+
- ".ruby-version"
|
73
|
+
- ".travis.yml"
|
74
|
+
- Gemfile
|
75
|
+
- Gemfile.lock
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- bin/bundle
|
79
|
+
- bin/rspec
|
80
|
+
- lib/steam_ladder.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
- spec/steam_ladder_spec.rb
|
83
|
+
- steam_ladder.gemspec
|
84
|
+
homepage: https://rubygems.org/gems/steam_ladder
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata:
|
88
|
+
source_code_uri: https://github.com/melvinsh/steam_ladder
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubygems_version: 3.0.3.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Ruby wrapper for the Steam Ladder API.
|
108
|
+
test_files:
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/steam_ladder_spec.rb
|