cinch-toolbox 1.1.4 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +11 -1
- data/cinch-toolbox.gemspec +10 -11
- data/lib/cinch/toolbox.rb +6 -7
- data/lib/cinch/toolbox/version.rb +1 -1
- data/spec/cinch-toolbox_spec.rb +42 -44
- data/spec/spec_helper.rb +2 -8
- metadata +37 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8e4cb9163dbda37fe9464c44c7e1c535393ff7e3
|
4
|
+
data.tar.gz: 58fdb864943f0814c191725e138e54066995842f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ea636880ff96553030ecba06476291a4c3a83226d51fcd962d4000f502d7b933ec55d53945a19c110b49e27d05696a700c307c2094f18e24de7cbc0cc713b62
|
7
|
+
data.tar.gz: 581c1ca7340726201fc6fc09f96a6ffc445b8c01f1b5c0effc0d1761f7142a4873dc42fb68769cf180d7480123a71d0fefea578a3e2c059c684f99431309d023
|
data/.travis.yml
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
+
addons:
|
2
|
+
code_climate:
|
3
|
+
repo_token: 09ffc7d4f0f2912b317e719d8f95fd14fcfa3a0a117a24335a33c81d5013c8e5
|
1
4
|
language: ruby
|
5
|
+
before_install:
|
6
|
+
- gem update --system
|
7
|
+
- gem update bundler
|
2
8
|
env:
|
3
9
|
global:
|
4
10
|
- "JRUBY_OPTS=-Xcext.enabled=true"
|
5
11
|
rvm:
|
12
|
+
- 2.3.0
|
13
|
+
- 2.2.0
|
6
14
|
- 2.1.0
|
7
15
|
- 2.0.0
|
8
16
|
- 1.9.3
|
@@ -10,15 +18,17 @@ rvm:
|
|
10
18
|
- 1.8.7
|
11
19
|
- jruby-18mode
|
12
20
|
- jruby-19mode
|
13
|
-
- rbx
|
14
21
|
- ruby-head
|
15
22
|
- jruby-head
|
16
23
|
- ree
|
17
24
|
matrix:
|
18
25
|
allow_failures:
|
19
26
|
- rvm: 1.8.7
|
27
|
+
- rvm: 1.9.2
|
28
|
+
- rvm: 1.9.3
|
20
29
|
- rvm: ree
|
21
30
|
- rvm: jruby-18mode
|
22
31
|
- rvm: jruby-19mode
|
23
32
|
- rvm: jruby-head
|
33
|
+
- rvm: ruby-head
|
24
34
|
fast_finish: true
|
data/cinch-toolbox.gemspec
CHANGED
@@ -8,21 +8,20 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Cinch::Toolbox::VERSION
|
9
9
|
gem.authors = ['Brian Haberer']
|
10
10
|
gem.email = ['bhaberer@gmail.com']
|
11
|
-
gem.description = %q
|
12
|
-
gem.summary = %q
|
11
|
+
gem.description = %q(A gem of various methods used in many of my plugins. If you need the namespace, let me know.)
|
12
|
+
gem.summary = %q(Common methods used in Cinch Plugins.)
|
13
13
|
gem.homepage = 'https://github.com/bhaberer/cinch-toolbox'
|
14
14
|
gem.license = 'MIT'
|
15
|
-
|
16
15
|
gem.files = `git ls-files`.split($/)
|
17
|
-
gem.executables = gem.files.grep(
|
18
|
-
gem.test_files = gem.files.grep(
|
16
|
+
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
19
18
|
gem.require_paths = ['lib']
|
20
19
|
|
21
|
-
gem.add_development_dependency
|
22
|
-
gem.add_development_dependency
|
23
|
-
gem.add_development_dependency
|
24
|
-
gem.add_development_dependency
|
25
|
-
gem.add_development_dependency
|
20
|
+
gem.add_development_dependency 'rake', '~> 10'
|
21
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
22
|
+
gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.0'
|
23
|
+
gem.add_development_dependency 'fakeweb', '~> 1.3'
|
24
|
+
gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
|
26
25
|
|
27
|
-
gem.add_dependency
|
26
|
+
gem.add_dependency 'nokogiri', '~> 1.6'
|
28
27
|
end
|
data/lib/cinch/toolbox.rb
CHANGED
@@ -64,9 +64,9 @@ module Cinch
|
|
64
64
|
return url if url.length < 45
|
65
65
|
uri = URI.parse("http://is.gd/create.php?format=simple&url=#{url}")
|
66
66
|
shortened = Net::HTTP.get(uri)
|
67
|
-
shortened if shortened.match(%r
|
67
|
+
shortened if shortened.match(%r{https?://is.gd/})
|
68
68
|
rescue Errno::ETIMEDOUT
|
69
|
-
# if the URL shortener is down, handle it.
|
69
|
+
# if the URL shortener is down, handle it.
|
70
70
|
url
|
71
71
|
end
|
72
72
|
|
@@ -76,7 +76,7 @@ module Cinch
|
|
76
76
|
def self.expand(url)
|
77
77
|
uri = URI.parse("http://is.gd/forward.php?format=simple&shorturl=#{url}")
|
78
78
|
unshortened = Net::HTTP.get(uri)
|
79
|
-
unshortened unless unshortened.match(%r
|
79
|
+
unshortened unless unshortened.match(%r{https?://is.gd/})
|
80
80
|
end
|
81
81
|
|
82
82
|
# Truncate a given block of text, used for making sure the bot doesn't
|
@@ -150,10 +150,9 @@ module Cinch
|
|
150
150
|
def self.parse_time_hash(times, format)
|
151
151
|
string = []
|
152
152
|
times.each_pair do |period, time|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
end
|
153
|
+
next unless period == :seconds || !(time.zero? && string.empty?)
|
154
|
+
|
155
|
+
string << [time, format == :long ? " #{period}" : period.slice(0)].join
|
157
156
|
end
|
158
157
|
string.join(', ')
|
159
158
|
end
|
data/spec/cinch-toolbox_spec.rb
CHANGED
@@ -11,94 +11,92 @@ describe Cinch::Toolbox do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'should return a string with contents of a css selector of a web page' do
|
14
|
-
Cinch::Toolbox.get_html_element('http://example.com/', '.foo', :css)
|
15
|
-
|
14
|
+
element = Cinch::Toolbox.get_html_element('http://example.com/', '.foo', :css)
|
15
|
+
expect(element).to eq('Bar')
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should return a string with full markup of a css selector of a web page' do
|
19
|
-
Cinch::Toolbox.get_html_element('http://example.com/', '.top', :css_full)
|
20
|
-
|
19
|
+
element = Cinch::Toolbox.get_html_element('http://example.com/', '.top', :css_full)
|
20
|
+
expect(element).to eq(@fake_web_html)
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should return a string with contents of a xpath selector of a web page' do
|
24
|
-
Cinch::Toolbox.get_html_element('http://example.com/', "//div/div[1]", :xpath)
|
25
|
-
|
24
|
+
element = Cinch::Toolbox.get_html_element('http://example.com/', "//div/div[1]", :xpath)
|
25
|
+
expect(element).to eq('Bar')
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should return a string with contents of a xpath selector of a web page' do
|
29
|
-
Cinch::Toolbox.get_html_element('http://example.com/', "//div[@id='a1']", :xpath_full)
|
30
|
-
|
29
|
+
element = Cinch::Toolbox.get_html_element('http://example.com/', "//div[@id='a1']", :xpath_full)
|
30
|
+
expect(element).to eq(@fake_web_html)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should return nil if the css element does not exist' do
|
34
|
-
Cinch::Toolbox.get_html_element('http://example.com/', '.foo2', :css)
|
35
|
-
|
34
|
+
element = Cinch::Toolbox.get_html_element('http://example.com/', '.foo2', :css)
|
35
|
+
expect(element).to be_nil
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should return nil if the xpath element does not exist' do
|
39
|
-
Cinch::Toolbox.get_html_element('http://example.com/', "//div/div[3]", :xpath)
|
40
|
-
|
39
|
+
element = Cinch::Toolbox.get_html_element('http://example.com/', "//div/div[3]", :xpath)
|
40
|
+
expect(element).to be_nil
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'should return nil if there is a problem finding the site' do
|
44
|
-
Cinch::Toolbox.get_html_element('http://baddurl.com/', '.foo2', :css)
|
45
|
-
|
44
|
+
element = Cinch::Toolbox.get_html_element('http://baddurl.com/', '.foo2', :css)
|
45
|
+
expect(element).to be_nil
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should return the page title if there is a http => https trasition' do
|
49
|
-
Cinch::Toolbox.get_html_element('http://github.com/bhaberer/', 'title', :css)
|
50
|
-
|
49
|
+
element = Cinch::Toolbox.get_html_element('http://github.com/bhaberer/', 'title', :css)
|
50
|
+
expect(element).to include('bhaberer (Brian Haberer)')
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'should return nil if there is a https => http trasition' do
|
54
|
-
Cinch::Toolbox.get_html_element('https://www.amazon.com/', 'title', :css)
|
55
|
-
|
54
|
+
element = Cinch::Toolbox.get_html_element('https://www.amazon.com/', 'title', :css)
|
55
|
+
expect(element).to be_nil
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe 'the get_page_title method' do
|
60
|
-
before(:all) do
|
61
|
-
end
|
62
|
-
|
63
60
|
it 'should return a page title for a given url' do
|
64
|
-
FakeWeb.register_uri( :get,
|
65
|
-
|
66
|
-
|
61
|
+
FakeWeb.register_uri( :get, 'http://example.com/',
|
62
|
+
body: '<body><title>Page Title</title></body>')
|
63
|
+
element = Cinch::Toolbox.get_page_title('http://example.com/')
|
64
|
+
expect(element).to eq('Page Title')
|
67
65
|
end
|
68
66
|
|
69
67
|
it 'should return Nil if a page is lacking a title' do
|
70
|
-
FakeWeb.register_uri( :get, "http://example.com/", :
|
71
|
-
Cinch::Toolbox.get_page_title(
|
72
|
-
|
68
|
+
FakeWeb.register_uri( :get, "http://example.com/", body: '<body>Page Title</body>')
|
69
|
+
element = Cinch::Toolbox.get_page_title('http://example.com/')
|
70
|
+
expect(element).to be_nil
|
73
71
|
end
|
74
72
|
|
75
73
|
it 'should return an image title if a page is a supported image type' do
|
76
74
|
[:jpg, :jpeg, :gif, :png].each do |image|
|
77
|
-
Cinch::Toolbox.get_page_title("http://example.com/image.#{image}")
|
78
|
-
|
75
|
+
img = Cinch::Toolbox.get_page_title("http://example.com/image.#{image}")
|
76
|
+
expect(img).to eq('Image from http://example.com')
|
79
77
|
end
|
80
78
|
end
|
81
79
|
|
82
80
|
it 'should return Nil if a page is lacking a title' do
|
83
|
-
Cinch::Toolbox.get_page_title("http://i.imgur.com/oMndYK7.jpg")
|
84
|
-
|
81
|
+
element = Cinch::Toolbox.get_page_title("http://i.imgur.com/oMndYK7.jpg")
|
82
|
+
expect(element).to eq('Anybody with a cat will relate. - Imgur')
|
85
83
|
end
|
86
84
|
end
|
87
85
|
|
88
86
|
describe 'url shortening and expanding' do
|
89
87
|
it 'should shorten long urls' do
|
90
|
-
Cinch::Toolbox.shorten('http://en.wikipedia.org/wiki/Llanfairpwllgwyngyllgogerychwyrndrobwllllan')
|
91
|
-
|
88
|
+
url = Cinch::Toolbox.shorten('http://en.wikipedia.org/wiki/Llanfairpwllgwyngyllgogerychwyrndrobwllllan')
|
89
|
+
expect(url).to eq('http://is.gd/PaUTII')
|
92
90
|
end
|
93
91
|
|
94
92
|
it 'should not shorten urls that are already short enough (< 45 cha)' do
|
95
|
-
Cinch::Toolbox.shorten('http://en.wikipedia.org/')
|
96
|
-
|
93
|
+
url = Cinch::Toolbox.shorten('http://en.wikipedia.org/')
|
94
|
+
expect(url).to eq('http://en.wikipedia.org/')
|
97
95
|
end
|
98
96
|
|
99
97
|
it 'should be able to expand shortened links' do
|
100
98
|
url = 'http://en.wikipedia.org/wiki/Llanfairpwllgwyngyll'
|
101
|
-
Cinch::Toolbox.expand(Cinch::Toolbox.shorten(url))
|
99
|
+
expect(url).to eq(Cinch::Toolbox.expand(Cinch::Toolbox.shorten(url)))
|
102
100
|
end
|
103
101
|
end
|
104
102
|
|
@@ -106,30 +104,30 @@ describe Cinch::Toolbox do
|
|
106
104
|
it 'should truncate text past the limit' do
|
107
105
|
foo = String.new
|
108
106
|
1000.times { foo << 'a' }
|
109
|
-
Cinch::Toolbox.truncate(foo).length.
|
107
|
+
expect(Cinch::Toolbox.truncate(foo).length).to eq(250)
|
110
108
|
end
|
111
109
|
|
112
110
|
it 'should not truncate text within limit' do
|
113
111
|
foo = String.new
|
114
112
|
1000.times { foo << 'a' }
|
115
|
-
Cinch::Toolbox.truncate(foo, 100).length.
|
113
|
+
expect(Cinch::Toolbox.truncate(foo, 100).length).to eq(100)
|
116
114
|
end
|
117
115
|
end
|
118
116
|
|
119
117
|
describe 'time parseing' do
|
120
118
|
it 'should parse seconds into a user friendly string' do
|
121
|
-
Cinch::Toolbox.time_format(126)
|
122
|
-
|
119
|
+
expect(Cinch::Toolbox.time_format(126))
|
120
|
+
.to eq('2 mins, 6 seconds')
|
123
121
|
end
|
124
122
|
|
125
123
|
it 'should allow users to limit the kinds of units returned' do
|
126
|
-
Cinch::Toolbox.time_format(126020, [:days, :seconds])
|
127
|
-
|
124
|
+
expect(Cinch::Toolbox.time_format(126020, [:days, :seconds]))
|
125
|
+
.to eq('1 days, 20 seconds')
|
128
126
|
end
|
129
127
|
|
130
128
|
it 'should allow users to specify short form' do
|
131
|
-
Cinch::Toolbox.time_format(126000, [:days], :short)
|
132
|
-
|
129
|
+
expect(Cinch::Toolbox.time_format(126000, [:days], :short))
|
130
|
+
.to eq('1d')
|
133
131
|
end
|
134
132
|
end
|
135
133
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
-
SimpleCov::Formatter::HTMLFormatter,
|
6
|
-
Coveralls::SimpleCov::Formatter
|
7
|
-
]
|
8
|
-
SimpleCov.start
|
1
|
+
require "codeclimate-test-reporter"
|
2
|
+
CodeClimate::TestReporter.start
|
9
3
|
|
10
4
|
require 'cinch/toolbox'
|
11
5
|
require 'cinch/test'
|
metadata
CHANGED
@@ -1,99 +1,105 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Haberer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '10'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: cinch-test
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
- - ">="
|
46
49
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
50
|
+
version: 0.1.0
|
48
51
|
type: :development
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
|
-
- -
|
55
|
+
- - "~>"
|
53
56
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
57
|
+
version: '0.1'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.1.0
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: fakeweb
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- - ~>
|
65
|
+
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
67
|
version: '1.3'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- - ~>
|
72
|
+
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '1.3'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
76
|
+
name: codeclimate-test-reporter
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
|
-
- -
|
79
|
+
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
81
|
+
version: '0.4'
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- -
|
86
|
+
- - "~>"
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
88
|
+
version: '0.4'
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
90
|
name: nokogiri
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
|
-
- - ~>
|
93
|
+
- - "~>"
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.6
|
95
|
+
version: '1.6'
|
90
96
|
type: :runtime
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
|
-
- - ~>
|
100
|
+
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.6
|
102
|
+
version: '1.6'
|
97
103
|
description: A gem of various methods used in many of my plugins. If you need the
|
98
104
|
namespace, let me know.
|
99
105
|
email:
|
@@ -102,8 +108,8 @@ executables: []
|
|
102
108
|
extensions: []
|
103
109
|
extra_rdoc_files: []
|
104
110
|
files:
|
105
|
-
- .gitignore
|
106
|
-
- .travis.yml
|
111
|
+
- ".gitignore"
|
112
|
+
- ".travis.yml"
|
107
113
|
- Gemfile
|
108
114
|
- LICENSE.txt
|
109
115
|
- README.md
|
@@ -123,17 +129,17 @@ require_paths:
|
|
123
129
|
- lib
|
124
130
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
131
|
requirements:
|
126
|
-
- -
|
132
|
+
- - ">="
|
127
133
|
- !ruby/object:Gem::Version
|
128
134
|
version: '0'
|
129
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
136
|
requirements:
|
131
|
-
- -
|
137
|
+
- - ">="
|
132
138
|
- !ruby/object:Gem::Version
|
133
139
|
version: '0'
|
134
140
|
requirements: []
|
135
141
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.5.1
|
137
143
|
signing_key:
|
138
144
|
specification_version: 4
|
139
145
|
summary: Common methods used in Cinch Plugins.
|