discourse_api 0.12.0 → 0.13.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 +5 -0
- data/examples/create_update_category.rb +38 -0
- data/examples/upload.rb +12 -0
- data/lib/discourse_api/api/categories.rb +12 -1
- data/lib/discourse_api/api/topics.rb +2 -2
- data/lib/discourse_api/api/uploads.rb +13 -0
- data/lib/discourse_api/api/users.rb +1 -1
- data/lib/discourse_api/client.rb +2 -0
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/uploads_spec.rb +18 -0
- data/spec/discourse_api/api/users_spec.rb +1 -1
- data/spec/fixtures/upload_post_image.json +14 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5e090466c70d88bfb066f1c386941a3ef8dfef2
|
4
|
+
data.tar.gz: 5f0d7f3b8ce464254a7d60dcab7f0cf5278da843
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de5bfc7a37df4f79cce7c1ccc357f47e9e7f6335f723b1577ef3743d19e55b503d8c6ccbdfd8beec9989ae31f86dd1d7396df6b2ad21b455a4f3403c65517d10
|
7
|
+
data.tar.gz: 3a2020987363559ec2bd44080716d4bfe526c81d169cfeeb8ce467f80c83576bed655f6cbe9866c57f8aac93c4373465f5a9d8932636a8c6c5d677599a04aa86
|
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.13.0] - 2016-10-09
|
6
|
+
### Added
|
7
|
+
- added `update_category`
|
8
|
+
- added `upload_post_image`
|
9
|
+
|
5
10
|
## [0.12.0] - 2016-10-06
|
6
11
|
### Added
|
7
12
|
- add endpoint for `/admin/users/{id}/suspend`
|
@@ -0,0 +1,38 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
3
|
+
|
4
|
+
# client = DiscourseApi::Client.new("http://localhost:3000")
|
5
|
+
# client.api_key = "YOUR_API_KEY"
|
6
|
+
# client.api_username = "YOUR_USERNAME"
|
7
|
+
#
|
8
|
+
|
9
|
+
client = DiscourseApi::Client.new("http://localhost:8080")
|
10
|
+
client.api_key = "a56a349e1870529d8d8da11453ea782ce8ab8de34d6564a65727171163be4338"
|
11
|
+
client.api_username = "system"
|
12
|
+
|
13
|
+
###
|
14
|
+
# Required category params:
|
15
|
+
# :name, :color, :text_color
|
16
|
+
# Optional category params:
|
17
|
+
# :slug, :permissions, :auto_close_hours, :auto_close_based_on_last_post, :position, :email_in,
|
18
|
+
# :email_in_allow_strangers, :logo_url, :background_url, :allow_badges, :topic_template
|
19
|
+
###
|
20
|
+
|
21
|
+
|
22
|
+
# Create category
|
23
|
+
new_category = client.create_category(
|
24
|
+
name: "Test Category",
|
25
|
+
color: "AB9364",
|
26
|
+
text_color: "FFFFFF"
|
27
|
+
)
|
28
|
+
puts 'Created category: ' + new_category.to_s
|
29
|
+
|
30
|
+
# Update category
|
31
|
+
response = client.update_category(
|
32
|
+
id: new_category['id'],
|
33
|
+
name: "The Best Test Category",
|
34
|
+
slug: "the-best-test-category",
|
35
|
+
color: "0E76BD",
|
36
|
+
text_color: "000000"
|
37
|
+
)
|
38
|
+
puts 'Updated category: ' + response.to_s
|
data/examples/upload.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require File.expand_path('../../lib/discourse_api', __FILE__)
|
3
|
+
|
4
|
+
client = DiscourseApi::Client.new("http://localhost:3000")
|
5
|
+
client.api_key = "YOUR_API_KEY"
|
6
|
+
client.api_username = "YOUR_USERNAME"
|
7
|
+
|
8
|
+
# Upload an image via file
|
9
|
+
client.upload_post_image(file: 'grumpy_cat.gif')
|
10
|
+
|
11
|
+
# Upload an image via URL
|
12
|
+
client.upload_post_image(url: 'https://giphy.com/grumpy_cat.gif')
|
@@ -13,6 +13,17 @@ module DiscourseApi
|
|
13
13
|
response['category']
|
14
14
|
end
|
15
15
|
|
16
|
+
def update_category(args={})
|
17
|
+
category_id = args[:id]
|
18
|
+
args = API.params(args)
|
19
|
+
.required(:id, :name, :color, :text_color)
|
20
|
+
.optional(:slug, :permissions, :auto_close_hours, :auto_close_based_on_last_post, :position, :email_in,
|
21
|
+
:email_in_allow_strangers, :logo_url, :background_url, :allow_badges, :topic_template)
|
22
|
+
.default(parent_category_id: nil)
|
23
|
+
response = put("/categories/#{category_id}", args)
|
24
|
+
response['body']['category'] if response['body']
|
25
|
+
end
|
26
|
+
|
16
27
|
def categories(params={})
|
17
28
|
response = get('/categories.json', params)
|
18
29
|
response[:body]['category_list']['categories']
|
@@ -25,7 +36,7 @@ module DiscourseApi
|
|
25
36
|
url = "/c/#{params[:category_slug]}/l/latest.json"
|
26
37
|
if params.include?(:page)
|
27
38
|
url = "#{url}?page=#{params[:page]}"
|
28
|
-
end
|
39
|
+
end
|
29
40
|
response = get(url)
|
30
41
|
if response[:body]['errors']
|
31
42
|
response[:body]['errors']
|
data/lib/discourse_api/client.rb
CHANGED
@@ -18,6 +18,7 @@ require 'discourse_api/api/email'
|
|
18
18
|
require 'discourse_api/api/api_key'
|
19
19
|
require 'discourse_api/api/backups'
|
20
20
|
require 'discourse_api/api/dashboard'
|
21
|
+
require 'discourse_api/api/uploads'
|
21
22
|
|
22
23
|
module DiscourseApi
|
23
24
|
class Client
|
@@ -40,6 +41,7 @@ module DiscourseApi
|
|
40
41
|
include DiscourseApi::API::ApiKey
|
41
42
|
include DiscourseApi::API::Backups
|
42
43
|
include DiscourseApi::API::Dashboard
|
44
|
+
include DiscourseApi::API::Uploads
|
43
45
|
|
44
46
|
def initialize(host, api_key = nil, api_username = nil)
|
45
47
|
raise ArgumentError, 'host needs to be defined' if host.nil? || host.empty?
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DiscourseApi::API::Uploads do
|
4
|
+
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
5
|
+
|
6
|
+
describe "#upload_post_image" do
|
7
|
+
before do
|
8
|
+
stub_post("http://localhost:3000/uploads?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("upload_post_image.json"), headers: { content_type: "application/json" })
|
9
|
+
end
|
10
|
+
|
11
|
+
it "uploads an image via URL" do
|
12
|
+
image = "https://meta-discourse.global.ssl.fastly.net/user_avatar/meta.discourse.org/sam/120/5243.png"
|
13
|
+
args = { url: image }
|
14
|
+
response = subject.upload_post_image(args)
|
15
|
+
expect(response["url"]).to eq("/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -197,7 +197,7 @@ describe DiscourseApi::API::Users do
|
|
197
197
|
end
|
198
198
|
|
199
199
|
it "makes the correct put request" do
|
200
|
-
|
200
|
+
subject.grant_admin(11)
|
201
201
|
url = "http://localhost:3000/admin/users/11/grant_admin?api_key=test_d7fd0429940&api_username=test_user"
|
202
202
|
expect(a_put(url)).to have_been_made
|
203
203
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"id": 11,
|
3
|
+
"user_id": 1,
|
4
|
+
"original_filename": "grumpy_cat.gif",
|
5
|
+
"filesize": 86900,
|
6
|
+
"width": 360,
|
7
|
+
"height": 360,
|
8
|
+
"url": "/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg",
|
9
|
+
"created_at": "2015-06-21T12:35:45.182Z",
|
10
|
+
"updated_at": "2015-06-21T12:35:45.195Z",
|
11
|
+
"sha1": "417e624d2453925e6c68748b9aa67637c284b5aa",
|
12
|
+
"origin": null,
|
13
|
+
"retain_hours": null
|
14
|
+
}
|
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.13.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: 2016-10-
|
14
|
+
date: 2016-10-09 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: faraday
|
@@ -190,6 +190,7 @@ files:
|
|
190
190
|
- examples/category.rb
|
191
191
|
- examples/change_topic_status.rb
|
192
192
|
- examples/create_topic.rb
|
193
|
+
- examples/create_update_category.rb
|
193
194
|
- examples/create_user.rb
|
194
195
|
- examples/dashboard.rb
|
195
196
|
- examples/disposable_invite_tokens.rb
|
@@ -201,6 +202,7 @@ files:
|
|
201
202
|
- examples/sso.rb
|
202
203
|
- examples/topic_lists.rb
|
203
204
|
- examples/update_user.rb
|
205
|
+
- examples/upload.rb
|
204
206
|
- lib/discourse_api.rb
|
205
207
|
- lib/discourse_api/api/api_key.rb
|
206
208
|
- lib/discourse_api/api/backups.rb
|
@@ -218,6 +220,7 @@ files:
|
|
218
220
|
- lib/discourse_api/api/sso.rb
|
219
221
|
- lib/discourse_api/api/tags.rb
|
220
222
|
- lib/discourse_api/api/topics.rb
|
223
|
+
- lib/discourse_api/api/uploads.rb
|
221
224
|
- lib/discourse_api/api/users.rb
|
222
225
|
- lib/discourse_api/client.rb
|
223
226
|
- lib/discourse_api/error.rb
|
@@ -237,6 +240,7 @@ files:
|
|
237
240
|
- spec/discourse_api/api/search_spec.rb
|
238
241
|
- spec/discourse_api/api/sso_spec.rb
|
239
242
|
- spec/discourse_api/api/topics_spec.rb
|
243
|
+
- spec/discourse_api/api/uploads_spec.rb
|
240
244
|
- spec/discourse_api/api/users_spec.rb
|
241
245
|
- spec/discourse_api/client_spec.rb
|
242
246
|
- spec/fixtures/api.json
|
@@ -266,6 +270,7 @@ files:
|
|
266
270
|
- spec/fixtures/topics_created_by.json
|
267
271
|
- spec/fixtures/update_trust_level.json
|
268
272
|
- spec/fixtures/upload_avatar.json
|
273
|
+
- spec/fixtures/upload_post_image.json
|
269
274
|
- spec/fixtures/user.json
|
270
275
|
- spec/fixtures/user_activate_success.json
|
271
276
|
- spec/fixtures/user_badges.json
|
@@ -315,6 +320,7 @@ test_files:
|
|
315
320
|
- spec/discourse_api/api/search_spec.rb
|
316
321
|
- spec/discourse_api/api/sso_spec.rb
|
317
322
|
- spec/discourse_api/api/topics_spec.rb
|
323
|
+
- spec/discourse_api/api/uploads_spec.rb
|
318
324
|
- spec/discourse_api/api/users_spec.rb
|
319
325
|
- spec/discourse_api/client_spec.rb
|
320
326
|
- spec/fixtures/api.json
|
@@ -344,6 +350,7 @@ test_files:
|
|
344
350
|
- spec/fixtures/topics_created_by.json
|
345
351
|
- spec/fixtures/update_trust_level.json
|
346
352
|
- spec/fixtures/upload_avatar.json
|
353
|
+
- spec/fixtures/upload_post_image.json
|
347
354
|
- spec/fixtures/user.json
|
348
355
|
- spec/fixtures/user_activate_success.json
|
349
356
|
- spec/fixtures/user_badges.json
|