Class: Imagize::Imagizer
- Inherits:
-
Object
- Object
- Imagize::Imagizer
- Defined in:
- lib/imagize.rb
Instance Method Summary collapse
- #add_cloud_app_image(images, code) ⇒ Object
- #extract_shortener(short_url) ⇒ Object
- #imagize(message, extract_shorteners = false) ⇒ Object
- #make_url(servicename, code) ⇒ Object
- #make_youtube_url(code) ⇒ Object
Instance Method Details
#add_cloud_app_image(images, code) ⇒ Object
167 168 169 170 171 172 |
# File 'lib/imagize.rb', line 167 def add_cloud_app_image(images, code) drop = CloudApp::Drop.find code if drop.image? images << drop.remote_url end end |
#extract_shortener(short_url) ⇒ Object
149 150 151 152 153 154 155 156 157 |
# File 'lib/imagize.rb', line 149 def extract_shortener (short_url) uri = URI.parse(short_url) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Get.new(uri.request_uri) response = http.request(request) response['location'] end |
#imagize(message, extract_shorteners = false) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/imagize.rb', line 91 def imagize(, extract_shorteners=false) tweet = .clone images = Array.new #find shortened content if extract_shorteners SHORTENERS.each do |service, details| currentService = details[:url] tweet.scan /#{currentService}\w*/ do |current| tweet = tweet.sub(current, extract_shortener(current)) end end end #find image services URL_DEFINITIONS.each do |service, details| currentService = details[:url] tweet.scan /#{currentService}\w*/ do |current| code = current.sub(currentService, "") images << make_url(service, code) end end #Find cl.ly tweet.scan /#{CLOUD_APP}\w*/ do |current| p "Current is " + current code = current.sub(CLOUD_APP, "") p code add_cloud_app_image images, code end #Find shorteners that use cl.ly # Resolv.getaddress "dirk.si" # long youtube tweet.scan /#{YOUTUBE_LONG_URL}\?v=\w*/ do |current| p "Current is " + current code = current.sub(YOUTUBE_LONG_URL+"?v=", "") p code images << make_youtube_url(code) end IMAGE_FINDERS.each do |finder| images += tweet.scan(finder) end images end |
#make_url(servicename, code) ⇒ Object
159 160 161 |
# File 'lib/imagize.rb', line 159 def make_url (servicename, code) URL_DEFINITIONS[servicename][:convert].gsub "§ID§", code end |
#make_youtube_url(code) ⇒ Object
163 164 165 |
# File 'lib/imagize.rb', line 163 def make_youtube_url (code) YOUTUBE_LONG_CONVERT_URL.gsub "§ID§", code end |