Sha256: 77246183d459f5a62996548b97568c567bc7049e1e949f0ab6e7091ce47502e6
Contents?: true
Size: 862 Bytes
Versions: 3
Compression:
Stored size: 862 Bytes
Contents
# frozen_string_literal: true require 'net/http' module Hahamut # Chat Message Sender class Sender ENDPOINT = 'https://us-central1-hahamut-8888.cloudfunctions.net/' \ 'messagePush?access_token=%<token>s' def initialize(token) @token = token end def uri @uri ||= URI(format(ENDPOINT, token: @token)) end def ssl? uri.scheme == 'https' end def send(recipient, message) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = ssl? http.request build_request(recipient, message) end private def build_request(recipient, message) @request = Net::HTTP::Post.new(uri) @request['Content-Type'] = 'application/json' @request.body = { recipient: { id: recipient }, message: message }.to_json @request end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hahamut-0.1.2 | lib/hahamut/sender.rb |
hahamut-0.1.1 | lib/hahamut/sender.rb |
hahamut-0.1.0 | lib/hahamut/sender.rb |