Class: PlayStationNetwork::Store
- Inherits:
-
Object
- Object
- PlayStationNetwork::Store
- Includes:
- HTTParty
- Defined in:
- lib/playstationnetwork/store.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Instance Method Summary collapse
- #details ⇒ Object
-
#initialize(args, region: 'GB', language: 'en') ⇒ Store
constructor
A new instance of Store.
- #search(game_type = 'Full Game') ⇒ Object
Constructor Details
#initialize(args, region: 'GB', language: 'en') ⇒ Store
Returns a new instance of Store.
8 9 10 11 12 |
# File 'lib/playstationnetwork/store.rb', line 8 def initialize(args, region: 'GB', language: 'en') @args = args @region = region @language = language end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
6 7 8 |
# File 'lib/playstationnetwork/store.rb', line 6 def args @args end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
6 7 8 |
# File 'lib/playstationnetwork/store.rb', line 6 def language @language end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
6 7 8 |
# File 'lib/playstationnetwork/store.rb', line 6 def region @region end |
Instance Method Details
#details ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/playstationnetwork/store.rb', line 55 def details = { headers: { "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", "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Authority" => "store.playstation.com" } } request = self.class.get(details_url(args), ) if request.success? return request.parsed_response else raise request.response end end |
#search(game_type = 'Full Game') ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/playstationnetwork/store.rb', line 14 def search(game_type = 'Full Game') raise '' unless game_type != 'Full Game' || game_type != 'Bundle' = { headers: { "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", "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", "Authority" => "store.playstation.com" }, query: { suggested_size: 5, mode: 'game' } } request = self.class.get(search_url(args), ) if request.success? response = [] results = request.parsed_response['included'].select do |result| result['attributes']['game-content-type'] == game_type end results.each do |result| response << { store_id: result['id'], name: result['attributes']['name'], description: result['attributes']['long-description'], type: result['type'], raw: result } end return response else raise request.response end end |