mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2026-09-19 14:53:49 +00:00
Initial pass of fetching and using application news, server events, server ping display now shows unit (ms) instead of just the number- also helps with confusing it for player count
This commit is contained in:
@@ -54,12 +54,12 @@ module W3DHubLauncher
|
||||
|
||||
# returns news for application
|
||||
def self.news(category = "launcher-home", &block)
|
||||
Worker::Request.new(:news, category, &block)
|
||||
W3DHubLauncher::Worker::Request.new(:w3dhub_api_call, { call: :fetch_news, arguments: [category] }, &block)
|
||||
end
|
||||
|
||||
# returns news for application
|
||||
def self.events(app_id, &block)
|
||||
Worker::Request.new(:events, app_id, &block)
|
||||
def self.events(category, &block)
|
||||
W3DHubLauncher::Worker::Request.new(:w3dhub_api_call, { call: :fetch_events, arguments: [category] }, &block)
|
||||
end
|
||||
|
||||
# request installation of application
|
||||
|
||||
28
lib/worker/api/news_item.rb
Normal file
28
lib/worker/api/news_item.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module W3DHubLauncher
|
||||
class Worker
|
||||
class Api
|
||||
class NewsItem
|
||||
attr_reader :topic_id, :title, :blurb, :uri, :image_uri, :author_id, :author, :author_uri, :timestamp
|
||||
|
||||
def initialize(data)
|
||||
@topic_id = Integer(data["topic-id"] || 0)
|
||||
@title = data["title"].to_s
|
||||
@blurb = clean_and_scrub_blurb(data["blurb"].to_s)
|
||||
@uri = data["uri"].to_s
|
||||
@image_uri = data["image"].to_s
|
||||
|
||||
@author_id = data["author-id"].to_s
|
||||
@author = data["author"].to_s
|
||||
@author_uri = data["author-uri"].to_s
|
||||
|
||||
@timestamp = Time.at(Integer(data["timestamp"] || 0), in: "UTC").localtime
|
||||
end
|
||||
|
||||
# Replaces multiple newlines with a single newline, and trims off any leading and trailing whitespace.
|
||||
def clean_and_scrub_blurb(string)
|
||||
string.gsub(/\n+/, "\n").strip
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
17
lib/worker/api/server_event.rb
Normal file
17
lib/worker/api/server_event.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
module W3DHubLauncher
|
||||
class Worker
|
||||
class Api
|
||||
class ServerEvent
|
||||
attr_reader :title, :image_uri, :app_id, :start_time, :end_time, :timestamp
|
||||
def initialize(data)
|
||||
@title = data["title"]
|
||||
@image_uri = data["image"]
|
||||
@app_id = data["server"]
|
||||
@start_time = Time.parse(data["starttime"], in: "UTC").localtime
|
||||
@end_time = Time.parse(data["endtime"], in: "UTC").localtime
|
||||
@timestamp = Time.parse(data["dateTime"], in: "UTC").localtime
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
19
lib/worker/api/test_event.rb
Normal file
19
lib/worker/api/test_event.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module W3DHubLauncher
|
||||
class Worker
|
||||
class Api
|
||||
class TestEvent
|
||||
attr_reader :title, :image_uri, :timestamp
|
||||
|
||||
def initialize(data)
|
||||
@title = data["name"]
|
||||
# @title = data["title"]
|
||||
@image_uri = data["image"]
|
||||
# @app_id = data["server"]
|
||||
# @start_time = Time.parse(data["starttime"]).localtime
|
||||
# @end_time = Time.parse(data["endtime"]).localtime
|
||||
@timestamp = Time.parse(data["dateTime"], in: "UTC").localtime
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
0
lib/worker/tasks/move_application.rb
Normal file
0
lib/worker/tasks/move_application.rb
Normal file
@@ -33,10 +33,10 @@ module W3DHubLauncher
|
||||
Sync do |task|
|
||||
task.with_timeout(API_TIMEOUT) do
|
||||
Async::HTTP::Internet.send(method, url, headers, body) do |response|
|
||||
# pp [method, url, headers, body]
|
||||
if response.success?
|
||||
result.data = response.read
|
||||
else
|
||||
# pp response
|
||||
result.error = true
|
||||
end
|
||||
end
|
||||
@@ -124,12 +124,16 @@ module W3DHubLauncher
|
||||
result
|
||||
end
|
||||
|
||||
def fetch_news()
|
||||
result = CyberarmEngine::Result.new
|
||||
def fetch_news(category)
|
||||
fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/w3dhub/1/get-news", method: :post, body: "data={\"category\":\"#{category}\"}", headers: headers(form_encoded: true))
|
||||
end
|
||||
|
||||
def fetch_events()
|
||||
result = CyberarmEngine::Result.new
|
||||
def fetch_events(category)
|
||||
fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/w3dhub/1/get-server-events", method: :post, body: "data={\"serverPath\":\"#{category}\"}", headers: headers(form_encoded: true))
|
||||
end
|
||||
|
||||
def fetch_test_events(category)
|
||||
fetch("#{PRIMARY_W3DHUB_API_ENDPOINT}/apis/w3dhub/1/get-testing-times")
|
||||
end
|
||||
|
||||
def fetch_manifest()
|
||||
|
||||
Reference in New Issue
Block a user