mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 17:22:35 +00:00
Access W3D Hub API
This commit is contained in:
64
lib/api/applications.rb
Normal file
64
lib/api/applications.rb
Normal file
@@ -0,0 +1,64 @@
|
||||
class W3DHub
|
||||
class Api
|
||||
class Applications
|
||||
def initialize(response)
|
||||
@data = JSON.parse(response, symbolize_names: true)
|
||||
|
||||
games = @data[:applications].select { |a| a[:category] == "games" }
|
||||
|
||||
@games = []
|
||||
|
||||
games.each { |hash| @games << Game.new(hash) }
|
||||
end
|
||||
|
||||
def games
|
||||
@games
|
||||
end
|
||||
|
||||
class Game
|
||||
attr_reader :id, :name, :type, :category, :studio_id, :channels, :web_links, :color
|
||||
|
||||
def initialize(hash)
|
||||
@data = hash
|
||||
|
||||
@id = @data[:id]
|
||||
@name = @data[:name]
|
||||
@type = @data[:type]
|
||||
@category = @data[:category]
|
||||
@studio_id = @data[:"studio-id"]
|
||||
|
||||
# TODO: Do processing
|
||||
@channels = @data[:channels]
|
||||
@web_links = @data[:"web-links"]
|
||||
@extended_data = @data[:"extended-data"]
|
||||
|
||||
color = @data[:"extended-data"].find { |h| h[:name] == "colour" }[:value].sub("#", "")
|
||||
|
||||
@color = "ff#{color}".to_i(16)
|
||||
end
|
||||
|
||||
class Channel
|
||||
def initialize(hash)
|
||||
@data = hash
|
||||
|
||||
@id = @data[:id]
|
||||
@name = @data[:name]
|
||||
@user_level = @data[:"user-level"]
|
||||
@current_version = @data[:"current-version"]
|
||||
end
|
||||
end
|
||||
|
||||
class WebLink
|
||||
attr_reader :name, :uri
|
||||
|
||||
def initialize(hash)
|
||||
@data = hash
|
||||
|
||||
@name = hash[:name]
|
||||
@uri = hash[:uri]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
17
lib/api/service_status.rb
Normal file
17
lib/api/service_status.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
class W3DHub
|
||||
class Api
|
||||
class ServiceStatus
|
||||
def initialize(response)
|
||||
@data = JSON.parse(response, symbolize_names: true)
|
||||
end
|
||||
|
||||
def authentication?
|
||||
@data[:services][:authentication]
|
||||
end
|
||||
|
||||
def package_download?
|
||||
@data[:services][:packageDownload]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user