class Gameworks::Notifier
Public Instance Methods
configured?()
click to toggle source
# File lib/gameworks/notifier.rb, line 5 def configured? ![app_id, key, secret, base_url].any?(&:nil?) end
push(game, body)
click to toggle source
# File lib/gameworks/notifier.rb, line 9 def push(game, body) return unless configured? uri = URI(build_url(game)) req = Net::HTTP::Post.new(uri) ssl = uri.scheme == 'https' req.basic_auth(key, secret) req.body = body req["Content-Type"] = "application/json" Net::HTTP.start(uri.hostname, uri.port, use_ssl: ssl) do |http| http.request(req) end end
Private Instance Methods
app_id()
click to toggle source
# File lib/gameworks/notifier.rb, line 30 def app_id @app_id ||= ENV["PANDA_PUSH_APP_ID"] end
base_url()
click to toggle source
# File lib/gameworks/notifier.rb, line 42 def base_url @base_url ||= ENV["PANDA_PUSH_URL"] end
build_url(game)
click to toggle source
# File lib/gameworks/notifier.rb, line 26 def build_url(game) "%s/channel/%s/public/games/%s" % [base_url, app_id, game.id] end
key()
click to toggle source
# File lib/gameworks/notifier.rb, line 34 def key @key ||= ENV["PANDA_PUSH_KEY"] end
secret()
click to toggle source
# File lib/gameworks/notifier.rb, line 38 def secret @secret ||= ENV["PANDA_PUSH_SECRET"] end