discourse_api 0.37.0 → 0.38.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11fa2d5cdcb3800c4bae5679d2644790c12d46c8d0797018f5a220a1f39d6ebe
4
- data.tar.gz: fb596a1e54cac03f298492561d86afb226cb51c3a69400fb4461eeec3ab39836
3
+ metadata.gz: 359440c0d7810ba745d422cb97b7465e55cb65d3abb145c7597f511d13e77609
4
+ data.tar.gz: 7be49a42e09f7d16c5e4ad564b57305c2f8eb17c78ed8781a1b19bf1645564b8
5
5
  SHA512:
6
- metadata.gz: 0ed9ad86bc438113850a8313d9672b7dfb67fdcb70c1d2c0ca668544f8f9babf2e4e0aa3b4392f6887592fdaa821aaae12e3e2c53277dede8fef06e8ca626d17
7
- data.tar.gz: 23ce5939282ca3686dd62f09eedb191d78592c64c1ce47f7e58df92368cda1471bf9da6c1697718307e96a1b12fb800ad85a63080798a91c95ee1669a9022f4a
6
+ metadata.gz: 07ae95153a40f0b84fa64d439608a403e47ad46d75bb1f201364f621101158048345160725733d21540288c0588ed4fdbf3a43a7af3b2df969b1347fa2c9a91f
7
+ data.tar.gz: 0e58fa5071debb6d6d62035c48c9494ee0c811ed8097dd147745a6aeba85fe06a6c8b699ed943c56d8a88af9c33c51d2a59563355c81324b41cd4aec5533fca5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
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.38.0] - 2019-10-18
6
+ ### Added
7
+ - Allow setting locale in SingleSignOn
8
+ - Optional param to group memebrs to include owners as well as members
9
+
5
10
  ## [0.37.0] - 2019-09-23
6
11
  ### Added
7
12
  - user-badges endpoint for full badges list
@@ -107,12 +107,18 @@ module DiscourseApi
107
107
  end
108
108
 
109
109
  def group_members(group_name, params = {})
110
+ options = params
110
111
  params = API.params(params)
111
112
  .optional(:offset, :limit)
112
113
  .default(offset: 0, limit: 100)
113
114
  .to_h
114
115
  response = get("/groups/#{group_name}/members.json", params)
115
- response.body['members']
116
+
117
+ if options[:all] == true
118
+ response.body
119
+ else
120
+ response.body['members']
121
+ end
116
122
  end
117
123
 
118
124
  def group_set_user_notification_level(group, user_id, notification_level)
@@ -140,7 +140,7 @@ module DiscourseApi
140
140
  response = connection.send(method.to_sym, path, params)
141
141
  handle_error(response)
142
142
  response.env
143
- rescue Faraday::Error::ClientError, JSON::ParserError
143
+ rescue Faraday::ClientError, JSON::ParserError
144
144
  raise DiscourseApi::Error
145
145
  end
146
146
 
@@ -7,9 +7,10 @@ module DiscourseApi
7
7
  class SingleSignOn
8
8
  ACCESSORS = [:nonce, :name, :username, :email, :avatar_url, :avatar_force_update, :require_activation,
9
9
  :bio, :external_id, :return_sso_url, :admin, :moderator, :suppress_welcome_message, :title,
10
- :add_groups, :remove_groups, :groups]
10
+ :add_groups, :remove_groups, :groups, :locale, :locale_force_update]
11
11
  FIXNUMS = []
12
- BOOLS = [:avatar_force_update, :admin, :moderator, :require_activation, :suppress_welcome_message]
12
+ BOOLS = [:avatar_force_update, :admin, :moderator, :require_activation, :suppress_welcome_message,
13
+ :locale_force_update]
13
14
  ARRAYS = [:groups]
14
15
  #NONCE_EXPIRY_TIME = 10.minutes # minutes is a rails method and is causing an error. Is this needed in the api?
