cinch-toolbox 1.1.0 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 821a1f2457c732c7890457a6b9982f7142438b6bd0515bd5547825167432ca0f
4
+ data.tar.gz: bb386a2ac771c85afed1c4ff7f7c24ad593c2dfb35d0a5336226a57afa9560b0
5
+ SHA512:
6
+ metadata.gz: 851639b4417c96141427a00309c7095ba7339e74ce50928c2a7a65c2b05a25a6c4cea40145f9b38dad09a97fd6bbd04aeb504ba9b0db2702ef2a83b3f7eca56e
7
+ data.tar.gz: 94d68b57b4ec6ac3ff31497838e0c127d8c6ace9862451ca11481584aa44ab5ce75c6a0c2fab37c5ae5ccf8a5dc0b475a983c1642c7d553b27087539a4468b6f
@@ -1,4 +1,34 @@
1
+ addons:
2
+ code_climate:
3
+ repo_token: 09ffc7d4f0f2912b317e719d8f95fd14fcfa3a0a117a24335a33c81d5013c8e5
1
4
  language: ruby
5
+ before_install:
6
+ - gem update --system
7
+ - gem update bundler
8
+ env:
9
+ global:
10
+ - "JRUBY_OPTS=-Xcext.enabled=true"
2
11
  rvm:
3
- - 1.9.2
12
+ - 2.3.0
13
+ - 2.2.0
14
+ - 2.1.0
15
+ - 2.0.0
4
16
  - 1.9.3
17
+ - 1.9.2
18
+ - 1.8.7
19
+ - jruby-18mode
20
+ - jruby-19mode
21
+ - ruby-head
22
+ - jruby-head
23
+ - ree
24
+ matrix:
25
+ allow_failures:
26
+ - rvm: 1.8.7
27
+ - rvm: 1.9.2
28
+ - rvm: 1.9.3
29
+ - rvm: ree
30
+ - rvm: jruby-18mode
31
+ - rvm: jruby-19mode
32
+ - rvm: jruby-head
33
+ - rvm: ruby-head
34
+ fast_finish: true
@@ -8,22 +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{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.}
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(%r{^bin/}).map{ |f| File.basename(f) }
18
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
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 'rake'
22
- gem.add_development_dependency 'rspec'
23
- gem.add_development_dependency 'coveralls'
24
- gem.add_development_dependency 'fakeweb', '~> 1.3'
25
- gem.add_development_dependency 'cinch-test'
20
+ gem.add_development_dependency 'rake', '~> 12.3.3'
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 'nokogiri', '~> 1.6.0'
28
- gem.add_dependency 'patron', '~> 0.4.18'
26
+ gem.add_dependency 'nokogiri', '~> 1.6'
29
27
  end
@@ -1,8 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'cinch/toolbox/version'
3
3
  require 'open-uri'
4
- require 'patron'
5
4
  require 'nokogiri'
5
+ require 'net/http'
6
+ require 'uri'
6
7
 
7
8
  module Cinch
8
9
  # Module for conveniance methods used in multiple Cinch plugins.
@@ -34,7 +35,7 @@ module Cinch
34
35
  url.send("at_#{mode.to_s.gsub(/_full/, '')}", selector).to_html
35
36
  end
36
37
  # Rescue for any kind of network sillyness
37
- rescue SocketError, RuntimeError, HTTPError
38
+ rescue SocketError, RuntimeError, Net::HTTPError
38
39
  nil
39
40
  end
40
41
 
@@ -63,7 +64,10 @@ module Cinch
63
64
  return url if url.length < 45
64
65
  uri = URI.parse("http://is.gd/create.php?format=simple&url=#{url}")
65
66
  shortened = Net::HTTP.get(uri)
