micropub 0.0.3 → 0.0.4

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: 8932207c82af7d33debdf836bce74c87be2a0628
4
- data.tar.gz: 664ba6a8be2d77f6759d3e5fe19ba81fffc79539
3
+ metadata.gz: c0709be3a6fa2b2476a227fe71963ae3c784ca52
4
+ data.tar.gz: ae7c74e58285a7b2c87363f817aee4a5a075b390
5
5
  SHA512:
6
- metadata.gz: 7faf7e89cef3e8fe004385f20c49561f490e97b776fc97fc7a2fd1ebf15ee01a55b4f0e0e5855262c8c4728cfe2dd948627bc112f409b2b3622e72875e339cdf
7
- data.tar.gz: 6b241d4694293e0da76d7b9c9f0a44ffc223e9da1e49f64e5566e2f3cdcfabc8b4f07ee1f4c941eaa010aacf8a49c7e6baa767df464411832f7469754528edad
6
+ metadata.gz: 2f7c1edbd18df933334941ad938747cc761874a4194a26ea343c896685b69d35fe20bae4ee4cc34578a3348896ae61138d4ed0a0d64041d63068c5558d319f03
7
+ data.tar.gz: b137dc258c754f6efdd581b8a4ade22a89bd330e60401123694539335596c64b9215f2cfbabb17e54e7cc2ff00f32a58dc6732894db4cf3a2dfdeb5a735c7d39
data/lib/micropub.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "micropub/version"
2
2
  require "micropub/token"
3
+ require "micropub/client"
3
4
  require "micropub/configuration"
4
5
  module Micropub
5
6
  class << self
@@ -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
@@ -0,0 +1,10 @@
1
+ module Micropub
2
+ class Response
3
+ attr_reader :status, :body, :location
4
+ def initialize(response)
5
+ @status = response.status
6
+ @body = response.body
7
+ @location = response.headers["Location"]
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Micropub
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/micropub.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "webmock"
25
25
 
26
26
  spec.add_dependency "httpclient"
27
+ spec.add_dependency "activesupport"
27
28
  end
@@ -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) { "https://tokens.indieauth.com/token" }
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
@@ -1,3 +1,9 @@
1
1
  require 'rspec'
2
2
  require 'webmock/rspec'
3
3
  require 'micropub'
4
+
5
+ Micropub.configure do |c|
6
+ c.token_endpoint = "https://tokens.indieauth.com/token"
7
+ c.me = "http://person.com"
8
+ c.allowed_scopes = [:post]
9
+ end
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.3
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