Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow parameter overriding in posting

  • Loading branch information...
commit 0be97a3f81cd53ca156f7bcb17b6c67b952ce32d 1 parent 9e2e498
Antti Pitkanen authored
Showing with 14 additions and 3 deletions.
  1. +3 −3 lib/flowdock.rb
  2. +11 −0 spec/flowdock_spec.rb
6 lib/flowdock.rb
View
@@ -22,10 +22,10 @@ def initialize(options = {})
end
def push_to_team_inbox(params)
- @source ||= params[:source]
+ @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]
+ @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])
@@ -59,7 +59,7 @@ def push_to_team_inbox(params)
def push_to_chat(params)
raise InvalidParameterError, "Message must have :content" if blank?(params[:content])
- @external_user_name ||= params[:external_user_name]
+ @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
11 spec/flowdock_spec.rb
View
@@ -223,6 +223,17 @@
it "should accept external_user_name in init" do
lambda {
stub_request(:post, push_to_chat_url(@token)).
+ with(:body => @valid_parameters.merge(:tags => "cool,stuff", :external_user_name => "foobar2")).
+ to_return(:body => "", :status => 200)
+
+ @flow = Flowdock::Flow.new(:api_token => @token, :external_user_name => "foobar")
+ @flow.push_to_chat(@valid_parameters.merge(:external_user_name => "foobar2"))
+ }.should_not raise_error
+ end
+
+ it "should allow overriding external_user_name" do
+ lambda {
+ stub_request(:post, push_to_chat_url(@token)).
with(:body => @valid_parameters.merge(:tags => "cool,stuff")).
to_return(:body => "", :status => 200)
Please sign in to comment.
Something went wrong with that request. Please try again.