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
authorization_token() click to toggle source
# File lib/google_music_api/mobile_client.rb, line 95
def authorization_token
  @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
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