discourse_api 0.35.0 → 0.36.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/CHANGELOG.md +8 -1
- data/examples/change_topic_status.rb +1 -1
- data/examples/create_topic.rb +2 -2
- data/examples/polls.rb +18 -0
- data/lib/discourse_api/api/polls.rb +31 -0
- data/lib/discourse_api/client.rb +7 -3
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/polls_spec.rb +70 -0
- data/spec/fixtures/polls_toggle_status.json +54 -0
- data/spec/fixtures/polls_vote.json +64 -0
- data/spec/fixtures/polls_voters.json +20 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f10d2acddddb15742c1a996952b9fabffade3d803a57bc8fd4a418891d491ad
|
4
|
+
data.tar.gz: a16816326aa5d4adf54262b8a043de73703e0437d76bc19216f7c09b4b22bc87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4810cfb72e3eeca6828759ba8ddd6480767626f24ef8831bb8ff164ed68a4f295117042f4a072813ff2305cd3bc2a88427a6cdb9b5acfad64307bcd2b5ba4699
|
7
|
+
data.tar.gz: a3f9a96b2b7ef9c4f37257f0e17cbac2fa9f86d67062808cdb2f55807349512b3d7ca6b968a83ac6912b833a4871d9f664f701967a06fc30422de7dd186553bb
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,14 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
4
4
|
|
5
|
-
## [0.
|
5
|
+
## [0.36.0] - 2019-07-18
|
6
|
+
### Added
|
7
|
+
- Added poll methods
|
8
|
+
### Fixed
|
9
|
+
- Updated create topic example
|
10
|
+
- Fixed capialization for header auth keys
|
11
|
+
|
12
|
+
## [0.35.0] - 2019-05-15
|
6
13
|
### Added
|
7
14
|
- Added `custom_fields` param to create/update category
|
8
15
|
- Added `frozen_string_literal: true` to all the files
|
data/examples/create_topic.rb
CHANGED
@@ -7,7 +7,7 @@ client.api_key = "YOUR_API_KEY"
|
|
7
7
|
client.api_username = "YOUR_USERNAME"
|
8
8
|
|
9
9
|
client.create_topic(
|
10
|
-
category:
|
10
|
+
category: 1,
|
11
11
|
skip_validations: true,
|
12
12
|
auto_track: false,
|
13
13
|
title: "Concert Master: A new way to choose",
|
@@ -16,7 +16,7 @@ client.create_topic(
|
|
16
16
|
|
17
17
|
# create Poll topic
|
18
18
|
client.create_topic(
|
19
|
-
category:
|
19
|
+
category: 2,
|
20
20
|
skip_validations: false,
|
21
21
|
auto_track: false,
|
22
22
|
title: "Your Favorite Color?",
|
data/examples/polls.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
5
|
+
|
6
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
7
|
+
client.api_key = "YOUR_API_KEY"
|
8
|
+
client.api_username = "YOUR_USERNAME"
|
9
|
+
|
10
|
+
options = ['8b4736b1ae3dfb5a28088530f036f9e5']
|
11
|
+
poll_option_votes = client.poll_vote post_id: 5, poll_name: 'poll', options: options
|
12
|
+
puts poll_option_votes.body['vote']
|
13
|
+
|
14
|
+
poll_option_votes = client.toggle_poll_status(post_id: 5, poll_name: 'poll', status: 'closed')
|
15
|
+
puts poll_option_votes[:body]['poll']['status']
|
16
|
+
|
17
|
+
poll_option_votes = client.poll_voters(post_id: 5, poll_name: 'poll')
|
18
|
+
puts poll_option_votes['voters']
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DiscourseApi
|
4
|
+
module API
|
5
|
+
module Polls
|
6
|
+
def poll_vote(args)
|
7
|
+
args = API.params(args)
|
8
|
+
.required(:post_id, :poll_name, :options)
|
9
|
+
.optional(:created_at)
|
10
|
+
put("/polls/vote", args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def toggle_poll_status(args)
|
14
|
+
args = API.params(args)
|
15
|
+
.required(:post_id, :poll_name, :status)
|
16
|
+
.optional(:api_username)
|
17
|
+
.optional(:raise_errors)
|
18
|
+
put("/polls/toggle_status", args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def poll_voters(args)
|
22
|
+
args = API.params(args)
|
23
|
+
.required(:post_id, :poll_name)
|
24
|
+
.optional(:opts)
|
25
|
+
response = get("/polls/voters.json", args)
|
26
|
+
response[:body]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/discourse_api/client.rb
CHANGED
@@ -9,6 +9,7 @@ require 'discourse_api/api/search'
|
|
9
9
|
require 'discourse_api/api/sso'
|
10
10
|
require 'discourse_api/api/tags'
|
11
11
|
require 'discourse_api/api/topics'
|
12
|
+
require 'discourse_api/api/polls'
|
12
13
|
require 'discourse_api/api/posts'
|
13
14
|
require 'discourse_api/api/users'
|
14
15
|
require 'discourse_api/api/groups'
|
@@ -34,6 +35,7 @@ module DiscourseApi
|
|
34
35
|
include DiscourseApi::API::SSO
|
35
36
|
include DiscourseApi::API::Tags
|
36
37
|
include DiscourseApi::API::Topics
|
38
|
+
include DiscourseApi::API::Polls
|
37
39
|
include DiscourseApi::API::Posts
|
38
40
|
include DiscourseApi::API::Users
|
39
41
|
include DiscourseApi::API::Groups
|
@@ -59,7 +61,7 @@ module DiscourseApi
|
|
59
61
|
|
60
62
|
def api_username=(api_username)
|
61
63
|
@api_username = api_username
|
62
|
-
@connection.headers['Api-
|
64
|
+
@connection.headers['Api-Username'] = api_username unless @connection.nil?
|
63
65
|
end
|
64
66
|
|
65
67
|
def connection_options
|
@@ -118,12 +120,14 @@ module DiscourseApi
|
|
118
120
|
conn.request :url_encoded
|
119
121
|
# Parse responses as JSON
|
120
122
|
conn.use FaradayMiddleware::ParseJson, content_type: 'application/json'
|
123
|
+
# For HTTP debugging, uncomment
|
124
|
+
# conn.response :logger
|
121
125
|
# Use Faraday's default HTTP adapter
|
122
126
|
conn.adapter Faraday.default_adapter
|
123
127
|
#pass api_key and api_username on every request
|
124
128
|
unless api_username.nil?
|
125
|
-
conn.headers['Api-
|
126
|
-
conn.headers['Api-
|
129
|
+
conn.headers['Api-Key'] = api_key
|
130
|
+
conn.headers['Api-Username'] = api_username
|
127
131
|
end
|
128
132
|
end
|
129
133
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::Polls do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
|
5
|
+
|
6
|
+
describe "#poll vote" do
|
7
|
+
before do
|
8
|
+
path = "http://localhost:3000/polls/vote"
|
9
|
+
stub_put(path)
|
10
|
+
.to_return(body: fixture("polls_vote.json"), headers: { content_type: "application/json" })
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
it "requests the correct resource" do
|
15
|
+
options = ['8b4736b1ae3dfb5a28088530f036f9e5']
|
16
|
+
subject.poll_vote post_id: 5, poll_name: 'poll', options: options
|
17
|
+
expect(a_put("http://localhost:3000/polls/vote")).to have_been_made
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns the expected votes" do
|
21
|
+
options = ['8b4736b1ae3dfb5a28088530f036f9e5']
|
22
|
+
vote = subject.poll_vote post_id: 5, poll_name: 'poll', options: options
|
23
|
+
expect(vote.body).to be_a Hash
|
24
|
+
expect(vote.body['poll']['options']).to be_an Array
|
25
|
+
expect(vote.body['vote']).to eq(['8b4736b1ae3dfb5a28088530f036f9e5'])
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#poll toggle_status" do
|
29
|
+
before do
|
30
|
+
path = "http://localhost:3000/polls/toggle_status"
|
31
|
+
stub_put(path)
|
32
|
+
.to_return(body: fixture("polls_toggle_status.json"), headers: { content_type: "application/json" })
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
it "toggles the poll status to closed" do
|
37
|
+
subject.toggle_poll_status post_id: 5, poll_name: 'poll', status: 'closed'
|
38
|
+
expect(a_put("http://localhost:3000/polls/toggle_status")).to have_been_made
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the expected results of closed poll" do
|
42
|
+
returned_poll_status = subject.toggle_poll_status post_id: 5, poll_name: 'poll', status: 'closed'
|
43
|
+
expect(returned_poll_status.body).to be_a Hash
|
44
|
+
returned_poll_status.body['poll']['options'].each { |g| expect(g).to be_a Hash }
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#poll voters" do
|
50
|
+
before do
|
51
|
+
stub_get("http://localhost:3000/polls/voters.json?post_id=5&poll_name=poll")
|
52
|
+
.to_return(body: fixture("polls_voters.json"), headers: { content_type: "application/json" })
|
53
|
+
end
|
54
|
+
|
55
|
+
it "requests the correct resource" do
|
56
|
+
subject.poll_voters post_id: 5, poll_name: 'poll'
|
57
|
+
expect(a_get("http://localhost:3000/polls/voters.json?post_id=5&poll_name=poll")).to have_been_made
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns the expected votes" do
|
61
|
+
voters = subject.poll_voters post_id: 5, poll_name: 'poll'
|
62
|
+
expect(voters).to be_a Hash
|
63
|
+
voters.each { |g| expect(g).to be_an Array }
|
64
|
+
expect(voters['voters']['e539a9df8700d0d05c69356a07b768cf']).to be_an Array
|
65
|
+
expect(voters['voters']['e539a9df8700d0d05c69356a07b768cf'][0]['id']).to eq(356)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
{
|
2
|
+
"poll": {
|
3
|
+
"name": "poll",
|
4
|
+
"type": "regular",
|
5
|
+
"status": "closed",
|
6
|
+
"public": true,
|
7
|
+
"results": "always",
|
8
|
+
"options": [
|
9
|
+
{
|
10
|
+
"id": "8b4736b1ae3dfb5a28088530f036f9e5",
|
11
|
+
"html": "I will attend the Apr 25, 2019 Launchpad meeting.",
|
12
|
+
"votes": 1
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"id": "e09884fbf9b72d83e804050078847643",
|
16
|
+
"html": "I want to lead the meeting.",
|
17
|
+
"votes": 0
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"id": "e539a9df8700d0d05c69356a07b768cf",
|
21
|
+
"html": "I’ll not attend this meeting.",
|
22
|
+
"votes": 2
|
23
|
+
}
|
24
|
+
],
|
25
|
+
"voters": 3,
|
26
|
+
"preloaded_voters": {
|
27
|
+
"8b4736b1ae3dfb5a28088530f036f9e5": [
|
28
|
+
{
|
29
|
+
"id": 17,
|
30
|
+
"username": "Kim_Miller",
|
31
|
+
"name": "Kim Miller",
|
32
|
+
"avatar_template": "/user_avatar/discourse.gomomentum.org/user_one/{size}/3220_2.png",
|
33
|
+
"title": "New Owners Council"
|
34
|
+
}
|
35
|
+
],
|
36
|
+
"e539a9df8700d0d05c69356a07b768cf": [
|
37
|
+
{
|
38
|
+
"id": 356,
|
39
|
+
"username": "David_Ashby",
|
40
|
+
"name": "David Ashby",
|
41
|
+
"avatar_template": "/user_avatar/discourse.gomomentum.org/user_two/{size}/2403_2.png",
|
42
|
+
"title": "Team Agape"
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"id": 72,
|
46
|
+
"username": "David_Kirk",
|
47
|
+
"name": "David Kirk",
|
48
|
+
"avatar_template": "/user_avatar/discourse.gomomentum.org/user_three/{size}/236_2.png",
|
49
|
+
"title": "Foundry"
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
{
|
2
|
+
"poll": {
|
3
|
+
"name": "poll",
|
4
|
+
"type": "regular",
|
5
|
+
"status": "open",
|
6
|
+
"public": true,
|
7
|
+
"results": "always",
|
8
|
+
"options": [
|
9
|
+
{
|
10
|
+
"id": "8b4736b1ae3dfb5a28088530f036f9e5",
|
11
|
+
"html": "I will attend the Apr 25, 2019 Launchpad meeting.",
|
12
|
+
"votes": 2
|
13
|
+
},
|
14
|
+
{
|
15
|
+
"id": "e09884fbf9b72d83e804050078847643",
|
16
|
+
"html": "I want to lead the meeting.",
|
17
|
+
"votes": 0
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"id": "e539a9df8700d0d05c69356a07b768cf",
|
21
|
+
"html": "I’ll not attend this meeting.",
|
22
|
+
"votes": 2
|
23
|
+
}
|
24
|
+
],
|
25
|
+
"voters": 4,
|
26
|
+
"preloaded_voters": {
|
27
|
+
"8b4736b1ae3dfb5a28088530f036f9e5": [
|
28
|
+
{
|
29
|
+
"id": 17,
|
30
|
+
"username": "Kim_Miller",
|
31
|
+
"name": "Kim Miller",
|
32
|
+
"avatar_template": "/user_avatar/discourse.gomomentum.org/kim_miller/{size}/3220_2.png",
|
33
|
+
"title": "New Owners Council"
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"id": 150,
|
37
|
+
"username": "KM_Admin",
|
38
|
+
"name": "Kim Miller",
|
39
|
+
"avatar_template": "/user_avatar/discourse.gomomentum.org/km_admin/{size}/1232_2.png",
|
40
|
+
"title": "Admin"
|
41
|
+
}
|
42
|
+
],
|
43
|
+
"e539a9df8700d0d05c69356a07b768cf": [
|
44
|
+
{
|
45
|
+
"id": 356,
|
46
|
+
"username": "David_Ashby",
|
47
|
+
"name": "David Ashby",
|
48
|
+
"avatar_template": "/user_avatar/discourse.gomomentum.org/david_ashby/{size}/2403_2.png",
|
49
|
+
"title": "Team Agape"
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"id": 72,
|
53
|
+
"username": "David_Kirk",
|
54
|
+
"name": "David Kirk",
|
55
|
+
"avatar_template": "/user_avatar/discourse.gomomentum.org/david_kirk/{size}/236_2.png",
|
56
|
+
"title": "Foundry"
|
57
|
+
}
|
58
|
+
]
|
59
|
+
}
|
60
|
+
},
|
61
|
+
"vote": [
|
62
|
+
"8b4736b1ae3dfb5a28088530f036f9e5"
|
63
|
+
]
|
64
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
{
|
2
|
+
"voters": {
|
3
|
+
"e539a9df8700d0d05c69356a07b768cf": [
|
4
|
+
{
|
5
|
+
"id": 356,
|
6
|
+
"username": "David_Ashby",
|
7
|
+
"name": "David Ashby",
|
8
|
+
"avatar_template": "/user_avatar/discourse.gomomentum.org/david_ashby/{size}/2403_2.png",
|
9
|
+
"title": "Team Agape"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"id": 72,
|
13
|
+
"username": "David_Kirk",
|
14
|
+
"name": "David Kirk",
|
15
|
+
"avatar_template": "/user_avatar/discourse.gomomentum.org/david_kirk/{size}/236_2.png",
|
16
|
+
"title": "Foundry"
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
20
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.36.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2019-
|
14
|
+
date: 2019-07-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: faraday
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- examples/group_set_user_notification_level.rb
|
216
216
|
- examples/groups.rb
|
217
217
|
- examples/invite_users.rb
|
218
|
+
- examples/polls.rb
|
218
219
|
- examples/post_action.rb
|
219
220
|
- examples/search.rb
|
220
221
|
- examples/sent_private_messages.rb
|
@@ -233,6 +234,7 @@ files:
|
|
233
234
|
- lib/discourse_api/api/invite.rb
|
234
235
|
- lib/discourse_api/api/notifications.rb
|
235
236
|
- lib/discourse_api/api/params.rb
|
237
|
+
- lib/discourse_api/api/polls.rb
|
236
238
|
- lib/discourse_api/api/posts.rb
|
237
239
|
- lib/discourse_api/api/private_messages.rb
|
238
240
|
- lib/discourse_api/api/search.rb
|
@@ -255,6 +257,7 @@ files:
|
|
255
257
|
- spec/discourse_api/api/groups_spec.rb
|
256
258
|
- spec/discourse_api/api/notifications_spec.rb
|
257
259
|
- spec/discourse_api/api/params_spec.rb
|
260
|
+
- spec/discourse_api/api/polls_spec.rb
|
258
261
|
- spec/discourse_api/api/posts_spec.rb
|
259
262
|
- spec/discourse_api/api/private_messages_spec.rb
|
260
263
|
- spec/discourse_api/api/search_spec.rb
|
@@ -284,6 +287,9 @@ files:
|
|
284
287
|
- spec/fixtures/members_1.json
|
285
288
|
- spec/fixtures/new.json
|
286
289
|
- spec/fixtures/notifications.json
|
290
|
+
- spec/fixtures/polls_toggle_status.json
|
291
|
+
- spec/fixtures/polls_vote.json
|
292
|
+
- spec/fixtures/polls_voters.json
|
287
293
|
- spec/fixtures/post.json
|
288
294
|
- spec/fixtures/post_action_users.json
|
289
295
|
- spec/fixtures/private_messages.json
|
@@ -340,6 +346,7 @@ test_files:
|
|
340
346
|
- spec/discourse_api/api/groups_spec.rb
|
341
347
|
- spec/discourse_api/api/notifications_spec.rb
|
342
348
|
- spec/discourse_api/api/params_spec.rb
|
349
|
+
- spec/discourse_api/api/polls_spec.rb
|
343
350
|
- spec/discourse_api/api/posts_spec.rb
|
344
351
|
- spec/discourse_api/api/private_messages_spec.rb
|
345
352
|
- spec/discourse_api/api/search_spec.rb
|
@@ -369,6 +376,9 @@ test_files:
|
|
369
376
|
- spec/fixtures/members_1.json
|
370
377
|
- spec/fixtures/new.json
|
371
378
|
- spec/fixtures/notifications.json
|
379
|
+
- spec/fixtures/polls_toggle_status.json
|
380
|
+
- spec/fixtures/polls_vote.json
|
381
|
+
- spec/fixtures/polls_voters.json
|
372
382
|
- spec/fixtures/post.json
|
373
383
|
- spec/fixtures/post_action_users.json
|
374
384
|
- spec/fixtures/private_messages.json
|