Class: HangoutsChat::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/hangouts_chat.rb,
lib/hangouts_chat/http.rb,
lib/hangouts_chat/exceptions.rb

Overview

Provide methods to send messages to Hangouts Chat rooms using webhooks API

Defined Under Namespace

Classes: APIError, HTTP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(webhook_url) ⇒ Sender

Creates Sender object

Parameters:

  • webhook_url (String)

    URL for incoming webhook



14
15
16
17
# File 'lib/hangouts_chat.rb', line 14

def initialize(webhook_url)
  @url = webhook_url
  @http = HTTP.new(@url)
end

Instance Attribute Details

#urlString (readonly)

Returns Webhook URL, given on initialization.

Returns:

  • (String)

    Webhook URL, given on initialization



10
11
12
# File 'lib/hangouts_chat.rb', line 10

def url
  @url
end

Instance Method Details

#card(header, sections) ⇒ Net::HTTPResponse

Sends Card Message

Parameters:

  • header (Hash)

    card header content

  • sections (Array<Hash>)

    card widgets array

Returns:

  • (Net::HTTPResponse)

    response object

Since:

  • 0.0.4



32
33
34
35
# File 'lib/hangouts_chat.rb', line 32

def card(header, sections)
  payload = { cards: [header: header, sections: sections] }
  send_request(payload)
end

#simple(text) ⇒ Net::HTTPResponse

Sends Simple Text Message

Parameters:

  • text (String)

    text to send to room

Returns:

  • (Net::HTTPResponse)

    response object



22
23
24
25
# File 'lib/hangouts_chat.rb', line 22

def simple(text)
  payload = { text: text }
  send_request(payload)
end