File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ # Dropzone Destination Info
2+ # Name: bit.ly
3+ # Description: A dropped URL will be converted to an bit.ly URL.
4+ # Handles: NSStringPboardType
5+ # Creator: Sergej Müller
6+ # URL: http://www.ebiene.de
7+ # IconURL: http://aptonic.com/destinations/icons/bit.ly.png
8+ # OptionsNIB: Login
9+ # LoginTitle: bit.ly Login Details
10+
11+ require 'open-uri'
12+ require 'net/http'
13+ require 'cgi'
14+ require 'rexml/document'
15+
16+ def dragged
17+ $dz.determinate(false)
18+ $dz.begin("Getting bit.ly URL")
19+
20+ if $items[0] =~ /http/
21+ Net::HTTP.start('api.bit.ly') do |http|
22+ req = Net::HTTP::Get.new('/shorten?version=2.0.1&format=xml&longUrl=' + CGI::escape($items[0]))
23+ req.basic_auth ENV['USERNAME'], ENV['PASSWORD']
24+ res = http.request(req)
25+
26+ doc = REXML::Document.new(res.body)
27+ doc.elements.each("bitly/statusCode") do |a|
28+ if a.text == "ERROR"
29+ $dz.finish("Invalid user or password")
30+ $dz.url(false)
31+ else
32+ doc.elements.each("bitly/results/nodeKeyVal/shortUrl") do |b|
33+ if b.text.empty?
34+ $dz.finish("Empty URL is returned")
35+ $dz.url(false)
36+ else
37+ $dz.finish("URL is now on clipboard")
38+ $dz.url(b.text)
39+ end
40+ end
41+ end
42+ end
43+ end
44+ else
45+ $dz.finish("Invalid URL")
46+ $dz.url(false)
47+ end
48+ end
49+
50+ def clicked
51+ system("open http://bit.ly/")
52+ end
You can’t perform that action at this time.
0 commit comments