Skip to content

Commit

Permalink
support posting private messages
Browse files Browse the repository at this point in the history
  • Loading branch information
muffinista committed Mar 27, 2015
1 parent bca78fa commit cb168ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/flowdock.rb
Expand Up @@ -146,6 +146,18 @@ def chat_message(params)
post(event + 's', params.merge(tags: tags, event: event))
end

def private_message(params)
raise InvalidParameterError, "Message must have :content" if blank?(params[:content])
raise InvalidParameterError, "Message must have :user_id" if blank?(params[:user_id])

user_id = params.delete(:user_id)

params = params.clone
event = "message"

post("private/#{user_id}/messages", params.merge(event: event))
end

def post(path, data = {})
resp = self.class.post(api_url(path), :body => MultiJson.dump(data), :basic_auth => {:username => @api_token, :password => ''}, :headers => headers)
handle_response(resp)
Expand Down
10 changes: 10 additions & 0 deletions spec/flowdock_spec.rb
Expand Up @@ -375,6 +375,16 @@ def join_tokens(tokens)
expect(res).to eq({"id" => 1234})
}.not_to raise_error
end
it 'posts to /private/:user_id/messages' do
expect {
stub_request(:post, "https://#{token}:@api.flowdock.com/v1/private/12345/messages").
with(:body => MultiJson.dump(content: "foobar", event: "message"), :headers => {"Accept" => "application/json", "Content-Type" => "application/json"}).
to_return(:status => 201, :body => '{"id":1234}', :headers => {"Content-Type" => "application/json"})
res = client.private_message(user_id: "12345", content: 'foobar')
expect(res).to eq({"id" => 1234})
}.not_to raise_error
end

it 'raises without flow' do
expect {
client.chat_message(content: 'foobar')
Expand Down

0 comments on commit cb168ff

Please sign in to comment.