paladins 0.1.1 → 0.1.2
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 +5 -5
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -3
- data/README.md +16 -3
- data/bin/console +1 -0
- data/lib/paladins.rb +24 -8
- data/lib/paladins/client.rb +74 -0
- data/lib/paladins/configuration.rb +5 -4
- data/lib/paladins/utils.rb +11 -0
- data/lib/paladins/version.rb +1 -1
- metadata +6 -5
- data/lib/paladins/player.rb +0 -13
- data/lib/paladins/session.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a1459a4fe6fcf781c004bb9842aab968dc537ed38a74cca643ef78d40ab7cb82
|
4
|
+
data.tar.gz: 53a2c401373e5ecf077a3d9942deb66768050d7af8a7733120f6957c07d23155
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c740c94a9317523bdf299fff8f9d1c462b3737c5408dbbc743b1269c4d1b32700b217cb605f3955f36f5663cbccd7af0dd92c371e71a476ff1348f8c8cc1bc2a
|
7
|
+
data.tar.gz: ef16c78222bb039fa977cbb3afebadab36165a53d2fec49a6df8ffc00505a69b3c22eb5f137ef86cba04725d9e9a55e6137d3fd5be87e8eb4df7c0187e3e087f
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
paladins (0.1.
|
4
|
+
paladins (0.1.1)
|
5
5
|
faraday
|
6
6
|
json
|
7
7
|
|
@@ -10,7 +10,6 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
coderay (1.1.2)
|
12
12
|
diff-lcs (1.3)
|
13
|
-
dotenv (2.4.0)
|
14
13
|
faraday (0.15.2)
|
15
14
|
multipart-post (>= 1.2, < 3)
|
16
15
|
json (2.1.0)
|
@@ -39,7 +38,6 @@ PLATFORMS
|
|
39
38
|
|
40
39
|
DEPENDENCIES
|
41
40
|
bundler (~> 1.16)
|
42
|
-
dotenv
|
43
41
|
paladins!
|
44
42
|
pry
|
45
43
|
rake (~> 10.0)
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ See [Paladins API DOCS](https://docs.google.com/document/d/1OFS-3ocSx-1Rvg4afAnE
|
|
6
6
|
|
7
7
|
## Status
|
8
8
|
|
9
|
-
|
9
|
+
Alpha (see CHANGELOG.md)
|
10
10
|
|
11
11
|
## Installation
|
12
12
|
|
@@ -26,13 +26,26 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
Create an initializer in `config/initializers` to
|
29
|
+
Create an initializer in `config/initializers` to set your `dev_id` and `auth_key` in a block:
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
Paladins.configure do |config|
|
33
33
|
config.dev_id = ''
|
34
34
|
config.auth_key = ''
|
35
35
|
end
|
36
|
+
|
37
|
+
Paladins.getfoobar
|
38
|
+
```
|
39
|
+
|
40
|
+
or
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
config = Paladins::Configuration.new
|
44
|
+
config.dev_id = ''
|
45
|
+
config.auth_key = ''
|
46
|
+
|
47
|
+
client = Paladins::Client.new(config)
|
48
|
+
client.getfoobar
|
36
49
|
```
|
37
50
|
|
38
51
|
Configs are then available like:
|
@@ -58,7 +71,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
58
71
|
|
59
72
|
## Contributing
|
60
73
|
|
61
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
74
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/davideghz/paladins.
|
62
75
|
|
63
76
|
## License
|
64
77
|
|
data/bin/console
CHANGED
data/lib/paladins.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require "paladins/configuration"
|
2
1
|
require "paladins/version"
|
3
|
-
require "paladins/
|
4
|
-
require "paladins/
|
2
|
+
require "paladins/configuration"
|
3
|
+
require "paladins/client"
|
4
|
+
require "paladins/utils"
|
5
5
|
|
6
6
|
module Paladins
|
7
7
|
class << self
|
@@ -9,14 +9,30 @@ module Paladins
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.configuration
|
12
|
-
@configuration ||= Configuration.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.reset
|
16
|
-
@configuration = Configuration.new
|
12
|
+
@configuration ||= Paladins::Configuration.new
|
17
13
|
end
|
18
14
|
|
19
15
|
def self.configure
|
20
16
|
yield(configuration)
|
21
17
|
end
|
18
|
+
|
19
|
+
# def self.configure(&block)
|
20
|
+
# c = self.configuration
|
21
|
+
# block.call(c)
|
22
|
+
# end
|
23
|
+
|
24
|
+
def self.gethirezserverstatus
|
25
|
+
client = Paladins::Client.new(configuration)
|
26
|
+
client.get_hirez_server_status
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.ping
|
30
|
+
client = Paladins::Client.new(configuration)
|
31
|
+
client.ping
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.getchampionranks(player_name)
|
35
|
+
client = Paladins::Client.new(configuration)
|
36
|
+
client.get_champion_ranks(player_name)
|
37
|
+
end
|
22
38
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module Paladins
|
6
|
+
class Client
|
7
|
+
@@session_id = nil
|
8
|
+
|
9
|
+
attr_accessor :api_url, :dev_id, :auth_key, :response_format
|
10
|
+
|
11
|
+
def initialize(configuration)
|
12
|
+
@api_url = configuration.api_url
|
13
|
+
@dev_id = configuration.dev_id
|
14
|
+
@auth_key = configuration.auth_key
|
15
|
+
@response_format = configuration.response_format
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_signature(method_name, time_now)
|
19
|
+
raise ArgumentError.new('Missing dev_id or auth_key') if ( @dev_id.to_s.empty? || @auth_key.to_s.empty? )
|
20
|
+
Digest::MD5.hexdigest(@dev_id + method_name + @auth_key + time_now);
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_session
|
24
|
+
# /createsession[ResponseFormat]/{developerId}/{signature}/{timestamp}
|
25
|
+
response = Faraday.get(url(method: 'createsession', session: false))
|
26
|
+
@@session_id = JSON.parse(response.body).dig('session_id')
|
27
|
+
|
28
|
+
@@session_id
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_session
|
32
|
+
# /testsession[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}
|
33
|
+
time_now = Paladins::Utils.time_now
|
34
|
+
response = Faraday.get("#{@api_url}/testsessionJson/#{@dev_id}/#{get_signature('testsession', time_now)}/#{@@session_id}/#{time_now}")
|
35
|
+
attributes = JSON.parse(response.body)
|
36
|
+
end
|
37
|
+
|
38
|
+
def session_expired?
|
39
|
+
true
|
40
|
+
## TODO: return TRUE only when #test_session returns something saying session is expired
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_or_create_session
|
44
|
+
create_session if ( @@session_id.nil? || session_expired? )
|
45
|
+
end
|
46
|
+
|
47
|
+
def ping
|
48
|
+
# /ping[ResponseFormat]
|
49
|
+
response = Faraday.get("#{@api_url}/pingJson")
|
50
|
+
attributes = JSON.parse(response.body)
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_hirez_server_status
|
54
|
+
# /gethirezserverstatus[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}
|
55
|
+
response = Faraday.get(url(method: 'gethirezserverstatus', session: true))
|
56
|
+
attributes = JSON.parse(response.body)
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_champion_ranks(player_name)
|
60
|
+
# /getchampionranks[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}/{player}
|
61
|
+
response = Faraday.get(url(method: 'getchampionranks', session: true) + "/#{player_name}")
|
62
|
+
attributes = JSON.parse(response.body)
|
63
|
+
end
|
64
|
+
|
65
|
+
def url(method:, session: false)
|
66
|
+
time_now = Paladins::Utils.time_now
|
67
|
+
url = "#{@api_url}/#{method}#{@response_format}/#{@dev_id}/#{get_signature(method, time_now)}"
|
68
|
+
url += "/#{get_or_create_session}" if session
|
69
|
+
url += "/#{time_now}"
|
70
|
+
|
71
|
+
url
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module Paladins
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :api_url, :dev_id, :auth_key
|
3
|
+
attr_accessor :api_url, :dev_id, :auth_key, :response_format
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@api_url
|
7
|
-
@dev_id
|
8
|
-
@auth_key
|
6
|
+
@api_url = "http://api.paladins.com/paladinsapi.svc"
|
7
|
+
@dev_id = ENV['PALADINS_DEV_ID'] || nil
|
8
|
+
@auth_key = ENV['PALADINS_AUTH_KEY'] || nil
|
9
|
+
@response_format = 'Json'
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
data/lib/paladins/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paladins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davide Ghezzi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- ".gitignore"
|
105
105
|
- ".rspec"
|
106
106
|
- ".travis.yml"
|
107
|
+
- CHANGELOG.md
|
107
108
|
- Gemfile
|
108
109
|
- Gemfile.lock
|
109
110
|
- LICENSE.txt
|
@@ -112,9 +113,9 @@ files:
|
|
112
113
|
- bin/console
|
113
114
|
- bin/setup
|
114
115
|
- lib/paladins.rb
|
116
|
+
- lib/paladins/client.rb
|
115
117
|
- lib/paladins/configuration.rb
|
116
|
-
- lib/paladins/
|
117
|
-
- lib/paladins/session.rb
|
118
|
+
- lib/paladins/utils.rb
|
118
119
|
- lib/paladins/version.rb
|
119
120
|
- paladins.gemspec
|
120
121
|
homepage: https://www.github.com/davideghz/paladins
|
@@ -137,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
140
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.6
|
141
|
+
rubygems_version: 2.7.6
|
141
142
|
signing_key:
|
142
143
|
specification_version: 4
|
143
144
|
summary: Ruby wrapper for Paladins API.
|
data/lib/paladins/player.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module Paladins
|
5
|
-
class Player
|
6
|
-
def self.getchampionranks(player_name)
|
7
|
-
# /getchampionranks[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}/{player}
|
8
|
-
|
9
|
-
response = Faraday.get("#{Paladins.configuration.api_url}/getchampionranksJson/#{Paladins.configuration.dev_id}/#{get_signature('createsession', date_time)}/#{date_time}/#{player_name}")
|
10
|
-
attributes = JSON.parse(response.body)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
data/lib/paladins/session.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'json'
|
3
|
-
require 'digest'
|
4
|
-
|
5
|
-
module Paladins
|
6
|
-
class Session
|
7
|
-
def self.ping
|
8
|
-
# /ping[ResponseFormat]
|
9
|
-
|
10
|
-
response = Faraday.get("#{Paladins.configuration.api_url}/pingJson")
|
11
|
-
attributes = JSON.parse(response.body)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.createsession
|
15
|
-
# /createsession[ResponseFormat]/{developerId}/{signature}/{timestamp}
|
16
|
-
|
17
|
-
date_time = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
18
|
-
url = "#{Paladins.configuration.api_url}/createsessionJson/#{Paladins.configuration.dev_id}/#{get_signature('createsession', date_time)}/#{date_time}"
|
19
|
-
response = Faraday.get(url)
|
20
|
-
attributes = JSON.parse(response.body)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.testsession(session_id)
|
24
|
-
# /testsession[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}
|
25
|
-
|
26
|
-
date_time = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
27
|
-
url = "#{Paladins.configuration.api_url}/testsessionJson/#{Paladins.configuration.dev_id}/#{get_signature('testsession', date_time)}/#{session_id}/#{date_time}"
|
28
|
-
response = Faraday.get(url)
|
29
|
-
attributes = JSON.parse(response.body)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.gethirezserverstatus(session_id)
|
33
|
-
# /gethirezserverstatus[ResponseFormat]/{developerId}/{signature}/{session}/{timestamp}
|
34
|
-
|
35
|
-
date_time = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
36
|
-
url = "#{Paladins.configuration.api_url}/gethirezserverstatusJson/#{Paladins.configuration.dev_id}/#{get_signature('gethirezserverstatus', date_time)}/#{session_id}/#{date_time}"
|
37
|
-
response = Faraday.get(url)
|
38
|
-
attributes = JSON.parse(response.body)
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def self.get_signature(method_name, date_time)
|
44
|
-
raise ArgumentError.new('Missing dev_id or auth_key') if ( Paladins.configuration.dev_id.to_s.empty? || Paladins.configuration.auth_key.to_s.empty? )
|
45
|
-
Digest::MD5.hexdigest(Paladins.configuration.dev_id + method_name + Paladins.configuration.auth_key + date_time);
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|