rocketleague 0.0.3 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5ed39bb3ba4b136142265cf60efaa5fdf8d96f3c
4
- data.tar.gz: 55a75d94479eeef90f327e296165ea13d6c01999
3
+ metadata.gz: b31f5a906cf1de804ed0f63dee9258d5da5c118c
4
+ data.tar.gz: 32f65d9df7c9378390b360a145d4972a69084654
5
5
  SHA512:
6
- metadata.gz: 5eeeeddf927edfd6b573c10a87921e4fdfab02b2587a7e1ea1be6c72a071d0132d89f5ab6f34d6e973854e624a4992b98b995b9da67c95b8e2c7e558ee7825ca
7
- data.tar.gz: 8658ba7ac5be7cd8fe0139e2007b40dd30d0224a87e2e26dbd7de8d1e3570ee364c11e7a64a80f7ed60e20ca2d297a63bdce805e48a88783e725c06cbc73de72
6
+ metadata.gz: c087768063c3279852fd773d6a4e3d0054f0bc0d566d74db0fea705c48b5a12fcc2b4ae70b4433549dbaffe2bbcea41d3097ace220bf2b8858a37950f48c9294
7
+ data.tar.gz: a4756cf270e1064626a47c7456e8276ad182125b7e15cba7b087744e105a2ee30c4afad7bed1b090addbac262c7055d9fb9f5ab8b61d20d5c7b80c75eb8ec282
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
- rvm:
3
- - 2.3.0
4
- before_install: gem install bundler -v 1.11.2
2
+ sudo: false
3
+ before_install: gem install bundler
4
+ script:
5
+ - bundle exec rake test
6
+ - gem build rocketleague.gemspec
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", "dUe3SE4YsR8B0c30E6r7F2KqpZSbGiVx", "pX9pn8F4JnBpoO8Aa219QC6N7g18FJ0F"
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"]])
@@ -4,48 +4,50 @@ require "net/https"
4
4
 
5
5
  module RocketLeague
6
6
  class API
7
- DEFAULT_HEADERS = {
8
- "Content-Type" => "application/x-www-form-urlencoded",
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
- # login_secret_key should be "dUe3SE4YsR8B0c30E6r7F2KqpZSbGiVx" (it's not very secret)
19
- # call_proc_key should be "pX9pn8F4JnBpoO8Aa219QC6N7g18FJ0F"
20
- def initialize(api_url, build_id, platform, login_secret_key, call_proc_key)
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 obj
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 << "#{key}=#{URI.encode_www_form_component(v)}"
38
+ params += "&#{key}=#{URI.encode_www_form_component(v)}"
37
39
  end
38
40
  else
39
- params << "#{key}=#{URI.encode_www_form_component(val)}"
41
+ params += "&#{key}=#{URI.encode_www_form_component(val)}"
40
42
  end
41
43
  end
42
- params.join("&")
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 str
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 commands
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 response
87
+ # each result is an Array of `formdecode` Hashes and/or RuntimeErrors
88
+ def procparse(response)
87
89
  results = []
88
- parts = response.split(/^\r\n/, -1) # Psyonix ¯\_(ツ)_/¯
89
- parts.pop
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 "\r\n"
99
+ lines = part.split /\r?\n/, -1
93
100
  lines.each do |line|
94
- result << formdecode(line)
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 `DEFAULT_HEADERS` and `extra_headers`
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, exra_headers = {}, payload)
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 @SessionID
126
+ if @session_id
111
127
  # Used for all requests except initial auth call
112
128
  exra_headers.merge!({
113
- "SessionID" => @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, DEFAULT_HEADERS.merge(exra_headers))
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
- # returns boolean whether a SessionID was returned
125
- def login player_id, player_name, auth_code
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" => @login_secret_key }, payload)
135
- !!(@SessionID = response["sessionid"])
152
+ response = request("/auth/", {"LoginSecretKey" => login_secret_key }, payload)
153
+ !!(@session_id = response["sessionid"])
136
154
  end
137
155
  end
138
156
  end
@@ -1,3 +1,3 @@
1
1
  module RocketLeague
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
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.3
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-04-07 00:00:00.000000000 Z
11
+ date: 2016-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler