alephant-scout 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 426febd1ef7d655e339a07a119386a521b5c58a3
4
+ data.tar.gz: ada16f35afc2d6b2e8f4e60636cd3637824a59a0
5
+ SHA512:
6
+ metadata.gz: cbdcf4bcf6d8d18e58d985224425c0218359d79bda29ceee61c284b7beda5aff3e612f655f7ec8396fe9cb0dcfb1f02b3e1067917d662cf49130837835bbe52a
7
+ data.tar.gz: 72a91040e69b017d1c2c7169ef9e9f1abae2a9bdb42c70b374a1b74140a9368b606d24d5f2199fb7a0333e56f8ba89f5f9a8dc166eb3e2301c7239f43cc00331
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ jruby-1.7.8
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alephant-scout.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Oliver Godby
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Alephant::Scout
2
+
3
+ This is a gem to allow Alephant based applications to check the validity of an arbitrary URL / URI
4
+ before enqueuing messages to render content based on the content of said URL / URI, thereby protecting
5
+ render nodes from having to handle bogus URLs / URIs.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'alephant-scout'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install alephant-scout
20
+
21
+ ## Usage
22
+
23
+ ```rb
24
+ require 'alephant-scout'
25
+
26
+ # => true
27
+
28
+ good_url = 'http://www.bbc.co.uk/persian/world'
29
+
30
+ # => "http://www.bbc.co.uk/persian/world"
31
+
32
+ bad_url = 'http://www.bbc.co.uk/persian/lobster-hatstand'
33
+
34
+ # => "http://www.bbc.co.uk/persian/lobster-hatstand"
35
+
36
+ url_scout = Alephant::Scout::Url.new()
37
+
38
+ # = > #<Alephant::Scout::Url:[ObjectId]>
39
+
40
+ url_scout.valid?(good_url)
41
+
42
+ # => true
43
+
44
+ url_scout.valid?(bad_url)
45
+
46
+ # => false
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+
3
+ require 'rspec/core/rake_task'
4
+ require 'bundler/gem_tasks'
5
+ require 'alephant/scout'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alephant/scout/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "alephant-scout"
8
+ spec.version = Alephant::Scout::VERSION
9
+ spec.authors = ["C. Oliver Godby"]
10
+ spec.email = ["oliver.godby02@bbc.co.uk"]
11
+ spec.description = %q{"Scout URLs to see if they are valid"}
12
+ spec.summary = %q{"Scout URLs to see if they are valid"}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_runtime_dependency "httparty", "~> 0.13.1"
25
+ spec.add_runtime_dependency "alephant-logger"
26
+ spec.add_runtime_dependency "alephant-support"
27
+ end
@@ -0,0 +1,13 @@
1
+ require "httparty"
2
+
3
+ module Alephant
4
+ module Scout
5
+ class Url
6
+ def valid?(url_to_scout)
7
+ HTTParty.head(url_to_scout).code == 200
8
+ rescue
9
+ false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Alephant
2
+ module Scout
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "alephant/scout/version"
2
+ require "alephant/scout/url"
@@ -0,0 +1,3 @@
1
+ $: << File.join(File.dirname(__FILE__),"..", "lib")
2
+
3
+ require 'alephant/scout'
data/spec/url_spec.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Alephant::Scout::Url do
4
+ describe ".valid?(url)" do
5
+ let(:response) { double('HTTParty::Response') }
6
+ it "is a valid url" do
7
+ allow(response).to receive(:code).and_return(200)
8
+ allow(HTTParty).to receive(:head).and_return(response)
9
+ expect(subject.valid?('http://www.avalidurl.com')).to be true
10
+ end
11
+
12
+ it "is a valid url with an issue" do
13
+ allow(response).to receive(:code).and_return(500)
14
+ allow(HTTParty).to receive(:head).and_return(response)
15
+ expect(subject.valid?('http://www.notavalidurl.com')).to be false
16
+ end
17
+
18
+ it "is an invalid URL - i.e. host is resolved but resource does not exist" do
19
+ allow(response).to receive(:code).and_return(404)
20
+ allow(HTTParty).to receive(:head).and_return(response)
21
+ expect(subject.valid?('http://www.avalidurl.com/but/a/nonexistent/resource')).to be false
22
+ end
23
+
24
+ it "is an invalid host - i.e. no DNS resolution" do
25
+ allow(response).to receive(:code).and_return(500)
26
+ allow(HTTParty).to receive(:head).and_raise("Hostname not found")
27
+ expect(subject.valid?('test://www.notavalidurl.test')).to be false
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alephant-scout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - C. Oliver Godby
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.3'
25
+ prerelease: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.1
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: 0.13.1
53
+ prerelease: false
54
+ type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: alephant-logger
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :runtime
69
+ - !ruby/object:Gem::Dependency
70
+ name: alephant-support
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :runtime
83
+ description: '"Scout URLs to see if they are valid"'
84
+ email:
85
+ - oliver.godby02@bbc.co.uk
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .ruby-version
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - alephant-scout.gemspec
97
+ - lib/alephant/scout.rb
98
+ - lib/alephant/scout/url.rb
99
+ - lib/alephant/scout/version.rb
100
+ - spec/spec_helper.rb
101
+ - spec/url_spec.rb
102
+ homepage: ''
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.1.9
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: '"Scout URLs to see if they are valid"'
126
+ test_files:
127
+ - spec/spec_helper.rb
128
+ - spec/url_spec.rb