playstationnetwork-api 1.0.2 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -5
- data/README.md +43 -8
- data/lib/playstationnetwork-api.rb +1 -2
- data/lib/playstationnetwork/api.rb +68 -5
- data/lib/playstationnetwork/game.rb +74 -0
- data/lib/playstationnetwork/user.rb +37 -0
- data/lib/playstationnetwork/version.rb +38 -16
- data/playstationnetwork-api.gemspec +10 -12
- metadata +20 -51
- data/lib/playstationnetwork/g/game.rb +0 -97
- data/lib/playstationnetwork/g/games.rb +0 -61
- data/lib/playstationnetwork/g/trophies.rb +0 -34
- data/lib/playstationnetwork/u/games.rb +0 -30
- data/lib/playstationnetwork/u/trophies.rb +0 -28
- data/lib/playstationnetwork/u/user.rb +0 -121
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e44ca9df594def37247156fd28288a63c5ae9fd
|
4
|
+
data.tar.gz: f266eb96a23753dfcd1b3f08e930159c4a6121bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3dfb69b339de351972fa8c44b9b4f62170a6e3dd86ec55988f281d9366ebb6980b4a12ab344d92853cb249bb05bd998a996f624b04f09dc8230b1d29e48860a
|
7
|
+
data.tar.gz: 7cc86eab3cf0c3ffdae34050ef1ad500dca2cb0f66c4e9618b7c76588b0fcb99fefe5de816b0652845a8d22c10728a0a7cc6424b366e64e16ced8fbd6cc3a6e1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# PlayStationNetwork::API
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Retrieve User, Trophies and Game data from PlayStationNetwork.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
11
9
|
```ruby
|
12
|
-
gem 'playstationnetwork-api'
|
10
|
+
gem 'playstationnetwork-api', '~> 2.0'
|
13
11
|
```
|
14
12
|
|
15
13
|
And then execute:
|
@@ -22,17 +20,54 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
#### Get a User
|
24
|
+
`PlayStationNetwork::User.new('pacMakaveli90').profile`
|
25
|
+
|
26
|
+
#### Get all Games for a User
|
27
|
+
`PlayStationNetwork::User.new('pacMakaveli90').games`
|
28
|
+
|
29
|
+
|
30
|
+
#### Get all Trophies for a Game
|
31
|
+
`PlayStationNetwork::User.new('pacMakaveli90').trophies('NPWR00132_00')`
|
32
|
+
|
33
|
+
|
34
|
+
#### Get a Game
|
35
|
+
`PlayStationNetwork::Game.new('NPWR00132_00').details`
|
36
|
+
|
37
|
+
|
38
|
+
#### Get all Trophies for a Game
|
39
|
+
`PlayStationNetwork::Game.new('NPWR00132_00').trophies`
|
40
|
+
|
41
|
+
|
42
|
+
#### Get all Games
|
43
|
+
`PlayStationNetwork::Game.new().all(platform: 'ps4') # you don't have to pass an argument. By default, it will get all games.`
|
44
|
+
|
45
|
+
#### Get Popular Games
|
46
|
+
`PlayStationNetwork::Game.new().all(popular: true)`
|
47
|
+
|
48
|
+
## Configuration
|
49
|
+
|
50
|
+
In your app, create a new initializer `playstationnetwork.rb` and add the following:
|
51
|
+
|
52
|
+
```
|
53
|
+
PlayStationNetwork::API.configure do |config|
|
54
|
+
config.key = '<API_KEY>',
|
55
|
+
config.secret = '<API_SECRET>'
|
56
|
+
config.url = '<API_URL>'
|
57
|
+
})
|
58
|
+
```
|
59
|
+
|
60
|
+
Get Endpoint, your Key and Secret from: http://www.psnleaderboard.com/
|
26
61
|
|
27
62
|
## Development
|
28
63
|
|
29
64
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
65
|
|
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
|
66
|
+
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 add any changes to the `changelog`.
|
32
67
|
|
33
68
|
## Contributing
|
34
69
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
70
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/games-directory/api-playstationnetwork/. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
71
|
|
37
72
|
|
38
73
|
## License
|
@@ -2,8 +2,7 @@ require 'playstationnetwork/version'
|
|
2
2
|
require 'httparty'
|
3
3
|
|
4
4
|
module PlayStationNetwork
|
5
|
-
|
6
|
-
Dir[File.dirname(__FILE__) + '/playstationnetwork/**/*.rb'].each do |file|
|
5
|
+
Dir[File.dirname(__FILE__) + '/playstationnetwork/*.rb'].each do |file|
|
7
6
|
require file
|
8
7
|
end
|
9
8
|
end
|
@@ -1,15 +1,78 @@
|
|
1
1
|
module PlayStationNetwork
|
2
|
+
class Configuration
|
3
|
+
attr_writer :key, :secret, :url
|
4
|
+
|
5
|
+
def key
|
6
|
+
@key
|
7
|
+
end
|
8
|
+
|
9
|
+
def secret
|
10
|
+
@secret
|
11
|
+
end
|
12
|
+
|
13
|
+
def url
|
14
|
+
@url
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.configure(&block)
|
19
|
+
block.call(configuration)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.configuration
|
23
|
+
@configuration ||= Configuration.new
|
24
|
+
end
|
25
|
+
|
2
26
|
module API
|
3
27
|
include HTTParty
|
28
|
+
base_uri ""
|
29
|
+
|
30
|
+
extend self
|
31
|
+
|
32
|
+
MISSING_CONFIGURATION ||= "You must configure the PlayStationNetwork module before using this Gem. See the README.md for how to configure it"
|
33
|
+
MISSING_URL ||= "You must pass the 'url' to the PlayStationNetwork module before using this Gem. See the README.md for how to configure it"
|
34
|
+
MISSING_KEY ||= "You must pass your 'key' to the PlayStationNetwork module before using this Gem. See the README.md for how to configure it"
|
35
|
+
MISSING_SECRET ||= "You must pass your 'secret' to the PlayStationNetwork module before using this Gem. See the README.md for how to configure it"
|
36
|
+
|
37
|
+
def request
|
38
|
+
handle_response do
|
39
|
+
raise MISSING_CONFIGURATION if PlayStationNetwork.configuration.nil?
|
40
|
+
raise MISSING_KEY if PlayStationNetwork.configuration.key.nil?
|
41
|
+
raise MISSING_SECRET if PlayStationNetwork.configuration.secret.nil?
|
42
|
+
raise MISSING_URL if PlayStationNetwork.configuration.url.nil?
|
4
43
|
|
5
|
-
|
44
|
+
self.base_uri PlayStationNetwork.configuration.url
|
6
45
|
|
7
|
-
|
46
|
+
return {
|
47
|
+
api_key: PlayStationNetwork.configuration.key,
|
48
|
+
api_secret: PlayStationNetwork.configuration.secret,
|
49
|
+
response_type: 'json'
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def handle_response(&block)
|
55
|
+
yield
|
56
|
+
rescue => e
|
8
57
|
{
|
9
|
-
|
10
|
-
|
11
|
-
|
58
|
+
success: false,
|
59
|
+
code: 500,
|
60
|
+
message: e
|
12
61
|
}
|
13
62
|
end
|
63
|
+
|
64
|
+
def parse_response(url, body)
|
65
|
+
request = post(url, body)
|
66
|
+
|
67
|
+
if request.success?
|
68
|
+
begin
|
69
|
+
JSON.parse(request)
|
70
|
+
rescue
|
71
|
+
raise "There was a problem parsing the JSON. Most likely an API problem."
|
72
|
+
end
|
73
|
+
else
|
74
|
+
raise request.response
|
75
|
+
end
|
76
|
+
end
|
14
77
|
end
|
15
78
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module PlayStationNetwork
|
2
|
+
class Game
|
3
|
+
attr_accessor :options
|
4
|
+
|
5
|
+
GAMES_PARAMETERS_TYPES ||= ['all', 'ps4', 'ps3', 'psvita']
|
6
|
+
|
7
|
+
INVALID_NPCOMMID_TYPE ||="'npcommid' parameter needs to be a String"
|
8
|
+
INVALID_PLATFORM_TYPE ||= "'platform' parameter needs to be a String and be one of #{ GAMES_PARAMETERS_TYPES.join(', ') }"
|
9
|
+
INVALID_PLATFORM_PARAM ||= "'platform' needs to be one of #{ GAMES_PARAMETERS_TYPES.join(', ') }"
|
10
|
+
INVALID_POPULAR_TYPE ||= "'popular' parameter needs to be a Boolean"
|
11
|
+
|
12
|
+
def initialize(npcommid = "")
|
13
|
+
PlayStationNetwork::API.handle_response do
|
14
|
+
raise INVALID_NPCOMMID_TYPE unless npcommid.is_a?(String)
|
15
|
+
|
16
|
+
@options = PlayStationNetwork::API.request
|
17
|
+
|
18
|
+
unless npcommid.blank?
|
19
|
+
@options = @options.merge(npcommid: npcommid)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def details
|
25
|
+
PlayStationNetwork::API.handle_response do
|
26
|
+
PlayStationNetwork::API.parse_response('/psnGetGame', body: options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def trophies
|
31
|
+
PlayStationNetwork::API.handle_response do
|
32
|
+
PlayStationNetwork::API.parse_response('/psnGetTrophies', body: options)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def all(platform: 'all', popular: false)
|
37
|
+
PlayStationNetwork::API.handle_response do
|
38
|
+
raise INVALID_PLATFORM_TYPE unless platform.is_a?(String)
|
39
|
+
raise INVALID_PLATFORM_PARAM unless GAMES_PARAMETERS_TYPES.include?(platform)
|
40
|
+
raise INVALID_POPULAR_TYPE unless popular.is_a?(FalseClass) || popular.is_a?(TrueClass)
|
41
|
+
|
42
|
+
if popular
|
43
|
+
url = '/psnPopularThisWeek'
|
44
|
+
else
|
45
|
+
@options = options.merge(platform: platform)
|
46
|
+
url = '/psnListGames'
|
47
|
+
end
|
48
|
+
|
49
|
+
request = PlayStationNetwork::API.post(url, body: options)
|
50
|
+
|
51
|
+
if request.success?
|
52
|
+
begin
|
53
|
+
parse_xml(request)['psn_api']
|
54
|
+
rescue
|
55
|
+
raise "There was a problem parsing the XML response"
|
56
|
+
end
|
57
|
+
else
|
58
|
+
raise request.response
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def parse_xml(response)
|
66
|
+
xml_parsed = response
|
67
|
+
.gsub('<?xml version=\"1.0\"?>', '')
|
68
|
+
.gsub('<\/', '</')
|
69
|
+
.tr('"', '')
|
70
|
+
|
71
|
+
return Hash.from_xml(xml_parsed)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module PlayStationNetwork
|
2
|
+
class User
|
3
|
+
attr_accessor :options
|
4
|
+
|
5
|
+
INVALID_IDENTITY_TYPE ||="'identity' parameter needs to be a String"
|
6
|
+
INVALID_NPCOMMID_TYPE ||= "'npcommid' parameter needs to be a String"
|
7
|
+
|
8
|
+
def initialize(identity)
|
9
|
+
PlayStationNetwork::API.handle_response do
|
10
|
+
raise ArgumentError, INVALID_IDENTITY_TYPE unless identity.is_a?(String)
|
11
|
+
|
12
|
+
@options = PlayStationNetwork::API.request.merge(user_id: identity)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def profile
|
17
|
+
PlayStationNetwork::API.handle_response do
|
18
|
+
PlayStationNetwork::API.parse_response('/psnGetUser', body: options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def games
|
23
|
+
PlayStationNetwork::API.handle_response do
|
24
|
+
PlayStationNetwork::API.parse_response('/psnGetUserGames', body: options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def trophies(npcommid)
|
29
|
+
PlayStationNetwork::API.handle_response do
|
30
|
+
raise INVALID_NPCOMMID_TYPE unless npcommid.is_a?(String)
|
31
|
+
|
32
|
+
@options = options.merge(npcommid: npcommid)
|
33
|
+
PlayStationNetwork::API.parse_response('/psnGetUserTrophies', body: options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,21 +1,43 @@
|
|
1
1
|
module PlayStationNetwork
|
2
|
-
VERSION
|
2
|
+
VERSION ||= '2.0'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
def self.changelog
|
5
|
+
puts "
|
6
|
+
v0.0
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
v0.0.1 - Initial
|
9
|
+
v0.0.2 - Added Trophy Information
|
10
|
+
v0.0.3 - Added Trophies offset
|
11
|
+
v0.1.0 - Pluralized Renamed Trophy and TrophyGroup classes
|
12
|
+
v0.1.1 - Added a convenient method 'all' on Trophies, without having to pass the group id as an argument
|
13
|
+
|
14
|
+
v1.0 - This version is not backwards compatible! Read below for new API endpoints
|
15
|
+
|
16
|
+
v1.0.0 - Introduces a new API source and a new format
|
17
|
+
v1.0.1 - Fixes a bug where ActiveSupport version would cause an issue with existing rails apps
|
18
|
+
v1.0.2 - Adds correct hash format to pass the api key and secret to each route
|
19
|
+
|
20
|
+
v2.0 - This version is not backwards compatible! Read below for new API endpoints
|
21
|
+
|
22
|
+
v2.0.0
|
23
|
+
- Simplified API calls. Instead of separating each endpoint into its own file, use one file per class
|
24
|
+
- Remove all dependencies except HTTParty and use native Ruby where dependency was required
|
25
|
+
- No more parsing the data inside the gem, instead return the RAW data and let the application decide how to parse it
|
14
26
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
27
|
+
## Old method -> New method ( PlayStationNetwork:: removed for breviety )
|
28
|
+
#
|
29
|
+
# User
|
30
|
+
#
|
31
|
+
Profile: ::U::User.profile('pacMakaveli90') -> ::User.new('pacMakaveli90').profile
|
32
|
+
Games: ::U::Games.all('pacMakaveli90') -> ::User.new('pacMakaveli90').games
|
33
|
+
Trophies: ::U::Trophies.all('pacMakaveli90', 'NPWR00132_00') -> ::User.new('pacMakaveli90').trophies('NPWR00132_00')
|
34
|
+
|
35
|
+
# Games
|
36
|
+
#
|
37
|
+
Game: ::G::Game.find('NPWR00132_00') -> ::Game.new('NPWR00132_00').details
|
38
|
+
Trophies: ::G::Trophies.all('NPWR00132_00') -> ::Game.new('NPWR00132_00').trophies
|
39
|
+
All: ::G::Games.all('all') -> ::Game.new().all(platform: 'ps4') # default 'all'
|
40
|
+
Popular: ::G::Games.popular() -> ::Game.new().all(popular: true)
|
41
|
+
"
|
42
|
+
end
|
21
43
|
end
|
@@ -2,25 +2,23 @@
|
|
2
2
|
require './lib/playstationnetwork/version'
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
|
-
spec.name =
|
5
|
+
spec.name = 'playstationnetwork-api'
|
6
6
|
spec.version = PlayStationNetwork::VERSION
|
7
|
-
spec.authors = [
|
8
|
-
spec.email = [
|
7
|
+
spec.authors = ['Vlad Radulescu']
|
8
|
+
spec.email = ['vlad@games.directory']
|
9
9
|
|
10
|
-
spec.summary = %q{A Ruby wrapper for
|
11
|
-
spec.description = %q{A Ruby wrapper
|
10
|
+
spec.summary = %q{ A Ruby wrapper for PSN Leaderboard API }
|
11
|
+
spec.description = %q{ A Ruby wrapper around PSN Leaderboard's API for grabbing Users, Games and Trophies }
|
12
12
|
spec.homepage = ''
|
13
|
-
spec.license =
|
13
|
+
spec.license = 'MIT'
|
14
14
|
|
15
15
|
spec.files = `git ls-files`.split("\n")
|
16
16
|
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
17
|
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_dependency 'httparty'
|
21
|
-
spec.
|
22
|
-
spec.
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
20
|
+
spec.add_dependency 'httparty', '~> 0.15.6'
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.15.3'
|
22
|
+
spec.add_development_dependency 'rake', '~> 12.0.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.6.0'
|
26
24
|
end
|
metadata
CHANGED
@@ -1,103 +1,75 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: playstationnetwork-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vlad Radulescu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: json
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activesupport
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
17
|
+
- - "~>"
|
46
18
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
19
|
+
version: 0.15.6
|
48
20
|
type: :runtime
|
49
21
|
prerelease: false
|
50
22
|
version_requirements: !ruby/object:Gem::Requirement
|
51
23
|
requirements:
|
52
|
-
- - "
|
24
|
+
- - "~>"
|
53
25
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
26
|
+
version: 0.15.6
|
55
27
|
- !ruby/object:Gem::Dependency
|
56
28
|
name: bundler
|
57
29
|
requirement: !ruby/object:Gem::Requirement
|
58
30
|
requirements:
|
59
31
|
- - "~>"
|
60
32
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
33
|
+
version: 1.15.3
|
62
34
|
type: :development
|
63
35
|
prerelease: false
|
64
36
|
version_requirements: !ruby/object:Gem::Requirement
|
65
37
|
requirements:
|
66
38
|
- - "~>"
|
67
39
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
40
|
+
version: 1.15.3
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: rake
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
72
44
|
requirements:
|
73
45
|
- - "~>"
|
74
46
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
47
|
+
version: 12.0.0
|
76
48
|
type: :development
|
77
49
|
prerelease: false
|
78
50
|
version_requirements: !ruby/object:Gem::Requirement
|
79
51
|
requirements:
|
80
52
|
- - "~>"
|
81
53
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
54
|
+
version: 12.0.0
|
83
55
|
- !ruby/object:Gem::Dependency
|
84
56
|
name: rspec
|
85
57
|
requirement: !ruby/object:Gem::Requirement
|
86
58
|
requirements:
|
87
59
|
- - "~>"
|
88
60
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
61
|
+
version: 3.6.0
|
90
62
|
type: :development
|
91
63
|
prerelease: false
|
92
64
|
version_requirements: !ruby/object:Gem::Requirement
|
93
65
|
requirements:
|
94
66
|
- - "~>"
|
95
67
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
97
|
-
description: A Ruby wrapper
|
98
|
-
|
68
|
+
version: 3.6.0
|
69
|
+
description: " A Ruby wrapper around PSN Leaderboard's API for grabbing Users, Games
|
70
|
+
and Trophies "
|
99
71
|
email:
|
100
|
-
-
|
72
|
+
- vlad@games.directory
|
101
73
|
executables:
|
102
74
|
- console
|
103
75
|
- setup
|
@@ -113,12 +85,8 @@ files:
|
|
113
85
|
- bin/setup
|
114
86
|
- lib/playstationnetwork-api.rb
|
115
87
|
- lib/playstationnetwork/api.rb
|
116
|
-
- lib/playstationnetwork/
|
117
|
-
- lib/playstationnetwork/
|
118
|
-
- lib/playstationnetwork/g/trophies.rb
|
119
|
-
- lib/playstationnetwork/u/games.rb
|
120
|
-
- lib/playstationnetwork/u/trophies.rb
|
121
|
-
- lib/playstationnetwork/u/user.rb
|
88
|
+
- lib/playstationnetwork/game.rb
|
89
|
+
- lib/playstationnetwork/user.rb
|
122
90
|
- lib/playstationnetwork/version.rb
|
123
91
|
- playstationnetwork-api.gemspec
|
124
92
|
- spec/playstationnetwork/api_spec.rb
|
@@ -143,10 +111,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
111
|
version: '0'
|
144
112
|
requirements: []
|
145
113
|
rubyforge_project:
|
146
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.6.12
|
147
115
|
signing_key:
|
148
116
|
specification_version: 4
|
149
|
-
summary: A Ruby wrapper for
|
117
|
+
summary: A Ruby wrapper for PSN Leaderboard API
|
150
118
|
test_files:
|
151
119
|
- spec/playstationnetwork/api_spec.rb
|
152
120
|
- spec/spec_helper.rb
|
121
|
+
has_rdoc:
|
@@ -1,97 +0,0 @@
|
|
1
|
-
module PlayStationNetwork
|
2
|
-
module G
|
3
|
-
|
4
|
-
class Game
|
5
|
-
attr_accessor :media, :updates, :trophies, :stats,
|
6
|
-
:psn_id, :psn_hash, :psn_type, :psn_slug, :name, :cover, :platforms,
|
7
|
-
:updated, :checked,
|
8
|
-
:total, :platinum, :gold, :silver, :bronze,
|
9
|
-
:points, :points_platinum, :average_percentage, :owners, :completers, :completers_platinum, :trophies_earned, :played_this_week
|
10
|
-
|
11
|
-
def initialize(
|
12
|
-
psn_id, psn_hash, psn_type, psn_slug, name, cover, platforms,
|
13
|
-
updated, checked,
|
14
|
-
artworks, videos,
|
15
|
-
total, platinum, gold, silver, bronze,
|
16
|
-
points, points_platinum, average_percentage, owners, completers, completers_platinum, trophies_earned, played_this_week
|
17
|
-
)
|
18
|
-
|
19
|
-
game_updates = Hash.new
|
20
|
-
game_updates[:last_updated] = updated
|
21
|
-
game_updates[:last_checked] = checked
|
22
|
-
|
23
|
-
game_media = Hash.new
|
24
|
-
game_media[:artworks] = artworks
|
25
|
-
game_media[:videos] = videos
|
26
|
-
|
27
|
-
game_trophies = Hash.new
|
28
|
-
game_trophies[:total] = total
|
29
|
-
game_trophies[:platinum] = platinum
|
30
|
-
game_trophies[:gold] = gold
|
31
|
-
game_trophies[:silver] = silver
|
32
|
-
game_trophies[:bronze] = bronze
|
33
|
-
|
34
|
-
game_stats = Hash.new
|
35
|
-
game_stats[:points] = points
|
36
|
-
game_stats[:points_platinum] = points_platinum
|
37
|
-
game_stats[:average_percentage] = "#{average_percentage}%"
|
38
|
-
game_stats[:owners] = owners
|
39
|
-
game_stats[:completers] = completers
|
40
|
-
game_stats[:completers_platinum] = completers_platinum
|
41
|
-
game_stats[:trophies_earned] = trophies_earned
|
42
|
-
game_stats[:played_this_week] = played_this_week
|
43
|
-
|
44
|
-
self.psn_id = psn_id
|
45
|
-
self.psn_hash = psn_hash
|
46
|
-
self.psn_type = psn_type
|
47
|
-
self.psn_slug = psn_slug
|
48
|
-
self.name = name
|
49
|
-
self.cover = cover
|
50
|
-
self.platforms = platforms.split(',')
|
51
|
-
self.media = game_media
|
52
|
-
self.updates = game_updates
|
53
|
-
self.trophies = game_trophies
|
54
|
-
self.stats = game_stats
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.find(psn_game_id)
|
58
|
-
options = PlayStationNetwork::API.config.merge({ npcommid: psn_game_id })
|
59
|
-
response = PlayStationNetwork::API.post('/psnGetGame', body: options)
|
60
|
-
|
61
|
-
if response.success?
|
62
|
-
parsed = JSON.parse(response)
|
63
|
-
|
64
|
-
new(
|
65
|
-
parsed['npcommid'],
|
66
|
-
parsed['game_hash'],
|
67
|
-
parsed['content_Type'],
|
68
|
-
parsed['unique_url'],
|
69
|
-
parsed['title'],
|
70
|
-
parsed['image'],
|
71
|
-
parsed['pf'],
|
72
|
-
parsed['updated'].to_i,
|
73
|
-
parsed['meta_check'].to_i,
|
74
|
-
parsed['screenshots'],
|
75
|
-
parsed['videos'],
|
76
|
-
parsed['total'].to_i,
|
77
|
-
parsed['platinum'].to_i,
|
78
|
-
parsed['gold'].to_i,
|
79
|
-
parsed['silver'].to_i,
|
80
|
-
parsed['bronze'].to_i,
|
81
|
-
parsed['total_points'].to_i,
|
82
|
-
parsed['total_points_plat'].to_i,
|
83
|
-
parsed['average_perc'].to_f,
|
84
|
-
parsed['owners'].to_i,
|
85
|
-
parsed['completers'].to_i,
|
86
|
-
parsed['platters'].to_i,
|
87
|
-
parsed['trophies_earned'].to_i,
|
88
|
-
parsed['played_this_week'].to_i
|
89
|
-
)
|
90
|
-
else
|
91
|
-
raise response.response
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'active_support/core_ext/hash'
|
3
|
-
require 'pp'
|
4
|
-
|
5
|
-
module PlayStationNetwork
|
6
|
-
module G
|
7
|
-
|
8
|
-
class Games
|
9
|
-
attr_accessor :success, :total_games, :games
|
10
|
-
|
11
|
-
def initialize(success, total_games, games)
|
12
|
-
self.success = success
|
13
|
-
self.total_games = total_games
|
14
|
-
self.games = games
|
15
|
-
end
|
16
|
-
|
17
|
-
# Available platform options
|
18
|
-
#
|
19
|
-
# => all returns all PlayStation Network games
|
20
|
-
# => psp2 returns all PSP games
|
21
|
-
# => ps3 returns all PS3 games
|
22
|
-
# => ps4 returns all PS4 games
|
23
|
-
#
|
24
|
-
def self.all(psn_platform = 'all')
|
25
|
-
options = PlayStationNetwork::API.config.merge({ platform: psn_platform })
|
26
|
-
response = PlayStationNetwork::API.post('/psnListGames', body: options)
|
27
|
-
|
28
|
-
sanitized_response = response.gsub('<?xml version=\"1.0\"?>', '').gsub('<\/', '</').tr('"', '')
|
29
|
-
parsed_response = Hash.from_xml(sanitized_response)
|
30
|
-
|
31
|
-
if response.success?
|
32
|
-
new(
|
33
|
-
(parsed_response['psn_api']['success'].to_i == 1 ? true : false),
|
34
|
-
parsed_response['psn_api']['game'].size,
|
35
|
-
parsed_response['psn_api']['game']
|
36
|
-
)
|
37
|
-
else
|
38
|
-
raise response.response
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.popular
|
43
|
-
response = PlayStationNetwork::API.post('/psnPopularThisWeek')
|
44
|
-
|
45
|
-
sanitized_response = response.gsub('<?xml version=\"1.0\"?>', '').gsub('<\/', '</').tr('"', '')
|
46
|
-
parsed_response = Hash.from_xml(sanitized_response)
|
47
|
-
|
48
|
-
if response.success?
|
49
|
-
new(
|
50
|
-
(parsed_response['psn_api']['success'].to_i == 1 ? true : false),
|
51
|
-
parsed_response['psn_api']['game'].size,
|
52
|
-
parsed_response['psn_api']['game']
|
53
|
-
)
|
54
|
-
else
|
55
|
-
raise response.response
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module PlayStationNetwork
|
2
|
-
module G
|
3
|
-
|
4
|
-
class Trophies
|
5
|
-
attr_accessor :psn_id, :image_prefix, :trophies, :groups
|
6
|
-
|
7
|
-
def initialize(psn_id, image_prefix, trophies, groups)
|
8
|
-
self.psn_id = psn_id
|
9
|
-
self.image_prefix = image_prefix
|
10
|
-
self.trophies = trophies
|
11
|
-
self.groups = groups
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.all(psn_game_id)
|
15
|
-
options = PlayStationNetwork::API.config.merge({ npcommid: psn_game_id })
|
16
|
-
response = PlayStationNetwork::API.post('/psnGetTrophies', body: options)
|
17
|
-
|
18
|
-
if response.success?
|
19
|
-
parsed = JSON.parse(response)
|
20
|
-
|
21
|
-
new(
|
22
|
-
parsed['npcommid'],
|
23
|
-
parsed['image_prefix'],
|
24
|
-
parsed['trophies'],
|
25
|
-
parsed['groups']
|
26
|
-
)
|
27
|
-
else
|
28
|
-
raise response.response
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module PlayStationNetwork
|
2
|
-
module U
|
3
|
-
|
4
|
-
class Games
|
5
|
-
attr_accessor :total_games, :games
|
6
|
-
|
7
|
-
def initialize(total_games, games)
|
8
|
-
self.total_games = total_games
|
9
|
-
self.games = games
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.all(psn_user_id)
|
13
|
-
options = PlayStationNetwork::API.config.merge({ user_id: psn_user_id })
|
14
|
-
response = PlayStationNetwork::API.post('/psnGetUserGames', body: options)
|
15
|
-
|
16
|
-
if response.success?
|
17
|
-
parsed = JSON.parse(response)
|
18
|
-
|
19
|
-
new(
|
20
|
-
parsed['games'].size,
|
21
|
-
parsed['games']
|
22
|
-
)
|
23
|
-
else
|
24
|
-
raise response.response
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module PlayStationNetwork
|
2
|
-
module U
|
3
|
-
|
4
|
-
class Trophies
|
5
|
-
attr_accessor :trophies
|
6
|
-
|
7
|
-
def initialize(trophies)
|
8
|
-
self.trophies = trophies
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.all(psn_user_id, psn_game_id)
|
12
|
-
options = PlayStationNetwork::API.config.merge({ user_id: psn_user_id, npcommid: psn_game_id })
|
13
|
-
response = PlayStationNetwork::API.post('/psnGetUserTrophies', body: options)
|
14
|
-
|
15
|
-
if response.success?
|
16
|
-
parsed = JSON.parse(response)
|
17
|
-
|
18
|
-
new(
|
19
|
-
parsed['trophies']
|
20
|
-
)
|
21
|
-
else
|
22
|
-
raise response.response
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
@@ -1,121 +0,0 @@
|
|
1
|
-
module PlayStationNetwork
|
2
|
-
module U
|
3
|
-
|
4
|
-
class User
|
5
|
-
attr_accessor :profile, :trophies, :points, :level, :stats,
|
6
|
-
:membership, :avatar, :username, :about, :country, :region,
|
7
|
-
:total, :platinum, :gold, :silver, :bronze, :total_possible,
|
8
|
-
:points_base, :points, :points_next,
|
9
|
-
:level, :projected_level, :progress, :projected_progress,
|
10
|
-
:total_games, :completed_games, :completion_percentage, :world_rank, :region_rank, :hardcore_rank
|
11
|
-
|
12
|
-
def initialize(
|
13
|
-
membership, avatar, username, about, country, region,
|
14
|
-
total, platinum, gold, silver, bronze, total_possible,
|
15
|
-
points_base, points, points_next,
|
16
|
-
level, projected_level, progress, projected_progress,
|
17
|
-
total_games, completed_games, completion_percentage, world_rank, region_rank, hardcore_rank
|
18
|
-
)
|
19
|
-
|
20
|
-
# Build the Profile Hash
|
21
|
-
#
|
22
|
-
psn_profile = Hash.new
|
23
|
-
psn_profile[:membership] = membership.to_i
|
24
|
-
psn_profile[:avatar] = avatar
|
25
|
-
psn_profile[:username] = username
|
26
|
-
psn_profile[:about] = about
|
27
|
-
psn_profile[:location] = Hash.new
|
28
|
-
psn_profile[:location][:country] = country
|
29
|
-
psn_profile[:location][:region] = region
|
30
|
-
|
31
|
-
# Build the Trophies hash
|
32
|
-
#
|
33
|
-
psn_profile_trophies = Hash.new
|
34
|
-
psn_profile_trophies[:total] = total.to_i
|
35
|
-
psn_profile_trophies[:platinum] = platinum.to_i
|
36
|
-
psn_profile_trophies[:gold] = gold.to_i
|
37
|
-
psn_profile_trophies[:silver] = silver.to_i
|
38
|
-
psn_profile_trophies[:bronze] = bronze.to_i
|
39
|
-
psn_profile_trophies[:total_possible] = total_possible.to_i
|
40
|
-
|
41
|
-
# Build the Points hash
|
42
|
-
#
|
43
|
-
psn_profile_points = Hash.new
|
44
|
-
psn_profile_points[:base] = points_base.to_i
|
45
|
-
psn_profile_points[:actual] = points.to_i
|
46
|
-
psn_profile_points[:next] = points_next.to_i
|
47
|
-
|
48
|
-
# Build the Level hash
|
49
|
-
#
|
50
|
-
psn_profile_level = Hash.new
|
51
|
-
psn_profile_level[:level] = level.to_i
|
52
|
-
psn_profile_level[:projected_level] = projected_level.to_i
|
53
|
-
psn_profile_level[:progress] = progress.to_f
|
54
|
-
psn_profile_level[:projected_progress] = projected_progress.to_f
|
55
|
-
|
56
|
-
# Build the Points hash
|
57
|
-
#
|
58
|
-
psn_profile_stats = Hash.new
|
59
|
-
psn_profile_stats[:games] = total_games.to_i
|
60
|
-
psn_profile_stats[:completed_games] = completed_games.to_i
|
61
|
-
psn_profile_stats[:completion_percentage] = completion_percentage.to_f
|
62
|
-
psn_profile_stats[:rank] = Hash.new
|
63
|
-
psn_profile_stats[:rank][:world_rank] = world_rank.to_i
|
64
|
-
psn_profile_stats[:rank][:region_rank] = region_rank.to_i
|
65
|
-
psn_profile_stats[:rank][:hardcore_rank] = hardcore_rank.to_i
|
66
|
-
|
67
|
-
self.profile = psn_profile
|
68
|
-
self.trophies = psn_profile_trophies
|
69
|
-
self.level = psn_profile_level
|
70
|
-
self.points = psn_profile_points
|
71
|
-
self.stats = psn_profile_stats
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.profile(psn_user_id)
|
76
|
-
options = PlayStationNetwork::API.config.merge({ user_id: psn_user_id })
|
77
|
-
response = PlayStationNetwork::API.post('/psnGetUser', body: options)
|
78
|
-
|
79
|
-
if response.success?
|
80
|
-
parsed = JSON.parse(response)
|
81
|
-
|
82
|
-
self.new(
|
83
|
-
parsed['psnplus'],
|
84
|
-
parsed['avatar'],
|
85
|
-
parsed['psn_id'],
|
86
|
-
parsed['about_me'],
|
87
|
-
parsed['country'],
|
88
|
-
parsed['region'],
|
89
|
-
|
90
|
-
parsed['total'],
|
91
|
-
parsed['platinum'],
|
92
|
-
parsed['gold'],
|
93
|
-
parsed['silver'],
|
94
|
-
parsed['bronze'],
|
95
|
-
parsed['total_possible_trophies'],
|
96
|
-
|
97
|
-
parsed['base'],
|
98
|
-
parsed['points'],
|
99
|
-
parsed['next'],
|
100
|
-
|
101
|
-
parsed['level'],
|
102
|
-
parsed['projected_level'],
|
103
|
-
parsed['progress'],
|
104
|
-
parsed['projected_progress'],
|
105
|
-
|
106
|
-
parsed['total_games'],
|
107
|
-
parsed['games_complete'],
|
108
|
-
parsed['completion_percentage'],
|
109
|
-
parsed['worldrank'],
|
110
|
-
parsed['regionrank'],
|
111
|
-
parsed['hardcore_rank']
|
112
|
-
|
113
|
-
)
|
114
|
-
else
|
115
|
-
raise response.response
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
end
|