micropub-server-rails 0.1.7 → 0.1.8
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29c9fb9910a4330b00b3fb19e63935be0f91992b
|
4
|
+
data.tar.gz: 300dfa66ec27fdd0127038f02cec47834cc003ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c50bfe29f6749d1433194c006540b46b5527e1e6cc3783bb3aa0ec1f8f72e9303c303576468e66fc2f9ad1b902eb25164b15f604468024b31ad0f272d2ca861d
|
7
|
+
data.tar.gz: 8782410070a75905028d3a2455e32d67ed73199b46b6e8810407e3d557d7874054c8f6066f6542fa75a7b5af3d758c65c713badcb99b51a64db35dc792d8cb84
|
@@ -3,6 +3,7 @@ require 'micropub'
|
|
3
3
|
module Micropub::Server::Rails
|
4
4
|
class Middleware
|
5
5
|
class HTTPError < StandardError
|
6
|
+
attr_reader :status
|
6
7
|
def initialize(env, status, body="")
|
7
8
|
@env = env
|
8
9
|
@status = status
|
@@ -17,15 +18,14 @@ module Micropub::Server::Rails
|
|
17
18
|
def call(env)
|
18
19
|
begin
|
19
20
|
@params = request(env).params
|
20
|
-
@headers = {"Content-Type" => "
|
21
|
+
@headers = {"Content-Type" => "application/x-www-form-urlencoded"}
|
21
22
|
if env["PATH_INFO"] == "/micropub"
|
22
|
-
check_token(env)
|
23
23
|
micropub_call env
|
24
24
|
else
|
25
25
|
@app.call env
|
26
26
|
end
|
27
|
-
rescue
|
28
|
-
error_response(
|
27
|
+
rescue HTTPError => env
|
28
|
+
error_response(env.status)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -40,6 +40,21 @@ module Micropub::Server::Rails
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def micropub_call(env)
|
43
|
+
case env["REQUEST_METHOD"]
|
44
|
+
when "GET" then syndicate_to env
|
45
|
+
when "POST" then post env
|
46
|
+
else
|
47
|
+
raise HTTPError.new env, 405
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def syndicate_to(env)
|
52
|
+
# TODO: Remove hardcoded syndicate link
|
53
|
+
[200, @headers, ["syndicate-to[]=twitter.com%2fbookis"]]
|
54
|
+
end
|
55
|
+
|
56
|
+
def post(env)
|
57
|
+
check_token env
|
43
58
|
router = Micropub::Homesteading::Router.new(@params)
|
44
59
|
client = Micropub::Client.new(router.as, token: auth_token(env))
|
45
60
|
response = client.post(@params.except("access_token"))
|
@@ -48,10 +63,6 @@ module Micropub::Server::Rails
|
|
48
63
|
|
49
64
|
@headers["Location"] = response.location
|
50
65
|
|
51
|
-
success_response
|
52
|
-
end
|
53
|
-
|
54
|
-
def success_response
|
55
66
|
[201, @headers, [""]]
|
56
67
|
end
|
57
68
|
|
@@ -2,9 +2,6 @@ require "micropub/server/rails/middleware"
|
|
2
2
|
require 'webmock/rspec'
|
3
3
|
require "rack/test"
|
4
4
|
|
5
|
-
# How do we determine what host to hit?
|
6
|
-
# Where does the code go which tells the mapping how to notes to work?
|
7
|
-
|
8
5
|
Micropub.configure do |c|
|
9
6
|
c.token_endpoint = "https://tokens.indieauth.com/token"
|
10
7
|
c.me = "http://bookisworthy.com"
|
@@ -25,6 +22,18 @@ describe Micropub::Server::Rails::Middleware do
|
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
25
|
+
describe "GET /micropub?q=syndicate-to" do
|
26
|
+
it "returns a 200" do
|
27
|
+
get "/micropub", q: "synicate-to"
|
28
|
+
expect(last_response.status).to eq 200
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns an http array called syndicate-to" do
|
32
|
+
get "/micropub", q: "synicate-to"
|
33
|
+
expect(last_response.body).to match /syndicate-to/
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
28
37
|
describe "POST /micropub" do
|
29
38
|
before do
|
30
39
|
expect(Micropub::Token).to receive(:new).with("1234").and_return(token)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: micropub-server-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Becker
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-03-
|
12
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|