webmention 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -42,6 +42,17 @@ if endpoint = Webmention::Client.supports_webmention?(target)
42
42
  end
43
43
  ```
44
44
 
45
+ Command Line Utility
46
+ --------------------
47
+
48
+ For testing or for sending webmentions manually, you can use the command-line utility provided.
49
+
50
+ ```bash
51
+ $ webmention http://source.example.com/post/100
52
+ ```
53
+
54
+ This will look for an [h-entry](http://indiewebcamp.com/h-entry) on the given URL and attempt to send webmentions to each URL in the entry.
55
+
45
56
 
46
57
  Webmention
47
58
  ----------
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
4
+ require "webmention"
5
+ require "link_header"
6
+
7
+ url = ARGV[0]
8
+
9
+ if url == nil
10
+ puts "Usage: webmention http://example.com/post/100"
11
+ exit 1
12
+ end
13
+
14
+ if !Webmention::Client.valid_http_url?(url)
15
+ puts "Not a valid URL"
16
+ exit 1
17
+ end
18
+
19
+ client = Webmention::Client.new url
20
+
21
+ def debug(msg)
22
+ puts msg
23
+ end
24
+
25
+ debug "Finding links on #{url}"
26
+ client.crawl
27
+
28
+ links = client.links
29
+ debug "Found #{links.length} links:"
30
+ debug links.to_a.map{|m| "\t#{m}"}.join("\n")
31
+
32
+ debug ""
33
+
34
+ links.each do |link|
35
+ debug link
36
+
37
+ endpoint = Webmention::Client.supports_webmention?(link)
38
+ if endpoint
39
+ debug "\tDiscovered Webmention endpoint:"
40
+ debug "\t#{endpoint}"
41
+ debug "\tSending webmention..."
42
+ result = Webmention::Client.send_mention endpoint, url, link, true
43
+ if result
44
+ debug "\tReturned HTTP #{result.code}"
45
+ if result.headers['link']
46
+ link_headers = LinkHeader.parse result.headers['link']
47
+ if status_link = link_headers.find_link(['rel', 'status'])
48
+ debug "\tWebmention status: #{status_link.href}"
49
+ end
50
+ end
51
+ else
52
+ debug "\tEncountered an unknown error sending this webmention!"
53
+ end
54
+ else
55
+ debug "\tNo webmention endpoint found"
56
+ end
57
+
58
+ debug ""
59
+ end
@@ -63,7 +63,7 @@ module Webmention
63
63
  # target - The link that was mentioned in the source page.
64
64
  #
65
65
  # Returns a boolean.
66
- def self.send_mention endpoint, source, target
66
+ def self.send_mention endpoint, source, target, full_response=false
67
67
  data = {
68
68
  :source => source,
69
69
  :target => target,
@@ -74,7 +74,11 @@ module Webmention
74
74
  :body => data
75
75
  })
76
76
 
77
- return response.code == 200 || response.code == 202
77
+ if full_response
78
+ return response
79
+ else
80
+ return response.code == 200 || response.code == 202
81
+ end
78
82
  rescue
79
83
  return false
80
84
  end
@@ -1,3 +1,3 @@
1
1
  module Webmention
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -20,9 +20,12 @@ Gem::Specification.new do |s|
20
20
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
21
21
  s.require_paths = ['lib']
22
22
 
23
+ s.required_ruby_version = '>= 1.9.3'
24
+
23
25
  s.add_dependency 'json'
24
26
  s.add_dependency 'nokogiri'
25
27
  s.add_dependency 'httparty', '~> 0.13.1'
28
+ s.add_dependency 'link_header', '~> 0.0.8'
26
29
 
27
30
  s.add_development_dependency 'bundler', '~> 1.3'
28
31
  s.add_development_dependency 'rake'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmention
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -60,6 +60,22 @@ dependencies:
60
60
  - - ~>
61
61
  - !ruby/object:Gem::Version
62
62
  version: 0.13.1
63
+ - !ruby/object:Gem::Dependency
64
+ name: link_header
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 0.0.8
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 0.0.8
63
79
  - !ruby/object:Gem::Dependency
64
80
  name: bundler
65
81
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +142,8 @@ dependencies:
126
142
  version: '0'
127
143
  description:
128
144
  email: aaron@parecki.com
129
- executables: []
145
+ executables:
146
+ - webmention
130
147
  extensions: []
131
148
  extra_rdoc_files: []
132
149
  files:
@@ -135,6 +152,7 @@ files:
135
152
  - Gemfile
136
153
  - README.md
137
154
  - Rakefile
155
+ - bin/webmention
138
156
  - example.rb
139
157
  - lib/webmention.rb
140
158
  - lib/webmention/client.rb
@@ -158,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
176
  requirements:
159
177
  - - ! '>='
160
178
  - !ruby/object:Gem::Version
161
- version: '0'
179
+ version: 1.9.3
162
180
  required_rubygems_version: !ruby/object:Gem::Requirement
163
181
  none: false
164
182
  requirements: