Class: Flowdock::Flow
Defined Under Namespace
Classes: ApiError, InvalidParameterError
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#external_user_name ⇒ Object
readonly
Returns the value of attribute external_user_name.
-
#from ⇒ Object
readonly
Returns the value of attribute from.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Flow
constructor
Required options keys: :api_token Optional keys: :external_user_name, :source, :project, :from => { :name, :address }, :reply_to.
- #push_to_chat(params) ⇒ Object
- #push_to_team_inbox(params) ⇒ Object
-
#send_message(params) ⇒ Object
DEPRECATED: Please use
useful
instead.
Constructor Details
#initialize(options = {}) ⇒ Flow
Required options keys: :api_token Optional keys: :external_user_name, :source, :project, :from => { :name, :address }, :reply_to
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/flowdock.rb', line 17 def initialize( = {}) @api_token = if [:api_token].kind_of?(Array) [:api_token].join(",") else [:api_token].to_s end raise InvalidParameterError, "Flow must have :api_token attribute" if blank?(@api_token) @source = [:source] || nil @project = [:project] || nil @from = [:from] || {} @reply_to = [:reply_to] || nil @external_user_name = [:external_user_name] || nil end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
13 14 15 |
# File 'lib/flowdock.rb', line 13 def api_token @api_token end |
#external_user_name ⇒ Object (readonly)
Returns the value of attribute external_user_name.
13 14 15 |
# File 'lib/flowdock.rb', line 13 def external_user_name @external_user_name end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
13 14 15 |
# File 'lib/flowdock.rb', line 13 def from @from end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
13 14 15 |
# File 'lib/flowdock.rb', line 13 def project @project end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
13 14 15 |
# File 'lib/flowdock.rb', line 13 def source @source end |
Instance Method Details
#push_to_chat(params) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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 = (params[:tags].kind_of?(Array)) ? params[:tags] : [] .reject! { |tag| !tag.kind_of?(String) || blank?(tag) } params = { :content => params[:content], :external_user_name => @external_user_name } params[:tags] = .join(",") if .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) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# 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\-_ ]+$/i) @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\-_ ]+$/i) 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 = (params[:tags].kind_of?(Array)) ? params[: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] = .join(",") if .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) ⇒ Object
DEPRECATED: Please use useful
instead.
94 95 96 97 |
# File 'lib/flowdock.rb', line 94 def (params) warn "[DEPRECATION] `send_message` is deprecated. Please use `push_to_team_inbox` instead." push_to_team_inbox(params) end |