15
16
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DiscourseApi
3
- VERSION = "0.37.0"
3
+ VERSION = "0.38.0"
4
4
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe DiscourseApi::API::ApiKey do
4
4
  subject {
5
5
  DiscourseApi::Client.new(
6
- "http://localhost:3000",
6
+ "#{host}",
7
7
  "test_d7fd0429940",
8
8
  "test_user"
9
9
  )
@@ -11,14 +11,14 @@ describe DiscourseApi::API::ApiKey do
11
11
 
12
12
  describe "#api" do
13
13
  before do
14
- url = "http://localhost:3000/admin/api.json"
14
+ url = "#{host}/admin/api.json"
15
15
  stub_get(url).to_return(body: fixture("api.json"),
16
16
  headers: { content_type: "application/json" })
17
17
  end
18
18
 
19
19
  it "requests the correct resource" do
20
20
  subject.api
21
- url = "http://localhost:3000/admin/api.json"
21
+ url = "#{host}/admin/api.json"
22
22
  expect(a_get(url)).to have_been_made
23
23
  end
24
24
 
@@ -32,7 +32,7 @@ describe DiscourseApi::API::ApiKey do
32
32
 
33
33
  describe "#generate_user_api_key" do
34
34
  before do
35
- url = "http://localhost:3000/admin/users/2/generate_api_key.json"
35
+ url = "#{host}/admin/users/2/generate_api_key.json"
36
36
  stub_post(url).to_return(body: fixture("generate_api_key.json"),
37
37
  headers: { content_type: "application/json" })
38
38
  end
@@ -46,7 +46,7 @@ describe DiscourseApi::API::ApiKey do
46
46
 
47
47
  describe "#revoke_user_api_key" do
48
48
  before do
49
- url = "http://localhost:3000/admin/users/2/revoke_api_key.json"
49
+ url = "#{host}/admin/users/2/revoke_api_key.json"
50
50
  stub_delete(url).to_return(body: "",
51
51
  headers: { content_type: "application/json" })
52
52
  end
@@ -59,7 +59,7 @@ describe DiscourseApi::API::ApiKey do
59
59
 
60
60
  describe "#generate_master_key" do
61
61
  before do
62
- url = "http://localhost:3000/admin/api/key"
62
+ url = "#{host}/admin/api/key"
63
63
  stub_post(url).to_return(body: fixture("generate_master_key.json"),
64
64
  headers: { content_type: "application/json" })
65
65
  end
@@ -74,14 +74,14 @@ describe DiscourseApi::API::ApiKey do
74
74
 
75
75
  describe "#revoke_api_key" do
76
76
  before do
77
- url = "http://localhost:3000/admin/api/key?id=10"
77
+ url = "#{host}/admin/api/key?id=10"
78
78
  stub_delete(url).to_return(body: "",
79
79
  headers: { content_type: "application/json" })
80
80
  end
81
81
 
82
82
  it "requests the correct resource" do
83
83
  subject.revoke_api_key(10)
84
- url = "http://localhost:3000/admin/api/key?id=10"
84
+ url = "#{host}/admin/api/key?id=10"
85
85
  expect(a_delete(url)).to have_been_made
86
86
  end
87
87
 
@@ -93,14 +93,14 @@ describe DiscourseApi::API::ApiKey do
93
93
 
94
94
  describe "#regenerate_api_key" do
95
95
  before do
96
- url = "http://localhost:3000/admin/api/key"
96
+ url = "#{host}/admin/api/key"
97
97
  stub_put(url).to_return(body: fixture("regenerate_api_key.json"),
98
98
  headers: { content_type: "application/json" })
99
99
  end
100
100
 
101
101
  it "requests the correct resource" do
102
102
  subject.regenerate_api_key(10)
103
- url = "http://localhost:3000/admin/api/key"
103
+ url = "#{host}/admin/api/key"
104
104
  expect(a_put(url)).to have_been_made
105
105
  end
106
106
 
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Backups do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
5
5
 
6
6
  describe "#backups" do
7
7
  before do
8
- stub_get("http://localhost:3000/admin/backups.json").to_return(body: fixture("backups.json"), headers: { content_type: "application/json" })
8
+ stub_get("#{host}/admin/backups.json").to_return(body: fixture("backups.json"), headers: { content_type: "application/json" })
9
9
  end
10
10
 
11
11
  it "requests the correct resource" do
12
12
  subject.backups
13
- expect(a_get("http://localhost:3000/admin/backups.json")).to have_been_made
13
+ expect(a_get("#{host}/admin/backups.json")).to have_been_made
14
14
  end
15
15
 
16
16
  it "returns the requested backups" do
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Badges do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
5
5
 
6
6
  describe "#badges" do
7
7
  before do
8
- stub_get("http://localhost:3000/admin/badges.json").to_return(body: fixture("badges.json"), headers: { content_type: "application/json" })
8
+ stub_get("#{host}/admin/badges.json").to_return(body: fixture("badges.json"), headers: { content_type: "application/json" })
9
9
  end
10
10
 
11
11
  it "requests the correct resource" do
12
12
  subject.badges
13
- expect(a_get("http://localhost:3000/admin/badges.json")).to have_been_made
13
+ expect(a_get("#{host}/admin/badges.json")).to have_been_made
14
14
  end
15
15
 
16
16
  it "returns the requested badges" do
@@ -22,12 +22,12 @@ describe DiscourseApi::API::Badges do
22
22
 
23
23
  describe "#user-badges" do
24
24
  before do
25
- stub_get("http://localhost:3000/user-badges/test_user.json").to_return(body: fixture("user_badges.json"), headers: { content_type: "application/json" })
25
+ stub_get("#{host}/user-badges/test_user.json").to_return(body: fixture("user_badges.json"), headers: { content_type: "application/json" })
26
26
  end
27
27
 
28
28
  it "requests the correct resource" do
29
29
  subject.user_badges('test_user')
30
- expect(a_get("http://localhost:3000/user-badges/test_user.json")).to have_been_made
30
+ expect(a_get("#{host}/user-badges/test_user.json")).to have_been_made
31
31
  end
32
32
 
33
33
  it "returns the requested user badges" do
@@ -1,17 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Categories do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
5
5
 
6
6
  describe "#categories" do
7
7
  before do
8
- stub_get("http://localhost:3000/categories.json")
8
+ stub_get("#{host}/categories.json")
9
9
  .to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
10
10
  end
11
11
 
12
12
  it "requests the correct resource" do
13
13
  subject.categories
14
- expect(a_get("http://localhost:3000/categories.json")).to have_been_made
14
+ expect(a_get("#{host}/categories.json")).to have_been_made
15
15
  end
16
16
 
17
17
  it "returns the requested categories" do
@@ -29,7 +29,7 @@ describe DiscourseApi::API::Categories do
29
29
 
30
30
  describe '#category_latest_topics' do
31
31
  before do
32
- stub_get("http://localhost:3000/c/category-slug/l/latest.json")
32
+ stub_get("#{host}/c/category-slug/l/latest.json")
33
33
  .to_return(body: fixture("category_latest_topics.json"), headers: { content_type: "application/json" })
34
34
  end
35
35
 
@@ -41,7 +41,7 @@ describe DiscourseApi::API::Categories do
41
41
 
42
42
  describe '#category_top_topics' do
43
43
  before do
44
- stub_get("http://localhost:3000/c/category-slug/l/top.json")
44
+ stub_get("#{host}/c/category-slug/l/top.json")
45
45
  .to_return(
46
46
  body: fixture("category_topics.json"),
47
47
  headers: { content_type: "application/json" }
@@ -56,7 +56,7 @@ describe DiscourseApi::API::Categories do
56
56
 
57
57
  describe '#category_new_topics' do
58
58
  before do
59
- stub_get("http://localhost:3000/c/category-slug/l/new.json")
59
+ stub_get("#{host}/c/category-slug/l/new.json")
60
60
  .to_return(
61
61
  body: fixture("category_topics.json"),
62
62
  headers: { content_type: "application/json" }
@@ -71,14 +71,14 @@ describe DiscourseApi::API::Categories do
71
71
 
72
72
  describe '#category_new_category' do
73
73
  before do
74
- stub_post("http://localhost:3000/categories")
74
+ stub_post("#{host}/categories")
75
75
  subject.create_category(name: "test_category", color: "283890", text_color: "FFFFFF",
76
76
  description: "This is a description",
77
77
  permissions: {"group_1" => 1, "admins" => 1})
78
78
  end
79
79
 
80
80
  it "makes a create category request" do
81
- expect(a_post("http://localhost:3000/categories").with(body:
81
+ expect(a_post("#{host}/categories").with(body:
82
82
  "color=283890&description=This+is+a+description&name=test_category&parent_category_id&permissions%5Badmins%5D=1&permissions%5Bgroup_1%5D=1&text_color=FFFFFF")
83
83
  ).to have_been_made
84
84
  end
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Email do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
5
5
 
6
6
  describe "#email_settings" do
7
7
  before do
8
- stub_get("http://localhost:3000/admin/email.json").to_return(body: fixture("email_settings.json"), headers: { content_type: "application/json" })
8
+ stub_get("#{host}/admin/email.json").to_return(body: fixture("email_settings.json"), headers: { content_type: "application/json" })
9
9
  end
10
10
 
11
11
  it "requests the correct resource" do
12
12
  subject.email_settings
13
- expect(a_get("http://localhost:3000/admin/email.json")).to have_been_made
13
+ expect(a_get("#{host}/admin/email.json")).to have_been_made
14
14
  end
15
15
 
16
16
  it "returns the requested settings" do
@@ -23,12 +23,12 @@ describe DiscourseApi::API::Email do
23
23
 
24
24
  describe "#list_email_all" do
25
25
  before do
26
- stub_get("http://localhost:3000/admin/email/all.json").to_return(body: fixture("email_list_all.json"), headers: { content_type: "application/json" })
26
+ stub_get("#{host}/admin/email/all.json").to_return(body: fixture("email_list_all.json"), headers: { content_type: "application/json" })
27
27
  end
28
28
 
29
29
  it "requests the correct resource" do
30
30
  subject.list_email('all')
31
- expect(a_get("http://localhost:3000/admin/email/all.json")).to have_been_made
31
+ expect(a_get("#{host}/admin/email/all.json")).to have_been_made
32
32
  end
33
33
 
34
34
  it "returns all email" do
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DiscourseApi::API::Groups do
4
- subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user" )}
4
+ subject { DiscourseApi::Client.new("#{host}", "test_d7fd0429940", "test_user" )}
5
5
 
6
6
  describe "#groups" do
7
7
  before do
8
- stub_get("http://localhost:3000/groups.json").to_return(body: fixture("groups.json"), headers: { content_type: "application/json" })
8
+ stub_get("#{host}/groups.json").to_return(body: fixture("groups.json"), headers: { content_type: "application/json" })
9
9
  end
10
10
 
11
11
  it "requests the correct resource" do
12
12
  subject.groups
13
- expect(a_get("http://localhost:3000/groups.json")).to have_been_made
13
+ expect(a_get("#{host}/groups.json")).to have_been_made
14
14
  end
15
15
 
16
16
  it "returns the requested groups" do
@@ -20,65 +20,65 @@ describe DiscourseApi::API::Groups do
20
20
  end
21
21
 
22
22
  it "returns a single group" do
23
- stub_get("http://localhost:3000/groups/some-group.json").to_return(body: fixture("group.json"), headers: { content_type: "application/json" })
23
+ stub_get("#{host}/groups/some-group.json").to_return(body: fixture("group.json"), headers: { content_type: "application/json" })
24
24
  group = subject.group('some-group')
25
25
  expect(group['basic_group']).to be_a Hash
26
26
  end
27
27
 
28
28
  it "create new groups" do
29
- stub_post("http://localhost:3000/admin/groups")
29
+ stub_post("#{host}/admin/groups")
30
30
  subject.create_group(name: "test_group")
31
31
  params = escape_params("group[name]" => "test_group", "group[visibility_level]" => 0)
32
- expect(a_post("http://localhost:3000/admin/groups").
32
+ expect(a_post("#{host}/admin/groups").
33
33
  with(body: params)
34
34
  ).to have_been_made
35
35
  end
36
36
 
37
37
  it "update an existing group" do
38
- stub_put("http://localhost:3000/groups/42")
38
+ stub_put("#{host}/groups/42")
39
39
  subject.update_group(42, name: "test_group")
40
40
  params = escape_params("group[name]" => "test_group", "group[visibility_level]" => 0)
41
- expect(a_put("http://localhost:3000/groups/42").
41
+ expect(a_put("#{host}/groups/42").
42
42
  with(body: params)
43
43
  ).to have_been_made
44
44
  end
45
45
 
46
46
  describe "add members" do
47
47
  before do
48
- stub_request(:put, "http://localhost:3000/admin/groups/123/members.json")
48
+ stub_request(:put, "#{host}/admin/groups/123/members.json")
49
49
  end
50
50
 
51
51
  it "adds a single member by username" do
52
52
  subject.group_add(123, username: "sam")
53
- expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json").
53
+ expect(a_request(:put, "#{host}/admin/groups/123/members.json").
54
54
  with(body: {usernames: "sam"})
55
55
  ).to have_been_made
56
56
  end
57
57
 
58
58
  it "adds an array of members by username" do
59
59
  subject.group_add(123, usernames: ["sam", "jeff"])
60
- expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json").
60
+ expect(a_request(:put, "#{host}/admin/groups/123/members.json").
61
61
  with(body: {usernames: "sam,jeff"})
62
62
  ).to have_been_made
63
63
  end
64
64
 
65
65
  it "adds a single member by user_id" do
66
66
  subject.group_add(123, user_id: 456)
67
- expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json").
67
+ expect(a_request(:put, "#{host}/admin/groups/123/members.json").
68
68
  with(body: {user_ids: "456"})
69
69
  ).to have_been_made
70
70
  end
71
71
 
72
72
  it "adds an array of members by user_id" do
73
73
  subject.group_add(123, user_id: [123, 456])
74
- expect(a_request(:put, "http://localhost:3000/admin/groups/123/members.json").
74
+ expect(a_request(:put, "#{host}/admin/groups/123/members.json").
75
75
  with(body: {user_ids: "123,456"})
76
76
  ).to have_been_made
77
77
  end
78
78
  end
79
79
 
80
80
  describe "remove members" do
81
- let(:url) { "http://localhost:3000/admin/groups/123/members.json?usernames=sam" }
81
+ let(:url) { "#{host}/admin/groups/123/members.json?usernames=sam" }
82
82
 
83
83
  before do
84
84
  stub_delete(url)
@@ -91,29 +91,37 @@ describe DiscourseApi::API::Groups do
91
91
  end
92
92
 
93
93
  describe "group members" do
94
- before do
95
- stub_get("http://localhost:3000/groups/mygroup/members.json?limit=100&offset=0").to_return(body: fixture("members_0.json"), headers: { content_type: "application/json" })
96
- stub_get("http://localhost:3000/groups/mygroup/members.json?limit=100&offset=100").to_return(body: fixture("members_1.json"), headers: { content_type: "application/json" })
97
- end
98
-
99
94
  it "list members" do
95
+ stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(body: fixture("members_0.json"), headers: { content_type: "application/json" })
96
+ stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=100").to_return(body: fixture("members_1.json"), headers: { content_type: "application/json" })
100
97
  members = subject.group_members('mygroup')
101
- expect(a_get("http://localhost:3000/groups/mygroup/members.json?limit=100&offset=0")).to have_been_made
98
+ expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=0")).to have_been_made
102
99
  expect(members.length).to eq(100)
103
100
  members = subject.group_members('mygroup', offset: 100)
104
- expect(a_get("http://localhost:3000/groups/mygroup/members.json?limit=100&offset=100")).to have_been_made
101
+ expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=100")).to have_been_made
105
102
  expect(members.length).to eq(90)
106
103
  end
104
+
105
+ context "with :all params" do
106
+ it "lists members and owners" do
107
+ stub_get("#{host}/groups/mygroup/members.json?limit=100&offset=0").to_return(body: fixture("members_2.json"), headers: { content_type: "application/json" })
108
+ member_data = subject.group_members('mygroup', all: true)
109
+ expect(a_get("#{host}/groups/mygroup/members.json?limit=100&offset=0")).to have_been_made
110
+ expect(member_data["members"].length).to eq(100)
111
+ expect(member_data["owners"].length).to eq(7)
112
+ expect(member_data.keys.sort).to eq(["members", "meta", "owners"])
113
+ end
114
+ end
107
115
  end
108
116
 
109
117
  describe "group user notification level" do
110
118
  before do
111
- stub_post("http://localhost:3000/groups/mygroup/notifications?user_id=77&notification_level=3")
119
+ stub_post("#{host}/groups/mygroup/notifications?user_id=77&notification_level=3")
112
120
  end
113
121
 
114
122
  it "updates user's notification level for group" do
115
123
  subject.group_set_user_notification_level("mygroup", 77, 3)
116
- expect(a_post("http://localhost:3000/groups/mygroup/notifications?user_id=77&notification_level=3"))
124
+ expect(a_post("#{host}/groups/mygroup/notifications?user_id=77&notification_level=3"))
117
125
  .to have_been_made
118
126
  end
119
127
  end