Module: PlayStationNetwork::API
Instance Method Summary collapse
- #handle_response(&block) ⇒ Object
- #parse_response(url, options, reduce_to = {}) ⇒ Object
- #request ⇒ Object
Instance Method Details
#handle_response(&block) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/playstationnetwork/api.rb', line 59 def handle_response(&block) yield rescue => e { success: false, code: 500, message: e } end |
#parse_response(url, options, reduce_to = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/playstationnetwork/api.rb', line 69 def parse_response(url, , reduce_to = {}) request = post(url, body: ) if request.success? begin if reduce_to.blank? JSON.parse(request) else JSON.parse(request)[reduce_to] end rescue raise 'There was a problem parsing the JSON. Most likely an API problem.' end else raise request.response end end |
#request ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/playstationnetwork/api.rb', line 41 def request handle_response do raise MISSING_CONFIGURATION if PlayStationNetwork.configuration.nil? raise MISSING_KEY if PlayStationNetwork.configuration.key.nil? raise MISSING_SECRET if PlayStationNetwork.configuration.secret.nil? raise MISSING_URL if PlayStationNetwork.configuration.url.nil? .update(base_uri: PlayStationNetwork.configuration.url) .update(verify: PlayStationNetwork.configuration.verify_ssl) return { api_key: PlayStationNetwork.configuration.key, api_secret: PlayStationNetwork.configuration.secret, response_type: 'json' } end end |