discourse_api 0.1.1

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.
data/routes.txt ADDED
@@ -0,0 +1,203 @@
1
+ forums GET /forums(.:format) forums#index
2
+ POST /forums(.:format) forums#create
3
+ new_forum GET /forums/new(.:format) forums#new
4
+ edit_forum GET /forums/:id/edit(.:format) forums#edit
5
+ forum GET /forums/:id(.:format) forums#show
6
+ PUT /forums/:id(.:format) forums#update
7
+ DELETE /forums/:id(.:format) forums#destroy
8
+ srv_status GET /srv/status(.:format) forums#status
9
+ generate_key_admin_api_index POST /admin/api/generate_key(.:format) admin/api#generate_key
10
+ admin_api_index GET /admin/api(.:format) admin/api#index
11
+ email_preferences_redirect GET /email_preferences(.:format) email#preferences_redirect
12
+ email_unsubscribe GET /email/unsubscribe/:key(.:format) email#unsubscribe
13
+ email_resubscribe POST /email/resubscribe/:key(.:format) email#resubscribe
14
+ forgot_password_session_index POST /session/forgot_password(.:format) session#forgot_password {:id=>/[A-Za-z0-9\_]+/}
15
+ session_index POST /session(.:format) session#create {:id=>/[A-Za-z0-9\_]+/}
16
+ session DELETE /session/:id(.:format) session#destroy {:id=>/[A-Za-z0-9\_]+/}
17
+ session_csrf GET /session/csrf(.:format) session#csrf
18
+ GET /composer-messages(.:format) composer_messages#index
19
+ check_username_users GET /users/check_username(.:format) users#check_username
20
+ is_local_username_users GET /users/is_local_username(.:format) users#is_local_username
21
+ users GET /users(.:format) users#index
22
+ POST /users(.:format) users#create
23
+ new_user GET /users/new(.:format) users#new
24
+ edit_user GET /users/:id/edit(.:format) users#edit
25
+ user DELETE /users/:id(.:format) users#destroy
26
+ static_index GET /static(.:format) static#index
27
+ POST /static(.:format) static#create
28
+ new_static GET /static/new(.:format) static#new
29
+ edit_static GET /static/:id/edit(.:format) static#edit
30
+ static GET /static/:id(.:format) static#show
31
+ PUT /static/:id(.:format) static#update
32
+ DELETE /static/:id(.:format) static#destroy
33
+ login POST /login(.:format) static#enter
34
+ GET /login(.:format) static#show {:id=>"login"}
35
+ faq GET /faq(.:format) static#show {:id=>"faq"}
36
+ tos GET /tos(.:format) static#show {:id=>"tos"}
37
+ privacy GET /privacy(.:format) static#show {:id=>"privacy"}
38
+ users_search_users GET /users/search/users(.:format) users#search_users
39
+ GET /users/password-reset/:token(.:format) users#password_reset
40
+ PUT /users/password-reset/:token(.:format) users#password_reset
41
+ GET /users/activate-account/:token(.:format) users#activate_account
42
+ GET /users/authorize-email/:token(.:format) users#authorize_email
43
+ users_hp GET /users/hp(.:format) users#get_honeypot_value
44
+ user_preferences GET /user_preferences(.:format) users#user_preferences_redirect
45
+ GET /users/:username/private-messages(.:format) user_actions#private_messages {:username=>/[A-Za-z0-9\_]+/}
46
+ GET /users/:username/private-messages/:filter(.:format) user_actions#private_messages {:username=>/[A-Za-z0-9\_]+/}
47
+ GET /users/:username(.:format) users#show {:username=>/[A-Za-z0-9\_]+/}
48
+ PUT /users/:username(.:format) users#update {:username=>/[A-Za-z0-9\_]+/}
49
+ email_preferences GET /users/:username/preferences(.:format) users#preferences {:username=>/[A-Za-z0-9\_]+/}
50
+ GET /users/:username/preferences/email(.:format) users#preferences {:username=>/[A-Za-z0-9\_]+/}
51
+ PUT /users/:username/preferences/email(.:format) users#change_email {:username=>/[A-Za-z0-9\_]+/}
52
+ GET /users/:username/preferences/about-me(.:format) users#preferences {:username=>/[A-Za-z0-9\_]+/}
53
+ GET /users/:username/preferences/username(.:format) users#preferences {:username=>/[A-Za-z0-9\_]+/}
54
+ PUT /users/:username/preferences/username(.:format) users#username {:username=>/[A-Za-z0-9\_]+/}
55
+ GET /users/:username/avatar(/:size)(.:format) users#avatar {:username=>/[A-Za-z0-9\_]+/}
56
+ POST /users/:username/preferences/avatar(.:format) users#upload_avatar {:username=>/[A-Za-z0-9\_]+/}
57
+ PUT /users/:username/preferences/avatar/toggle(.:format) users#toggle_avatar {:username=>/[A-Za-z0-9\_]+/}
58
+ GET /users/:username/invited(.:format) users#invited {:username=>/[A-Za-z0-9\_]+/}
59
+ POST /users/:username/send_activation_email(.:format) users#send_activation_email {:username=>/[A-Za-z0-9\_]+/}
60
+ GET /users/:username/activity(.:format) users#show {:username=>/[A-Za-z0-9\_]+/}
61
+ GET /users/:username/activity/:filter(.:format) users#show {:username=>/[A-Za-z0-9\_]+/}
62
+ GET /uploads/:site/:id/:sha.:extension(.:format) uploads#show {:site=>/\w+/, :id=>/\d+/, :sha=>/[a-z0-9]{15,16}/i, :extension=>/\w{2,}/}
63
+ uploads POST /uploads(.:format) uploads#create
64
+ GET /posts/by_number/:topic_id/:post_number(.:format) posts#by_number
65
+ GET /posts/:id/reply-history(.:format) posts#reply_history
66
+ post_versions GET /posts/:post_id/versions(.:format) posts#versions
67
+ post_bookmark PUT /posts/:post_id/bookmark(.:format) posts#bookmark
68
+ post_replies GET /posts/:post_id/replies(.:format) posts#replies
69
+ post_recover PUT /posts/:post_id/recover(.:format) posts#recover
70
+ destroy_many_posts DELETE /posts/destroy_many(.:format) posts#destroy_many
71
+ posts GET /posts(.:format) posts#index
72
+ POST /posts(.:format) posts#create
73
+ new_post GET /posts/new(.:format) posts#new
74
+ edit_post GET /posts/:id/edit(.:format) posts#edit
75
+ post GET /posts/:id(.:format) posts#show
76
+ PUT /posts/:id(.:format) posts#update
77
+ DELETE /posts/:id(.:format) posts#destroy
78
+ GET /p/:post_id/:user_id(.:format) posts#short_link
79
+ notifications GET /notifications(.:format) notifications#index
80
+ POST /notifications(.:format) notifications#create
81
+ new_notification GET /notifications/new(.:format) notifications#new
82
+ edit_notification GET /notifications/:id/edit(.:format) notifications#edit
83
+ notification GET /notifications/:id(.:format) notifications#show
84
+ PUT /notifications/:id(.:format) notifications#update
85
+ DELETE /notifications/:id(.:format) notifications#destroy
86
+ GET|POST /auth/:provider/callback(.:format) users/omniauth_callbacks#complete
87
+ auth_failure GET|POST /auth/failure(.:format) users/omniauth_callbacks#failure
88
+ track_clicks GET /clicks/track(.:format) clicks#track
89
+ clicks GET /clicks(.:format) clicks#index
90
+ POST /clicks(.:format) clicks#create
91
+ new_click GET /clicks/new(.:format) clicks#new
92
+ edit_click GET /clicks/:id/edit(.:format) clicks#edit
93
+ click GET /clicks/:id(.:format) clicks#show
94
+ PUT /clicks/:id(.:format) clicks#update
95
+ DELETE /clicks/:id(.:format) clicks#destroy
96
+ excerpt GET /excerpt(.:format) excerpt#show
97
+ users_post_actions GET /post_actions/users(.:format) post_actions#users
98
+ clear_flags_post_actions POST /post_actions/clear_flags(.:format) post_actions#clear_flags
99
+ post_actions GET /post_actions(.:format) post_actions#index
100
+ POST /post_actions(.:format) post_actions#create
101
+ new_post_action GET /post_actions/new(.:format) post_actions#new
102
+ edit_post_action GET /post_actions/:id/edit(.:format) post_actions#edit
103
+ post_action GET /post_actions/:id(.:format) post_actions#show
104
+ PUT /post_actions/:id(.:format) post_actions#update
105
+ DELETE /post_actions/:id(.:format) post_actions#destroy
106
+ user_actions GET /user_actions(.:format) user_actions#index
107
+ POST /user_actions(.:format) user_actions#create
108
+ new_user_action GET /user_actions/new(.:format) user_actions#new
109
+ edit_user_action GET /user_actions/:id/edit(.:format) user_actions#edit
110
+ user_action GET /user_actions/:id(.:format) user_actions#show
111
+ PUT /user_actions/:id(.:format) user_actions#update
112
+ DELETE /user_actions/:id(.:format) user_actions#destroy
113
+ categories GET /categories(.:format) categories#index
114
+ POST /categories(.:format) categories#create
115
+ new_category GET /categories/new(.:format) categories#new
116
+ edit_category GET /categories/:id/edit(.:format) categories#edit
117
+ category PUT /categories/:id(.:format) categories#update
118
+ DELETE /categories/:id(.:format) categories#destroy
119
+ GET /category/:id/show(.:format) categories#show
120
+ category_feed GET /category/:category.rss(.:format) list#category_feed {:format=>:rss}
121
+ category_list GET /category/:category(.:format) list#category
122
+ category_list_more GET /category/:category/more(.:format) list#category
123
+ popular GET /popular(.:format) list#popular_redirect
124
+ popular_more GET /popular/more(.:format) list#popular_redirect
125
+ latest_feed GET /latest.rss(.:format) list#latest_feed {:format=>:rss, :filter=>:latest}
126
+ hot_feed GET /hot.rss(.:format) list#hot_feed {:format=>:rss, :filter=>:hot}
127
+ latest GET /latest(.:format) list#latest
128
+ latest_more GET /latest/more(.:format) list#latest
129
+ hot GET /hot(.:format) list#hot
130
+ hot_more GET /hot/more(.:format) list#hot
131
+ favorited GET /favorited(.:format) list#favorited
132
+ favorited_more GET /favorited/more(.:format) list#favorited
133
+ read GET /read(.:format) list#read
134
+ read_more GET /read/more(.:format) list#read
135
+ posted GET /posted(.:format) list#posted
136
+ posted_more GET /posted/more(.:format) list#posted
137
+ unread GET /unread(.:format) list#unread
138
+ unread_more GET /unread/more(.:format) list#unread
139
+ new GET /new(.:format) list#new
140
+ new_more GET /new/more(.:format) list#new
141
+ search GET /search(.:format) search#query
142
+ GET /t/:id(.:format) topics#show
143
+ DELETE /t/:id(.:format) topics#destroy
144
+ PUT /t/:id(.:format) topics#update
145
+ t POST /t(.:format) topics#create
146
+ topics_timings POST /topics/timings(.:format) topics#timings
147
+ topics_similar_to GET /topics/similar_to(.:format) topics#similar_to
148
+ topics_by GET /topics/created-by/:username(.:format) list#topics_by {:username=>/[A-Za-z0-9\_]+/}
149
+ topics_private_messages GET /topics/private-messages/:username(.:format) list#private_messages {:username=>/[A-Za-z0-9\_]+/}
150
+ topics_private_messages_sent GET /topics/private-messages-sent/:username(.:format) list#private_messages_sent {:username=>/[A-Za-z0-9\_]+/}
151
+ topics_private_messages_unread GET /topics/private-messages-unread/:username(.:format) list#private_messages_unread {:username=>/[A-Za-z0-9\_]+/}
152
+ GET /t/:slug/:topic_id/wordpress(.:format) topics#wordpress {:topic_id=>/\d+/}
153
+ GET /t/:slug/:topic_id/moderator-liked(.:format) topics#moderator_liked {:topic_id=>/\d+/}
154
+ GET /t/:topic_id/wordpress(.:format) topics#wordpress {:topic_id=>/\d+/}
155
+ GET /t/:slug/:topic_id/best_of(.:format) topics#show {:topic_id=>/\d+/, :post_number=>/\d+/, :best_of=>true}
156
+ GET /t/:topic_id/best_of(.:format) topics#show {:topic_id=>/\d+/, :post_number=>/\d+/}
157
+ PUT /t/:slug/:topic_id(.:format) topics#update {:topic_id=>/\d+/}
158
+ PUT /t/:slug/:topic_id/star(.:format) topics#star {:topic_id=>/\d+/}
159
+ PUT /t/:topic_id/star(.:format) topics#star {:topic_id=>/\d+/}
160
+ PUT /t/:slug/:topic_id/status(.:format) topics#status {:topic_id=>/\d+/}
161
+ PUT /t/:topic_id/status(.:format) topics#status {:topic_id=>/\d+/}
162
+ PUT /t/:topic_id/clear-pin(.:format) topics#clear_pin {:topic_id=>/\d+/}
163
+ PUT /t/:topic_id/mute(.:format) topics#mute {:topic_id=>/\d+/}
164
+ PUT /t/:topic_id/unmute(.:format) topics#unmute {:topic_id=>/\d+/}
165
+ PUT /t/:topic_id/autoclose(.:format) topics#autoclose {:topic_id=>/\d+/}
166
+ PUT /t/:topic_id/remove-allowed-user(.:format) topics#remove_allowed_user {:topic_id=>/\d+/}
167
+ PUT /t/:topic_id/recover(.:format) topics#recover {:topic_id=>/\d+/}
168
+ GET /t/:topic_id/:post_number(.:format) topics#show {:topic_id=>/\d+/, :post_number=>/\d+/}
169
+ GET /t/:slug/:topic_id.rss(.:format) topics#feed {:topic_id=>/\d+/, :format=>:rss}
170
+ GET /t/:slug/:topic_id(.:format) topics#show {:topic_id=>/\d+/}
171
+ GET /t/:slug/:topic_id/:post_number(.:format) topics#show {:topic_id=>/\d+/, :post_number=>/\d+/}
172
+ GET /t/:topic_id/posts(.:format) topics#posts {:topic_id=>/\d+/}
173
+ POST /t/:topic_id/timings(.:format) topics#timings {:topic_id=>/\d+/}
174
+ POST /t/:topic_id/invite(.:format) topics#invite {:topic_id=>/\d+/}
175
+ POST /t/:topic_id/move-posts(.:format) topics#move_posts {:topic_id=>/\d+/}
176
+ POST /t/:topic_id/merge-topic(.:format) topics#merge_topic {:topic_id=>/\d+/}
177
+ DELETE /t/:topic_id/timings(.:format) topics#destroy_timings {:topic_id=>/\d+/}
178
+ POST /t/:topic_id/notifications(.:format) topics#set_notifications {:topic_id=>/\d+/}
179
+ GET /raw/:topic_id(/:post_number)(.:format) posts#markdown
180
+ invites GET /invites(.:format) invites#index
181
+ POST /invites(.:format) invites#create
182
+ new_invite GET /invites/new(.:format) invites#new
183
+ edit_invite GET /invites/:id/edit(.:format) invites#edit
184
+ invite GET /invites/:id(.:format) invites#show
185
+ PUT /invites/:id(.:format) invites#update
186
+ DELETE /invites/:id(.:format) invites#destroy
187
+ DELETE /invites(.:format) invites#destroy
188
+ onebox GET /onebox(.:format) onebox#show
189
+ error GET /error(.:format) forums#error
190
+ GET /message-bus/poll(.:format) message_bus#poll
191
+ draft GET /draft(.:format) draft#show
192
+ POST /draft(.:format) draft#update
193
+ DELETE /draft(.:format) draft#destroy
194
+ GET /robots.txt(.:format) robots_txt#index
195
+ list_latest / list#latest
196
+ list_hot / list#hot
197
+ list_unread / list#unread
198
+ list_new / list#new
199
+ list_favorited / list#favorited
200
+ list_read / list#read
201
+ list_posted / list#posted
202
+ categories_index / categories#index
203
+
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe DiscourseApi::API::Categories do
4
+ subject { DiscourseApi::Client.new("http://localhost") }
5
+
6
+ describe "#categories" do
7
+ before do
8
+ stub_get("http://localhost/categories.json").to_return(body: fixture("categories.json"), headers: { content_type: "application/json" })
9
+ end
10
+
11
+ it "requests the correct resource" do
12
+ subject.categories
13
+ expect(a_get("http://localhost/categories.json")).to have_been_made
14
+ end
15
+
16
+ it "returns the requested categories" do
17
+ categories = subject.categories
18
+ expect(categories).to be_an Array
19
+ expect(categories.first).to be_a Hash
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe DiscourseApi::API::Search do
4
+ subject { DiscourseApi::Client.new("http://localhost") }
5
+
6
+ describe "#search" do
7
+ before do
8
+ stub_get("http://localhost/search.json").with(query: { term: "test"} ).to_return(body: fixture("search.json"), headers: { content_type: "application/json" })
9
+ end
10
+
11
+ it "requests the correct resource" do
12
+ subject.search("test")
13
+ expect(a_get("http://localhost/search.json").with(query: { term: "test"} )).to have_been_made
14
+ end
15
+
16
+ it "returns the requested search" do
17
+ results = subject.search("test")
18
+ expect(results).to be_an Array
19
+ expect(results.first).to be_a Hash
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe DiscourseApi::API::Topics do
4
+ subject { DiscourseApi::Client.new("http://localhost") }
5
+
6
+ describe "#hot_topics" do
7
+ before do
8
+ stub_get("http://localhost/hot.json").to_return(body: fixture("hot.json"), headers: { content_type: "application/json" })
9
+ end
10
+
11
+ it "requests the correct resource" do
12
+ subject.hot_topics
13
+ expect(a_get("http://localhost/hot.json")).to have_been_made
14
+ end
15
+
16
+ it "returns the requested topics" do
17
+ topics = subject.hot_topics
18
+ expect(topics).to be_an Array
19
+ expect(topics.first).to be_a Hash
20
+ end
21
+ end
22
+
23
+ describe "#invite_user_to_topic" do
24
+ it "needs to have a test written for it"
25
+ end
26
+
27
+ describe "#latest_topics" do
28
+ before do
29
+ stub_get("http://localhost/latest.json").to_return(body: fixture("latest.json"), headers: { content_type: "application/json" })
30
+ end
31
+
32
+ it "requests the correct resource" do
33
+ subject.latest_topics
34
+ expect(a_get("http://localhost/latest.json")).to have_been_made
35
+ end
36
+
37
+ it "returns the requested topics" do
38
+ topics = subject.latest_topics
39
+ expect(topics).to be_an Array
40
+ expect(topics.first).to be_a Hash
41
+ end
42
+ end
43
+
44
+ describe "#new_topics" do
45
+ before do
46
+ stub_get("http://localhost/new.json").to_return(body: fixture("new.json"), headers: { content_type: "application/json" })
47
+ end
48
+
49
+ it "requests the correct resource" do
50
+ subject.new_topics
51
+ expect(a_get("http://localhost/new.json")).to have_been_made
52
+ end
53
+
54
+ it "returns the requested topics" do
55
+ topics = subject.new_topics
56
+ expect(topics).to be_an Array
57
+ expect(topics.first).to be_a Hash
58
+ end
59
+ end
60
+
61
+ describe "#topic" do
62
+ before do
63
+ stub_get("http://localhost/t/57.json").to_return(body: fixture("topic.json"), headers: { content_type: "application/json" })
64
+ end
65
+
66
+ it "requests the correct resource" do
67
+ subject.topic(57)
68
+ expect(a_get("http://localhost/t/57.json")).to have_been_made
69
+ end
70
+
71
+ it "returns the requested topic" do
72
+ topic = subject.topic(57)
73
+ expect(topic).to be_a Hash
74
+ expect(topic["id"]).to eq(57)
75
+ end
76
+ end
77
+
78
+ describe "#topics_by" do
79
+ before do
80
+ stub_get("http://localhost/topics/created-by/test_user.json").to_return(body: fixture("topics_created_by.json"), headers: { content_type: "application/json" })
81
+ end
82
+
83
+ it "requests the correct resource" do
84
+ subject.topics_by('test_user')
85
+ expect(a_get("http://localhost/topics/created-by/test_user.json")).to have_been_made
86
+ end
87
+
88
+ it "returns the requested topics" do
89
+ topics = subject.topics_by('test_user')
90
+ expect(topics).to be_an Array
91
+ expect(topics.first).to be_a Hash
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe DiscourseApi::API::Users do
4
+ subject { DiscourseApi::Client.new("http://localhost") }
5
+
6
+ describe "#toggle_avatar" do
7
+ it "needs to have a test written for it"
8
+ end
9
+
10
+ describe "#user" do
11
+ before do
12
+ stub_get("http://localhost/user/test_user.json").to_return(body: fixture("user.json"), headers: { content_type: "application/json" })
13
+ end
14
+
15
+ it "requests the correct resource" do
16
+ subject.user("test_user")
17
+ expect(a_get("http://localhost/user/test_user.json")).to have_been_made
18
+ end
19
+
20
+ it "returns the requested user" do
21
+ user = subject.user("test_user")
22
+ expect(user).to be_a Hash
23
+ end
24
+ end
25
+
26
+ describe "#update_avatar" do
27
+ it "needs to have a test written for it"
28
+ end
29
+
30
+ describe "#update_email" do
31
+ it "needs to have a test written for it"
32
+ end
33
+
34
+ describe "#update_user" do
35
+ it "needs to have a test written for it"
36
+ end
37
+
38
+ describe "#update_username" do
39
+ it "needs to have a test written for it"
40
+ end
41
+ end
@@ -0,0 +1,105 @@
1
+ require 'spec_helper'
2
+
3
+ describe DiscourseApi::Client do
4
+ subject { DiscourseApi::Client.new('http://localhost') }
5
+
6
+ describe ".new" do
7
+ it "requires a host argument" do
8
+ expect { DiscourseApi::Client.new }.to raise_error ArgumentError
9
+ end
10
+
11
+ it "defaults api key to nil" do
12
+ expect(subject.api_key).to be_nil
13
+ end
14
+
15
+ it "defaults api username to nil" do
16
+ expect(subject.api_username).to be_nil
17
+ end
18
+
19
+ it "accepts an api key argument" do
20
+ client = DiscourseApi::Client.new('http://localhost', 'test')
21
+ expect(client.api_key).to eq('test')
22
+ end
23
+
24
+ it "accepts an api username argument" do
25
+ client = DiscourseApi::Client.new('http://localhost', 'test', 'test_user')
26
+ expect(client.api_username).to eq('test_user')
27
+ end
28
+ end
29
+
30
+ describe "#api_key" do
31
+ it "is publically accessible" do
32
+ subject.api_key = "test_key"
33
+ expect(subject.api_key).to eq("test_key")
34
+ end
35
+ end
36
+
37
+ describe "#api_username" do
38
+ it "is publically accessible" do
39
+ subject.api_username = "test_user"
40
+ expect(subject.api_username).to eq("test_user")
41
+ end
42
+ end
43
+
44
+ describe "#host" do
45
+ it "is publically readable" do
46
+ expect(subject.host).to eq("http://localhost")
47
+ end
48
+
49
+ it "is not publically writeable" do
50
+ expect(subject).not_to respond_to(:host=)
51
+ end
52
+ end
53
+
54
+ describe "#connection" do
55
+ it "looks like a Faraday connection" do
56
+ expect(subject.send(:connection)).to respond_to :run_request
57
+ end
58
+ it "memoizes the connection" do
59
+ c1, c2 = subject.send(:connection), subject.send(:connection)
60
+ expect(c1.object_id).to eq(c2.object_id)
61
+ end
62
+ end
63
+
64
+ describe "#delete" do
65
+ before do
66
+ stub_delete("http://localhost/test/delete").with(query: { deleted: "object" })
67
+ end
68
+ it "allows custom delete requests" do
69
+ subject.delete("/test/delete", { deleted: "object" })
70
+ expect(a_delete("http://localhost/test/delete").with(query: { deleted: "object" })).to have_been_made
71
+ end
72
+ end
73
+
74
+ describe "#post" do
75
+ before do
76
+ stub_post("http://localhost/test/post").with(body: { created: "object"})
77
+ end
78
+
79
+ it "allows custom post requests" do
80
+ subject.post("/test/post", { created: "object" })
81
+ expect(a_post("http://localhost/test/post").with(body: { created: "object"})).to have_been_made
82
+ end
83
+ end
84
+
85
+ describe "#put" do
86
+ before do
87
+ stub_put("http://localhost/test/put").with(body: { updated: "object" })
88
+ end
89
+ it "allows custom delete requests" do
90
+ subject.put("/test/put", { updated: "object" })
91
+ expect(a_put("http://localhost/test/put").with(body: { updated: "object" })).to have_been_made
92
+ end
93
+ end
94
+
95
+ describe "#request" do
96
+ it "catches Faraday errors" do
97
+ allow(subject).to receive(:connection).and_raise(Faraday::Error::ClientError.new("BOOM!"))
98
+ expect{subject.send(:request, :get, "/test")}.to raise_error DiscourseApi::Error
99
+ end
100
+ it "catches JSON::ParserError errors" do
101
+ allow(subject).to receive(:connection).and_raise(JSON::ParserError.new("unexpected token"))
102
+ expect{subject.send(:request, :get, "/test")}.to raise_error DiscourseApi::Error
103
+ end
104
+ end
105
+ end