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/"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, key: nil) ⇒ PushMore

Returns a new instance of PushMore.



27
28
29
30
# File 'lib/push_more.rb', line 27

def initialize(body, key: nil)
  @body = body
  @key = key || PushMore.configuration.api_key || ENV.fetch("PUSH_MORE_KEY")
end

Class Method Details

.configurationObject



7
8
9
# File 'lib/push_more.rb', line 7

def self.configuration
  @configuration ||= OpenStruct.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



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

def self.configure
  yield(configuration)
end

Instance Method Details

#deliverObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/push_more.rb', line 32

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