trim-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1,23 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'autotest/restart'
4
+
5
+ # Autotest.add_hook :initialize do |at|
6
+ # at.extra_files << "../some/external/dependency.rb"
7
+ #
8
+ # at.libs << ":../some/external"
9
+ #
10
+ # at.add_exception 'vendor'
11
+ #
12
+ # at.add_mapping(/dependency.rb/) do |f, _|
13
+ # at.files_matching(/test_.*rb$/)
14
+ # end
15
+ #
16
+ # %w(TestA TestB).each do |klass|
17
+ # at.extra_class_map[klass] = "test/test_misc.rb"
18
+ # end
19
+ # end
20
+
21
+ # Autotest.add_hook :run_command do |at|
22
+ # system "rake build"
23
+ # end
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 / 2009-10-18
2
+
3
+ * Initial release
4
+
data/Manifest.txt ADDED
@@ -0,0 +1,9 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/trim_api
7
+ lib/trim-api/trim-api.rb
8
+ lib/trim_api.rb
9
+ test/test_trim_api.rb
data/README.txt ADDED
@@ -0,0 +1,57 @@
1
+ = trim_api
2
+
3
+ http://github.com/robinjfisher/trim-api
4
+
5
+ == DESCRIPTION:
6
+
7
+ A simple Ruby library for accessing the tr.im API
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ Currently only supports the trimming of a URL with limited error checking.
12
+
13
+ == REQUIREMENTS:
14
+
15
+ The following gems are required:
16
+
17
+ - HTTPClient
18
+
19
+ == INSTALL:
20
+
21
+ gem sources -a http://gemcutter.org
22
+ gem install trim-api
23
+
24
+ == USAGE:
25
+
26
+ require 'rubygems'
27
+ require 'trim_api'
28
+
29
+ api = TrimApi::Trim.new
30
+ api.trim("http://www.google.com/")
31
+
32
+ Returns the trimmed url as a string.
33
+
34
+ == LICENSE:
35
+
36
+ (The MIT License)
37
+
38
+ Copyright (c) 2009 captured sparks
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining
41
+ a copy of this software and associated documentation files (the
42
+ 'Software'), to deal in the Software without restriction, including
43
+ without limitation the rights to use, copy, modify, merge, publish,
44
+ distribute, sublicense, and/or sell copies of the Software, and to
45
+ permit persons to whom the Software is furnished to do so, subject to
46
+ the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be
49
+ included in all copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
52
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
53
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
54
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
55
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
56
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
57
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.spec 'trim-api' do
7
+ developer('Robin Fisher', 'robinjfisher@capturedsparks.com')
8
+
9
+ # self.rubyforge_name = 'trim_apix' # if different than 'trim_api'
10
+ end
11
+
12
+ # vim: syntax=ruby
data/bin/trim_api ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ abort "you need to write me"
@@ -0,0 +1,41 @@
1
+ module TrimApi
2
+
3
+ VERSION = "0.0.1"
4
+ API_URL = "http://api.tr.im/api/"
5
+
6
+ class TrimError < StandardError
7
+
8
+ def initialize(code, message)
9
+ super("#{code} - #{message}")
10
+ end
11
+
12
+ end
13
+
14
+ class Trim
15
+
16
+ def initialize(options = {})
17
+ @client = HTTPClient.new
18
+ end
19
+
20
+ def trim(original_url)
21
+ raise ArgumentError.new(":url to shorten is required") if original_url.nil?
22
+ response = @client.get_content(create_url(original_url))
23
+ data = JSON.parse(response)
24
+ unless data["status"]["result"] == "OK"
25
+ raise TrimError.new(data["status"]["code"],data["status"]["message"])
26
+ else
27
+ data["url"]
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def create_url(original_url)
34
+ base_url = "#{API_URL}trim_url.json?"
35
+ url = "url=#{CGI::escape(original_url)}"
36
+ base_url + url
37
+ end
38
+
39
+ end
40
+
41
+ end
data/lib/trim_api.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'httpclient'
3
+ require 'json'
4
+ require 'CGI'
5
+ require 'trim-api/trim-api.rb'
6
+
7
+ module TrimApi
8
+ VERSION = '0.0.1'
9
+ end
@@ -0,0 +1,8 @@
1
+ require "test/unit"
2
+ require "trim_api"
3
+
4
+ class TestTrimApi < Test::Unit::TestCase
5
+ def test_sanity
6
+ flunk "write tests or I will kneecap you"
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trim-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robin Fisher
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-18 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ description: A simple Ruby library for accessing the tr.im API
26
+ email:
27
+ - robinjfisher@capturedsparks.com
28
+ executables:
29
+ - trim_api
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - .autotest
38
+ - History.txt
39
+ - Manifest.txt
40
+ - README.txt
41
+ - Rakefile
42
+ - bin/trim_api
43
+ - lib/trim-api/trim-api.rb
44
+ - lib/trim_api.rb
45
+ - test/test_trim_api.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/robinjfisher/trim-api
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --main
53
+ - README.txt
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: trim-api
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: A simple Ruby library for accessing the tr.im API
75
+ test_files:
76
+ - test/test_trim_api.rb