discourse_api 0.15.0 → 0.16.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 +6 -0
- data/README.md +10 -0
- data/examples/create_private_message.rb +1 -1
- data/examples/{upload.rb → sent_private_messages.rb} +1 -5
- data/examples/upload_file.rb +13 -0
- data/lib/discourse_api/api/private_messages.rb +5 -0
- data/lib/discourse_api/api/uploads.rb +1 -1
- data/lib/discourse_api/client.rb +4 -0
- data/lib/discourse_api/version.rb +1 -1
- data/spec/discourse_api/api/private_messages_spec.rb +18 -2
- data/spec/discourse_api/api/uploads_spec.rb +11 -3
- data/spec/discourse_api/client_spec.rb +7 -0
- data/spec/fixtures/{upload_post_image.json → upload_file.json} +0 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbc919ed6b4b910836e7c49ee0eeeba549089ab0
|
4
|
+
data.tar.gz: 66a670a076264fed42fc8763358c94a698d2fc0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d29e787eb57d150ee9ceac985e41ac185a56316a2083a59f756e9f4a04ca3bb1ee0440cc772f33198c7222b1ff322dc67080c8ff1ac0610a550938a8b09c4c69
|
7
|
+
data.tar.gz: 696ff6e30a2c947d7a3c4906ebff3cc43b55b71ca7c3c95e77d530b083ceece1a7bf6ffd2899da18a5976f7fc7becc817fc472c572e201f531979e5426b05f6e
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
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.16.0] - 2017-05-14
|
6
|
+
### Added
|
7
|
+
- added `upload_file`
|
8
|
+
### Removed
|
9
|
+
- removed `upload_post_image`
|
10
|
+
|
5
11
|
## [0.15.0] - 2017-04-12
|
6
12
|
### Added
|
7
13
|
- added the ability to create private messages
|
data/README.md
CHANGED
@@ -54,6 +54,16 @@ client.sync_sso( #=> Synchronizes the SSO record
|
|
54
54
|
email: "name@example.com",
|
55
55
|
external_id: "2"
|
56
56
|
)
|
57
|
+
|
58
|
+
# Private messages
|
59
|
+
client.private_messages("test_user") #=> Gets a list of private messages received by "test_user"
|
60
|
+
client.sent_private_messages("test_user") #=> Gets a list of private messages sent by "test_user"
|
61
|
+
client.create_private_message( #=> Creates a private messages by api_username user
|
62
|
+
title: "Confidential: Hello World!",
|
63
|
+
raw: "This is the raw markdown for my private message",
|
64
|
+
target_usernames: "user1,user2"
|
65
|
+
)
|
66
|
+
|
57
67
|
```
|
58
68
|
|
59
69
|
|
@@ -5,8 +5,4 @@ client = DiscourseApi::Client.new("http://localhost:3000")
|
|
5
5
|
client.api_key = "YOUR_API_KEY"
|
6
6
|
client.api_username = "YOUR_USERNAME"
|
7
7
|
|
8
|
-
|
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')
|
8
|
+
client.sent_private_messages('test_user')
|
@@ -0,0 +1,13 @@
|
|
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 a file
|
9
|
+
file = Faraday::UploadIO.new('grumpy_cat.pdf', "application/pdf")
|
10
|
+
client.upload_file(file: file)
|
11
|
+
|
12
|
+
# Upload a file via URL
|
13
|
+
client.upload_file(url: 'https://giphy.com/grumpy_cat.gif')
|
@@ -17,6 +17,11 @@ module DiscourseApi
|
|
17
17
|
response = get("topics/private-messages/#{username}.json", args)
|
18
18
|
response[:body]['topic_list']['topics']
|
19
19
|
end
|
20
|
+
|
21
|
+
def sent_private_messages(username, *args)
|
22
|
+
response = get("topics/private-messages-sent/#{username}.json", args)
|
23
|
+
response[:body]['topic_list']['topics']
|
24
|
+
end
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
data/lib/discourse_api/client.rb
CHANGED
@@ -100,6 +100,8 @@ module DiscourseApi
|
|
100
100
|
@connection ||= Faraday.new connection_options do |conn|
|
101
101
|
# Follow redirects
|
102
102
|
conn.use FaradayMiddleware::FollowRedirects, limit: 5
|
103
|
+
# Allow uploading of files
|
104
|
+
conn.request :multipart
|
103
105
|
# Convert request params to "www-form-encoded"
|
104
106
|
conn.request :url_encoded
|
105
107
|
# Parse responses as JSON
|
@@ -135,6 +137,8 @@ module DiscourseApi
|
|
135
137
|
raise DiscourseApi::UnprocessableEntity.new(response.env[:body])
|
136
138
|
when 429
|
137
139
|
raise DiscourseApi::TooManyRequests.new(response.env[:body])
|
140
|
+
when 500...600
|
141
|
+
raise DiscourseApi::Error.new(response.env[:body])
|
138
142
|
end
|
139
143
|
end
|
140
144
|
end
|
@@ -19,19 +19,35 @@ describe DiscourseApi::API::PrivateMessages do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
describe "#sent_private_messages" do
|
23
|
+
before do
|
24
|
+
stub_get("http://localhost:3000/topics/private-messages-sent/test_user.json?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("private_messages.json"), headers: { content_type: "application/json" })
|
25
|
+
end
|
26
|
+
|
27
|
+
it "requests the correct resource" do
|
28
|
+
subject.sent_private_messages('test_user')
|
29
|
+
expect(a_get("http://localhost:3000/topics/private-messages-sent/test_user.json?api_key=test_d7fd0429940&api_username=test_user")).to have_been_made
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns the requested sent private messages" do
|
33
|
+
private_messages = subject.sent_private_messages('test_user')
|
34
|
+
expect(private_messages).to be_an Array
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
22
38
|
describe '#create_private_message' do
|
23
39
|
before do
|
24
40
|
stub_post("http://localhost:3000/posts?api_key=test_d7fd0429940&api_username=test_user")
|
25
41
|
subject.create_private_message(
|
26
42
|
title: "Confidential: Hello World!",
|
27
43
|
raw: "This is the raw markdown for my private message",
|
28
|
-
target_usernames:
|
44
|
+
target_usernames: "user1,user2"
|
29
45
|
)
|
30
46
|
end
|
31
47
|
|
32
48
|
it "makes a create private message request" do
|
33
49
|
expect(a_post("http://localhost:3000/posts?api_key=test_d7fd0429940&api_username=test_user").with(body:
|
34
|
-
'archetype=private_message&raw=This+is+the+raw+markdown+for+my+private+message&target_usernames
|
50
|
+
'archetype=private_message&raw=This+is+the+raw+markdown+for+my+private+message&target_usernames=user1%2Cuser2&title=Confidential%3A+Hello+World%21')
|
35
51
|
).to have_been_made
|
36
52
|
end
|
37
53
|
end
|
@@ -3,16 +3,24 @@ require 'spec_helper'
|
|
3
3
|
describe DiscourseApi::API::Uploads do
|
4
4
|
subject { DiscourseApi::Client.new("http://localhost:3000", "test_d7fd0429940", "test_user") }
|
5
5
|
|
6
|
-
describe "#
|
6
|
+
describe "#upload_file" do
|
7
7
|
before do
|
8
|
-
stub_post("http://localhost:3000/uploads?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("
|
8
|
+
stub_post("http://localhost:3000/uploads?api_key=test_d7fd0429940&api_username=test_user").to_return(body: fixture("upload_file.json"), headers: { content_type: "application/json" })
|
9
9
|
end
|
10
10
|
|
11
11
|
it "uploads an image via URL" do
|
12
12
|
image = "https://meta-discourse.global.ssl.fastly.net/user_avatar/meta.discourse.org/sam/120/5243.png"
|
13
13
|
args = { url: image }
|
14
|
-
response = subject.
|
14
|
+
response = subject.upload_file(args)
|
15
15
|
expect(response["url"]).to eq("/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg")
|
16
16
|
end
|
17
|
+
|
18
|
+
it "uploads a file" do
|
19
|
+
file = Faraday::UploadIO.new('spec/fixtures/upload_file.json', "application/json")
|
20
|
+
args = { file: file }
|
21
|
+
response = subject.upload_file(args)
|
22
|
+
expect(response["url"]).to eq("/uploads/default/original/1X/417e624d2453925e6c68748b9aa67637c284b5aa.jpg")
|
23
|
+
end
|
24
|
+
|
17
25
|
end
|
18
26
|
end
|
@@ -102,6 +102,13 @@ describe DiscourseApi::Client do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
describe "#request" do
|
105
|
+
it "catches 500 errors" do
|
106
|
+
connection = instance_double(Faraday::Connection)
|
107
|
+
allow(connection).to receive(:get).and_return(OpenStruct.new(env: { body: 'error page html' }, status: 500))
|
108
|
+
allow(subject).to receive(:connection).and_return(connection)
|
109
|
+
expect{subject.send(:request, :get, "/test")}.to raise_error DiscourseApi::Error
|
110
|
+
end
|
111
|
+
|
105
112
|
it "catches Faraday errors" do
|
106
113
|
allow(subject).to receive(:connection).and_raise(Faraday::Error::ClientError.new("BOOM!"))
|
107
114
|
expect{subject.send(:request, :get, "/test")}.to raise_error DiscourseApi::Error
|
File without changes
|
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.16.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: 2017-
|
14
|
+
date: 2017-05-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: faraday
|
@@ -201,10 +201,11 @@ files:
|
|
201
201
|
- examples/invite_users.rb
|
202
202
|
- examples/post_action.rb
|
203
203
|
- examples/search.rb
|
204
|
+
- examples/sent_private_messages.rb
|
204
205
|
- examples/sso.rb
|
205
206
|
- examples/topic_lists.rb
|
206
207
|
- examples/update_user.rb
|
207
|
-
- examples/
|
208
|
+
- examples/upload_file.rb
|
208
209
|
- lib/discourse_api.rb
|
209
210
|
- lib/discourse_api/api/api_key.rb
|
210
211
|
- lib/discourse_api/api/backups.rb
|
@@ -272,7 +273,7 @@ files:
|
|
272
273
|
- spec/fixtures/topics_created_by.json
|
273
274
|
- spec/fixtures/update_trust_level.json
|
274
275
|
- spec/fixtures/upload_avatar.json
|
275
|
-
- spec/fixtures/
|
276
|
+
- spec/fixtures/upload_file.json
|
276
277
|
- spec/fixtures/user.json
|
277
278
|
- spec/fixtures/user_activate_success.json
|
278
279
|
- spec/fixtures/user_badges.json
|
@@ -352,7 +353,7 @@ test_files:
|
|
352
353
|
- spec/fixtures/topics_created_by.json
|
353
354
|
- spec/fixtures/update_trust_level.json
|
354
355
|
- spec/fixtures/upload_avatar.json
|
355
|
-
- spec/fixtures/
|
356
|
+
- spec/fixtures/upload_file.json
|
356
357
|
- spec/fixtures/user.json
|
357
358
|
- spec/fixtures/user_activate_success.json
|
358
359
|
- spec/fixtures/user_badges.json
|