Class: PushMore

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

Constant Summary collapse

WEBHOOK_BASE_URL =

Send notifcations to Telegram through PushMore.io

Example:

>> PushMore.new("hello world!", key: "foobar123").deliver
=> true

Arguments:

body: (String)
key: (String)
"https://pushmore.io/webhook/"

Instance Method Summary collapse

Constructor Details

#initialize(body, key: ENV.fetch("PUSH_MORE_KEY")) ⇒ PushMore

Returns a new instance of PushMore.



18
19
20
21
# File 'lib/push_more.rb', line 18

def initialize(body, key: ENV.fetch("PUSH_MORE_KEY"))
  @body = body
  @key = key
end

Instance Method Details

#deliverObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/push_more.rb', line 23

def deliver
  http = Net::HTTP.new(webhook_uri.host, webhook_uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER

  request = Net::HTTP::Post.new(webhook_uri.request_uri)
  request.body = @body

  response = http.request(request)

  if response.body.include? "Error"
    raise response.body
  else
    true
  end
end