rocketleague 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3aae213e01144412cf6423d503af31dff944052c
4
- data.tar.gz: f1937fce750d5d689b6a3b8dd7a7c9a649bfd9cd
3
+ metadata.gz: 5ed39bb3ba4b136142265cf60efaa5fdf8d96f3c
4
+ data.tar.gz: 55a75d94479eeef90f327e296165ea13d6c01999
5
5
  SHA512:
6
- metadata.gz: a5222edcf990ee095ef904da24a454c1d80b96d80e116af1828d9481396aea51e4e594809357948291457d477fa3666c2ea3d78cebd5ba82c650c192a4b4bb4f
7
- data.tar.gz: 5961e4782c42bfc5c7944a0e7c8b9df242a6bb5224abf0f18c5e31c74d42034e3444cdde18ac725255c5b22c169976ed06b0cf6e895f02f9d66e86202db34a02
6
+ metadata.gz: 5eeeeddf927edfd6b573c10a87921e4fdfab02b2587a7e1ea1be6c72a071d0132d89f5ab6f34d6e973854e624a4992b98b995b9da67c95b8e2c7e558ee7825ca
7
+ data.tar.gz: 8658ba7ac5be7cd8fe0139e2007b40dd30d0224a87e2e26dbd7de8d1e3570ee364c11e7a64a80f7ed60e20ca2d297a63bdce805e48a88783e725c06cbc73de72
data/README.md CHANGED
@@ -1,41 +1,75 @@
1
- # Rocketleague
1
+ # RocketLeague [![Gem](https://img.shields.io/gem/v/rocketleague.svg?style=flat-square)](https://rubygems.org/gems/rocketleague)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rocketleague`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ *Who needs standards?* ¯\\\_(ツ)\_/¯
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ A work in progress ruby gem for the Rocket League API.
6
6
 
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'rocketleague'
7
+ ```shell
8
+ gem install rocketleague
13
9
  ```
14
10
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install rocketleague
22
-
23
- ## Usage
11
+ ## Example usage
24
12
 
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
13
+ ```ruby
14
+ require "rocketleague"
34
15
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rocketleague.
16
+ # these parameters seem to change very rarely
17
+ rl = RocketLeague::API.new "https://psyonix-rl.appspot.com", 342373649, "Steam", "dUe3SE4YsR8B0c30E6r7F2KqpZSbGiVx", "pX9pn8F4JnBpoO8Aa219QC6N7g18FJ0F"
36
18
 
19
+ # let's start a session!
20
+ rl.login 123456789, "MyUserName", "MyAuthCode"
37
21
 
38
- ## License
22
+ # we want to get some generic info + game servers
23
+ payload = rl.procencode([["GetGenericDataAll"], ["GetGameServerPingList"]])
24
+ response = rl.request "/callproc105/", payload
39
25
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
26
+ # parse the response
27
+ result = rl.procparse(response.body)
28
+ ```
41
29
 
30
+ The result looks like this:
31
+ ```ruby
32
+ [
33
+ [
34
+ {
35
+ "DataKey" => "Analytics",
36
+ "DataValue" => "1"
37
+ }, {
38
+ "DataKey" => "BugReports",
39
+ "DataValue" => "0"
40
+ }, {
41
+ "DataKey" => "RankEnabled",
42
+ "DataValue" => "1"
43
+ }
44
+ ], [
45
+ {
46
+ "Region" => "ASC",
47
+ "IP" => "103.16.26.248:7717"
48
+ }, {
49
+ "Region" => "EU",
50
+ "IP" => "104.238.188.227:7762"
51
+ }, {
52
+ "Region" => "JPN",
53
+ "IP" => "45.32.19.87:7798"
54
+ }, {
55
+ "Region" => "ME",
56
+ "IP" => "45.32.152.240:7906"
57
+ }, {
58
+ "Region" => "nrt",
59
+ "IP" => "103.16.26.248:7801"
60
+ }, {
61
+ "Region" => "OCE",
62
+ "IP" => "45.32.241.199:7874"
63
+ }, {
64
+ "Region" => "SAM",
65
+ "IP" => "185.50.104.101:7756"
66
+ }, {
67
+ "Region" => "USE",
68
+ "IP" => "104.238.137.154:7758"
69
+ }, {
70
+ "Region" => "USW",
71
+ "IP" => "45.32.206.103:7818"
72
+ }
73
+ ]
74
+ ]
75
+ ```
@@ -1,5 +1,6 @@
1
1
  require "rocketleague/version"
2
+ require "rocketleague/api"
2
3
 
