Class: Flowdock::Flow
- Inherits:
-
Object
- Object
- Flowdock::Flow
- Includes:
- Helpers, HTTParty
- Defined in:
- lib/flowdock.rb
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.
Methods included from Helpers
Constructor Details
#initialize(options = {}) ⇒ Flow
Required options keys: :api_token Optional keys: :external_user_name, :source, :project, :from => { :name, :address }, :reply_to
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/flowdock.rb', line 43 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.
39 40 41 |
# File 'lib/flowdock.rb', line 39 def api_token @api_token end |
#external_user_name ⇒ Object (readonly)
Returns the value of attribute external_user_name.
39 40 41 |
# File 'lib/flowdock.rb', line 39 def external_user_name @external_user_name end |
#from ⇒ Object (readonly)
Returns the value of attribute from.
39 40 41 |
# File 'lib/flowdock.rb', line 39 def from @from end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
39 40 41 |
# File 'lib/flowdock.rb', line 39 def project @project end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
39 40 41 |
# File 'lib/flowdock.rb', line 39 def source @source end |
Instance Method Details
#push_to_chat(params) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/flowdock.rb', line 96 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) } thread_id = params[:thread_id] = params[:message_id] || params[:message] params = { :content => params[:content], :external_user_name => @external_user_name } params[:tags] = .join(",") if .size > 0 params[:thread_id] = thread_id if thread_id params[:message_id] = if # 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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/flowdock.rb', line 58 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.
124 125 126 127 |
# File 'lib/flowdock.rb', line 124 def (params) warn "[DEPRECATION] `send_message` is deprecated. Please use `push_to_team_inbox` instead." push_to_team_inbox(params) end |