Sha256: f2a3b466c1a1851b1c09884f3641b4c36058225ae4294376eb5399e6bf63f61f

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require "hall/version"
require "httparty"

module Hall

  class Client
    include HTTParty
    base_uri 'https://hall.com/api/1/'

    # Client initialization
    #
    # Usage:
    #
    #   Hall::Client.new('room_token', 'from_name')
    #
    # Parametrs:
    #
    # +room_token+::  token for your room grab it through the Add integration -> Other or https://hall.com/docs/integrations/generic/
    #
    # +from_name+::  defines the name used for message posting
    #
    # +from_picture+::  optional add picture to the post
    #

    def initialize(room_token, from_name, from_picture = nil)
      @room_token   = room_token
      @from_name    = from_name
      @from_picture = from_picture
    end

    # Post a message.
    #
    # Usage:
    #
    #   post_message 'plain text'
    #
    #
    # Parametrs:
    #
    # +text+::  plain text to be send to the chat

    def post_message(text)
      body ={
        "title"   => @from_name,
        "picture" => @from_picture,
        "message" => text
      }

      self.class.post(room_path, request_options(body))
    end

    private

    def room_path
      '/services/generic/' + @room_token
    end

    def request_options(body)
      {body: body, options: { headers: { 'ContentType' => 'application/json' } } }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hall-0.0.4 lib/hall.rb