Browse files

Support pushing to multiple flows

  • Loading branch information...
1 parent 5fb742c commit d9f2ebf0edecd25afe595b71179f79824a111926 Antti Pitkanen committed Mar 15, 2013
Showing with 43 additions and 3 deletions.
  1. +5 −1 lib/flowdock.rb
  2. +38 −2 spec/flowdock_spec.rb
View
6 lib/flowdock.rb
@@ -15,7 +15,11 @@ class ApiError < StandardError; end
# 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]
+ @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
View
40 spec/flowdock_spec.rb
@@ -13,6 +13,12 @@
@flow = Flowdock::Flow.new(:api_token => "")
}.should raise_error(Flowdock::Flow::InvalidParameterError)
end
+
+ it "should succeed with array of tokens" do
+ lambda {
+ @flow = Flowdock::Flow.new(:api_token => ["test", "foobar"])
+ }.should_not raise_error
+ end
end
describe "with sending Team Inbox messages" do
@@ -93,6 +99,28 @@
}.should_not raise_error
end
+ it "should succeed with correct params and multiple tokens" do
+ lambda {
+ tokens = ["test", "foobar"]
+ stub_request(:post, push_to_team_inbox_url(tokens)).
+ with(:body => {
+ :source => "myapp",
+ :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",
+ :link => "http://www.flowdock.com/"
+ }).
+ to_return(:body => "", :status => 200)
+
+ @flow = Flowdock::Flow.new(@flow_attributes.merge(:project => "", :api_token => tokens))
+ @flow.push_to_team_inbox(@valid_attributes)
+ }.should_not raise_error
+ end
+
it "should succeed without the optional from-name parameter" do
lambda {
stub_request(:post, push_to_team_inbox_url(@token)).
@@ -267,10 +295,18 @@
end
def push_to_chat_url(token)
- "#{Flowdock::FLOWDOCK_API_URL}/messages/chat/#{token}"
+ "#{Flowdock::FLOWDOCK_API_URL}/messages/chat/#{join_tokens(token)}"
end
def push_to_team_inbox_url(token)
- "#{Flowdock::FLOWDOCK_API_URL}/messages/team_inbox/#{token}"
+ "#{Flowdock::FLOWDOCK_API_URL}/messages/team_inbox/#{join_tokens(token)}"
+ end
+
+ def join_tokens(tokens)
+ if tokens.kind_of?(Array)
+ tokens.join(",")
+ else
+ tokens.to_s
+ end
end
end

0 comments on commit d9f2ebf

Please sign in to comment.