micropub 0.0.1 → 0.0.2
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/.travis.yml +2 -0
- data/README.md +6 -0
- data/lib/micropub/configuration.rb +10 -0
- data/lib/micropub/token.rb +55 -0
- data/lib/micropub/version.rb +1 -1
- data/lib/micropub.rb +11 -2
- data/micropub.gemspec +4 -0
- data/spec/lib/micropub/token_spec.rb +69 -0
- data/spec/lib/micropub_spec.rb +16 -0
- data/spec/spec_helper.rb +3 -0
- metadata +55 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84b70a92a9926bd8f8142b17204cbbc9f59cc962
|
4
|
+
data.tar.gz: 34546caa3bec8a6f2d209f0e9978780113d8c8ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c97ae53cd79c89b22caab696419a7e03a5de10f4a02dbc906408074e96867b0f618ac90b953e3e51fa1dc2aa805652c3bca8a5e6a3bea438119e08b12232070
|
7
|
+
data.tar.gz: e1da3bf25030af7226d0a516ae0f836763208a3c3644e8f60ab1847f4715ed2ac3c3648440728bcff06c9aa6b8cb7cf6937aaa415c534711695356a9a72a000e
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'httpclient'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
module Micropub
|
5
|
+
class ValidationError < StandardError;end
|
6
|
+
|
7
|
+
class Token
|
8
|
+
def initialize(token)
|
9
|
+
@token = token
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
begin
|
14
|
+
valid_host? &&
|
15
|
+
valid_scope?
|
16
|
+
rescue ValidationError
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_scope?
|
22
|
+
(config.allowed_scopes & scope).any?
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_host?
|
26
|
+
me.host == config.me.host
|
27
|
+
end
|
28
|
+
|
29
|
+
def scope
|
30
|
+
response["scope"].split(",").map(&:to_sym)
|
31
|
+
end
|
32
|
+
|
33
|
+
def me
|
34
|
+
begin
|
35
|
+
URI.parse(response["me"])
|
36
|
+
rescue URI::InvalidURIError
|
37
|
+
raise ValidationError, "The token endpoint did not contain a valid 'me' URI"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def response
|
42
|
+
@response ||= begin
|
43
|
+
URI::decode_www_form(request.body).to_h
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def request
|
48
|
+
HTTPClient.get(config.token_endpoint, {}, {'Authorization' => "Bearer #{@token}"})
|
49
|
+
end
|
50
|
+
|
51
|
+
def config
|
52
|
+
Micropub.configuration
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/micropub/version.rb
CHANGED
data/lib/micropub.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
require "micropub/version"
|
2
|
-
|
2
|
+
require "micropub/token"
|
3
|
+
require "micropub/configuration"
|
3
4
|
module Micropub
|
4
|
-
|
5
|
+
class << self
|
6
|
+
def configure
|
7
|
+
yield configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
def configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
end
|
5
14
|
end
|
data/micropub.gemspec
CHANGED
@@ -20,4 +20,8 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "webmock"
|
25
|
+
|
26
|
+
spec.add_dependency "httpclient"
|
23
27
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Micropub::Token do
|
4
|
+
let(:token) { Micropub::Token.new("1234") }
|
5
|
+
|
6
|
+
describe ".initialize" do
|
7
|
+
it "requires a string token" do
|
8
|
+
expect { Micropub::Token.new }.to raise_error ArgumentError
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "making requests" do
|
13
|
+
let(:endpoint) { "https://tokens.indieauth.com/token" }
|
14
|
+
let(:raw_response) { "me=https://person.com/&client_id=https://ownyourgram.com&scope=post,patch&issued_at=1399155608&nonce=501884823" }
|
15
|
+
before do
|
16
|
+
Micropub.configure do |c|
|
17
|
+
c.token_endpoint = endpoint
|
18
|
+
c.me = "http://person.com"
|
19
|
+
c.allowed_scopes = [:post]
|
20
|
+
end
|
21
|
+
stub_request(:get, endpoint).with(headers: {"Authorization" => "Bearer 1234"}).to_return(body: raw_response)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#valid?" do
|
25
|
+
context "with valid params" do
|
26
|
+
it "accepts multiple scopes" do
|
27
|
+
expect(token.valid?).to eq true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
context "fails with invalid params" do
|
31
|
+
it "with wrong scope" do
|
32
|
+
Micropub.configure {|c| c.allowed_scopes = [:delete] }
|
33
|
+
expect(token.valid?).to eq false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "with wrong host" do
|
37
|
+
Micropub.configure {|c| c.me = "http://blah.com" }
|
38
|
+
expect(token.valid?).to eq false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when no me in token server" do
|
43
|
+
let(:raw_response) { "client_id=https://ownyourgram.com&scope=post,patch&issued_at=1399155608&nonce=501884823" }
|
44
|
+
it "returns false" do
|
45
|
+
expect(token.valid?).to eq false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#me" do
|
51
|
+
let(:raw_response) { "client_id=https://ownyourgram.com&scope=post,patch&issued_at=1399155608&nonce=501884823" }
|
52
|
+
it "raises an error when token server me is not present" do
|
53
|
+
expect { token.me }.to raise_error Micropub::ValidationError
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#response" do
|
58
|
+
it "returns a hash" do
|
59
|
+
response = {
|
60
|
+
"me" => "https://person.com/",
|
61
|
+
"client_id" => "https://ownyourgram.com",
|
62
|
+
"scope" => "post,patch",
|
63
|
+
"issued_at" => "1399155608",
|
64
|
+
"nonce" => "501884823"}
|
65
|
+
expect(token.response).to eq(response)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Micropub do
|
4
|
+
describe ".configure" do
|
5
|
+
let(:endpoint) { "https://tokens.indieauth.com/token" }
|
6
|
+
before do
|
7
|
+
Micropub.configure do |c|
|
8
|
+
c.token_endpoint = endpoint
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets a token endpoint" do
|
13
|
+
expect(Micropub.configuration.token_endpoint).to eq endpoint
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: micropub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -39,6 +39,48 @@ dependencies:
|
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: webmock
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: httpclient
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :runtime
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
42
84
|
description: Ruby implementation of Micropub.
|
43
85
|
email:
|
44
86
|
- veganstraightedge@gmail.com
|
@@ -48,13 +90,19 @@ extensions: []
|
|
48
90
|
extra_rdoc_files: []
|
49
91
|
files:
|
50
92
|
- ".gitignore"
|
93
|
+
- ".travis.yml"
|
51
94
|
- Gemfile
|
52
95
|
- LICENSE.txt
|
53
96
|
- README.md
|
54
97
|
- Rakefile
|
55
98
|
- lib/micropub.rb
|
99
|
+
- lib/micropub/configuration.rb
|
100
|
+
- lib/micropub/token.rb
|
56
101
|
- lib/micropub/version.rb
|
57
102
|
- micropub.gemspec
|
103
|
+
- spec/lib/micropub/token_spec.rb
|
104
|
+
- spec/lib/micropub_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
58
106
|
homepage: https://github.com/homesteading/micropub
|
59
107
|
licenses:
|
60
108
|
- Public Domain (CC0)
|
@@ -75,9 +123,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
123
|
version: '0'
|
76
124
|
requirements: []
|
77
125
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.4.
|
126
|
+
rubygems_version: 2.4.5
|
79
127
|
signing_key:
|
80
128
|
specification_version: 4
|
81
129
|
summary: Ruby implementation of Micropub.
|
82
|
-
test_files:
|
83
|
-
|
130
|
+
test_files:
|
131
|
+
- spec/lib/micropub/token_spec.rb
|
132
|
+
- spec/lib/micropub_spec.rb
|
133
|
+
- spec/spec_helper.rb
|