66
- shortened if shortened.match(%r(https?://is.gd/))
67
+ shortened if shortened.match(%r{https?://is.gd/})
68
+ rescue Errno::ETIMEDOUT
69
+ # if the URL shortener is down, handle it.
70
+ url
67
71
  end
68
72
 
69
73
  # Expand a previously shortened URL via the configured shortener
@@ -72,7 +76,7 @@ module Cinch
72
76
  def self.expand(url)
73
77
  uri = URI.parse("http://is.gd/forward.php?format=simple&shorturl=#{url}")
74
78
  unshortened = Net::HTTP.get(uri)
75
- unshortened unless unshortened.match(%r(https?://is.gd/))
79
+ unshortened unless unshortened.match(%r{https?://is.gd/})
76
80
  end
77
81
 
78
82
  # Truncate a given block of text, used for making sure the bot doesn't
@@ -146,10 +150,9 @@ module Cinch
146
150
  def self.parse_time_hash(times, format)
147
151
  string = []
148
152
  times.each_pair do |period, time|
149
- if period == :seconds || !(time.zero? && string.empty?)
150
- string << [time, format == :long ? " #{period}" : period.slice(0)]
151
- .join
152
- end
153
+ next unless period == :seconds || !(time.zero? && string.empty?)
154
+
155
+ string << [time, format == :long ? " #{period}" : period.slice(0)].join
153
156
  end
154
157
  string.join(', ')
155
158
  end
@@ -2,6 +2,6 @@
2
2
  module Cinch
3
3
  # Version Info
4
4
  module Toolbox
5
- VERSION = '1.1.0'
5
+ VERSION = '1.1.7'
6
6
  end
7
7
  end
@@ -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
- should == 'Bar'
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
- should == @fake_web_html
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
- should == 'Bar'
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
- should == @fake_web_html
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
- should be_nil
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
- should be_nil
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
- should be_nil
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
- should include 'bhaberer (Brian Haberer)'
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
- should be_nil
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, "http://example.com/", :body => "<title>Page Title</table>")
65
- Cinch::Toolbox.get_page_title("http://example.com/").
66
- should == 'Page Title'
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/", :body => "<body>Page Title</body>")
71
- Cinch::Toolbox.get_page_title("http://example.com/").
72
- should be_nil
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
- should == "Image from http://example.com"
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
- should == "Anybody with a cat will relate. - Imgur"
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
- should == "http://is.gd/PaUTII"
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
- should == 'http://en.wikipedia.org/'
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)).should == 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.should == 250
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.should == 100
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
- should == '2 mins, 6 seconds'
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
- should == '1 days, 20 seconds'
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
- should == '1d'
129
+ expect(Cinch::Toolbox.time_format(126000, [:days], :short))
130
+ .to eq('1d')
133
131
  end
134
132
  end
135
133
  end
@@ -1,11 +1,5 @@
1
- require 'coveralls'
2
- require 'simplecov'
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,128 +1,105 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.1.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brian Haberer
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-02-18 00:00:00.000000000 Z
11
+ date: 2021-01-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 12.3.3
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: 12.3.3
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: '3'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: '3'
46
41
  - !ruby/object:Gem::Dependency
47
- name: coveralls
42
+ name: cinch-test
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ - - ">="
52
49
  - !ruby/object:Gem::Version
53
- version: '0'
50
+ version: 0.1.0
54
51
  type: :development
55
52
  prerelease: false
56
53
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
54
  requirements:
59
- - - ! '>='
55
+ - - "~>"
60
56
  - !ruby/object:Gem::Version
61
- version: '0'
57
+ version: '0.1'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.1.0
62
61
  - !ruby/object:Gem::Dependency
63
62
  name: fakeweb
64
63
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
64
  requirements:
67
- - - ~>
65
+ - - "~>"
68
66
  - !ruby/object:Gem::Version
69
67
  version: '1.3'
70
68
  type: :development
71
69
  prerelease: false
72
70
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
71
  requirements:
75
- - - ~>
72
+ - - "~>"
76
73
  - !ruby/object:Gem::Version
77
74
  version: '1.3'
78
75
  - !ruby/object:Gem::Dependency
79
- name: cinch-test
76
+ name: codeclimate-test-reporter
80
77
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
78
  requirements:
83
- - - ! '>='
79
+ - - "~>"
84
80
  - !ruby/object:Gem::Version
85
- version: '0'
81
+ version: '0.4'
86
82
  type: :development
87
83
  prerelease: false
88
84
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
85
  requirements:
91
- - - ! '>='
86
+ - - "~>"
92
87
  - !ruby/object:Gem::Version
93
- version: '0'
88
+ version: '0.4'
94
89
  - !ruby/object:Gem::Dependency
95
90
  name: nokogiri
96
91
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: 1.6.0
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: 1.6.0
110
- - !ruby/object:Gem::Dependency
111
- name: patron
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
92
  requirements:
115
- - - ~>
93
+ - - "~>"
116
94
  - !ruby/object:Gem::Version
117
- version: 0.4.18
95
+ version: '1.6'
118
96
  type: :runtime
119
97
  prerelease: false
120
98
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
99
  requirements:
123
- - - ~>
100
+ - - "~>"
124
101
  - !ruby/object:Gem::Version
125
- version: 0.4.18
102
+ version: '1.6'
126
103
  description: A gem of various methods used in many of my plugins. If you need the
127
104
  namespace, let me know.
128
105
  email:
@@ -131,8 +108,8 @@ executables: []
131
108
  extensions: []
132
109
  extra_rdoc_files: []
133
110
  files:
134
- - .gitignore
135
- - .travis.yml
111
+ - ".gitignore"
112
+ - ".travis.yml"
136
113
  - Gemfile
137
114
  - LICENSE.txt
138
115
  - README.md
@@ -145,29 +122,26 @@ files:
145
122
  homepage: https://github.com/bhaberer/cinch-toolbox
146
123
  licenses:
147
124
  - MIT
148
- post_install_message:
125
+ metadata: {}
126
+ post_install_message:
149
127
  rdoc_options: []
150
128
  require_paths:
151
129
  - lib
152
130
  required_ruby_version: !ruby/object:Gem::Requirement
153
- none: false
154
131
  requirements:
155
- - - ! '>='
132
+ - - ">="
156
133
  - !ruby/object:Gem::Version
157
134
  version: '0'
158
135
  required_rubygems_version: !ruby/object:Gem::Requirement
159
- none: false
160
136
  requirements:
161
- - - ! '>='
137
+ - - ">="
162
138
  - !ruby/object:Gem::Version
163
139
  version: '0'
164
140
  requirements: []
165
- rubyforge_project:
166
- rubygems_version: 1.8.25
167
- signing_key:
168
- specification_version: 3
141
+ rubygems_version: 3.1.4
142
+ signing_key:
143
+ specification_version: 4
169
144
  summary: Common methods used in Cinch Plugins.
170
145
  test_files:
171
146
  - spec/cinch-toolbox_spec.rb
172
147
  - spec/spec_helper.rb
173
- has_rdoc: