cinch-links-tumblr 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,3 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'cinch/plugins/links-tumblr/version'
2
- require 'cinch/plugins/links-tumblr/links-tumblr'
3
+ require 'cinch/plugins/links-tumblr'
@@ -1,11 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'open-uri'
3
3
  require 'tumblr'
4
+ require 'yaml'
4
5
  require 'cinch'
5
6
  require 'cinch-storage'
6
7
  require 'cinch/toolbox'
7
8
 
8
9
  module Cinch::Plugins
10
+ # Cinch Plugin to tumbl links from a given channel to a configured tumblr.
9
11
  class LinksTumblr
10
12
  include Cinch::Plugin
11
13
 
@@ -13,7 +15,7 @@ module Cinch::Plugins
13
15
 
14
16
  match /tumblr/
15
17
 
16
- self.help = 'Use .tumblr for the url and password (if any) for the channel\'s tumblr.'
18
+ self.help = 'Use .tumblr for the url/password for the channel\'s tumblr.'
17
19
 
18
20
  def initialize(*args)
19
21
  super
@@ -39,7 +41,7 @@ module Cinch::Plugins
39
41
  end
40
42
 
41
43
  def listen(m)
42
- urls = URI.extract(m.message, ["http", "https"])
44
+ urls = URI.extract(m.message, %w(http https))
43
45
  urls.each do |url|
44
46
  @storage.data[m.channel.name] ||= []
45
47
 
@@ -47,7 +49,8 @@ module Cinch::Plugins
47
49
  unless @storage.data[m.channel.name].include?(url)
48
50
  tumble(url, m.user.nick)
49
51
 
50
- # Store the links to try and cut down on popular urls getting tumbled 20 times
52
+ # Store the links to try and cut down on popular urls getting
53
+ # tumbled 20 times
51
54
  @storage.data[m.channel.name] << url
52
55
  end
53
56
  @storage.synced_save(@bot)
@@ -58,17 +61,14 @@ module Cinch::Plugins
58
61
 
59
62
  def tumble(url, nick)
60
63
  title = Cinch::Toolbox.get_page_title(url)
61
- # Parse out common Redit formats
62
- if redit = url.match(/^https?:\/\/.*imgur\.com.*\/([A-Za-z0-9]+\.\S{3})/)
63
- post_image("http://i.imgur.com/#{redit[1]}", title, nick)
64
- elsif redit = url.match(/^https?:\/\/.*imgur\.com.*\/([A-Za-z0-9]+)\/?/)
65
- # It may not be a jpg, but most browsers will read the meta regardless.
66
- post_image("http://i.imgur.com/#{redit[1]}.jpg", title, nick)
64
+ # Imgur
65
+ if url.match(%r(^https?:\/\/.*imgur\.com))
66
+ post_image(url, title, nick)
67
67
  # Images
68
68
  elsif url.match(/\.jpg|jpeg|gif|png$/i)
69
69
  post_image(url, title, nick)
70
70
  # Youtube / Vimeo
71
- elsif url.match(/https?:\/\/[^\/]*\.?(youtube|youtu|vimeo)\./)
71
+ elsif url.match(%r(https?://[^\/]*\.?(youtube|youtu|vimeo)\.))
72
72
  post_video(url, title, nick)
73
73
  # Everything else
74
74
  else
@@ -76,34 +76,49 @@ module Cinch::Plugins
76
76
  end
77
77
  end
78
78
 
79
+ def post_imgur(url, title, nick)
80
+ # Imgur direct links
81
+ imgur = url[%r(^https?://.*imgur\.com.*/([A-Za-z0-9]+\.\S{3})), 1]
82
+
83
+ unless imgur
84
+ # It may not be a jpg, but most browsers will read the meta regardless.
85
+ imgur = url[%r(^https?://.*imgur\.com.*/([A-Za-z0-9]+)/?), 1] + '.jpg'
86
+ end
87
+ post_image("http://i.imgur.com/#{imgur}", title, nick)
88
+ end
89
+
79
90
  def post_link(url, title = nil, nick = nil)
80
- document = tumblr_header(:link, { title: title, tags: nick })
91
+ document = tumblr_header(:link, title: title, tags: nick)
81
92
  document << url
82
93
  tumblr_post(document)
83
94
  end
84
95
 
85
96
  def post_image(url, title = nil, nick = nil)
86
- document = tumblr_header(:text, { title: title, tags: [nick, 'image'] })
87
- document << "<p><a href='#{url}'><img src='#{url}' style='max-width: 650px;'/></a><br/><a href='#{url}'>#{url}</a></p>"
97
+ document = tumblr_header(:text, title: title, tags: [nick, 'image'])
98
+ document << "<p><a href='#{url}'>" +
99
+ "<img src='#{url}' style='max-width: 650px;'/></a><br/>" +
100
+ "<a href='#{url}'>#{url}</a></p>"
88
101
  tumblr_post(document)
89
102
  end
90
103
 
91
104
  def post_video(url, title, nick = nil)
92
- document = tumblr_header(:video, { caption: title, tags: [nick, 'video'] })
105
+ document = tumblr_header(:video,
106
+ caption: title, tags: [nick, 'video'])
93
107
  document << url
94
108
  tumblr_post(document)
95
109
  end
96
110
 
97
111
  def tumblr_header(type = :text, options = {})
98
112
  opts = { type: type, hostname: @hostname }.update(options)
99
- doc = YAML::dump(opts)
113
+ doc = Psych.dump(opts)
100
114
  doc << "---\n"
101
- return doc
115
+ doc
102
116
  end
103
117
 
104
118
  def credential_check
105
119
  if @creds.values.include?(nil)
106
- raise ArgumentError, 'Credentials are not set correctly, please see documentation.'
120
+ fail ArgumentError,
121
+ 'Credentials are not set correctly, please see documentation.'
107
122
  end
108
123
  end
109
124
 
@@ -113,10 +128,9 @@ module Cinch::Plugins
113
128
  request = post.post(client)
114
129
 
115
130
  request.perform do |response|
116
- if response.success?
117
- debug "Successfully posted to Tumblr"
118
- else
119
- debug "Something went wrong posting to Tumblr #{response.code} #{response.message}"
131
+ unless response.success?
132
+ debug 'Something went wrong posting to Tumblr ' +
133
+ "#{response.code} #{response.message}"
120
134
  end
121
135
  end
122
136
  end
@@ -1,7 +1,9 @@
1
+ # -*- coding: utf-8 -*-
1
2
  module Cinch
2
3
  module Plugins
4
+ # Versioning info
3
5
  class LinksTumblr
4
- VERSION = "1.0.0"
6
+ VERSION = '1.0.1'
5
7
  end
6
8
  end
7
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-links-tumblr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-13 00:00:00.000000000 Z
12
+ date: 2014-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -186,7 +186,7 @@ files:
186
186
  - Rakefile
187
187
  - cinch-links-tumblr.gemspec
188
188
  - lib/cinch-links-tumblr.rb
189
- - lib/cinch/plugins/links-tumblr/links-tumblr.rb
189
+ - lib/cinch/plugins/links-tumblr.rb
190
190
  - lib/cinch/plugins/links-tumblr/version.rb
191
191
  - spec/cinch-links-tumblr_spec.rb
192
192
  - spec/spec_helper.rb