micropub 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/micropub.rb +1 -0
- data/lib/micropub/client.rb +33 -0
- data/lib/micropub/response.rb +10 -0
- data/lib/micropub/version.rb +1 -1
- data/micropub.gemspec +1 -0
- data/spec/lib/micropub/client_spec.rb +36 -0
- data/spec/lib/micropub/response_spec.rb +21 -0
- data/spec/lib/micropub/token_spec.rb +1 -6
- data/spec/spec_helper.rb +6 -0
- metadata +21 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0709be3a6fa2b2476a227fe71963ae3c784ca52
|
4
|
+
data.tar.gz: ae7c74e58285a7b2c87363f817aee4a5a075b390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f7c1edbd18df933334941ad938747cc761874a4194a26ea343c896685b69d35fe20bae4ee4cc34578a3348896ae61138d4ed0a0d64041d63068c5558d319f03
|
7
|
+
data.tar.gz: b137dc258c754f6efdd581b8a4ade22a89bd330e60401123694539335596c64b9215f2cfbabb17e54e7cc2ff00f32a58dc6732894db4cf3a2dfdeb5a735c7d39
|
data/lib/micropub.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "micropub/response"
|
2
|
+
require "active_support"
|
3
|
+
require "active_support/core_ext/string/inflections"
|
4
|
+
|
5
|
+
module Micropub
|
6
|
+
class Client
|
7
|
+
attr_reader :post_type, :token
|
8
|
+
def initialize(post_type, attrs={})
|
9
|
+
@post_type = post_type
|
10
|
+
@token = attrs[:token]
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(content)
|
14
|
+
request HTTPClient.post(uri, content, headers)
|
15
|
+
end
|
16
|
+
|
17
|
+
def request(response)
|
18
|
+
Micropub::Response.new(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
def headers
|
22
|
+
{"Authorization" => "Bearer #{token}"}
|
23
|
+
end
|
24
|
+
|
25
|
+
def publisher
|
26
|
+
post_type.pluralize
|
27
|
+
end
|
28
|
+
|
29
|
+
def uri
|
30
|
+
"#{Micropub.configuration.me}/#{publisher}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/micropub/version.rb
CHANGED
data/micropub.gemspec
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Micropub::Client do
|
4
|
+
let(:body) { {content: "Blah Blah"} }
|
5
|
+
let(:client) { Micropub::Client.new("note", token: "1234") }
|
6
|
+
before do
|
7
|
+
@stub = stub_request(:post, "http://person.com/notes").with(body: body, headers: {"Authorization" => "Bearer 1234"})
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#publisher" do
|
11
|
+
it "is pluralized post type" do
|
12
|
+
expect(client.publisher).to eq "notes"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".new" do
|
17
|
+
it "sets the post_type" do
|
18
|
+
expect(client.post_type).to eq "note"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets the token" do
|
22
|
+
expect(client.token).to eq "1234"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#post" do
|
27
|
+
it "makes a request" do
|
28
|
+
client.post(body)
|
29
|
+
expect(@stub).to have_been_requested
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns a Micropub::Response" do
|
33
|
+
expect(client.post(body)).to be_a Micropub::Response
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "micropub/response"
|
3
|
+
|
4
|
+
describe Micropub::Response do
|
5
|
+
let(:http_response) { double("http", status: 201, body: "Blah", headers: {"Location" => "http://example.com/1"}) }
|
6
|
+
let(:response) { Micropub::Response.new(http_response) }
|
7
|
+
|
8
|
+
describe ".initialize" do
|
9
|
+
it "sets the status" do
|
10
|
+
expect(response.status).to eq 201
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets the body" do
|
14
|
+
expect(response.body).to eq "Blah"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets the location" do
|
18
|
+
expect(response.location).to eq "http://example.com/1"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -10,14 +10,9 @@ describe Micropub::Token do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "making requests" do
|
13
|
-
let(:endpoint) {
|
13
|
+
let(:endpoint) { Micropub.configuration.token_endpoint }
|
14
14
|
let(:raw_response) { "me=https://person.com/&client_id=https://ownyourgram.com&scope=post,patch&issued_at=1399155608&nonce=501884823" }
|
15
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
16
|
stub_request(:get, endpoint).with(headers: {"Authorization" => "Bearer 1234"}).to_return(body: raw_response)
|
22
17
|
end
|
23
18
|
|
data/spec/spec_helper.rb
CHANGED
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Becker
|
@@ -81,6 +81,20 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: activesupport
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
84
98
|
description: Ruby implementation of Micropub.
|
85
99
|
email:
|
86
100
|
- veganstraightedge@gmail.com
|
@@ -96,10 +110,14 @@ files:
|
|
96
110
|
- README.md
|
97
111
|
- Rakefile
|
98
112
|
- lib/micropub.rb
|
113
|
+
- lib/micropub/client.rb
|
99
114
|
- lib/micropub/configuration.rb
|
115
|
+
- lib/micropub/response.rb
|
100
116
|
- lib/micropub/token.rb
|
101
117
|
- lib/micropub/version.rb
|
102
118
|
- micropub.gemspec
|
119
|
+
- spec/lib/micropub/client_spec.rb
|
120
|
+
- spec/lib/micropub/response_spec.rb
|
103
121
|
- spec/lib/micropub/token_spec.rb
|
104
122
|
- spec/lib/micropub_spec.rb
|
105
123
|
- spec/spec_helper.rb
|
@@ -128,6 +146,8 @@ signing_key:
|
|
128
146
|
specification_version: 4
|
129
147
|
summary: Ruby implementation of Micropub.
|
130
148
|
test_files:
|
149
|
+
- spec/lib/micropub/client_spec.rb
|
150
|
+
- spec/lib/micropub/response_spec.rb
|
131
151
|
- spec/lib/micropub/token_spec.rb
|
132
152
|
- spec/lib/micropub_spec.rb
|
133
153
|
- spec/spec_helper.rb
|