3
- module Rocketleague
4
- # TODO
5
- end
4
+ module RocketLeague
5
+
6
+ end
@@ -0,0 +1,138 @@
1
+ require "uri"
2
+ require "net/http"
3
+ require "net/https"
4
+
5
+ module RocketLeague
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
+ }
13
+
14
+ # initializes the API
15
+ # api_url should be "https://psyonix-rl.appspot.com"
16
+ # build_id changes with every Rocket League update
17
+ # 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)
21
+ @api_url = api_url
22
+ @build_id = build_id
23
+ @platform = platform
24
+ @login_secret_key = login_secret_key
25
+ @call_proc_key = call_proc_key
26
+ end
27
+
28
+ # returns a Psyonix-Style www-form-urlencoded string
29
+ # which always starts with '&'
30
+ # and keys are not encoded (e.g. contain unencoded '[]')
31
+ def formencode obj
32
+ params = [""]
33
+ obj.each do |key, val|
34
+ if val.kind_of? Array
35
+ val.each do |v|
36
+ params << "#{key}=#{URI.encode_www_form_component(v)}"
37
+ end
38
+ else
39
+ params << "#{key}=#{URI.encode_www_form_component(val)}"
40
+ end
41
+ end
42
+ params.join("&")
43
+ end
44
+
45
+ # decodes a www-form-urlencoded string
46
+ # returns a key-value Hash, where values are either strings
47
+ # or Array of strings if the key is not unique
48
+ def formdecode str
49
+ result = {}
50
+ URI.decode_www_form(str).each do |pair|
51
+ key = pair.first
52
+ val = pair.last
53
+ if result.key? key
54
+ if result[key].kind_of? Array
55
+ result[key] << val
56
+ else
57
+ result[key] = [result[key], val]
58
+ end
59
+ else
60
+ result[key] = val
61
+ end
62
+ end
63
+ result
64
+ end
65
+
66
+ # creates a Psyonix-Style Proclist body
67
+ #
68
+ # `commands` is an array of arrays where the first item is the Proc name
69
+ # followed by option arguments
70
+ #
71
+ # returns a `formencode` string with 'Proc[]=' function names and 'P#P=' arguments, where '#' is the index of the Proc
72
+ def procencode commands
73
+ payload = {}
74
+ procs = []
75
+ commands.each_with_index do |cmd, i|
76
+ procs << cmd.shift
77
+ payload["P#{i}P[]"] = cmd
78
+ end
79
+ payload["Proc[]"] = procs
80
+ formencode payload
81
+ end
82
+
83
+ # parses the response to a Proc request
84
+ # 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
+ results = []
88
+ parts = response.split(/^\r\n/, -1) # Psyonix ¯\_(ツ)_/¯
89
+ parts.pop
90
+ parts.each do |part|
91
+ result = []
92
+ lines = part.split "\r\n"
93
+ lines.each do |line|
94
+ result << formdecode(line)
95
+ end
96
+ results << result
97
+ end
98
+ results
99
+ end
100
+
101
+ # performs a POST request to the Rocket League API
102
+ # with the `DEFAULT_HEADERS` and `extra_headers`
103
+ # SessionID and CallProcKey headers are added unless SessionID is unset
104
+ # returns HTTPResponse
105
+ def request(path, exra_headers = {}, payload)
106
+ uri = URI.parse(@api_url)
107
+ http = Net::HTTP.new(uri.host, uri.port)
108
+ http.use_ssl = (uri.scheme == "https")
109
+
110
+ if @SessionID
111
+ # Used for all requests except initial auth call
112
+ exra_headers.merge!({
113
+ "SessionID" => @SessionID,
114
+ "CallProcKey" => @call_proc_key
115
+ })
116
+ end
117
+
118
+ req = Net::HTTP::Post.new(path, DEFAULT_HEADERS.merge(exra_headers))
119
+ req.body = payload
120
+ http.request(req)
121
+ end
122
+
123
+ # 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
126
+ payload = formencode({
127
+ "PlayerName" => player_name,
128
+ "PlayerID" => player_id,
129
+ "Platform" => @platform,
130
+ "BuildID" => @build_id,
131
+ "AuthCode" => auth_code,
132
+ "IssuerID" => 0
133
+ })
134
+ response = request("/auth/", {"LoginSecretKey" => @login_secret_key }, payload)
135
+ !!(@SessionID = response["sessionid"])
136
+ end
137
+ end
138
+ end
@@ -1,3 +1,3 @@
1
- module Rocketleague
2
- VERSION = "0.0.1"
1
+ module RocketLeague
2
+ VERSION = "0.0.3"
3
3
  end
@@ -5,11 +5,11 @@ require 'rocketleague/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "rocketleague"
8
- spec.version = Rocketleague::VERSION
8
+ spec.version = RocketLeague::VERSION
9
9
  spec.author = "rltracker"
10
10
 
11
- spec.summary = "[WIP]"
12
- spec.description = "[WIP]"
11
+ spec.summary = "Rocket League API"
12
+ spec.description = "Rocket League API"
13
13
  spec.homepage = "https://github.com/rltracker/rocketleague"
14
14
  spec.license = "MIT"
15
15
 
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.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - rltracker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.0'
55
- description: "[WIP]"
55
+ description: Rocket League API
56
56
  email:
57
57
  executables: []
58
58
  extensions: []
@@ -65,6 +65,7 @@ files:
65
65
  - README.md
66
66
  - Rakefile
67
67
  - lib/rocketleague.rb
68
+ - lib/rocketleague/api.rb
68
69
  - lib/rocketleague/version.rb
69
70
  - rocketleague.gemspec
70
71
  homepage: https://github.com/rltracker/rocketleague
@@ -90,5 +91,5 @@ rubyforge_project:
90
91
  rubygems_version: 2.5.1
91
92
  signing_key:
92
93
  specification_version: 4
93
- summary: "[WIP]"
94
+ summary: Rocket League API
94
95
  test_files: []