Permalink
Browse files

Added reply_to parameter for Inbox messages

  • Loading branch information...
1 parent fa69d9a commit d7560ac850527e3c2b8522890fce4a4547f6625b Antti Pitkanen committed Nov 19, 2012
Showing with 20 additions and 3 deletions.
  1. +6 −1 lib/flowdock.rb
  2. +14 −2 spec/flowdock_spec.rb
View
@@ -12,14 +12,16 @@ class ApiError < StandardError; end
attr_reader :api_token, :source, :project, :from, :external_user_name
- # Required options keys: :api_token, optional keys: :external_user_name, :source, :project, :from => { :name, :address }
+ # Required options keys: :api_token
+ # Optional keys: :external_user_name, :source, :project, :from => { :name, :address }, :reply_to
def initialize(options = {})
@api_token = options[:api_token]
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
@@ -35,6 +37,8 @@ def push_to_team_inbox(params)
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) }
@@ -48,6 +52,7 @@ def push_to_team_inbox(params)
: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)
View
@@ -19,7 +19,7 @@
before(:each) do
@token = "test"
@flow_attributes = {:api_token => @token, :source => "myapp", :project => "myproject",
- :from => {:name => "Eric Example", :address => "eric@example.com"}}
+ :from => {:name => "Eric Example", :address => "eric@example.com"}, :reply_to => "john@example.com" }
@flow = Flowdock::Flow.new(@flow_attributes)
@example_content = "<h1>Hello</h1>\n<p>Let's rock and roll!</p>"
@valid_attributes = {:subject => "Hello World", :content => @example_content,
@@ -66,6 +66,12 @@
}.should raise_error(Flowdock::Flow::InvalidParameterError)
end
+ it "should send without reply_to address" do
+ lambda {
+ @flow.push_to_team_inbox(@valid_attributes.merge(:reply_to => ""))
+ }.should_not raise_error(Flowdock::Flow::InvalidParameterError)
+ end
+
it "should succeed with correct token, source and sender information" do
lambda {
stub_request(:post, push_to_team_inbox_url(@token)).
@@ -74,6 +80,7 @@
:format => "html",
:from_name => "Eric Example",
:from_address => "eric@example.com",
+ :reply_to => "john@example.com",
:subject => "Hello World",
:content => @example_content,
:tags => "cool,stuff",
@@ -94,6 +101,7 @@
:project => "myproject",
:format => "html",
:from_address => "eric@example.com",
+ :reply_to => "john@example.com",
:subject => "Hello World",
:content => @example_content,
:tags => "cool,stuff",
@@ -114,6 +122,7 @@
:format => "html",
:from_name => "Eric Example",
:from_address => "eric@example.com",
+ :reply_to => "john@example.com",
:subject => "Hello World",
:content => @example_content,
:tags => "cool,stuff",
@@ -134,6 +143,7 @@
:format => "html",
:from_name => "Eric Example",
:from_address => "eric@example.com",
+ :reply_to => "john@example.com",
:subject => "Hello World",
:content => @example_content,
:tags => "cool,stuff",
@@ -155,14 +165,15 @@
:format => "html",
:from_name => "Test",
:from_address => "invalid@nodeta.fi",
+ :reply_to => "foobar@example.com",
:subject => "Hello World",
:content => @example_content,
:tags => "cool,stuff",
}).
to_return(:body => "", :status => 200)
@flow.push_to_team_inbox(:subject => "Hello World", :content => @example_content, :tags => ["cool", "stuff"],
- :from => {:name => "Test", :address => "invalid@nodeta.fi"}).should be_true
+ :from => {:name => "Test", :address => "invalid@nodeta.fi"}, :reply_to => "foobar@example.com").should be_true
}.should_not raise_error
end
@@ -175,6 +186,7 @@
:format => "html",
:from_name => "Eric Example",
:from_address => "eric@example.com",
+ :reply_to => "john@example.com",
:subject => "Hello World",
:content => @example_content
}).

0 comments on commit d7560ac

Please sign in to comment.