Class: XLiveServices::XLive

Inherits:
Object
  • Object
show all
Defined in:
lib/xlive_services/xlive.rb

Constant Summary collapse

LiveIdGUID =
'{D34F9E47-A73B-44E5-AE67-5D0D8B8CFA76}'
LiveIdVersion =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username = nil, password = nil, locale = nil) ⇒ XLive

Returns a new instance of XLive.


10
11
12
13
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
# File 'lib/xlive_services/xlive.rb', line 10

def initialize(username = nil, password = nil, locale = nil)
    @Locale = 'en-US'
    @Locale = locale if locale
    @Config = XLiveServices.GetLcwConfig(@Locale)
    @Live = LiveIdentity.new(LiveIdGUID, LiveIdVersion, :NO_UI, { :IDCRL_OPTION_ENVIRONMENT => 'Production' })

    if username.nil?
        identities = @Live.GetIdentities(LiveIdentity::PPCRL_CREDTYPE_PASSWORD)
        @Username = identities.GetNextIdentityName
        if !@Username
            identities = @Live.GetIdentities(LiveIdentity::PPCRL_CREDTYPE_MEMBERNAMEONLY)
            @Username = identities.GetNextIdentityName
        end
        raise XLiveServicesError.new('No Username!') unless @Username
    else
        @Username = username
    end

    @Identity = @Live.GetIdentity(@Username, :IDENTITY_SHARE_ALL)
    if !@Identity.HasPersistedCredential?(LiveIdentity::PPCRL_CREDTYPE_MEMBERNAMEONLY)
        @Identity.SetCredential(LiveIdentity::PPCRL_CREDTYPE_MEMBERNAMEONLY, @Username)
    end

    if password
        @Identity.SetCredential(LiveIdentity::PPCRL_CREDTYPE_PASSWORD, password)
    elsif !@Identity.HasPersistedCredential?(LiveIdentity::PPCRL_CREDTYPE_PASSWORD)
        raise XLiveServicesError.new("No Password for #{@Username}!")
    end
end

Instance Attribute Details

#ConfigObject (readonly)

Returns the value of attribute Config


6
7
8
# File 'lib/xlive_services/xlive.rb', line 6

def Config
  @Config
end

#IdentityObject (readonly)

Returns the value of attribute Identity


8
9
10
# File 'lib/xlive_services/xlive.rb', line 8

def Identity
  @Identity
end

#LiveObject (readonly)

Returns the value of attribute Live


7
8
9
# File 'lib/xlive_services/xlive.rb', line 7

def Live
  @Live
end

#LocaleObject (readonly)

Returns the value of attribute Locale


5
6
7
# File 'lib/xlive_services/xlive.rb', line 5

def Locale
  @Locale
end

#UsernameObject (readonly)

Returns the value of attribute Username


9
10
11
# File 'lib/xlive_services/xlive.rb', line 9

def Username
  @Username
end

Instance Method Details

#AuthenticateObject


54
55
56
57
# File 'lib/xlive_services/xlive.rb', line 54

def Authenticate
    return if IsAuthenticated?()
    @Identity.Authenticate(nil, :LOGONIDENTITY_ALLOW_PERSISTENT_COOKIES)
end

#GetMarketplaceObject


72
73
74
75
# File 'lib/xlive_services/xlive.rb', line 72

def GetMarketplace
    # Alternative service url https://services.gamesforwindows.com/SecurePublic/MarketplaceRestSecure.svc
    XLiveServices::MarketplacePublic.new(@Config[:URL][:WgxService].first, GetWgxService())
end

#GetUserAuthorizationInfoObject


63
64
65
66
# File 'lib/xlive_services/xlive.rb', line 63

def GetUserAuthorizationInfo
    userAuthorization = XLiveServices.GetUserAuthorization(@Config[:URL][:GetUserAuth].first, GetUserAuthService())
    userAuthorization['GetUserAuthorizationInfo']
end

#GetUserAuthServiceObject


59
60
61
# File 'lib/xlive_services/xlive.rb', line 59

def GetUserAuthService
    @GetUserAuthService ||= XLiveServices.GetUserAuthService(@Identity, @Config)
end

#GetWgxServiceObject


68
69
70
# File 'lib/xlive_services/xlive.rb', line 68

def GetWgxService
    @WgxService ||= XLiveServices.GetWgxService(@Identity, @Config)
end

#IsAuthenticated?Boolean

Returns:

  • (Boolean)

50
51
52
# File 'lib/xlive_services/xlive.rb', line 50

def IsAuthenticated?
    @Identity.IsAuthenticated?
end

#PersistCredentialsObject


40
41
42
43
# File 'lib/xlive_services/xlive.rb', line 40

def PersistCredentials
    @Identity.PersistCredential(LiveIdentity::PPCRL_CREDTYPE_MEMBERNAMEONLY)
    @Identity.PersistCredential(LiveIdentity::PPCRL_CREDTYPE_PASSWORD)
end

#RemovePersistedCredentialsObject


45
46
47
48
# File 'lib/xlive_services/xlive.rb', line 45

def RemovePersistedCredentials
    @Identity.RemovePersistedCredential(LiveIdentity::PPCRL_CREDTYPE_PASSWORD)
    @Identity.RemovePersistedCredential(LiveIdentity::PPCRL_CREDTYPE_MEMBERNAMEONLY)
end