morito 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/README.md +6 -2
- data/Rakefile +3 -0
- data/lib/morito/client.rb +24 -1
- data/lib/morito/connector.rb +2 -21
- data/lib/morito/processor.rb +6 -1
- data/lib/morito/version.rb +1 -1
- data/morito.gemspec +2 -0
- data/spec/morito/client_spec.rb +57 -26
- data/spec/spec_helper.rb +10 -0
- metadata +30 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50f1f0b304f54a4d042d91ab748679af6aa8064d
|
4
|
+
data.tar.gz: ada9db82752169ccfd43f7337bb97ec51d36827a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d864fa9b215e1b7b076b4fdba050e993ef52a402e4792dd8c882cc9f057eeb73c888eaeab624731393a2675b421801ffe7a32811719a1539f74f5d09ffcbdd3
|
7
|
+
data.tar.gz: 50a9ed68a538e2f8b15caa8b26221a770a5507abc51e310d0453223eb1b313e217f6954d4c4cf432eb8c0a5c6e6f3bfd4cdcce4d93e27a9562a796088cfb83a4
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Morito
|
1
|
+
# Morito [![Build Status](https://travis-ci.org/negipo/morito.svg?branch=master)](https://travis-ci.org/negipo/morito) [![Code Climate](https://codeclimate.com/github/negipo/morito.png)](https://codeclimate.com/github/negipo/morito) [![Code Climate](https://codeclimate.com/github/negipo/morito/coverage.png)](https://codeclimate.com/github/negipo/morito)
|
2
2
|
|
3
|
-
robots.txt
|
3
|
+
A client to handle robots.txt
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -24,6 +24,10 @@ client.allowed?('http://example.com/some/path') # => true / false
|
|
24
24
|
client.allowed?('http://example.com/some/path', cache: false) # => true / false without cache
|
25
25
|
```
|
26
26
|
|
27
|
+
## TODO
|
28
|
+
|
29
|
+
- Currently does not handle `Allow:` description.
|
30
|
+
|
27
31
|
## Contributing
|
28
32
|
|
29
33
|
1. Fork it ( https://github.com/negipo/morito/fork )
|
data/Rakefile
CHANGED
data/lib/morito/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
1
3
|
module Morito
|
2
4
|
class Client
|
3
5
|
def initialize(user_agent)
|
@@ -6,8 +8,29 @@ module Morito
|
|
6
8
|
|
7
9
|
def allowed?(requesting_url, cache: true)
|
8
10
|
uri = URI.parse(requesting_url)
|
9
|
-
robots_txt_body =
|
11
|
+
robots_txt_body = robots_txt_body(uri, cache: cache)
|
10
12
|
Morito::Processor.new(robots_txt_body).allowed?(@user_agent, uri.path)
|
11
13
|
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def robots_txt_body(uri, cache: true)
|
18
|
+
if cache
|
19
|
+
with_cache(uri.host) do
|
20
|
+
robots_txt_body_without_cache(uri)
|
21
|
+
end
|
22
|
+
else
|
23
|
+
robots_txt_body_without_cache(uri)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def robots_txt_body_without_cache(uri)
|
28
|
+
Morito::Connector.new(uri).get
|
29
|
+
end
|
30
|
+
|
31
|
+
def with_cache(host, &block)
|
32
|
+
@cache ||= {}
|
33
|
+
@cache[host] ||= yield
|
34
|
+
end
|
12
35
|
end
|
13
36
|
end
|
data/lib/morito/connector.rb
CHANGED
@@ -1,38 +1,19 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
require 'uri'
|
3
2
|
|
4
3
|
module Morito
|
5
4
|
class Connector
|
6
5
|
PATH = '/robots.txt'
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(uri, cache: true)
|
7
|
+
def initialize(uri)
|
11
8
|
@uri = uri
|
12
|
-
@cache = cache
|
13
9
|
end
|
14
10
|
|
15
11
|
def get
|
16
|
-
|
17
|
-
self.class.with_cache(base_url) do
|
18
|
-
raw_get
|
19
|
-
end
|
20
|
-
else
|
21
|
-
raw_get
|
22
|
-
end
|
12
|
+
@get ||= connection.get(PATH).body
|
23
13
|
end
|
24
14
|
|
25
15
|
private
|
26
16
|
|
27
|
-
def self.with_cache(base_url, &block)
|
28
|
-
@cache ||= {}
|
29
|
-
@cache[base_url] ||= yield
|
30
|
-
end
|
31
|
-
|
32
|
-
def raw_get
|
33
|
-
@get ||= connection.get(PATH).body
|
34
|
-
end
|
35
|
-
|
36
17
|
def connection
|
37
18
|
Faraday.new(url: base_url) do |connection|
|
38
19
|
connection.adapter :net_http
|
data/lib/morito/processor.rb
CHANGED
data/lib/morito/version.rb
CHANGED
data/morito.gemspec
CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "pry"
|
25
25
|
spec.add_development_dependency "rspec"
|
26
26
|
spec.add_development_dependency "webmock"
|
27
|
+
spec.add_development_dependency "simplecov"
|
28
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
27
29
|
end
|
data/spec/morito/client_spec.rb
CHANGED
@@ -1,50 +1,81 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Morito::Client do
|
4
|
-
before do
|
5
|
-
stub_request(:any, //).to_return(body: body)
|
6
|
-
end
|
7
|
-
|
8
4
|
let(:client) { described_class.new(user_agent) }
|
9
|
-
|
10
|
-
|
5
|
+
|
6
|
+
describe '#allowed?' do
|
7
|
+
subject { client.allowed?(requesting_url, cache: cache) }
|
8
|
+
|
9
|
+
let(:cache) { true }
|
10
|
+
|
11
|
+
context 'with response' do
|
12
|
+
let(:body) do
|
13
|
+
<<-EOS
|
11
14
|
User-agent: *
|
12
15
|
Disallow: /private
|
13
16
|
|
17
|
+
# Comment
|
14
18
|
User-agent: restricted agent # Comment
|
15
19
|
Disallow: /
|
20
|
+
|
21
|
+
User-agent: allowed agent
|
22
|
+
Disallow: /super_private
|
16
23
|
EOS
|
17
|
-
|
24
|
+
end
|
18
25
|
|
19
|
-
|
20
|
-
|
26
|
+
before do
|
27
|
+
stub_request(:any, //).to_return(body: body)
|
28
|
+
end
|
21
29
|
|
22
|
-
|
23
|
-
|
30
|
+
context 'with public path' do
|
31
|
+
let(:requesting_url) { 'http://example.com/public/path' }
|
32
|
+
|
33
|
+
context 'with some agent' do
|
34
|
+
let(:user_agent) { 'some agent' }
|
35
|
+
it { should == true }
|
36
|
+
end
|
24
37
|
|
25
|
-
|
26
|
-
|
27
|
-
|
38
|
+
context 'with restricted agent' do
|
39
|
+
let(:user_agent) { 'restricted agent' }
|
40
|
+
it { should == false }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'without cache' do
|
44
|
+
let(:user_agent) { 'some agent' }
|
45
|
+
let(:cache) { false }
|
46
|
+
it { should == true }
|
47
|
+
end
|
28
48
|
end
|
29
49
|
|
30
|
-
context 'with
|
31
|
-
let(:
|
32
|
-
|
50
|
+
context 'with private path' do
|
51
|
+
let(:requesting_url) { 'http://example.com/private/path' }
|
52
|
+
|
53
|
+
context 'with some agent' do
|
54
|
+
let(:user_agent) { 'some agent' }
|
55
|
+
it { should == false }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'with restricted agent' do
|
59
|
+
let(:user_agent) { 'restricted agent' }
|
60
|
+
it { should == false }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with allowed agent' do
|
64
|
+
let(:user_agent) { 'allowed agent' }
|
65
|
+
it { should == true }
|
66
|
+
end
|
33
67
|
end
|
34
68
|
end
|
35
69
|
|
36
|
-
context 'with
|
37
|
-
let(:requesting_url) { 'http://example.com/
|
70
|
+
context 'with 404' do
|
71
|
+
let(:requesting_url) { 'http://example.com/public/path' }
|
72
|
+
let(:user_agent) { 'restricted agent' }
|
38
73
|
|
39
|
-
|
40
|
-
|
41
|
-
it { should == false }
|
74
|
+
before do
|
75
|
+
stub_request(:any, //).to_return(body: '', status: 404)
|
42
76
|
end
|
43
77
|
|
44
|
-
|
45
|
-
let(:user_agent) { 'restricted agent' }
|
46
|
-
it { should == false }
|
47
|
-
end
|
78
|
+
it { should == true }
|
48
79
|
end
|
49
80
|
end
|
50
81
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
1
4
|
require 'webmock/rspec'
|
5
|
+
|
6
|
+
if ENV['CI']
|
7
|
+
WebMock.disable_net_connect!(allow: %w(codeclimate.com))
|
8
|
+
require 'codeclimate-test-reporter'
|
9
|
+
CodeClimate::TestReporter.start
|
10
|
+
end
|
11
|
+
|
2
12
|
require 'morito'
|
3
13
|
|
4
14
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morito
|
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
|
- negipo
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: codeclimate-test-reporter
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
97
125
|
description:
|
98
126
|
email:
|
99
127
|
- negipo@gmail.com
|
@@ -102,6 +130,7 @@ extensions: []
|
|
102
130
|
extra_rdoc_files: []
|
103
131
|
files:
|
104
132
|
- ".gitignore"
|
133
|
+
- ".travis.yml"
|
105
134
|
- Gemfile
|
106
135
|
- LICENSE.txt
|
107
136
|
- README.md
|