harakiri 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ == DESCRIPTION:
2
+ harakiri is a simple gem for url shortening, using a tinyurl and googl service
3
+
4
+ Autor: Lucas Allan Cardoso
5
+
6
+ == INSTALL:
7
+ gem install harakiri
8
+
9
+ == Using TinyUrl Service:
10
+ Harakiri.tiny_encode("www.lucasallan.com")
11
+
12
+ == Using Googl Service:
13
+ Harakiri.googl_encode("www.lucasallan.com")
14
+
15
+ == LICENSE:
16
+
17
+ (The MIT License)
18
+
19
+ Copyright (c) 2010
20
+
21
+ Permission is hereby granted, free of charge, to any person obtaining
22
+ a copy of this software and associated documentation files (the
23
+ 'Software'), to deal in the Software without restriction, including
24
+ without limitation the rights to use, copy, modify, merge, publish,
25
+ distribute, sublicense, and/or sell copies of the Software, and to
26
+ permit persons to whom the Software is furnished to do so, subject to
27
+ the following conditions:
28
+
29
+ The above copyright notice and this permission notice shall be
30
+ included in all copies or substantial portions of the Software.
31
+
32
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
33
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
35
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
36
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
37
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
38
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
+
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'bones'
3
+ rescue LoadError
4
+ abort '### Please install the "bones" gem ###'
5
+ end
6
+
7
+ ensure_in_path 'lib'
8
+ require 'harakiri'
9
+
10
+ task :default => 'test:run'
11
+ task 'gem:release' => 'test:run'
12
+
13
+ Bones {
14
+ name 'harakiri'
15
+ authors 'Lucas Allan Cardoso'
16
+ email 'lucas.allan@gmail.com'
17
+ url 'http://www.lucasallan.com'
18
+ version '0.0.1'
19
+ }
20
+
@@ -0,0 +1,9 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "harakiri"
3
+ s.version = "0.0.2"
4
+ s.description = "harakiri is a simple gem for url shortening, using a tinyurl and googl service"
5
+ s.summary = "Harakiri Gem"
6
+ s.author = "Lucas Allan Cardoso"
7
+ s.files = Dir["{lib/**/*.rb,README.rdoc,spec/**/*.rb,Rakefile,*.gemspec}"]
8
+ end
9
+
@@ -0,0 +1,16 @@
1
+ require 'net/http'
2
+ require 'cgi'
3
+ require 'services/tiny'
4
+ require 'services/googl'
5
+
6
+ module Harakiri
7
+
8
+ def self.tiny_encode(url)
9
+ Tiny.encode(url)
10
+ end
11
+
12
+ def self.googl_encode(url)
13
+ Googl.encode(url)
14
+ end
15
+ end
16
+
@@ -0,0 +1,25 @@
1
+ require 'httparty'
2
+
3
+ module Googl
4
+
5
+ include HTTParty
6
+
7
+ API_URL = 'https://www.googleapis.com/urlshortener/v1/url'
8
+
9
+ def self.encode(url)
10
+ change_header
11
+ options = {"longUrl" => url}.inspect
12
+ resp = self.post(API_URL, :body => options)
13
+ if resp.code == 200
14
+ resp['id']
15
+ else
16
+ resp.response
17
+ end
18
+ end
19
+
20
+ protected
21
+
22
+ def self.change_header
23
+ self.headers.merge!('Content-Type' => 'application/json')
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ module Tiny
2
+ def self.encode(url)
3
+ Net::HTTP.get(URI.parse("http://tinyurl.com/api-create.php?url=#{CGI::escape(url)}"))
4
+ end
5
+ end
6
+
@@ -0,0 +1,12 @@
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ describe Harakiri do
4
+ it "should shorten with tinyurl" do
5
+ Harakiri.tiny_encode("www.lucasallan.com").should == "http://tinyurl.com/26pwxbx"
6
+ end
7
+
8
+ it "should shorten with googl" do
9
+ Harakiri.googl_encode("www.lucasallan.com").should == "http://goo.gl/c7R93"
10
+ end
11
+ end
12
+
@@ -0,0 +1,6 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib harakiri]))
2
+
3
+ RSpec.configure do |config|
4
+
5
+ end
6
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harakiri
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Lucas Allan Cardoso
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-15 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: harakiri is a simple gem for url shortening, using a tinyurl and googl service
23
+ email:
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/services/tiny.rb
32
+ - lib/services/googl.rb
33
+ - lib/harakiri.rb
34
+ - README.rdoc
35
+ - spec/harakiri_spec.rb
36
+ - spec/spec_helper.rb
37
+ - Rakefile
38
+ - harakiri.gemspec
39
+ has_rdoc: true
40
+ homepage:
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.7
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Harakiri Gem
73
+ test_files: []
74
+