shortservice 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/shortservice.rb +39 -0
  2. metadata +75 -0
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'simplehttp'
3
+ require 'rexml/document'
4
+
5
+ module ShortService
6
+ API_URL = "http://shortservice.local/api"
7
+
8
+ Service = Struct.new(:key, :name)
9
+
10
+ def self.services
11
+ xml = SimpleHttp.get("#{API_URL}/services?format=xml")
12
+ doc = REXML::Document.new(xml)
13
+
14
+ services = []
15
+
16
+ doc.elements.each("services/service") do |service|
17
+ key, name = service.elements["key"].text, service.elements["name"].text
18
+ services << Service.new(key, name)
19
+ end
20
+
21
+ services
22
+ end
23
+
24
+ def self.shorten(url, service = "bitly")
25
+ xml = SimpleHttp.get("#{API_URL}/shorten?url=#{CGI::escape(url)}&service=#{service}&format=xml")
26
+ doc = REXML::Document.new(xml)
27
+
28
+ result = doc.elements["result"]
29
+
30
+ if result.elements["status"].text == "ok"
31
+ result.elements["url"].text
32
+ else
33
+ raise result.elements["description"].text
34
+ end
35
+ end
36
+ end
37
+
38
+ puts ShortService::services
39
+ puts ShortService::shorten("http://www.google.com", "bitly")
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shortservice
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Lasse Bunk
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-28 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: simplehttp
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 1
30
+ - 3
31
+ version: 0.1.3
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: The ShortService gem is a layer for talking to the ShortService.net API.
35
+ email: lassebunk@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - lib/shortservice.rb
44
+ has_rdoc: true
45
+ homepage:
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ requirements: []
68
+
69
+ rubyforge_project:
70
+ rubygems_version: 1.3.6
71
+ signing_key:
72
+ specification_version: 3
73
+ summary: Layer for talking to ShortService.net.
74
+ test_files: []
75
+