skyhook 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.example +1 -0
- data/.gitignore +15 -0
- data/.travis.yml +3 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +32 -0
- data/Rakefile +8 -0
- data/lib/skyhook/configuration.rb +20 -0
- data/lib/skyhook/core.rb +80 -0
- data/lib/skyhook/game.rb +34 -0
- data/lib/skyhook/user.rb +46 -0
- data/lib/skyhook/version.rb +3 -0
- data/lib/skyhook.rb +13 -0
- data/skyhook.gemspec +34 -0
- data/tasks/test.rake +23 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 23fb31890016fd720993dd6ac882d1339490c3b8
|
4
|
+
data.tar.gz: 3bef965d3c308229b4d86b5450d05a809e366d5d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1f685e986c9c0ec316b2bc4da8876ebf5c9d0db77c9361af1114880f683773a52ed463c814a721287b84058083f904650a5166c58ad70b81904e8b91232dbbd
|
7
|
+
data.tar.gz: 5d0619a0fe2e079b179357aa4d233087280dc194d844cae051cd9deffd1b0e9f518b2f0913f137ba9855ac94ae98820b0e0d8dedd75f54df56d0c238935873fb
|
data/.env.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
API_KEY='Fill me in'
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Wouter van der Meulen
|
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,32 @@
|
|
1
|
+
The Steampowered Skyhook
|
2
|
+
========================
|
3
|
+
|
4
|
+
A wrapper for the Steam web API.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'skyhook'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install skyhook
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it ( https://github.com/ClikeX/skyhook/fork )
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Skyhook
|
2
|
+
class Configuration
|
3
|
+
cattr_accessor :format
|
4
|
+
cattr_accessor :api_key
|
5
|
+
cattr_accessor :debug
|
6
|
+
|
7
|
+
FORMATS = %W(json xml vdf).map { |x| x.to_sym.freeze }
|
8
|
+
BASE = 'api.steampowered.com'
|
9
|
+
|
10
|
+
def self.configure( options = {} )
|
11
|
+
if options[ :format ]
|
12
|
+
FORMATS.include?( options[ :format ] ) ? self.format = options[ :format ] : raise(ArgumentError, "#{ options[ :format ] } is not a valid format" )
|
13
|
+
else
|
14
|
+
@@format = :json
|
15
|
+
end
|
16
|
+
@@api_key = options[:api_key] if options[:api_key]
|
17
|
+
@@debug = options[:debug] if options[:debug]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/skyhook/core.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
module Skyhook
|
2
|
+
class Core < Skyhook::Configuration
|
3
|
+
|
4
|
+
# These are default urls to use with #Service_request
|
5
|
+
RESTAPI = {
|
6
|
+
owned_games: "",
|
7
|
+
shared_games: ""
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def api_reference
|
11
|
+
url = "/ISteamWebAPIUtil/GetSupportedAPIList/v0001/"
|
12
|
+
|
13
|
+
unless @api_key.blank?
|
14
|
+
url << "?key=#{ self.api_key }"
|
15
|
+
end
|
16
|
+
|
17
|
+
request url
|
18
|
+
end
|
19
|
+
|
20
|
+
def resolve_vanity( vanityurl )
|
21
|
+
return vanityurl if vanityurl.is_a? Integer
|
22
|
+
response = request "/ISteamUser/ResolveVanityURL/v0001/?key=#{ self.api_key }&vanityurl=#{ vanityurl }"
|
23
|
+
response["response"]["steamid"].to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
def user_summaries( steamids = [] )
|
27
|
+
steamids = [ steamids ] unless steamids.is_a? Array
|
28
|
+
|
29
|
+
if steamids.empty?
|
30
|
+
p 'No steamids were defined'
|
31
|
+
return false
|
32
|
+
end
|
33
|
+
|
34
|
+
steamids.map! do |steamid|
|
35
|
+
steamid = resolve_vanity steamid
|
36
|
+
end
|
37
|
+
|
38
|
+
request "/ISteamUser/GetPlayerSummaries/v0002/?key=#{ self.api_key }&steamids=#{ steamids }"
|
39
|
+
end
|
40
|
+
|
41
|
+
def player_stats( appid, steamid )
|
42
|
+
steamid = resolve_vanity steamid
|
43
|
+
|
44
|
+
request "/ISteamUserStats/GetUserStatsForGame/v2/?key=#{self.api_key }&steamid=#{ steamid }&appid=#{ appid }"
|
45
|
+
end
|
46
|
+
|
47
|
+
# TODO (ClikeX) Test this with multiple names.
|
48
|
+
def global_stats( appid, count = 1, names = [], options = {} )
|
49
|
+
request "/ISteamUserStats/GetGlobalStatsForGame/v0001/?appidid=#{ appid }&count=#{}&name[0]=global.map.emp_isle"
|
50
|
+
end
|
51
|
+
|
52
|
+
def owned_games( steamid, options = {} )
|
53
|
+
steamid = resolve_vanity steamid
|
54
|
+
appinfo = options[:appinfo] == nil ? false : options[:appinfo]
|
55
|
+
free_games = options[:free_games] == nil ? false : options[:free_games]
|
56
|
+
|
57
|
+
request "/IPlayerService/GetOwnedGames/v1/?key=#{ self.api_key }&steamid=#{ steamid }&include_appinfo='#{ appinfo }'&include_played_free_games='#{ free_games }'"
|
58
|
+
end
|
59
|
+
|
60
|
+
def friend_list( steamid, relationship )
|
61
|
+
steamid = resolve_vanity steamid
|
62
|
+
raise( ArgumentError, 'Not a valid relationship' ) unless %w{ all friend }.include? relationship
|
63
|
+
|
64
|
+
request "/ISteamUser/GetFriendList/v1/?key=#{ self.api_key }&steamid=#{ steamid }&relationship=#{ relationship }"
|
65
|
+
end
|
66
|
+
|
67
|
+
protected
|
68
|
+
|
69
|
+
def request( uri )
|
70
|
+
puts "#{BASE}#{uri}" if self.debug
|
71
|
+
response = Net::HTTP.get_response BASE, uri
|
72
|
+
JSON.parse response.body
|
73
|
+
end
|
74
|
+
|
75
|
+
def service_request( uri, options = {} )
|
76
|
+
raise( ArgumentError, 'No JSON options were supplied' ) if options.empty?
|
77
|
+
request "#{ uri }?key=#{ self.api_key }}&format=#{ self.format }&input_json=#{ options[:json]} "
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/skyhook/game.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Skyhook
|
2
|
+
class Game < Skyhook::Core
|
3
|
+
|
4
|
+
attr_reader :appid, :user, :game_name, :achievements, :stats
|
5
|
+
|
6
|
+
def initialize( appid, steamid = nil )
|
7
|
+
@appid = appid
|
8
|
+
if steamid == nil
|
9
|
+
# If steamid is not set a game should contain global data
|
10
|
+
set_global_attributes
|
11
|
+
else
|
12
|
+
if steamid.is_a? Skyhook::User
|
13
|
+
@user = steamid
|
14
|
+
else
|
15
|
+
@user = Skyhook::User.new steamid
|
16
|
+
end
|
17
|
+
|
18
|
+
set_user_attributes player_stats( appid, user.steamid )['playerstats']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def set_user_attributes( response )
|
23
|
+
@game_name = response['gameName']
|
24
|
+
@achievements = ( Hash[ response['achievements'].each_slice(2).to_a ] ).deep_symbolize_keys if response['achievements']
|
25
|
+
@stats = ( Hash[ response['stats'].each_slice(2).to_a ] ).deep_symbolize_keys if response['stats']
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_global_attributes
|
29
|
+
#Will return a games global stats
|
30
|
+
raise NotImplementedError
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/lib/skyhook/user.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module Skyhook
|
2
|
+
class User < Skyhook::Core
|
3
|
+
|
4
|
+
attr_reader :steamid, :personaname, :realname, :profileurl
|
5
|
+
attr_reader :avatar, :avatarmedium, :avatarfull
|
6
|
+
attr_reader :communityvisibilitystate, :profilestate, :lastlogoff, :commentpermission
|
7
|
+
attr_reader :primaryclanid, :timecreated, :personastateflags, :personastate
|
8
|
+
attr_reader :loccityid, :locstatecode, :loccountrycode
|
9
|
+
|
10
|
+
def initialize( steamid )
|
11
|
+
set_attributes user_summaries( steamid )["response"]["players"][0]
|
12
|
+
end
|
13
|
+
|
14
|
+
def game( appid )
|
15
|
+
Skyhook::Game.new appid, self
|
16
|
+
end
|
17
|
+
|
18
|
+
def friends( relationship = 'friend' )
|
19
|
+
@friends ||= friend_list @steamid, relationship
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def set_attributes( response )
|
25
|
+
@steamid = response["steamid"].to_i
|
26
|
+
@personaname = response["personaname"]
|
27
|
+
@communityvisibilitystate = response["communityvisibilitystate"]
|
28
|
+
@profilestate = response["profilestate"]
|
29
|
+
@lastlogoff = response["lastlogoff"]
|
30
|
+
@commentpermission = response["commentpermission"]
|
31
|
+
@profileurl = response["profileurl"]
|
32
|
+
@avatar = response["avatar"]
|
33
|
+
@avatarmedium = response["avatarmedium"]
|
34
|
+
@avatarfull = response["avatarfull"]
|
35
|
+
@personastate = response["personastate"]
|
36
|
+
@realname = response["realname"]
|
37
|
+
@primaryclanid = response["primaryclanid"]
|
38
|
+
@timecreated = response["timecreated"]
|
39
|
+
@personastateflags = response["personastateflags"]
|
40
|
+
@loccountrycode = response["loccountrycode"]
|
41
|
+
@locstatecode = response["locstatecode"]
|
42
|
+
@loccityid = response["loccityid"]
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/skyhook.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
require 'skyhook/configuration'
|
5
|
+
require 'skyhook/core'
|
6
|
+
require 'skyhook/game'
|
7
|
+
require 'skyhook/user'
|
8
|
+
|
9
|
+
module Skyhook
|
10
|
+
def self.configure( options = {} )
|
11
|
+
self::Configuration.configure options
|
12
|
+
end
|
13
|
+
end
|
data/skyhook.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'skyhook/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'skyhook'
|
8
|
+
s.version = Skyhook::VERSION
|
9
|
+
s.date = '2014-04-28'
|
10
|
+
s.summary = 'Steam API wrapper/library'
|
11
|
+
s.description = 'A wrapper/library for the Steam web API'
|
12
|
+
|
13
|
+
s.authors = ['ClikeX']
|
14
|
+
s.email = 'w.s.van.der.meulen@gmail.com'
|
15
|
+
|
16
|
+
s.homepage = 'http://rubygems.org/gems/skyhook'
|
17
|
+
s.license = 'MIT'
|
18
|
+
|
19
|
+
|
20
|
+
s.post_install_message = 'Thank you for installing the Steampowered Skyhook for Ruby. Have fun!'
|
21
|
+
|
22
|
+
s.files = `git ls-files -z`.split("\x0")
|
23
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
24
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
|
+
s.require_paths = ["lib"]
|
26
|
+
|
27
|
+
s.add_development_dependency "bundler", "~> 1.7"
|
28
|
+
s.add_development_dependency 'dotenv', '~> 1.0', '>= 1.0.0'
|
29
|
+
s.add_development_dependency 'rspec', '~> 2.0', '>= 2.0.0'
|
30
|
+
s.add_development_dependency 'rake', '~> 10.0' ,'>= 10.0.0'
|
31
|
+
|
32
|
+
s.add_runtime_dependency 'activesupport', '~> 4.0 '
|
33
|
+
|
34
|
+
end
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
namespace :test do
|
2
|
+
|
3
|
+
# These are to test data return. They do not replace rspec.
|
4
|
+
|
5
|
+
task :key do
|
6
|
+
puts key
|
7
|
+
end
|
8
|
+
|
9
|
+
task :user do
|
10
|
+
puts "\nuser"
|
11
|
+
user = Skyhook::User.new 'ClikeX'
|
12
|
+
puts user.steamid, user.personaname
|
13
|
+
end
|
14
|
+
|
15
|
+
task :game do
|
16
|
+
puts "\ngame"
|
17
|
+
game = Skyhook::Game.new(218620, 'ClikeX')
|
18
|
+
puts game.game_name
|
19
|
+
end
|
20
|
+
|
21
|
+
task :all => ["test:user", "test:game"]
|
22
|
+
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skyhook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ClikeX
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-28 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: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.0.0
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.0'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.0.0
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2.0'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.0.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rake
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '10.0'
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 10.0.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '10.0'
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 10.0.0
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: activesupport
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '4.0'
|
94
|
+
type: :runtime
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '4.0'
|
101
|
+
description: A wrapper/library for the Steam web API
|
102
|
+
email: w.s.van.der.meulen@gmail.com
|
103
|
+
executables: []
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- ".env.example"
|
108
|
+
- ".gitignore"
|
109
|
+
- ".travis.yml"
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- lib/skyhook.rb
|
115
|
+
- lib/skyhook/configuration.rb
|
116
|
+
- lib/skyhook/core.rb
|
117
|
+
- lib/skyhook/game.rb
|
118
|
+
- lib/skyhook/user.rb
|
119
|
+
- lib/skyhook/version.rb
|
120
|
+
- skyhook.gemspec
|
121
|
+
- tasks/test.rake
|
122
|
+
homepage: http://rubygems.org/gems/skyhook
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message: Thank you for installing the Steampowered Skyhook for Ruby.
|
127
|
+
Have fun!
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.5
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Steam API wrapper/library
|
147
|
+
test_files: []
|