simple_bitly 0.0.1
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.txt +18 -0
- data/Rakefile +2 -0
- data/lib/simple_bitly/version.rb +3 -0
- data/lib/simple_bitly.rb +47 -0
- data/simple_bitly.gemspec +21 -0
- metadata +74 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.txt
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Description:
|
2
|
+
|
3
|
+
A simple and lightweight wrapper for the Bitly API.
|
4
|
+
|
5
|
+
|
6
|
+
Installation:
|
7
|
+
|
8
|
+
[sudo] gem install simple_bitly
|
9
|
+
|
10
|
+
|
11
|
+
Usage:
|
12
|
+
|
13
|
+
bitly = SimpleBitly.new(USERNAME, API_KEY)
|
14
|
+
data = bitly.shorten('http://github.com')
|
15
|
+
|
16
|
+
data.short_url
|
17
|
+
data.long_url
|
18
|
+
data.hash
|
data/Rakefile
ADDED
data/lib/simple_bitly.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module SimpleBitly
|
5
|
+
|
6
|
+
def self.new(username, api_key)
|
7
|
+
SimpleBitly::Client.new(username, api_key)
|
8
|
+
end
|
9
|
+
|
10
|
+
class Client
|
11
|
+
|
12
|
+
def initialize(username, api_key)
|
13
|
+
@username, @api_key = username, api_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def shorten(long_url)
|
17
|
+
SimpleBitly::URL.new(@username, @api_key, long_url)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
class URL
|
23
|
+
|
24
|
+
attr_reader :short_url, :long_url, :hash
|
25
|
+
|
26
|
+
def initialize(username, api_key, long_url)
|
27
|
+
@username, @api_key, @long_url = username, api_key, long_url
|
28
|
+
shorten
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def shorten
|
34
|
+
url = "http://api.bitly.com/v3/shorten?login=#{@username}&apiKey=#{@api_key}&longUrl=#{@long_url}&format=json"
|
35
|
+
resp = JSON.parse(Net::HTTP.get(URI.parse(url)))
|
36
|
+
if resp['status_code'] == 200
|
37
|
+
data = resp['data']
|
38
|
+
@long_url = data['long_url']
|
39
|
+
@short_url = data['url']
|
40
|
+
@hash = data['hash']
|
41
|
+
else
|
42
|
+
raise "Error from bitly: #{resp['status_code']}, #{resp['status_txt']}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "simple_bitly/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "simple_bitly"
|
7
|
+
s.version = SimpleBitly::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Nizar Dhamani"]
|
10
|
+
s.email = ["nizar.dhamani@gmail.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{A lightweight wrapper for the bit.ly API}
|
13
|
+
s.description = %q{lightweight bit.ly API wrapper}
|
14
|
+
|
15
|
+
s.rubyforge_project = "simple_bitly"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_bitly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nizar Dhamani
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-07 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: lightweight bit.ly API wrapper
|
23
|
+
email:
|
24
|
+
- nizar.dhamani@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- lib/simple_bitly.rb
|
37
|
+
- lib/simple_bitly/version.rb
|
38
|
+
- simple_bitly.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: simple_bitly
|
69
|
+
rubygems_version: 1.3.7
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: A lightweight wrapper for the bit.ly API
|
73
|
+
test_files: []
|
74
|
+
|