In Files

Parent

Included Modules

Files

Class/Module Index [+]

Quicksearch

Flowdock::Flow

Attributes

api_token[R]
external_user_name[R]
from[R]
project[R]
source[R]

Public Class Methods

new(options = {}) click to toggle source

Required options keys: :api_token Optional keys: :external_user_name, :source, :project, :from => { :name, :address }, :reply_to

# File lib/flowdock.rb, line 17
def initialize(options = {})
  @api_token = if options[:api_token].kind_of?(Array)
    options[:api_token].join(",")
  else
    options[:api_token].to_s
  end
  raise InvalidParameterError, "Flow must have :api_token attribute" if blank?(@api_token)

  @source = options[:source] || nil
  @project = options[:project] || nil
  @from = options[:from] || {}
  @reply_to = options[:reply_to] || nil
  @external_user_name = options[:external_user_name] || nil
end

Public Instance Methods

push_to_chat(params) click to toggle source
# File lib/flowdock.rb, line 70
def push_to_chat(params)
  raise InvalidParameterError, "Message must have :content" if blank?(params[:content])

  @external_user_name = params[:external_user_name] unless blank?(params[:external_user_name])
  if blank?(@external_user_name) || @external_user_name.match(/^[\S]+$/).nil? || @external_user_name.length > 16
    raise InvalidParameterError, "Message must have :external_user_name that has no whitespace and maximum of 16 characters"
  end

  tags = (params[:tags].kind_of?(Array)) ? params[:tags] : []
  tags.reject! { |tag| !tag.kind_of?(String) || blank?(tag) }

  params = {
    :content => params[:content],
    :external_user_name => @external_user_name
  }
  params[:tags] = tags.join(",") if tags.size > 0

  # Send the request
  resp = self.class.post(get_flowdock_api_url("messages/chat"), :body => params)
  handle_response(resp)
  true
end
push_to_team_inbox(params) click to toggle source
# File lib/flowdock.rb, line 32
def push_to_team_inbox(params)
  @source = params[:source] unless blank?(params[:source])
  raise InvalidParameterError, "Message must have valid :source attribute, only alphanumeric characters and underscores can be used" if blank?(@source) || !@source.match(/^[a-z0-9\-_ ]+$/)

  @project = params[:project] unless blank?(params[:project])
  raise InvalidParameterError, "Optional attribute :project can only contain alphanumeric characters and underscores" if !blank?(@project) && !@project.match(/^[a-z0-9\-_ ]+$/)

  raise InvalidParameterError, "Message must have both :subject and :content" if blank?(params[:subject]) || blank?(params[:content])

  from = (params[:from].kind_of?(Hash)) ? params[:from] : @from
  raise InvalidParameterError, "Message's :from attribute must have :address attribute" if blank?(from[:address])

  reply_to = (!blank?(params[:reply_to])) ? params[:reply_to] : @reply_to

  tags = (params[:tags].kind_of?(Array)) ? params[:tags] : []
  tags.reject! { |tag| !tag.kind_of?(String) || blank?(tag) }

  link = (!blank?(params[:link])) ? params[:link] : nil

  params = {
    :source => @source,
    :format => 'html', # currently only supported format
    :from_address => from[:address],
    :subject => params[:subject],
    :content => params[:content],
  }
  params[:from_name] = from[:name] unless blank?(from[:name])
  params[:reply_to] = reply_to unless blank?(reply_to)
  params[:tags] = tags.join(",") if tags.size > 0
  params[:project] = @project unless blank?(@project)
  params[:link] = link unless blank?(link)

  # Send the request
  resp = self.class.post(get_flowdock_api_url("messages/team_inbox"), :body => params)
  handle_response(resp)
  true
end
send_message(params) click to toggle source

DEPRECATED: Please use useful instead.

# File lib/flowdock.rb, line 94
def send_message(params)
  warn "[DEPRECATION] `send_message` is deprecated.  Please use `push_to_team_inbox` instead."
  push_to_team_inbox(params)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.