class PlayStationNetworkAPI::Search
Public Instance Methods
buckets()
click to toggle source
Returns a list of buckets available to pass to .query(domains: [])
# File lib/play_station_network_api/search.rb, line 27 def buckets BUCKETS.keys end
query(query, offset: 0, limit: 50, buckets: [:CONCEPT_GAME_MOBILE_APP])
click to toggle source
query [String] limit [Integer] {
min: 1, max: 50
} country [String] language [String]
# File lib/play_station_network_api/search.rb, line 38 def query(query, offset: 0, limit: 50, buckets: [:CONCEPT_GAME_MOBILE_APP]) search_domains = [] buckets.each do |bucket| search_domains.push({ "domain": BUCKETS[bucket.to_sym], "pagination": { # TODO: It seems to be a Java GraphQL pagination thingy, when present it breaks the offset. # So let's leave it out for now as we don't really need to paginate # "cursor": "10" "pageSize": limit, "offset": offset } }) end # https://m.np.playstation.net/api/search/v1/universalSearch request = post('/search/v1/universalSearch', body: { "domainRequests": search_domains, "age": "999", "countryCode": country, "searchTerm": query, "languageCode": language }.to_json ) buckets = [] request.dig('domainResponses').map do |domain_response| bucket = {} bucket[domain_response['domain']] = { total_results: domain_response['totalResultCount'], results: domain_response['results'] } buckets.push(bucket) end return { query: request['prefix'], suggestions: request['suggestions'], buckets: buckets, } end