glasner-bitly 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jordan Glasner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,10 @@
1
+ = bitly
2
+
3
+ RestClient based wrapper of bit.ly API. Currently supports..
4
+
5
+ - shortening a url
6
+ - expanding a bit.ly url
7
+
8
+ == Copyright
9
+
10
+ Copyright (c) 2009 Jordan Glasner. See LICENSE for details.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 2
3
+ :major: 0
4
+ :minor: 1
data/lib/bitly.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+
3
+ require 'json'
4
+ require 'restclient'
5
+
6
+
7
+ bitly = File.dirname(__FILE__) + "/bitly"
8
+
9
+ require bitly + "/api"
10
+ require bitly + "/url"
11
+
data/lib/bitly/api.rb ADDED
@@ -0,0 +1,43 @@
1
+ module Bitly
2
+ module API
3
+
4
+ LOGIN = 'concerthash'
5
+ KEY = 'R_0fd8ec1ba81bee526dc9043f443eafb1'
6
+
7
+ VERSION = '2.0.1'
8
+
9
+ def self.get(action,query={})
10
+ response = RestClient.get path(action,query)
11
+ JSON.parse(response)['results']
12
+ end
13
+
14
+ def self.path(path,query)
15
+ query_string = query.inject('') { |string,array| string.concat("&#{array[0]}=#{array[1]}") }
16
+ "http://api.bit.ly/#{path}?version=#{VERSION}#{query_string}&login=#{LOGIN}&apiKey=#{KEY}"
17
+ end
18
+
19
+
20
+ #--------------------------------------------------------------------------
21
+ # Shorten a URL
22
+ #--------------------------------------------------------------------------
23
+
24
+ # returns Bitly::URL for given URL
25
+ # currently only works for one url at a time
26
+ def self.shorten(url)
27
+ get('shorten','longUrl' => url)[url]
28
+ end
29
+
30
+ #--------------------------------------------------------------------------
31
+ # Expand a Bitly::URL
32
+ #--------------------------------------------------------------------------
33
+
34
+ def self.expand(url)
35
+ bitly_hash = url.split('/').last
36
+ get('expand','shortUrl' => url)[bitly_hash]['longUrl']
37
+ end
38
+
39
+
40
+
41
+ end
42
+ end
43
+
data/lib/bitly/url.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Bitly
2
+ class URL
3
+
4
+ end
5
+
6
+ end
data/spec/api_spec.rb ADDED
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+
4
+ describe Bitly::API do
5
+
6
+ context "shorten" do
7
+
8
+ before do
9
+ @long = 'http://yahoo.com'
10
+ @hash = Bitly::API.shorten(@long)
11
+ @short = @hash['shortUrl']
12
+ end
13
+
14
+ it "should return a hash" do
15
+ @hash.should be_a(Hash)
16
+ end
17
+
18
+ it "shortUrl should be string in the format http://bit.ly/xxxxx" do
19
+ @short.scan(/http:\/\/bit\.ly\/\S{3,}/).should_not be_empty
20
+ end
21
+
22
+ it "shortUrl should redirect to original url" do
23
+ RestClient.get(@short).include?('Yahoo')
24
+ end
25
+
26
+
27
+ end
28
+
29
+ context "expand" do
30
+
31
+ before do
32
+ @long = 'http://yahoo.com/'
33
+ @short = 'http://bit.ly/pxr7s'
34
+ end
35
+
36
+ it "should return full URL as string when given http://bit.ly/xxxxx" do
37
+ @expanded = Bitly::API.expand(@short)
38
+ @expanded.should.eql?(@long)
39
+ end
40
+
41
+ end
42
+
43
+
44
+
45
+
46
+
47
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'bitly'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
data/spec/url_spec.rb ADDED
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Bitly::URL do
4
+
5
+ context "created from long url"
6
+
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glasner-bitly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Glasner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-12 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: jordan@digitalignition.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ files:
26
+ - README.rdoc
27
+ - VERSION.yml
28
+ - lib/bitly
29
+ - lib/bitly/api.rb
30
+ - lib/bitly/url.rb
31
+ - lib/bitly.rb
32
+ - spec/api_spec.rb
33
+ - spec/spec_helper.rb
34
+ - spec/url_spec.rb
35
+ - LICENSE
36
+ has_rdoc: true
37
+ homepage: http://github.com/glasner/bitly
38
+ post_install_message:
39
+ rdoc_options:
40
+ - --inline-source
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: TODO
63
+ test_files: []
64
+