class PlayStationNetworkAPI::Client

Attributes

account_id[RW]
age[RW]
country[RW]
default_headers[RW]
language[RW]
refresh_token[RW]

Public Class Methods

new(refresh_token, account_id: 'me', country: 'GB', language: 'en') click to toggle source
# File lib/play_station_network_api/client.rb, line 12
def initialize(refresh_token, account_id: 'me', country: 'GB', language: 'en')
  @refresh_token = refresh_token
  @default_headers = {
    # TODO: Make this a variable for other languages
    'Accept-Language' => 'en-US',
    'User-Agent' => "psn-api/#{ VERSION }"
  }

  @account_id = account_id
  @country = country
  @language = language
end

Private Class Methods

changelog() click to toggle source
# File lib/play_station_network_api/client.rb, line 144
def self.changelog
  # v2.0
  # Implemented the new API that's currently present in the new PlayStation App.
  # There are quite a few endpoints that currently return Access Denied, which probably means they're not active yet
  
  # v1.0
end

Public Instance Methods

catalog() click to toggle source
# File lib/play_station_network_api/client.rb, line 27
def catalog
  PlayStationNetworkAPI::Catalog.new(refresh_token, 
    account_id: account_id, 
    country: country, 
    language: language
  )
end
entitlement() click to toggle source
# File lib/play_station_network_api/client.rb, line 35
def entitlement
  PlayStationNetworkAPI::Entitlement.new(refresh_token, 
    account_id: account_id, 
    country: country, 
    language: language
  )
end
explore() click to toggle source
# File lib/play_station_network_api/client.rb, line 43
def explore
  PlayStationNetworkAPI::Explore.new(refresh_token, 
    account_id: account_id, 
    country: country, 
    language: language
  )
end
game() click to toggle source
# File lib/play_station_network_api/client.rb, line 51
def game
  PlayStationNetworkAPI::Game.new(refresh_token, 
    account_id: account_id, 
    country: country, 
    language: language
  )
end
get_account_devices() click to toggle source
# File lib/play_station_network_api/client.rb, line 99
def get_account_devices
  self.class.base_uri 'https://dms.api.playstation.com/api'

  # https://dms.api.playstation.com/api/v1/devices/accounts/me
  get('/v1/devices/accounts/me').parsed_response['accountDevices']
end
get_account_id() click to toggle source

@private true

# File lib/play_station_network_api/client.rb, line 92
def get_account_id
  self.class.base_uri 'https://dms.api.playstation.com/api'

  # https://dms.api.playstation.com/api/v1/devices/accounts/me
  get('/v1/devices/accounts/me').parsed_response['accountId']
end
session() click to toggle source
# File lib/play_station_network_api/client.rb, line 67
def session
  PlayStationNetworkAPI::Session.new(refresh_token, 
    account_id: account_id, 
    country: country, 
    language: language
  )
end
trophy() click to toggle source
# File lib/play_station_network_api/client.rb, line 75
def trophy
  PlayStationNetworkAPI::Trophy.new(refresh_token, 
    account_id: account_id, 
    country: country, 
    language: language
  )
end
user() click to toggle source
# File lib/play_station_network_api/client.rb, line 83
def user
  PlayStationNetworkAPI::User.new(refresh_token, 
    account_id: account_id, 
    country: country, 
    language: language
  )
end

Protected Instance Methods

get(url, options = {}) click to toggle source
# File lib/play_station_network_api/client.rb, line 108
def get(url, options = {})
  access_token = PlayStationNetworkAPI::Session.new(refresh_token).access_token
  
  base_uri = options[:base_uri]
  options.delete(:base_uri)

  headers = options[:headers] || {}
  options.delete(:headers)

  self.class.base_uri base_uri if base_uri

  self.class.get(url,
    headers: {
      **default_headers,
      'Authorization' => "Bearer #{ access_token }",
      **headers
    },
    **options
  )
end
post(url, options = {}) click to toggle source
# File lib/play_station_network_api/client.rb, line 129
def post(url, options = {})
  access_token = PlayStationNetworkAPI::Session.new(refresh_token).access_token
  
  self.class.post(url,
    headers: {
      **default_headers,
      'Content-Type' => 'application/json',
      'Authorization' => "Bearer #{ access_token }"
    },
    **options
  )
end