Class: PlayStationNetwork::API

Inherits:
Object
  • Object
show all
Defined in:
lib/playstationnetwork/api.rb

Direct Known Subclasses

Game, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*options) ⇒ API

Returns a new instance of API.

Raises:

  • (CONFIG_ERROR)


57
58
59
60
61
62
63
64
65
66
# File 'lib/playstationnetwork/api.rb', line 57

def initialize(*options)
  raise CONFIG_ERROR unless PlayStationNetwork.valid?

  @config = PlayStationNetwork.configuration
  @options = {
    api_key: config.key,
    api_secret: config.secret,
    response_type: 'json'
  }
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



53
54
55
# File 'lib/playstationnetwork/api.rb', line 53

def config
  @config
end

#optionsObject

Returns the value of attribute options.



53
54
55
# File 'lib/playstationnetwork/api.rb', line 53

def options
  @options
end

Instance Method Details

#post(url, dig_to: [], xml: false) ⇒ Object

response(http.request(request), dig_to)

end

end



81
82
83
84
85
86
87
88
89
90
# File 'lib/playstationnetwork/api.rb', line 81

def post(url, dig_to: [], xml: false)
  uri = URI.parse([config.url, url].join)

  Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https'), verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
    request = Net::HTTP::Post.new(uri.request_uri)
    request.set_form_data(options)

    response(http.request(request), dig_to, xml)
  end
end