spacejam 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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +90 -0
- data/Rakefile +10 -0
- data/lib/spacejam.rb +15 -0
- data/lib/spacejam/http_check.rb +50 -0
- data/lib/spacejam/version.rb +3 -0
- data/spacejam.gemspec +25 -0
- data/test/http_check_test.rb +59 -0
- data/test/spacejam_test.rb +63 -0
- data/test/test_helper.rb +4 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac5243c6ac07615eb776378fef3d70026bbe9a14
|
4
|
+
data.tar.gz: 253dbbd2e2fcc0f4eba1d5c227775c1ceee1c04a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7582612ad797bf514f6989e3eafeb285037ca2a585c0034ef2bb8e720101bf6ea09e069bae48dc82189ecf8615bf711131eb7949e2c52d9eb2057af66b5bb93f
|
7
|
+
data.tar.gz: f71b9814cee14dd0b2747d33042b3bdf737a6dec361c9ea8d64f1559eb5b3e992f4354dc6ad121aac83970facdedad4bbb765f6005e0fdb2676d1513feaec968
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Colin Mitchell
|
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,90 @@
|
|
1
|
+
# Spacejam -- A simple tool to check on the status of a website
|
2
|
+
|
3
|
+
Spacejam is a ruby library for checking on the status of a website.
|
4
|
+
You can use it to check if a page or site is online. I wrote it to
|
5
|
+
keep an eye on the website for
|
6
|
+
[Space Jam](http://www2.warnerbros.com/spacejam/movie/jam.htm). I
|
7
|
+
wrote a [Twitter bot](https://twitter.com/SpaceJamCheck) that checks
|
8
|
+
the status of the website multiple times a day.
|
9
|
+
|
10
|
+
The library is basically a very simple wrapper around Curl. Here's how
|
11
|
+
it works:
|
12
|
+
|
13
|
+
|
14
|
+
Spacejam.online?('http://muffinlabs.com')
|
15
|
+
=> true
|
16
|
+
|
17
|
+
|
18
|
+
x = Spacejam::HTTPCheck.new('http://muffinlabs.com')
|
19
|
+
x.online?
|
20
|
+
=> true
|
21
|
+
|
22
|
+
Instead of just passing a URL, you can pass a hash with the URL and an expected
|
23
|
+
response code:
|
24
|
+
|
25
|
+
x = Spacejam::HTTPCheck.new(url:'http://muffinlabs.com/missing_file.html', response_code:200)
|
26
|
+
x.online?
|
27
|
+
=> false
|
28
|
+
|
29
|
+
|
30
|
+
You can also check non-200 response codes. Admittedly, looking for a
|
31
|
+
404 seems a little odd, but it still has it's uses.
|
32
|
+
|
33
|
+
x = Spacejam::HTTPCheck.new(url:'http://muffinlabs.com/missing_file.html', response_code:404)
|
34
|
+
x.online?
|
35
|
+
=> true
|
36
|
+
|
37
|
+
Also, you can check the body content of the page:
|
38
|
+
|
39
|
+
x = Spacejam::HTTPCheck.new(url:'http://muffinlabs.com/', body:"A string to check for")
|
40
|
+
x.online?
|
41
|
+
=> true
|
42
|
+
|
43
|
+
Both body and response_code attributes can be a regex:
|
44
|
+
|
45
|
+
x = Spacejam::HTTPCheck.new(
|
46
|
+
url:'http://muffinlabs.com/',
|
47
|
+
response_code:/20?/,
|
48
|
+
body:/muffinlabs/)
|
49
|
+
x.online?
|
50
|
+
=> true
|
51
|
+
|
52
|
+
If the request isn't successful, Spacejam can give you some
|
53
|
+
information about what went wrong via the **reason** attribute:
|
54
|
+
|
55
|
+
x.reason
|
56
|
+
=> :response_code
|
57
|
+
|
58
|
+
The possible values are:
|
59
|
+
* **:response_code** - an unexpected response code
|
60
|
+
* **:body** - the body check failed
|
61
|
+
* **:error** - a network/DNS error, etc. You would get this if the
|
62
|
+
remote server was inaccessible or unresponsive.
|
63
|
+
|
64
|
+
|
65
|
+
## Installation
|
66
|
+
|
67
|
+
Add this line to your application's Gemfile:
|
68
|
+
|
69
|
+
gem 'spacejam'
|
70
|
+
|
71
|
+
And then execute:
|
72
|
+
|
73
|
+
$ bundle
|
74
|
+
|
75
|
+
Or install it yourself as:
|
76
|
+
|
77
|
+
$ gem install spacejam
|
78
|
+
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
Please do! Pull requests are welcomed.
|
83
|
+
|
84
|
+
## Copyright/License
|
85
|
+
|
86
|
+
Copyright (c) 2014 Colin Mitchell. MIT License. Keep Circulating The Tapes.
|
87
|
+
|
88
|
+
http://muffinlabs.com
|
89
|
+
|
90
|
+
|
data/Rakefile
ADDED
data/lib/spacejam.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spacejam/version"
|
2
|
+
require 'curl'
|
3
|
+
|
4
|
+
module Spacejam
|
5
|
+
require 'spacejam/http_check'
|
6
|
+
class << self
|
7
|
+
def check(*args)
|
8
|
+
Spacejam::HTTPCheck.new(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def online?(*args)
|
12
|
+
Spacejam::HTTPCheck.new(*args).online?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Spacejam
|
2
|
+
class HTTPCheck
|
3
|
+
attr_accessor :url, :response_code, :body, :result, :reason
|
4
|
+
def initialize(opts={})
|
5
|
+
if opts.is_a?(String)
|
6
|
+
opts = {
|
7
|
+
url: opts
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
opts = {
|
12
|
+
response_code: 200,
|
13
|
+
body: nil
|
14
|
+
}.merge(opts)
|
15
|
+
|
16
|
+
@url = opts[:url]
|
17
|
+
@response_code = to_regexp(opts[:response_code])
|
18
|
+
@body = to_regexp(opts[:body])
|
19
|
+
end
|
20
|
+
|
21
|
+
def online?
|
22
|
+
@reason = nil
|
23
|
+
@result = Curl::Easy.perform(@url)
|
24
|
+
|
25
|
+
if @response_code && @response_code.match(@result.response_code.to_s) == nil
|
26
|
+
@reason = :response_code
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
|
30
|
+
if @body && @result.body_str.match(@body) == nil
|
31
|
+
@reason = :body
|
32
|
+
return false
|
33
|
+
end
|
34
|
+
|
35
|
+
true
|
36
|
+
rescue
|
37
|
+
@reason = :error
|
38
|
+
false
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
def to_regexp(s)
|
43
|
+
return if !s
|
44
|
+
if ! s.is_a?(Regexp)
|
45
|
+
s = Regexp.compile(s.to_s)
|
46
|
+
end
|
47
|
+
s
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spacejam.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'spacejam/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "spacejam"
|
8
|
+
spec.version = Spacejam::VERSION
|
9
|
+
spec.authors = ["Colin Mitchell"]
|
10
|
+
spec.email = ["colin@muffinlabs.com"]
|
11
|
+
spec.description = %q{Check on the status of a website}
|
12
|
+
spec.summary = %q{Check on the status of a website}
|
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
|
+
spec.add_development_dependency "minitest", "~> 5.2.1"
|
24
|
+
spec.add_dependency "curb"
|
25
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class HTTPCheckTest < MiniTest::Test
|
4
|
+
def test_works_with_string
|
5
|
+
@checker = Spacejam::HTTPCheck.new('http://www.google.com/')
|
6
|
+
assert @checker.online?
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_works_with_hash
|
10
|
+
@checker = Spacejam::HTTPCheck.new(url:'http://www.google.com/')
|
11
|
+
assert @checker.online?
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_works_with_hash_and_response_code
|
15
|
+
@checker = Spacejam::HTTPCheck.new(url:'http://www.google.com/', response_code:200)
|
16
|
+
assert @checker.online?
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_works_with_hash_and_bad_response_code
|
20
|
+
@checker = Spacejam::HTTPCheck.new(url:'http://www.google.com/', response_code:555)
|
21
|
+
assert !@checker.online?
|
22
|
+
assert @checker.reason == :response_code
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_works_with_bad_host
|
26
|
+
@checker = Spacejam::HTTPCheck.new('http://foobar.loc/')
|
27
|
+
assert !@checker.online?
|
28
|
+
assert @checker.reason == :error
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_works_with_bad_path
|
32
|
+
@checker = Spacejam::HTTPCheck.new('http://www.google.com/weird.html')
|
33
|
+
assert !@checker.online?
|
34
|
+
assert @checker.reason == :response_code
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_works_with_response_code_as_regex
|
38
|
+
@checker = Spacejam::HTTPCheck.new(url:'http://www.google.com/', response_code:Regexp.new('200'))
|
39
|
+
assert @checker.online?
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_works_with_body
|
43
|
+
@checker = Spacejam::HTTPCheck.new(url:'http://www.google.com/', body:"Google has many special features to help you find exactly what you're looking for")
|
44
|
+
assert @checker.online?
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_works_with_body_as_regex
|
48
|
+
@checker = Spacejam::HTTPCheck.new(url:'http://www.google.com/', body:Regexp.new("Google has many special features to help you find exactly what you're looking for"))
|
49
|
+
assert @checker.online?
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_works_with_body_as_regex
|
53
|
+
@checker = Spacejam::HTTPCheck.new(url:'http://www.google.com/', body:Regexp.new("Yahoo"))
|
54
|
+
assert !@checker.online?
|
55
|
+
assert @checker.reason == :body
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class SpacejamTest < MiniTest::Test
|
4
|
+
def test_online_works
|
5
|
+
assert Spacejam.online?('http://www.google.com/')
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_works_with_string
|
9
|
+
@checker = Spacejam.check('http://www.google.com/')
|
10
|
+
assert @checker.online?
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_works_with_hash
|
14
|
+
@checker = Spacejam.check(url:'http://www.google.com/')
|
15
|
+
assert @checker.online?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_works_with_hash_and_response_code
|
19
|
+
@checker = Spacejam.check(url:'http://www.google.com/', response_code:200)
|
20
|
+
assert @checker.online?
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_works_with_hash_and_bad_response_code
|
24
|
+
@checker = Spacejam.check(url:'http://www.google.com/', response_code:555)
|
25
|
+
assert !@checker.online?
|
26
|
+
assert @checker.reason == :response_code
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_works_with_bad_host
|
30
|
+
@checker = Spacejam.check('http://foobar.loc/')
|
31
|
+
assert !@checker.online?
|
32
|
+
assert @checker.reason == :error
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_works_with_bad_path
|
36
|
+
@checker = Spacejam.check('http://www.google.com/weird.html')
|
37
|
+
assert !@checker.online?
|
38
|
+
assert @checker.reason == :response_code
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_works_with_response_code_as_regex
|
42
|
+
@checker = Spacejam.check(url:'http://www.google.com/', response_code:Regexp.new('200'))
|
43
|
+
assert @checker.online?
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_works_with_body
|
47
|
+
@checker = Spacejam.check(url:'http://www.google.com/', body:"Google has many special features to help you find exactly what you're looking for")
|
48
|
+
assert @checker.online?
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_works_with_body_as_regex
|
52
|
+
@checker = Spacejam.check(url:'http://www.google.com/', body:Regexp.new("Google has many special features to help you find exactly what you're looking for"))
|
53
|
+
assert @checker.online?
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_works_with_body_as_regex
|
57
|
+
@checker = Spacejam.check(url:'http://www.google.com/', body:Regexp.new("Yahoo"))
|
58
|
+
assert !@checker.online?
|
59
|
+
assert @checker.reason == :body
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spacejam
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Colin Mitchell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.2.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.2.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: curb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Check on the status of a website
|
70
|
+
email:
|
71
|
+
- colin@muffinlabs.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/spacejam.rb
|
82
|
+
- lib/spacejam/http_check.rb
|
83
|
+
- lib/spacejam/version.rb
|
84
|
+
- spacejam.gemspec
|
85
|
+
- test/http_check_test.rb
|
86
|
+
- test/spacejam_test.rb
|
87
|
+
- test/test_helper.rb
|
88
|
+
homepage: ''
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.1.11
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Check on the status of a website
|
112
|
+
test_files:
|
113
|
+
- test/http_check_test.rb
|
114
|
+
- test/spacejam_test.rb
|
115
|
+
- test/test_helper.rb
|