playstationnetwork-api 2.0.1 → 3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/Gemfile +1 -1
- data/README.md +67 -5
- data/lib/playstationnetwork-api.rb +0 -1
- data/lib/playstationnetwork/api.rb +93 -52
- data/lib/playstationnetwork/game.rb +24 -56
- data/lib/playstationnetwork/store.rb +113 -0
- data/lib/playstationnetwork/user.rb +14 -23
- data/lib/playstationnetwork/version.rb +23 -1
- data/playstationnetwork-api.gemspec +9 -8
- metadata +26 -32
- data/.rspec +0 -2
- data/Rakefile +0 -6
- data/spec/playstationnetwork/api_spec.rb +0 -11
- data/spec/spec_helper.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed8df8d87ebafa825a4892aa8a5d4d8c468a3526891611deebcbfa6e13721ac6
|
4
|
+
data.tar.gz: 6b2fd961cf40dc0073dfcb59e7110e37c24b045103c5ee3882a4833262a3b9ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 750c870408d9c4de23cb83151d651bc3a4b9d83a03e419e9924d6847e822a7d23e85eedb34559756ddfbd7ae056242dd0fc813be915b6efab927abdaea1e8a2d
|
7
|
+
data.tar.gz: 552d9c738e2e05335dd103a29414e25bf0c4a3348ea6a36e1ca507626fbda40d20ea41a7eaef3c45a3c7468a6d9d07c75e2a61303bafb0a63c1c77f866d18c60
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
-
gemspec
|
2
|
+
gemspec
|
data/README.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
**[DEPRECATED]** The API is currently out of date as it's not been updated in over a year, from the time of writing this.
|
2
|
+
The API still works and it can still be used to retrieve historical data, assuming your user was there when API was active.
|
3
|
+
Use this to populate your PlayStation database if you must :)
|
4
|
+
|
5
|
+
If you need an active, maintained API, either contact psn@games.directory or check out https://github.com/games-directory/api-psn
|
6
|
+
|
7
|
+
The Store API is still working but not maintained. For a better, maintained version, use https://github.com/games-directory/api-psn
|
8
|
+
|
1
9
|
# PlayStationNetwork::API
|
2
10
|
|
3
11
|
Retrieve User, Trophies and Game data from PlayStationNetwork.
|
@@ -7,7 +15,7 @@ Retrieve User, Trophies and Game data from PlayStationNetwork.
|
|
7
15
|
Add this line to your application's Gemfile:
|
8
16
|
|
9
17
|
```ruby
|
10
|
-
gem 'playstationnetwork-api', '~>
|
18
|
+
gem 'playstationnetwork-api', '~> 3.1'
|
11
19
|
```
|
12
20
|
|
13
21
|
And then execute:
|
@@ -40,11 +48,34 @@ Or install it yourself as:
|
|
40
48
|
|
41
49
|
|
42
50
|
#### Get all Games
|
43
|
-
`PlayStationNetwork::Game.new().all(platform: 'ps4') # you don't have to pass an argument.
|
51
|
+
`PlayStationNetwork::Game.new().all(platform: 'ps4') # you don't have to pass an argument. It will get all games by default.`
|
44
52
|
|
45
53
|
#### Get Popular Games
|
46
54
|
`PlayStationNetwork::Game.new().all(popular: true)`
|
47
55
|
|
56
|
+
## NEW
|
57
|
+
|
58
|
+
```
|
59
|
+
The new PlayStationNetwork::Store.new() endpoint takes two additional arguments, 'region' and 'language'. Defaults to GB/en.
|
60
|
+
More debugging is required, but so far the available regions are: ['GB/en', 'US/en']
|
61
|
+
|
62
|
+
ex: PlayStationNetwork::Store.new('Rocket League', region: 'US', language: 'en')
|
63
|
+
```
|
64
|
+
|
65
|
+
#### Search PlayStation Store for a game(s)
|
66
|
+
```
|
67
|
+
PlayStationNetwork::Store.new('Rocket League').search()
|
68
|
+
|
69
|
+
Optionally, you can pass a `game_type` argument which can be either 'Full Game' ( default ) or 'Bundle' . This will reduce the amount of data returned by the query.
|
70
|
+
```
|
71
|
+
|
72
|
+
#### Get PlayStation Store details for a given game
|
73
|
+
```
|
74
|
+
Important!: You must use this endpoint only when you have a store_id, usually returned by the search() endpoint.
|
75
|
+
|
76
|
+
PlayStationNetwork::Store.new('EP2002-CUSA01433_00-ROCKETLEAGUEEU01').details()
|
77
|
+
```
|
78
|
+
|
48
79
|
## Configuration
|
49
80
|
|
50
81
|
In your app, create a new initializer `playstationnetwork.rb` and add the following:
|
@@ -54,10 +85,23 @@ PlayStationNetwork::API.configure do |config|
|
|
54
85
|
config.key = '<API_KEY>',
|
55
86
|
config.secret = '<API_SECRET>'
|
56
87
|
config.url = '<API_URL>'
|
88
|
+
config.verify_ssl = boolean ( default is true )
|
57
89
|
})
|
90
|
+
|
91
|
+
# visit: http://www.psnleaderboard.com/ to get your key, secret and endpoint details
|
92
|
+
```
|
93
|
+
|
94
|
+
`verify_ssl` was introduced in v2.1.0 in order to fix an error returned by the API when communicating through SSL.
|
95
|
+
If you get the following error when trying to access the API, set `verify_ssl` to `false`
|
96
|
+
```
|
97
|
+
{
|
98
|
+
success: false,
|
99
|
+
code: 500,
|
100
|
+
message: #<OpenSSL::SSL::SSLError: hostname '<API_URL>' does not match the server certificate>
|
101
|
+
}
|
58
102
|
```
|
59
103
|
|
60
|
-
|
104
|
+
Please note this option may be removed in a future release when a proper fix will be implemented.
|
61
105
|
|
62
106
|
## Development
|
63
107
|
|
@@ -69,8 +113,26 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
69
113
|
|
70
114
|
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.
|
71
115
|
|
72
|
-
|
73
116
|
## License
|
74
117
|
|
75
|
-
The
|
118
|
+
The MIT License (MIT)
|
119
|
+
|
120
|
+
Copyright (c) 2020 Vlad Radulescu, Studio51 Solutions, Studio51 Gaming Solutions
|
121
|
+
|
122
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
123
|
+
of this software and associated documentation files (the "Software"), to deal
|
124
|
+
in the Software without restriction, including without limitation the rights
|
125
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
126
|
+
copies of the Software, and to permit persons to whom the Software is
|
127
|
+
furnished to do so, subject to the following conditions:
|
128
|
+
|
129
|
+
The above copyright notice and this permission notice shall be included in
|
130
|
+
all copies or substantial portions of the Software.
|
76
131
|
|
132
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
133
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
134
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
135
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
136
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
137
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
138
|
+
THE SOFTWARE.
|
@@ -1,82 +1,123 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'active_support/core_ext/hash'
|
3
|
+
|
1
4
|
module PlayStationNetwork
|
5
|
+
|
6
|
+
MISSING_URL ||= "'url' is missing from your configuration."
|
7
|
+
MISSING_KEY ||= "'key' is missing from your configuration."
|
8
|
+
MISSING_SECRET ||= "'secret' is missing from your configuration."
|
9
|
+
|
10
|
+
# PlayStationNetwork.configure do |config|
|
11
|
+
# config.key = ''
|
12
|
+
# ..
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
def self.configure(&block)
|
16
|
+
block.call(configuration)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configuration
|
20
|
+
@configuration ||= Configuration.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.valid?
|
24
|
+
return MISSING_URL if configuration.url.nil?
|
25
|
+
return MISSING_KEY if configuration.key.nil?
|
26
|
+
return MISSING_SECRET if configuration.secret.nil?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
2
30
|
class Configuration
|
3
|
-
attr_writer :key, :secret, :url
|
31
|
+
attr_writer :key, :secret, :url, :verify_ssl
|
4
32
|
|
5
33
|
def key
|
6
|
-
@key
|
34
|
+
@key || '4047cc6b66393a82a0c7d90844cf0d88b14e0c3a'
|
7
35
|
end
|
8
36
|
|
9
37
|
def secret
|
10
|
-
@secret
|
38
|
+
@secret || 'pacMakaveli90'
|
11
39
|
end
|
12
40
|
|
13
41
|
def url
|
14
|
-
@url
|
42
|
+
@url || 'https://happynation.co.uk/api'
|
15
43
|
end
|
16
|
-
end
|
17
44
|
|
18
|
-
|
19
|
-
|
45
|
+
def verify_ssl
|
46
|
+
@verify_ssl
|
47
|
+
end
|
20
48
|
end
|
49
|
+
|
50
|
+
class API
|
51
|
+
require 'net/http'
|
21
52
|
|
22
|
-
|
23
|
-
|
24
|
-
|
53
|
+
attr_accessor :options, :config
|
54
|
+
|
55
|
+
CONFIG_ERROR ||= 'Please read the README.md on how to configure the PlayStationNetwork::API module.'
|
56
|
+
|
57
|
+
def initialize(*options)
|
58
|
+
raise CONFIG_ERROR unless PlayStationNetwork.valid?
|
59
|
+
|
60
|
+
@config = PlayStationNetwork.configuration
|
61
|
+
@options = {
|
62
|
+
api_key: config.key,
|
63
|
+
api_secret: config.secret,
|
64
|
+
response_type: 'json'
|
65
|
+
}
|
66
|
+
end
|
25
67
|
|
26
|
-
|
27
|
-
include HTTParty
|
28
|
-
base_uri ""
|
68
|
+
public
|
29
69
|
|
30
|
-
|
70
|
+
# def get(url, dig_to = [])
|
71
|
+
# uri = URI.parse([config.url, url].join)
|
31
72
|
|
32
|
-
|
33
|
-
|
34
|
-
|
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"
|
73
|
+
# Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
|
74
|
+
# request = Net::HTTP::Get.new(uri.request_uri)
|
75
|
+
# # request.set_form_data(options)
|
36
76
|
|
37
|
-
|
38
|
-
|
39
|
-
|
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?
|
77
|
+
# response(http.request(request), dig_to)
|
78
|
+
# end
|
79
|
+
# end
|
43
80
|
|
44
|
-
|
81
|
+
def post(url, dig_to: [], xml: false)
|
82
|
+
uri = URI.parse([config.url, url].join)
|
45
83
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
84
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https'), verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
85
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
86
|
+
request.set_form_data(options)
|
87
|
+
|
88
|
+
response(http.request(request), dig_to, xml)
|
51
89
|
end
|
52
90
|
end
|
53
91
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
92
|
+
private
|
93
|
+
|
94
|
+
def response(request, dig_to, xml)
|
95
|
+
if request.code == '200'
|
96
|
+
if xml
|
97
|
+
body = parse_xml(request.body)
|
98
|
+
else
|
99
|
+
body = request.body
|
100
|
+
end
|
63
101
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
JSON.parse(request)
|
71
|
-
else
|
72
|
-
JSON.parse(request)[reduce_to]
|
73
|
-
end
|
74
|
-
rescue
|
75
|
-
raise "There was a problem parsing the JSON. Most likely an API problem."
|
102
|
+
if dig_to.empty?
|
103
|
+
JSON.parse(body, object_class: OpenStruct)
|
104
|
+
else
|
105
|
+
results = JSON.parse(body, object_class: OpenStruct).dig(*dig_to)
|
106
|
+
results.pop if results&.last == 'Empty Node'
|
107
|
+
return results
|
76
108
|
end
|
77
109
|
else
|
78
|
-
raise request.
|
110
|
+
raise "There was a problem parsing the JSON. Most likely an API problem: #{ request.code }"
|
79
111
|
end
|
80
112
|
end
|
113
|
+
|
114
|
+
def parse_xml(response)
|
115
|
+
xml_parsed = response
|
116
|
+
.gsub('<?xml version=\"1.0\"?>', '')
|
117
|
+
.gsub('<\/', '</')
|
118
|
+
.tr('"', '')
|
119
|
+
|
120
|
+
return Hash.from_xml(xml_parsed).to_json
|
121
|
+
end
|
81
122
|
end
|
82
123
|
end
|
@@ -1,74 +1,42 @@
|
|
1
1
|
module PlayStationNetwork
|
2
|
-
class Game
|
3
|
-
|
2
|
+
class Game < PlayStationNetwork::API
|
3
|
+
GAMES_PARAMETERS_TYPES ||= ['all', 'ps4', 'ps3', 'psp2', 'psvita']
|
4
4
|
|
5
|
-
|
5
|
+
INVALID_NPCOMMID_TYPE ||= "'npcommid' parameter needs to be a String"
|
6
|
+
INVALID_PLATFORM_TYPE ||= "'platform' parameter needs to be a String and one of #{ GAMES_PARAMETERS_TYPES.join(', ') }"
|
7
|
+
INVALID_POPULAR_TYPE ||= "'popular' parameter needs to be a Boolean"
|
6
8
|
|
7
|
-
|
8
|
-
|
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)
|
9
|
+
def initialize(npcommid = '')
|
10
|
+
raise INVALID_NPCOMMID_TYPE unless npcommid.is_a?(String)
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@options = @options.merge(npcommid: npcommid)
|
20
|
-
end
|
12
|
+
super
|
13
|
+
unless npcommid.empty?
|
14
|
+
options[:npcommid] = npcommid
|
21
15
|
end
|
22
16
|
end
|
23
17
|
|
24
18
|
def details
|
25
|
-
|
26
|
-
PlayStationNetwork::API.parse_response('/psnGetGame', options)
|
27
|
-
end
|
19
|
+
post('/psnGetGame')
|
28
20
|
end
|
29
21
|
|
30
|
-
def trophies
|
31
|
-
|
32
|
-
PlayStationNetwork::API.parse_response('/psnGetTrophies', options)
|
33
|
-
end
|
22
|
+
def trophies
|
23
|
+
post('/psnGetTrophies')
|
34
24
|
end
|
35
25
|
|
36
26
|
def all(platform: 'all', popular: false)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
27
|
+
raise INVALID_PLATFORM_TYPE unless platform.is_a?(String)
|
28
|
+
raise INVALID_PLATFORM_TYPE unless GAMES_PARAMETERS_TYPES.include?(platform)
|
29
|
+
raise INVALID_POPULAR_TYPE unless popular.is_a?(FalseClass) || popular.is_a?(TrueClass)
|
30
|
+
|
31
|
+
if popular
|
32
|
+
options[:list] = platform
|
33
|
+
url = '/psnPopularThisWeek'
|
34
|
+
else
|
35
|
+
options[:platform] = platform
|
36
|
+
url = '/psnListGames'
|
60
37
|
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
38
|
|
71
|
-
|
39
|
+
post(url, dig_to: ['psn_api', 'game'], xml: true)
|
72
40
|
end
|
73
41
|
end
|
74
42
|
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module PlayStationNetwork
|
2
|
+
class Store
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
attr_reader :args, :region, :language, :headers
|
6
|
+
|
7
|
+
def initialize(args, region: 'GB', language: 'en')
|
8
|
+
@args = args
|
9
|
+
@region = region
|
10
|
+
@language = language
|
11
|
+
|
12
|
+
@headers = {
|
13
|
+
"User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36",
|
14
|
+
"Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
|
15
|
+
"Authority" => "store.playstation.com"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
def search(game_type = 'PSN Game')
|
20
|
+
raise '' unless game_type != 'PSN Game' || game_type != 'Bundle'
|
21
|
+
games = []
|
22
|
+
|
23
|
+
options = {
|
24
|
+
query: {
|
25
|
+
suggested_size: 5,
|
26
|
+
mode: 'game'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
uri = URI.parse(search_url(args))
|
31
|
+
uri.query = URI.encode_www_form(options[:query])
|
32
|
+
|
33
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
|
34
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
35
|
+
|
36
|
+
headers.each do |key, value|
|
37
|
+
request[key] = value
|
38
|
+
end
|
39
|
+
|
40
|
+
response = http.request(request)
|
41
|
+
|
42
|
+
if response.code == '200'
|
43
|
+
results = JSON.parse(response.body)['included'].select do |result|
|
44
|
+
result['attributes']['game-content-type'] == game_type
|
45
|
+
end
|
46
|
+
|
47
|
+
results.map { |r| r.deep_transform_keys(&:underscore) }.each do |result|
|
48
|
+
games << {
|
49
|
+
store_id: result['id'],
|
50
|
+
name: result['attributes']['name'],
|
51
|
+
description: result['attributes']['long_description'],
|
52
|
+
type: result['type'],
|
53
|
+
raw: result
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
return JSON.parse(games.to_json, object_class: OpenStruct)
|
58
|
+
else
|
59
|
+
raise response.code
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def details
|
65
|
+
uri = URI.parse(details_url(args))
|
66
|
+
|
67
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
|
68
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
69
|
+
|
70
|
+
headers.each do |key, value|
|
71
|
+
request[key] = value
|
72
|
+
end
|
73
|
+
|
74
|
+
response = http.request(request)
|
75
|
+
|
76
|
+
if response.code == '200'
|
77
|
+
return JSON.parse(
|
78
|
+
JSON.parse(response.body)
|
79
|
+
.deep_transform_keys(&:underscore)
|
80
|
+
.to_json,
|
81
|
+
|
82
|
+
object_class: OpenStruct
|
83
|
+
)
|
84
|
+
else
|
85
|
+
raise response.code
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def search_url(query)
|
93
|
+
"https://store.playstation.com/valkyrie-api/#{ language }/#{ region }/19/tumbler-search/#{ URI.encode(query) }"
|
94
|
+
end
|
95
|
+
|
96
|
+
def details_url(identifier)
|
97
|
+
"https://store.playstation.com/store/api/chihiro/00_09_000/container/#{ region }/#{ language }/19/#{ identifier }"
|
98
|
+
end
|
99
|
+
|
100
|
+
def deep_transform_keys(object, &block)
|
101
|
+
case object
|
102
|
+
when Hash
|
103
|
+
object.each_with_object({}) do |(key, value), result|
|
104
|
+
result[yield(key)] = deep_transform_keys(value, &block)
|
105
|
+
end
|
106
|
+
when Array
|
107
|
+
object.map { |e| deep_transform_keys(e, &block) }
|
108
|
+
else
|
109
|
+
object
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -1,37 +1,28 @@
|
|
1
1
|
module PlayStationNetwork
|
2
|
-
class User
|
3
|
-
|
4
|
-
|
5
|
-
INVALID_IDENTITY_TYPE ||="'identity' parameter needs to be a String"
|
2
|
+
class User < PlayStationNetwork::API
|
3
|
+
INVALID_IDENTITY_TYPE ||= "'identity' parameter needs to be a String"
|
6
4
|
INVALID_NPCOMMID_TYPE ||= "'npcommid' parameter needs to be a String"
|
7
5
|
|
8
6
|
def initialize(identity)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
7
|
+
raise INVALID_IDENTITY_TYPE unless identity.is_a?(String)
|
8
|
+
|
9
|
+
super
|
10
|
+
options[:user_id] = identity
|
14
11
|
end
|
15
12
|
|
16
13
|
def profile
|
17
|
-
|
18
|
-
PlayStationNetwork::API.parse_response('/psnGetUser', options)
|
19
|
-
end
|
14
|
+
post('/psnGetUser')
|
20
15
|
end
|
21
16
|
|
22
|
-
def games
|
23
|
-
|
24
|
-
PlayStationNetwork::API.parse_response('/psnGetUserGames', options, 'games')
|
25
|
-
end
|
17
|
+
def games(dig_to: ['games'])
|
18
|
+
post('/psnGetUserGames', dig_to: dig_to)
|
26
19
|
end
|
27
|
-
|
28
|
-
def trophies(npcommid)
|
29
|
-
PlayStationNetwork::API.handle_response do
|
30
|
-
raise INVALID_NPCOMMID_TYPE unless npcommid.is_a?(String)
|
31
20
|
|
32
|
-
|
33
|
-
|
34
|
-
|
21
|
+
def trophies(npcommid, dig_to: ['trophies'])
|
22
|
+
raise INVALID_IDENTITY_TYPE unless npcommid.is_a?(String)
|
23
|
+
|
24
|
+
options[:npcommid] = npcommid
|
25
|
+
post('/psnGetUserTrophies', dig_to: dig_to)
|
35
26
|
end
|
36
27
|
end
|
37
28
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module PlayStationNetwork
|
2
|
-
VERSION ||= '
|
2
|
+
VERSION ||= '3.1'
|
3
3
|
|
4
4
|
def self.changelog
|
5
5
|
puts "
|
@@ -41,6 +41,28 @@ module PlayStationNetwork
|
|
41
41
|
|
42
42
|
v2.0.1
|
43
43
|
- When requesting Games for a specific user, return only the games instead of a full response which returns the same data that ::User.new('pacMakaveli90').profile already returns
|
44
|
+
|
45
|
+
v2.1.0
|
46
|
+
- Added 'verify: false' to HTTParty default options to skip any SSL certification errors. Temporary measure until we can figure how to fix this.
|
47
|
+
|
48
|
+
v2.1.1
|
49
|
+
- Tidy up the code and add a new option which should make internal calls cleaner
|
50
|
+
|
51
|
+
v2.1.2
|
52
|
+
- Added 'verify: false' option introduced in v2.1.0 as a configurable option in the initializer
|
53
|
+
|
54
|
+
v2.2
|
55
|
+
- Added experimental PlayStation Store endpoint
|
56
|
+
|
57
|
+
v3.0
|
58
|
+
- (major) The API now returns OpenStruct objects instead of plain JSON
|
59
|
+
- Removed HTTParty dependency and used Ruby's Net::HTTP
|
60
|
+
- Removed a lot of logic and simplified the code and classes
|
61
|
+
- Integrated experimental PlayStation Stores endpoints into the gem
|
62
|
+
- Added Cache
|
63
|
+
|
64
|
+
v3.0.1
|
65
|
+
- Fixed an issue caused by the User not having any earned trophies and trying to get last item from an empty array
|
44
66
|
"
|
45
67
|
end
|
46
68
|
end
|
@@ -5,20 +5,21 @@ Gem::Specification.new do |spec|
|
|
5
5
|
spec.name = 'playstationnetwork-api'
|
6
6
|
spec.version = PlayStationNetwork::VERSION
|
7
7
|
spec.authors = ['Vlad Radulescu']
|
8
|
-
spec.email = ['
|
8
|
+
spec.email = ['oss@games.directory']
|
9
9
|
|
10
|
-
spec.summary = %q{ A Ruby wrapper
|
11
|
-
spec.description = %q{
|
10
|
+
spec.summary = %q{ A Ruby wrapper around PSN Leaderboard's API }
|
11
|
+
spec.description = %q{ Allows your app to communicate with the PlayStation Network API and retrieve your, or a given user, Games, Trophies and Achievements. API is provided by psnloaderboard.com . }
|
12
12
|
spec.homepage = ''
|
13
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
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_dependency '
|
21
|
-
|
22
|
-
spec.add_development_dependency '
|
23
|
-
spec.add_development_dependency '
|
20
|
+
spec.add_dependency 'activesupport'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'pry'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
24
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
24
25
|
end
|
metadata
CHANGED
@@ -1,75 +1,76 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: playstationnetwork-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '3.1'
|
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: 2020-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '2'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3
|
61
|
+
version: '12.3'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3
|
69
|
-
description: "
|
70
|
-
|
68
|
+
version: '12.3'
|
69
|
+
description: " Allows your app to communicate with the PlayStation Network API and
|
70
|
+
retrieve your, or a given user, Games, Trophies and Achievements. API is provided
|
71
|
+
by psnloaderboard.com . "
|
71
72
|
email:
|
72
|
-
-
|
73
|
+
- oss@games.directory
|
73
74
|
executables:
|
74
75
|
- console
|
75
76
|
- setup
|
@@ -77,20 +78,17 @@ extensions: []
|
|
77
78
|
extra_rdoc_files: []
|
78
79
|
files:
|
79
80
|
- ".gitignore"
|
80
|
-
- ".rspec"
|
81
81
|
- Gemfile
|
82
82
|
- README.md
|
83
|
-
- Rakefile
|
84
83
|
- bin/console
|
85
84
|
- bin/setup
|
86
85
|
- lib/playstationnetwork-api.rb
|
87
86
|
- lib/playstationnetwork/api.rb
|
88
87
|
- lib/playstationnetwork/game.rb
|
88
|
+
- lib/playstationnetwork/store.rb
|
89
89
|
- lib/playstationnetwork/user.rb
|
90
90
|
- lib/playstationnetwork/version.rb
|
91
91
|
- playstationnetwork-api.gemspec
|
92
|
-
- spec/playstationnetwork/api_spec.rb
|
93
|
-
- spec/spec_helper.rb
|
94
92
|
homepage: ''
|
95
93
|
licenses:
|
96
94
|
- MIT
|
@@ -110,12 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
108
|
- !ruby/object:Gem::Version
|
111
109
|
version: '0'
|
112
110
|
requirements: []
|
113
|
-
|
114
|
-
rubygems_version: 2.6.12
|
111
|
+
rubygems_version: 3.1.2
|
115
112
|
signing_key:
|
116
113
|
specification_version: 4
|
117
|
-
summary: A Ruby wrapper
|
118
|
-
test_files:
|
119
|
-
- spec/playstationnetwork/api_spec.rb
|
120
|
-
- spec/spec_helper.rb
|
121
|
-
has_rdoc:
|
114
|
+
summary: A Ruby wrapper around PSN Leaderboard's API
|
115
|
+
test_files: []
|
data/.rspec
DELETED
data/Rakefile
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require './lib/playstationnetwork/api'
|