Class: Gameworks::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/gameworks/notifier.rb

Instance Method Summary collapse

Instance Method Details

#configured?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/gameworks/notifier.rb', line 5

def configured?
  ![app_id, key, secret, base_url].any?(&:nil?)
end

#push(game, body) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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