discourse_api 0.20.1 → 0.22.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
  SHA1:
3
- metadata.gz: c81ac1a3d794e656c8653a7ee8a4a03974ed4736
4
- data.tar.gz: 279465d7b0f4c73134b4f06df0b2cd107428bb77
3
+ metadata.gz: a9d51b2cfe49d9321e7e800f2546744bdde713de
4
+ data.tar.gz: c5e3166b88afe5648610a67b4657fb3dfa371edb
5
5
  SHA512:
6
- metadata.gz: 7be49f0583b2d08a819cf9f6def284a795353f68c71db20c414beb22092805235971e673d170c658163f77bb5edcc6ddb5e94defa05f14a9fd82e9fda22a7c2d
7
- data.tar.gz: 0f493aea9db9218deb6d52b0aac68ff35395bf4b2f62985d0773c47d1080dfe21e46ead3c80c430f92227f36ea9f8acc1ea2104144d2211eabbfe2fd9dcc3af1
6
+ metadata.gz: 59dea74713ae2c6db273a223cfda6f3a825c77cfd2643feb3e6b34b19690ac6e3c394b03903493fd0349e0e4c55a483f7d4cfe78e4645315b528341815918fb5
7
+ data.tar.gz: e73d1365e79c1bf4bf0f4d546234b9f56919561b8b54004f3094ba1467b5279b9891835275fb9104cd903224b4b1cf210c63364774062271cafd7efed8caf029
@@ -2,6 +2,10 @@
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.22.0] - 2018-05-04
6
+ ### Added
7
+ - Support for subfolder paths
8
+
5
9
  ## [0.21.0] - 2018-04-23
6
10
  ### Fixed
7
11
  - Update GET groups api route
@@ -1,6 +1,7 @@
1
1
  require 'faraday'
2
2
  require 'faraday_middleware'
3
3
  require 'json'
4
+ require 'uri'
4
5
  require 'discourse_api/version'
5
6
  require 'discourse_api/api/categories'
6
7
  require 'discourse_api/api/search'
@@ -48,6 +49,7 @@ module DiscourseApi
48
49
  @host = host
49
50
  @api_key = api_key
50
51
  @api_username = api_username
52
+ @use_relative = check_subdirectory(host)
51
53
  end
52
54
 
53
55
  def connection_options
@@ -120,6 +122,7 @@ module DiscourseApi
120
122
  unless Hash === params
121
123
  params = params.to_h if params.respond_to? :to_h
122
124
  end
125
+ path = @use_relative ? path.sub(/^\//, '') : path
123
126
  response = connection.send(method.to_sym, path, params)
124
127
  handle_error(response)
125
128
  response.env
@@ -141,5 +144,9 @@ module DiscourseApi
141
144
  raise DiscourseApi::Error.new(response.env[:body])
142
145
  end
143
146
  end
147
+
148
+ def check_subdirectory(host)
149
+ URI(host).request_uri != '/'
150
+ end
144
151
  end
145
152
  end
@@ -1,3 +1,3 @@
1
1
  module DiscourseApi
2
- VERSION = "0.20.1"
2
+ VERSION = "0.22.0"
3
3
  end
@@ -65,40 +65,79 @@ describe DiscourseApi::Client do
65
65
  describe "#delete" do
66
66
  before do
67
67
  stub_delete("http://localhost:3000/test/delete?api_key=test_d7fd0429940&api_username=test_user").with(query: { deleted: "object" })
68
+ subject.api_key = 'test_d7fd0429940'
69
+ subject.api_username = 'test_user'
68
70
  end
69
71
 
70
72
  it "allows custom delete requests" do
71
- subject.api_key = 'test_d7fd0429940'
72
- subject.api_username = 'test_user'
73
73
  subject.delete("/test/delete", { deleted: "object" })
74
74
  expect(a_delete("http://localhost:3000/test/delete?api_key=test_d7fd0429940&api_username=test_user").with(query: { deleted: "object" })).to have_been_made
75
75
  end
76
+
77
+ context 'when using a host with a subdirectory' do
78
+ subject { DiscourseApi::Client.new('http://localhost:3000/forum') }
79
+
80
+ before do
81
+ stub_delete("http://localhost:3000/forum/test/delete?api_key=test_d7fd0429940&api_username=test_user").with(query: { deleted: "object" })
82
+ end
83
+
84
+ it "allows custom delete requests" do
85
+ subject.delete("/test/delete", { deleted: "object" })
86
+ expect(a_delete("http://localhost:3000/forum/test/delete?api_key=test_d7fd0429940&api_username=test_user").with(query: { deleted: "object" })).to have_been_made
87
+ end
88
+ end
76
89
  end
77
90
 
78
91
  describe "#post" do
79
92
  before do
80
93
  stub_post("http://localhost:3000/test/post?api_key=test_d7fd0429940&api_username=test_user").with(body: { created: "object"})
94
+ subject.api_key = 'test_d7fd0429940'
95
+ subject.api_username = 'test_user'
81
96
  end
82
97
 
83
98
  it "allows custom post requests" do
84
- subject.api_key = 'test_d7fd0429940'
85
- subject.api_username = 'test_user'
86
99
  subject.post("/test/post", { created: "object" })
87
100
  expect(a_post("http://localhost:3000/test/post?api_key=test_d7fd0429940&api_username=test_user").with(body: { created: "object"})).to have_been_made
88
101
  end
102
+
103
+ context 'when using a host with a subdirectory' do
104
+ subject { DiscourseApi::Client.new('http://localhost:3000/forum') }
105
+
106
+ before do
107
+ stub_post("http://localhost:3000/forum/test/post?api_key=test_d7fd0429940&api_username=test_user").with(body: { created: "object"})
108
+ end
109
+
110
+ it "allows custom post requests" do
111
+ subject.post("/test/post", { created: "object" })
112
+ expect(a_post("http://localhost:3000/forum/test/post?api_key=test_d7fd0429940&api_username=test_user").with(body: { created: "object"})).to have_been_made
113
+ end
114
+ end
89
115
  end
90
116
 
91
117
  describe "#put" do
92
118
  before do
93
119
  stub_put("http://localhost:3000/test/put?api_key=test_d7fd0429940&api_username=test_user").with(body: { updated: "object" })
120
+ subject.api_key = 'test_d7fd0429940'
121
+ subject.api_username = 'test_user'
94
122
  end
95
123
 
96
124
  it "allows custom put requests" do
97
- subject.api_key = 'test_d7fd0429940'
98
- subject.api_username = 'test_user'
99
125
  subject.put("/test/put", { updated: "object" })
100
126
  expect(a_put("http://localhost:3000/test/put?api_key=test_d7fd0429940&api_username=test_user").with(body: { updated: "object" })).to have_been_made
101
127
  end
128
+
129
+ context 'when using a host with a subdirectory' do
130
+ subject { DiscourseApi::Client.new('http://localhost:3000/forum') }
131
+
132
+ before do
133
+ stub_put("http://localhost:3000/forum/test/put?api_key=test_d7fd0429940&api_username=test_user").with(body: { updated: "object" })
134
+ end
135
+
136
+ it "allows custom post requests" do
137
+ subject.put("/test/put", { updated: "object" })
138
+ expect(a_put("http://localhost:3000/forum/test/put?api_key=test_d7fd0429940&api_username=test_user").with(body: { updated: "object" })).to have_been_made
139
+ end
140
+ end
102
141
  end
103
142
 
104
143
  describe "#request" do
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.20.1
4
+ version: 0.22.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: 2018-04-23 00:00:00.000000000 Z
14
+ date: 2018-05-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: faraday