class GoogleMusicApi::MobileClient
Constants
- APP
- CLIENT_SIGNATURE
- SERVICE
- SERVICE_ENDPOINT
Public Class Methods
new(authorization_token = nil)
click to toggle source
Pass an authorization token and you won't have to login
@param [string] authorization_token
# File lib/google_music_api/mobile_client.rb, line 31 def initialize(authorization_token = nil) @authorization_token = authorization_token end
Public Instance Methods
authenticated?()
click to toggle source
Checks if there's an authorization token present @return [boolean]
# File lib/google_music_api/mobile_client.rb, line 59 def authenticated? !!@authorization_token end
login(email, password, android_id, device_country='us', operator_country='us')
click to toggle source
Logs in to Google using OAuth and obtains an authorization token
@param email [String] your email @param [String] password you password @param [String] android_id 16 hex digits, eg '1234567890abcdef' @param [String] device_country the country code of the device you're impersonating, default = 'us' @param [String] operator_country the country code of the device's mobile operator, default = 'us'
@raise [AuthenticationError] if authentication fails @return true if success
# File lib/google_music_api/mobile_client.rb, line 46 def login(email, password, android_id, device_country='us', operator_country='us') g = Gpsoauth::Client.new(android_id, 'ac2dm', device_country, operator_country) response = g.master_login(email, password) oauth_response = g.oauth(email, response['Token'], SERVICE, APP, CLIENT_SIGNATURE) raise AuthenticationError.new('Invalid username/password') unless oauth_response.key?('Auth') @authorization_token = oauth_response['Auth'] true end
search(query, ct = '1,2,3,4,6,7,8', max_results = 50)
click to toggle source
Generic search
1: Song, 2: Artist, 3: Album, 4: Playlist, 6: Station, 7: Situation, 8: Video @param [string] query @param [string] ct Used to restrict search to specific items, comma-separated list of item type ids. @param [integer] max_results
# File lib/google_music_api/mobile_client.rb, line 81 def search(query, ct = '1,2,3,4,6,7,8', max_results = 50) url = 'query' options = { query: { 'ct': ct, 'q': query, 'max-results': max_results } } make_get_request(url, options)['entries'] end
subscribed?()
click to toggle source
Checks whether the user is subscribed or not @return [boolean]
# File lib/google_music_api/mobile_client.rb, line 65 def subscribed? url = 'config' options = {query: {dv: 0}} subscribed = make_get_request(url, options)['data']['entries'].find do |item| item['key'] == 'isNautilusUser' && item['value'] == 'true' end !subscribed.nil? end