Class: Hahamut::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/hahamut/sender.rb

Overview

Chat Message Sender

Constant Summary collapse

ENDPOINT =
'https://us-central1-hahamut-8888.cloudfunctions.net/' \
'messagePush?access_token=%<token>s'

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Sender

Returns a new instance of Sender.



11
12
13
# File 'lib/hahamut/sender.rb', line 11

def initialize(token)
  @token = token
end

Instance Method Details

#send(recipient, message) ⇒ Object



23
24
25
26
27
# File 'lib/hahamut/sender.rb', line 23

def send(recipient, message)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = ssl?
  http.request build_request(recipient, message)
end

#ssl?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/hahamut/sender.rb', line 19

def ssl?
  uri.scheme == 'https'
end

#uriObject



15
16
17
# File 'lib/hahamut/sender.rb', line 15

def uri
  @uri ||= URI(format(ENDPOINT, token: @token))
end