webmention 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/webmention.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  require 'json'
2
- require 'net/http'
2
+ require 'httparty'
3
3
  require 'nokogiri'
4
4
  require 'open-uri'
5
5
  require 'set'
6
6
  require 'uri'
7
7
 
8
- require './lib/webmention/version'
9
- require './lib/webmention/client'
8
+ require 'webmention/version'
9
+ require 'webmention/client'
@@ -70,16 +70,11 @@ module Webmention
70
70
  }
71
71
 
72
72
  begin
73
- uri = URI.parse(endpoint)
74
- http = Net::HTTP.new(uri.host, uri.port)
73
+ response = HTTParty.post(endpoint, {
74
+ :body => data
75
+ })
75
76
 
76
- request = Net::HTTP::Post.new(uri.request_uri)
77
- request.set_form_data(data)
78
- request['Content-Type'] = "application/x-www-form-urlencoded"
79
- request['Accept'] = 'application/json'
80
- response = http.request(request)
81
-
82
- return response.code.to_i == 200
77
+ return response.code == 200 || response.code == 202
83
78
  rescue
84
79
  return false
85
80
  end
@@ -97,21 +92,17 @@ module Webmention
97
92
  doc = nil
98
93
 
99
94
  begin
100
- uri = URI.parse(url)
101
- http = Net::HTTP.new(uri.host, uri.port)
102
- http.open_timeout = 3 # in seconds
103
- http.read_timeout = 3 # in seconds
104
-
105
- request = Net::HTTP::Get.new(uri.request_uri)
106
- # Send a user agent like a browser because some sites seem to reject requests made by non-browsers
107
- request["User-Agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36 (https://rubygems.org/gems/webmention)"
108
- request["Accept"] = "*/*"
109
-
110
- response = http.request(request)
95
+ response = HTTParty.get(url, {
96
+ :timeout => 3,
97
+ :headers => {
98
+ 'User-Agent' => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36 (https://rubygems.org/gems/webmention)",
99
+ 'Accept' => '*/*'
100
+ }
101
+ })
111
102
 
112
103
  # First check the HTTP Headers
113
- if !response['Link'].nil?
114
- endpoint = self.discover_webmention_endpoint_from_header response['Link']
104
+ if !response.headers['Link'].nil?
105
+ endpoint = self.discover_webmention_endpoint_from_header response.headers['Link']
115
106
  return endpoint if endpoint
116
107
  end
117
108
 
@@ -1,3 +1,3 @@
1
1
  module Webmention
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -3,19 +3,19 @@ require_relative '../../test_helper'
3
3
  describe Webmention::Client do
4
4
  before do
5
5
  WebMock.stub_request(:any, 'http://source.example.com/post/100').to_return(
6
- :status => 200,
6
+ :status => 202,
7
7
  :body => SampleData.sample_source_post_html,
8
8
  :headers => {}
9
9
  )
10
10
 
11
11
  WebMock.stub_request(:any, 'http://target.example.com/post/4').to_return(
12
- :status => 200,
12
+ :status => 202,
13
13
  :body => SampleData.rel_webmention_href,
14
14
  :headers => {}
15
15
  )
16
16
 
17
17
  WebMock.stub_request(:any, 'http://target.example.com/post/5').to_return(
18
- :status => 200,
18
+ :status => 202,
19
19
  :body => '',
20
20
  :headers => {
21
21
  'Link' => 'rel="webmention"; <http://webmention.io/example/webmention>'
@@ -23,7 +23,7 @@ describe Webmention::Client do
23
23
  )
24
24
 
25
25
  WebMock.stub_request(:any, 'http://webmention.io/example/webmention').to_return(
26
- :status => 200
26
+ :status => 202
27
27
  )
28
28
 
29
29
  @client = Webmention::Client.new "http://source.example.com/post/100"
data/webmention.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_dependency 'json'
24
24
  s.add_dependency 'nokogiri'
25
+ s.add_dependency 'httparty', '~> 0.13.1'
25
26
 
26
27
  s.add_development_dependency 'bundler', '~> 1.3'
27
28
  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.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -44,6 +44,22 @@ dependencies:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: httparty
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.1
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 0.13.1
47
63
  - !ruby/object:Gem::Dependency
48
64
  name: bundler
49
65
  requirement: !ruby/object:Gem::Requirement