rocketleague 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -3
- data/README.md +3 -3
- data/lib/rocketleague/api.rb +50 -32
- data/lib/rocketleague/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b31f5a906cf1de804ed0f63dee9258d5da5c118c
|
4
|
+
data.tar.gz: 32f65d9df7c9378390b360a145d4972a69084654
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c087768063c3279852fd773d6a4e3d0054f0bc0d566d74db0fea705c48b5a12fcc2b4ae70b4433549dbaffe2bbcea41d3097ace220bf2b8858a37950f48c9294
|
7
|
+
data.tar.gz: a4756cf270e1064626a47c7456e8276ad182125b7e15cba7b087744e105a2ee30c4afad7bed1b090addbac262c7055d9fb9f5ab8b61d20d5c7b80c75eb8ec282
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RocketLeague [![Gem](https://img.shields.io/gem/v/rocketleague.svg?style=flat-square)](https://rubygems.org/gems/rocketleague)
|
1
|
+
# RocketLeague [![Gem](https://img.shields.io/gem/v/rocketleague.svg?style=flat-square)](https://rubygems.org/gems/rocketleague) [![Travis](https://img.shields.io/travis/rltracker/rocketleague/master.svg?style=flat-square)](https://travis-ci.org/rltracker/rocketleague/branches)
|
2
2
|
|
3
3
|
*Who needs standards?* ¯\\\_(ツ)\_/¯
|
4
4
|
|
@@ -14,10 +14,10 @@ gem install rocketleague
|
|
14
14
|
require "rocketleague"
|
15
15
|
|
16
16
|
# these parameters seem to change very rarely
|
17
|
-
rl = RocketLeague::API.new "https://psyonix-rl.appspot.com", 342373649, "Steam", "
|
17
|
+
rl = RocketLeague::API.new "https://psyonix-rl.appspot.com", 342373649, "Steam", "pX9pn8F4JnBpoO8Aa219QC6N7g18FJ0F"
|
18
18
|
|
19
19
|
# let's start a session!
|
20
|
-
rl.login 123456789, "MyUserName", "MyAuthCode"
|
20
|
+
rl.login 123456789, "MyUserName", "MyAuthCode", "MyAuthTicket", "dUe3SE4YsR8B0c30E6r7F2KqpZSbGiVx"
|
21
21
|
|
22
22
|
# we want to get some generic info + game servers
|
23
23
|
payload = rl.procencode([["GetGenericDataAll"], ["GetGameServerPingList"]])
|
data/lib/rocketleague/api.rb
CHANGED
@@ -4,48 +4,50 @@ require "net/https"
|
|
4
4
|
|
5
5
|
module RocketLeague
|
6
6
|
class API
|
7
|
-
|
8
|
-
|
9
|
-
"Environment" => "Prod",
|
10
|
-
"User-Agent" => "UE3-TA,UE3Ver(10897)",
|
11
|
-
"Cache-Control" => "no-cache"
|
12
|
-
}
|
7
|
+
attr_accessor :session_id
|
8
|
+
attr_accessor :default_headers
|
13
9
|
|
14
10
|
# initializes the API
|
15
11
|
# api_url should be "https://psyonix-rl.appspot.com"
|
16
12
|
# build_id changes with every Rocket League update
|
17
13
|
# platform is one of "Steam", "PS4", "XboxOne"
|
18
|
-
#
|
19
|
-
|
20
|
-
|
14
|
+
# call_proc_key is usually "pX9pn8F4JnBpoO8Aa219QC6N7g18FJ0F"
|
15
|
+
def initialize(api_url, build_id, platform, call_proc_key)
|
16
|
+
# default headers sent with every request
|
17
|
+
@default_headers = {
|
18
|
+
"Content-Type" => "application/x-www-form-urlencoded",
|
19
|
+
"Environment" => "Prod",
|
20
|
+
"User-Agent" => "UE3-TA,UE3Ver(10897)",
|
21
|
+
"Cache-Control" => "no-cache"
|
22
|
+
}
|
23
|
+
|
21
24
|
@api_url = api_url
|
22
25
|
@build_id = build_id
|
23
26
|
@platform = platform
|
24
|
-
@login_secret_key = login_secret_key
|
25
27
|
@call_proc_key = call_proc_key
|
26
28
|
end
|
27
29
|
|
28
30
|
# returns a Psyonix-Style www-form-urlencoded string
|
29
31
|
# which always starts with '&'
|
30
32
|
# and keys are not encoded (e.g. contain unencoded '[]')
|
31
|
-
def formencode
|
32
|
-
params =
|
33
|
+
def formencode(obj)
|
34
|
+
params = ""
|
33
35
|
obj.each do |key, val|
|
34
36
|
if val.kind_of? Array
|
35
37
|
val.each do |v|
|
36
|
-
params
|
38
|
+
params += "&#{key}=#{URI.encode_www_form_component(v)}"
|
37
39
|
end
|
38
40
|
else
|
39
|
-
params
|
41
|
+
params += "&#{key}=#{URI.encode_www_form_component(val)}"
|
40
42
|
end
|
41
43
|
end
|
42
|
-
params
|
44
|
+
params
|
43
45
|
end
|
44
46
|
|
45
47
|
# decodes a www-form-urlencoded string
|
46
48
|
# returns a key-value Hash, where values are either strings
|
47
49
|
# or Array of strings if the key is not unique
|
48
|
-
def formdecode
|
50
|
+
def formdecode(str)
|
49
51
|
result = {}
|
50
52
|
URI.decode_www_form(str).each do |pair|
|
51
53
|
key = pair.first
|
@@ -69,7 +71,7 @@ module RocketLeague
|
|
69
71
|
# followed by option arguments
|
70
72
|
#
|
71
73
|
# returns a `formencode` string with 'Proc[]=' function names and 'P#P=' arguments, where '#' is the index of the Proc
|
72
|
-
def procencode
|
74
|
+
def procencode(commands)
|
73
75
|
payload = {}
|
74
76
|
procs = []
|
75
77
|
commands.each_with_index do |cmd, i|
|
@@ -82,16 +84,30 @@ module RocketLeague
|
|
82
84
|
|
83
85
|
# parses the response to a Proc request
|
84
86
|
# returns an Array of results, which should be analogue to the `procencode` command order.
|
85
|
-
# each result is an Array of `formdecode` Hashes
|
86
|
-
def procparse
|
87
|
+
# each result is an Array of `formdecode` Hashes and/or RuntimeErrors
|
88
|
+
def procparse(response)
|
87
89
|
results = []
|
88
|
-
|
89
|
-
|
90
|
+
# remove trailing empty line
|
91
|
+
response.gsub! /\r?\n\z/, ''
|
92
|
+
# split on empty lines
|
93
|
+
# may be first, intermediate, or last line
|
94
|
+
# may be using CRLF or LF
|
95
|
+
# Psyonix ¯\_(ツ)_/¯
|
96
|
+
parts = response.split(/^\r?$\n|\r?\n\r?\n|\r?$\n$/, -1)
|
90
97
|
parts.each do |part|
|
91
98
|
result = []
|
92
|
-
lines = part.split
|
99
|
+
lines = part.split /\r?\n/, -1
|
93
100
|
lines.each do |line|
|
94
|
-
|
101
|
+
# PROCEDURE ERROR = Function does not exist
|
102
|
+
# SCRIPT ERROR = Function parameters missing or invalid
|
103
|
+
# SQL ERROR = Data not available
|
104
|
+
if line =~ /^(PROCEDURE|SCRIPT|SQL) ERROR/
|
105
|
+
# Can be on a single line while others are fine
|
106
|
+
# We don't want to raise an exception cause 1 line failed
|
107
|
+
result << RuntimeError.new(line)
|
108
|
+
else
|
109
|
+
result << formdecode(line)
|
110
|
+
end
|
95
111
|
end
|
96
112
|
results << result
|
97
113
|
end
|
@@ -99,40 +115,42 @@ module RocketLeague
|
|
99
115
|
end
|
100
116
|
|
101
117
|
# performs a POST request to the Rocket League API
|
102
|
-
# with the `
|
118
|
+
# with the `default_headers` and `extra_headers`
|
103
119
|
# SessionID and CallProcKey headers are added unless SessionID is unset
|
104
120
|
# returns HTTPResponse
|
105
|
-
def request(path,
|
121
|
+
def request(path,exra_headers = {}, payload)
|
106
122
|
uri = URI.parse(@api_url)
|
107
123
|
http = Net::HTTP.new(uri.host, uri.port)
|
108
124
|
http.use_ssl = (uri.scheme == "https")
|
109
125
|
|
110
|
-
if @
|
126
|
+
if @session_id
|
111
127
|
# Used for all requests except initial auth call
|
112
128
|
exra_headers.merge!({
|
113
|
-
"SessionID" => @
|
129
|
+
"SessionID" => @session_id,
|
114
130
|
"CallProcKey" => @call_proc_key
|
115
131
|
})
|
116
132
|
end
|
117
133
|
|
118
|
-
req = Net::HTTP::Post.new(path,
|
134
|
+
req = Net::HTTP::Post.new(path, @default_headers.merge(exra_headers))
|
119
135
|
req.body = payload
|
120
136
|
http.request(req)
|
121
137
|
end
|
122
138
|
|
123
139
|
# initiates a new session by authenticating against the API
|
124
|
-
#
|
125
|
-
|
140
|
+
# login_secret_key is usually "dUe3SE4YsR8B0c30E6r7F2KqpZSbGiVx"
|
141
|
+
# returns boolean whether a SessionID was received
|
142
|
+
def login(player_id, player_name, auth_code, auth_ticket, login_secret_key)
|
126
143
|
payload = formencode({
|
127
144
|
"PlayerName" => player_name,
|
128
145
|
"PlayerID" => player_id,
|
129
146
|
"Platform" => @platform,
|
130
147
|
"BuildID" => @build_id,
|
131
148
|
"AuthCode" => auth_code,
|
149
|
+
"AuthTicket" => auth_ticket,
|
132
150
|
"IssuerID" => 0
|
133
151
|
})
|
134
|
-
response = request("/auth/", {"LoginSecretKey" =>
|
135
|
-
!!(@
|
152
|
+
response = request("/auth/", {"LoginSecretKey" => login_secret_key }, payload)
|
153
|
+
!!(@session_id = response["sessionid"])
|
136
154
|
end
|
137
155
|
end
|
138
156
|
end
|
data/lib/rocketleague/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rocketleague
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rltracker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|