Module: XLiveServices

Defined in:
lib/xlive_services.rb,
lib/xlive_services/media.rb,
lib/xlive_services/utils.rb,
lib/xlive_services/xlive.rb,
lib/xlive_services/hresult.rb,
lib/xlive_services/version.rb,
lib/xlive_services/xlive_services.rb,
lib/xlive_services/marketplace_public.rb

Defined Under Namespace

Modules: Media, Utils, WGX, XOnline Classes: MarketplacePublic, XLive, XLiveServicesError, XLiveServicesUnauthorized

Constant Summary collapse

CERT_FILE =
Pathname.new("#{File.dirname(__FILE__)}/../data/certs.pem").realpath.to_s.tr('/', File::ALT_SEPARATOR ? File::ALT_SEPARATOR : File::SEPARATOR)
VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.DoAuth(identity, serviceName, policy) ⇒ Object



34
35
36
37
# File 'lib/xlive_services/xlive_services.rb', line 34

def self.DoAuth(identity, serviceName, policy)
    return nil unless identity
    identity.GetService(serviceName, policy)
end

.GetLcwConfig(locale = 'en-US') ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
21
# File 'lib/xlive_services/xlive_services.rb', line 12

def self.GetLcwConfig(locale = 'en-US')
    raise XLiveServicesError.new('Invalid Locale!') if locale.nil? or locale.empty?
    request = HTTPI::Request.new("https://live.xbox.com/#{locale}/GetLcwConfig.ashx")
    request.auth.ssl.ca_cert_file = CERT_FILE
    request.auth.ssl.ssl_version = :TLSv1_2
    request.auth.ssl.verify_mode = :none if LiveIdentity.isAvailable?
    response = HTTPI.get(request)
    raise "Error! HTTP Status Code: #{response.code}" if response.error?
    XLiveServices.ParseConfig(MultiXml.parse(response.body))
end

.GetUserAuthorization(url, userAuthService) ⇒ Object

Raises:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/xlive_services/xlive_services.rb', line 49

def self.GetUserAuthorization(url, userAuthService)
    raise XLiveServicesError.new('Invalid AuthService Token!') if userAuthService.nil? or userAuthService.Token.nil? or userAuthService.Token.empty?
    request = HTTPI::Request.new(url)
    request.body = { :serviceType => 1, :titleId => 0 }
    request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
    request.headers['Authorization'] = "WLID1.0 #{userAuthService.Token}"
    request.headers['X-ClientType']  = 'panorama'
    request.auth.ssl.ca_cert_file = CERT_FILE
    request.auth.ssl.verify_mode = :none if LiveIdentity.isAvailable?
    response = HTTPI.post(request)
    if response.error?
        message = "Error! HTTP Status Code: #{response.code}"
        error_class = XLiveServicesError
        error_class = XLiveServicesUnauthorized if response.code == 401
        error_exception = error_class.new(message)
        error_exception.Code = response.code
        error_exception.Body = response.body
        raise error_exception
    end
    MultiXml.parse(response.body)
end

.GetUserAuthService(identity, config) ⇒ Object



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

def self.GetUserAuthService(identity, config)
    configData = config[:Auth][config[:URL][:GetUserAuth].last]
    DoAuth(identity, configData[:ServiceName], configData[:Policy])
end

.GetWgxService(identity, config) ⇒ Object



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

def self.GetWgxService(identity, config)
    configData = config[:Auth][config[:URL][:WgxService].last]
    DoAuth(identity, configData[:ServiceName], configData[:Policy])
end

.ParseConfig(config) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/xlive_services/xlive_services.rb', line 23

def self.ParseConfig(config)
    parsed = { :Auth => {}, :URL => {} }
    config['Environment']['Authentication']['AuthSetting'].each do |setting|
        parsed[:Auth][setting['name'].to_sym] = { ServiceName: setting['serviceName'], Policy: setting['policy'].to_sym }
    end
    config['Environment']['UrlSettings']['UrlSetting'].each do |setting|
        parsed[:URL][setting['name'].to_sym] = [ setting['url'], setting['authKey'].empty? ? nil : setting['authKey'].to_sym ]
    end
    parsed
end

.UserLogout(config) ⇒ Object

Raises:



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

def self.UserLogout(config)
    request = HTTPI::Request.new(config[:URL][:Logout].first)
    response = HTTPI.get(request)
    raise XLiveServicesError.new("Error! HTTP Status Code: #{response.code} #{response.body}") if response.error?
    response.body
end