flowdock 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/README.md +65 -30
- data/VERSION +1 -1
- data/flowdock.gemspec +4 -4
- data/lib/flowdock.rb +14 -3
- data/spec/flowdock_spec.rb +117 -98
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e8c2164455898ff017ff0cbe2a0fe9c0615de15
|
4
|
+
data.tar.gz: 67af9f77904b26d42864b709d1a8ed112bc4009c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20cf692d3e6f09405972d71b9888fd60c3eac5e27978a63c545f4e9d2ac782e390a33cf8773be14d5592d498f079557b92d195178c8d078711cf56c3469723a7
|
7
|
+
data.tar.gz: fea63857c0f2130a68f79f634a9c17feba1b46022efe437adb383499d14136aad8cb421d5e2c71ca103f0e83b2a7a9b9b59606b16f9d8a89dc183be1ebc47681
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Flowdock
|
2
2
|
|
3
|
-
Ruby
|
3
|
+
Ruby gem for using the Flowdock Push API. See the [Push API documentation](http://www.flowdock.com/api/push) for details.
|
4
4
|
|
5
5
|
## Build Status
|
6
6
|
|
7
7
|
[](http://travis-ci.org/flowdock/flowdock-api)
|
8
8
|
|
9
|
-
|
9
|
+
The Flowdock gem is tested on Ruby 2.1 and JRuby.
|
10
10
|
|
11
11
|
## Dependencies
|
12
12
|
|
@@ -17,47 +17,78 @@ flowdock gem is tested on Ruby 1.9.3 and JRuby.
|
|
17
17
|
|
18
18
|
gem install flowdock
|
19
19
|
|
20
|
-
If you're using JRuby, you'll also need to install jruby-openssl gem.
|
20
|
+
If you're using JRuby, you'll also need to install the `jruby-openssl` gem.
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
To post content to
|
24
|
+
To post content to a flow's chat or team inbox using `Flowdock::Flow`, you need to use the target flow's API token or a source's flow_token.
|
25
25
|
|
26
|
-
Alternatively you can use your personal
|
26
|
+
Alternatively, you can use your personal API token and the `Flowdock::Client`.
|
27
27
|
|
28
|
-
|
28
|
+
Personal and flow's tokens can be found on the [tokens page](https://www.flowdock.com/account/tokens).
|
29
29
|
|
30
30
|
### REST API
|
31
31
|
|
32
|
-
To create an
|
32
|
+
To create an API client, you need your personal [API token](https://flowdock.com/account/tokens), an [OAuth token](https://www.flowdock.com/api/authentication) or a [source's flow_token](https://www.flowdock.com/api/sources).
|
33
|
+
|
34
|
+
Note that a `flow_token` will only allow you to post [thread messages](https://www.flowdock.com/api/production-integrations#/post-inbox) to the flow that the source belongs to.
|
33
35
|
|
34
36
|
```ruby
|
35
37
|
require 'rubygems'
|
36
38
|
require 'flowdock'
|
37
39
|
|
38
|
-
# Create a client that uses
|
39
|
-
|
40
|
+
# Create a client that uses your personal API token to authenticate
|
41
|
+
api_token_client = Flowdock::Client.new(api_token: '__MY_PERSONAL_API_TOKEN__')
|
42
|
+
|
43
|
+
# Create a client that uses a source's flow_token to authenticate. Can only use post_to_thread
|
44
|
+
flow_token_client = Flowdock::Client.new(flow_token: '__FLOW_TOKEN__')
|
40
45
|
```
|
41
46
|
|
42
47
|
#### Posting to Chat
|
43
48
|
|
44
|
-
To send a chat message or comment, you can use
|
49
|
+
To send a chat message or comment, you can use `client.chat_message`:
|
45
50
|
|
46
51
|
```ruby
|
47
52
|
flow_id = 'acdcabbacd0123456789'
|
48
53
|
|
49
54
|
# Send a simple chat message
|
50
|
-
|
55
|
+
api_token_client.chat_message(flow: flow_id, content: "I'm sending a message!", tags: ['foo', 'bar'])
|
51
56
|
|
52
57
|
# Send a comment to message 1234
|
53
|
-
|
58
|
+
api_token_client.chat_message(flow: flow_id, content: "Now I'm commenting!", message: 1234)
|
54
59
|
```
|
55
60
|
|
56
61
|
Both methods return the created message as a hash.
|
57
62
|
|
58
|
-
####
|
63
|
+
#### Post a threaded messages
|
64
|
+
|
65
|
+
You can post `activity` and `discussion` events to a [threaded conversation](https://www.flowdock.com/api/integration-getting-started) in Flowdock.
|
66
|
+
|
67
|
+
```
|
68
|
+
flow_token_client.post_to_thread(
|
69
|
+
event: "activity",
|
70
|
+
author: {
|
71
|
+
name: "anttipitkanen",
|
72
|
+
avatar: "https://avatars.githubusercontent.com/u/946511?v=2",
|
73
|
+
},
|
74
|
+
title: "activity title",
|
75
|
+
external_thread_id: "your-id-here",
|
76
|
+
thread: {
|
77
|
+
title: "this is required if you provide a thread field at all",
|
78
|
+
body: "<p>some html content</p>",
|
79
|
+
external_url: "https://example.com/issue/123",
|
80
|
+
status: {
|
81
|
+
color: "green",
|
82
|
+
value: "open"
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
```
|
59
87
|
|
60
|
-
|
88
|
+
|
89
|
+
#### Arbitary API access
|
90
|
+
|
91
|
+
You can use the client to access the Flowdock API in other ways, too. See the [REST API documentation](http://www.flowdock.com/api/rest) for all the resources.
|
61
92
|
|
62
93
|
```ruby
|
63
94
|
|
@@ -75,32 +106,34 @@ client.post('/flows/acme/my_flow/invitations', email: 'user@example.com', messag
|
|
75
106
|
|
76
107
|
```
|
77
108
|
|
78
|
-
### Push
|
109
|
+
### Push API
|
79
110
|
|
80
|
-
|
111
|
+
**Note:** the Push API is in the process of being deprecated. [Creating a source](https://www.flowdock.com/api/integration-getting-started) along with a flow_token is recommended instead.
|
81
112
|
|
82
|
-
|
113
|
+
To use the Push API, you need the flow's API token:
|
114
|
+
|
115
|
+
#### Posting to the chat
|
83
116
|
|
84
117
|
```ruby
|
85
118
|
require 'rubygems'
|
86
119
|
require 'flowdock'
|
87
120
|
|
88
|
-
# create a new Flow object with target flow's
|
89
|
-
flow = Flowdock::Flow.new(:api_token => "
|
121
|
+
# create a new Flow object with target flow's API token and external user name (enough for posting to the chat)
|
122
|
+
flow = Flowdock::Flow.new(:api_token => "__FLOW_API_TOKEN__", :external_user_name => "John")
|
90
123
|
|
91
124
|
# send message to Chat
|
92
125
|
flow.push_to_chat(:content => "Hello!", :tags => ["cool", "stuff"])
|
93
126
|
```
|
94
127
|
|
95
|
-
#### Posting to
|
128
|
+
#### Posting to the team inbox
|
96
129
|
|
97
130
|
```ruby
|
98
|
-
# create a new Flow object with target flow's
|
99
|
-
flow = Flowdock::Flow.new(:api_token => "
|
131
|
+
# create a new Flow object with the target flow's API token and sender information
|
132
|
+
flow = Flowdock::Flow.new(:api_token => "__FLOW_API_TOKEN__",
|
100
133
|
:source => "myapp", :from => {:name => "John Doe", :address => "john.doe@example.com"})
|
101
134
|
|
102
135
|
# send message to Team Inbox
|
103
|
-
flow.push_to_team_inbox(:subject => "Greetings from Flowdock API
|
136
|
+
flow.push_to_team_inbox(:subject => "Greetings from the Flowdock API gem!",
|
104
137
|
:content => "<h2>It works!</h2><p>Now you can start developing your awesome application for Flowdock.</p>",
|
105
138
|
:tags => ["cool", "stuff"], :link => "http://www.flowdock.com/")
|
106
139
|
```
|
@@ -111,25 +144,27 @@ flow.push_to_team_inbox(:subject => "Greetings from Flowdock API Gem!",
|
|
111
144
|
require 'rubygems'
|
112
145
|
require 'flowdock'
|
113
146
|
|
114
|
-
# create a new Flow object with the
|
115
|
-
flow = Flowdock::Flow.new(:api_token => ["
|
147
|
+
# create a new Flow object with the API tokens of the target flows
|
148
|
+
flow = Flowdock::Flow.new(:api_token => ["__FLOW_API_TOKEN__", "__ANOTHER_FLOW_API_TOKEN__"], ... )
|
116
149
|
|
117
|
-
# see above examples of posting to
|
150
|
+
# see the above examples of posting to the chat or team inbox
|
118
151
|
```
|
119
152
|
|
120
153
|
## API methods
|
121
154
|
|
122
155
|
* `Flowdock::Flow` methods
|
123
156
|
|
124
|
-
`push_to_team_inbox` - Send message to
|
157
|
+
`push_to_team_inbox` - Send message to the team inbox. See [API documentation](http://www.flowdock.com/api/team-inbox) for details.
|
125
158
|
|
126
|
-
`push_to_chat` - Send message to
|
159
|
+
`push_to_chat` - Send message to the chat. See [API documentation](http://www.flowdock.com/api/chat) for details.
|
127
160
|
|
128
161
|
`send_message(params)` - Deprecated. Please use `push_to_team_inbox` instead.
|
129
162
|
|
130
163
|
* `Flowdock::Client` methods
|
131
164
|
|
132
|
-
`chat_message` - Send message to
|
165
|
+
`chat_message` - Send message to chat.
|
166
|
+
|
167
|
+
`post_to_thread` - Post messages to a team inbox thread.
|
133
168
|
|
134
169
|
`post`, `get`, `put`, `delete` - Send arbitary api calls. First parameter is the path, second is data. See [REST API documentation](http://www.flowdock.com/api/rest).
|
135
170
|
|
@@ -142,7 +177,7 @@ There are separate gems for deployment notifications:
|
|
142
177
|
|
143
178
|
## Changelog
|
144
179
|
|
145
|
-
* 0.5.0 - Added `Flowdock::Client` that authenticates using user credentials and can be used to interact with the
|
180
|
+
* 0.5.0 - Added `Flowdock::Client` that authenticates using user credentials and can be used to interact with the API. Better threads support for both `Flow` and `Client` so that comments can be made.
|
146
181
|
|
147
182
|
## Copyright
|
148
183
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/flowdock.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: flowdock 0.
|
5
|
+
# stub: flowdock 0.7.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "flowdock"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.7.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Antti Pitk\u{e4}nen"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2015-07-21"
|
15
15
|
s.email = "team@flowdock.com"
|
16
16
|
s.extra_rdoc_files = [
|
17
17
|
"LICENSE",
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
]
|
35
35
|
s.homepage = "http://github.com/flowdock/flowdock-api"
|
36
36
|
s.licenses = ["MIT"]
|
37
|
-
s.rubygems_version = "2.
|
37
|
+
s.rubygems_version = "2.4.1"
|
38
38
|
s.summary = "Ruby Gem for using Flowdock's API"
|
39
39
|
|
40
40
|
if s.respond_to? :specification_version then
|
data/lib/flowdock.rb
CHANGED
@@ -132,10 +132,12 @@ module Flowdock
|
|
132
132
|
attr_reader :api_token
|
133
133
|
def initialize(options = {})
|
134
134
|
@api_token = options[:api_token]
|
135
|
-
|
135
|
+
@flow_token = options[:flow_token]
|
136
|
+
raise InvalidParameterError, "Client must have :api_token or an :flow_token" if blank?(@api_token) && blank?(@flow_token)
|
136
137
|
end
|
137
138
|
|
138
139
|
def chat_message(params)
|
140
|
+
raise InvalidParameterError, "missing api_token" if blank?(@api_token)
|
139
141
|
raise InvalidParameterError, "Message must have :content" if blank?(params[:content])
|
140
142
|
raise InvalidParameterError, "Message must have :flow" if blank?(params[:flow])
|
141
143
|
params = params.clone
|
@@ -147,17 +149,26 @@ module Flowdock
|
|
147
149
|
end
|
148
150
|
|
149
151
|
def private_message(params)
|
152
|
+
raise InvalidParameterError, "missing api_token" if blank?(@api_token)
|
150
153
|
raise InvalidParameterError, "Message must have :content" if blank?(params[:content])
|
151
154
|
raise InvalidParameterError, "Message must have :user_id" if blank?(params[:user_id])
|
152
155
|
|
153
156
|
user_id = params.delete(:user_id)
|
154
|
-
|
157
|
+
|
155
158
|
params = params.clone
|
156
159
|
event = "message"
|
157
160
|
|
158
161
|
post("private/#{user_id}/messages", params.merge(event: event))
|
159
162
|
end
|
160
|
-
|
163
|
+
|
164
|
+
def post_to_thread(thread)
|
165
|
+
raise InvalidParameterError, "missing flow_token" if blank?(@flow_token)
|
166
|
+
resp = self.class.post(api_url("/messages"),
|
167
|
+
body: MultiJson.dump(thread.merge(flow_token: @flow_token)),
|
168
|
+
headers: headers)
|
169
|
+
handle_response resp
|
170
|
+
end
|
171
|
+
|
161
172
|
def post(path, data = {})
|
162
173
|
resp = self.class.post(api_url(path), :body => MultiJson.dump(data), :basic_auth => {:username => @api_token, :password => ''}, :headers => headers)
|
163
174
|
handle_response(resp)
|
data/spec/flowdock_spec.rb
CHANGED
@@ -73,9 +73,10 @@ describe Flowdock do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should send without reply_to address" do
|
76
|
-
|
76
|
+
expect {
|
77
|
+
stub_request(:post, push_to_team_inbox_url(@token)).to_return(:body => "", :status => 200)
|
77
78
|
@flow.push_to_team_inbox(@valid_attributes.merge(:reply_to => ""))
|
78
|
-
}.
|
79
|
+
}.not_to raise_error
|
79
80
|
end
|
80
81
|
|
81
82
|
it "should succeed with correct token, source and sender information" do
|
@@ -180,7 +181,7 @@ describe Flowdock do
|
|
180
181
|
to_return(:body => "", :status => 200)
|
181
182
|
|
182
183
|
@flow.push_to_team_inbox(:subject => "Hello World", :content => @example_content,
|
183
|
-
:tags => ["cool", "stuff"], :link => "http://www.flowdock.com/").should
|
184
|
+
:tags => ["cool", "stuff"], :link => "http://www.flowdock.com/").should be_truthy
|
184
185
|
}.should_not raise_error
|
185
186
|
end
|
186
187
|
|
@@ -201,7 +202,7 @@ describe Flowdock do
|
|
201
202
|
to_return(:body => "", :status => 200)
|
202
203
|
|
203
204
|
@flow.push_to_team_inbox(:subject => "Hello World", :content => @example_content, :tags => ["cool", "stuff"],
|
204
|
-
:from => {:name => "Test", :address => "invalid@nodeta.fi"}, :reply_to => "foobar@example.com").should
|
205
|
+
:from => {:name => "Test", :address => "invalid@nodeta.fi"}, :reply_to => "foobar@example.com").should be_truthy
|
205
206
|
}.should_not raise_error
|
206
207
|
end
|
207
208
|
|
@@ -256,7 +257,7 @@ describe Flowdock do
|
|
256
257
|
with(:body => @valid_parameters.merge(:tags => "cool,stuff")).
|
257
258
|
to_return(:body => "", :status => 200)
|
258
259
|
|
259
|
-
@flow.push_to_chat(@valid_parameters).should
|
260
|
+
@flow.push_to_chat(@valid_parameters).should be_truthy
|
260
261
|
}.should_not raise_error
|
261
262
|
end
|
262
263
|
|
@@ -335,111 +336,129 @@ end
|
|
335
336
|
|
336
337
|
describe Flowdock::Client do
|
337
338
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
expect {
|
351
|
-
client = Flowdock::Client.new(api_token: nil)
|
352
|
-
}.to raise_error(Flowdock::InvalidParameterError)
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
describe 'posting to chat' do
|
357
|
-
|
358
|
-
let(:flow) { SecureRandom.hex(8) }
|
359
|
-
|
360
|
-
it 'posts to /messages' do
|
361
|
-
expect {
|
362
|
-
stub_request(:post, "https://#{token}:@api.flowdock.com/v1/messages").
|
363
|
-
with(:body => MultiJson.dump(flow: flow, content: "foobar", tags: [], event: "message"), :headers => {"Accept" => "application/json", "Content-Type" => "application/json"}).
|
364
|
-
to_return(:status => 201, :body => '{"id":123}', :headers => {"Content-Type" => "application/json"})
|
365
|
-
res = client.chat_message(flow: flow, content: 'foobar')
|
339
|
+
context "with flow_token" do
|
340
|
+
let(:token) { SecureRandom.hex }
|
341
|
+
let(:client) { Flowdock::Client.new(flow_token: token) }
|
342
|
+
let(:flow) { SecureRandom.hex }
|
343
|
+
|
344
|
+
describe "post a threaded message" do
|
345
|
+
it "succeeds" do
|
346
|
+
stub_request(:post, "https://api.flowdock.com/v1/messages").
|
347
|
+
with(body: MultiJson.dump(flow: flow, flow_token: token),
|
348
|
+
headers: {"Accept" => "application/json", "Content-Type" => "application/json"}).
|
349
|
+
to_return(status: 201, body: '{"id":123}', headers: {"Content-Type" => "application/json"})
|
350
|
+
res = client.post_to_thread({flow: flow})
|
366
351
|
expect(res).to eq({"id" => 123})
|
367
|
-
|
368
|
-
end
|
369
|
-
it 'posts to /comments' do
|
370
|
-
expect {
|
371
|
-
stub_request(:post, "https://#{token}:@api.flowdock.com/v1/comments").
|
372
|
-
with(:body => MultiJson.dump(flow: flow, content: "foobar", message: 12345, tags: [], event: "comment"), :headers => {"Accept" => "application/json", "Content-Type" => "application/json"}).
|
373
|
-
to_return(:status => 201, :body => '{"id":1234}', :headers => {"Content-Type" => "application/json"})
|
374
|
-
res = client.chat_message(flow: flow, content: 'foobar', message: 12345)
|
375
|
-
expect(res).to eq({"id" => 1234})
|
376
|
-
}.not_to raise_error
|
377
|
-
end
|
378
|
-
it 'posts to /private/:user_id/messages' do
|
379
|
-
expect {
|
380
|
-
stub_request(:post, "https://#{token}:@api.flowdock.com/v1/private/12345/messages").
|
381
|
-
with(:body => MultiJson.dump(content: "foobar", event: "message"), :headers => {"Accept" => "application/json", "Content-Type" => "application/json"}).
|
382
|
-
to_return(:status => 201, :body => '{"id":1234}', :headers => {"Content-Type" => "application/json"})
|
383
|
-
res = client.private_message(user_id: "12345", content: 'foobar')
|
384
|
-
expect(res).to eq({"id" => 1234})
|
385
|
-
}.not_to raise_error
|
352
|
+
end
|
386
353
|
end
|
354
|
+
end
|
387
355
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
356
|
+
context "with api_token" do
|
357
|
+
let(:token) { SecureRandom.hex(8) }
|
358
|
+
let(:client) { Flowdock::Client.new(api_token: token) }
|
359
|
+
|
360
|
+
describe 'initializing' do
|
361
|
+
|
362
|
+
it 'should initialize with access token' do
|
363
|
+
expect {
|
364
|
+
client = Flowdock::Client.new(api_token: token)
|
365
|
+
expect(client.api_token).to equal(token)
|
366
|
+
}.not_to raise_error
|
367
|
+
end
|
368
|
+
it 'should raise error if initialized without access token' do
|
369
|
+
expect {
|
370
|
+
client = Flowdock::Client.new(api_token: nil)
|
371
|
+
}.to raise_error(Flowdock::InvalidParameterError)
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
describe 'posting to chat' do
|
376
|
+
|
377
|
+
let(:flow) { SecureRandom.hex(8) }
|
378
|
+
|
379
|
+
it 'posts to /messages' do
|
380
|
+
expect {
|
381
|
+
stub_request(:post, "https://#{token}:@api.flowdock.com/v1/messages").
|
382
|
+
with(:body => MultiJson.dump(flow: flow, content: "foobar", tags: [], event: "message"), :headers => {"Accept" => "application/json", "Content-Type" => "application/json"}).
|
383
|
+
to_return(:status => 201, :body => '{"id":123}', :headers => {"Content-Type" => "application/json"})
|
384
|
+
res = client.chat_message(flow: flow, content: 'foobar')
|
385
|
+
expect(res).to eq({"id" => 123})
|
386
|
+
}.not_to raise_error
|
387
|
+
end
|
388
|
+
it 'posts to /comments' do
|
389
|
+
expect {
|
390
|
+
stub_request(:post, "https://#{token}:@api.flowdock.com/v1/comments").
|
391
|
+
with(:body => MultiJson.dump(flow: flow, content: "foobar", message: 12345, tags: [], event: "comment"), :headers => {"Accept" => "application/json", "Content-Type" => "application/json"}).
|
392
|
+
to_return(:status => 201, :body => '{"id":1234}', :headers => {"Content-Type" => "application/json"})
|
393
|
+
res = client.chat_message(flow: flow, content: 'foobar', message: 12345)
|
394
|
+
expect(res).to eq({"id" => 1234})
|
395
|
+
}.not_to raise_error
|
396
|
+
end
|
397
|
+
it 'posts to /private/:user_id/messages' do
|
398
|
+
expect {
|
399
|
+
stub_request(:post, "https://#{token}:@api.flowdock.com/v1/private/12345/messages").
|
400
|
+
with(:body => MultiJson.dump(content: "foobar", event: "message"), :headers => {"Accept" => "application/json", "Content-Type" => "application/json"}).
|
401
|
+
to_return(:status => 201, :body => '{"id":1234}', :headers => {"Content-Type" => "application/json"})
|
402
|
+
res = client.private_message(user_id: "12345", content: 'foobar')
|
403
|
+
expect(res).to eq({"id" => 1234})
|
404
|
+
}.not_to raise_error
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'raises without flow' do
|
408
|
+
expect {
|
409
|
+
client.chat_message(content: 'foobar')
|
410
|
+
}.to raise_error(Flowdock::InvalidParameterError)
|
411
|
+
end
|
412
|
+
it 'raises without content' do
|
413
|
+
expect {
|
414
|
+
client.chat_message(flow: flow)
|
415
|
+
}.to raise_error(Flowdock::InvalidParameterError)
|
416
|
+
end
|
417
|
+
it 'handles error responses' do
|
418
|
+
expect {
|
419
|
+
stub_request(:post, "https://#{token}:@api.flowdock.com/v1/messages").
|
420
|
+
to_return(:body => '{"message":"Validation error","errors":{"content":["can\'t be blank"],"external_user_name":["should not contain whitespace"]}}',
|
421
|
+
:status => 400)
|
403
422
|
client.chat_message(flow: flow, content: 'foobar')
|
404
|
-
|
423
|
+
}.to raise_error(Flowdock::ApiError)
|
424
|
+
end
|
405
425
|
end
|
406
|
-
end
|
407
426
|
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
427
|
+
describe 'GET' do
|
428
|
+
it 'does abstract get with params' do
|
429
|
+
stub_request(:get, "https://#{token}:@api.flowdock.com/v1/some_path?sort_by=date").
|
430
|
+
with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json'}).
|
431
|
+
to_return(:status => 200, :body => '{"id": 123}', :headers => {"Content-Type" => "application/json"})
|
432
|
+
expect(client.get('/some_path', {sort_by: 'date'})).to eq({"id" => 123})
|
433
|
+
end
|
414
434
|
end
|
415
|
-
end
|
416
435
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
436
|
+
describe 'POST' do
|
437
|
+
it 'does abstract post with body' do
|
438
|
+
stub_request(:post, "https://#{token}:@api.flowdock.com/v1/other_path").
|
439
|
+
with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json'}, :body => MultiJson.dump(name: 'foobar')).
|
440
|
+
to_return(:status => 200, :body => '{"id": 123,"name": "foobar"}', :headers => {"Content-Type" => "application/json"})
|
441
|
+
expect(client.post('other_path', {name: 'foobar'})).to eq({"id" => 123, "name" => "foobar"})
|
442
|
+
end
|
424
443
|
|
425
|
-
|
444
|
+
end
|
426
445
|
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
446
|
+
describe 'PUT' do
|
447
|
+
it 'does abstract put with body' do
|
448
|
+
stub_request(:put, "https://#{token}:@api.flowdock.com/v1/other_path").
|
449
|
+
with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json'}, :body => MultiJson.dump(name: 'foobar')).
|
450
|
+
to_return(:status => 200, :body => '{"id": 123,"name": "foobar"}', :headers => {"Content-Type" => "application/json"})
|
451
|
+
expect(client.put('other_path', {name: 'foobar'})).to eq({"id" => 123, "name" => "foobar"})
|
452
|
+
end
|
433
453
|
end
|
434
|
-
end
|
435
454
|
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
455
|
+
describe 'DELETE' do
|
456
|
+
it 'does abstract delete with params' do
|
457
|
+
stub_request(:delete, "https://#{token}:@api.flowdock.com/v1/some_path").
|
458
|
+
with(:headers => {'Accept'=>'application/json', 'Content-Type'=>'application/json'}).
|
459
|
+
to_return(:status => 200, :body => '', :headers => {"Content-Type" => "application/json"})
|
460
|
+
expect(client.delete('/some_path')).to eq({})
|
461
|
+
end
|
442
462
|
end
|
443
463
|
end
|
444
|
-
|
445
464
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flowdock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antti Pitkänen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.4.1
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: Ruby Gem for using Flowdock's API
|