Hoodow-bitly-api 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/README.rdoc +4 -0
- data/bitly-api.gemspec +3 -1
- data/lib/bitly-api.rb +3 -3
- data/lib/bitly-api/bitly-api.rb +8 -6
- metadata +11 -1
data/History.txt
CHANGED
data/README.rdoc
CHANGED
data/bitly-api.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{bitly-api}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ole Riesenberg"]
|
@@ -34,4 +34,6 @@ Gem::Specification.new do |s|
|
|
34
34
|
s.add_dependency(%q<newgem>, [">= 1.4.1"])
|
35
35
|
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
36
36
|
end
|
37
|
+
|
38
|
+
s.add_dependency(%q<httpclient>, [">= 2.1.5.2"])
|
37
39
|
end
|
data/lib/bitly-api.rb
CHANGED
@@ -2,11 +2,11 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
|
-
require '
|
6
|
-
require 'open-uri'
|
5
|
+
require 'httpclient'
|
7
6
|
require 'json'
|
7
|
+
require 'cgi'
|
8
8
|
require 'bitly-api/bitly-api'
|
9
9
|
|
10
10
|
module BitlyApi
|
11
|
-
VERSION = '0.1.
|
11
|
+
VERSION = '0.1.1'
|
12
12
|
end
|
data/lib/bitly-api/bitly-api.rb
CHANGED
@@ -5,7 +5,7 @@ module BitlyApi
|
|
5
5
|
class Bitly
|
6
6
|
attr_accessor :login
|
7
7
|
attr_accessor :api_key
|
8
|
-
attr_accessor :api_version
|
8
|
+
attr_accessor :api_version
|
9
9
|
|
10
10
|
def initialize(options = {})
|
11
11
|
raise ArgumentError.new(":login and :api_key are required") if (options[:login].nil? or options[:api_key].nil?)
|
@@ -14,38 +14,40 @@ module BitlyApi
|
|
14
14
|
self.login = options[:login]
|
15
15
|
self.api_key = options[:api_key]
|
16
16
|
self.api_version = options[:version]
|
17
|
+
@httpclient = HTTPClient.new
|
17
18
|
end
|
18
19
|
|
20
|
+
# shorten +long_url+. +long_url+ is CGI escaped, so you shouldn't escape it yourself.
|
19
21
|
def shorten(long_url)
|
20
|
-
http_response =
|
22
|
+
http_response = @httpclient.get_content(build_url("shorten", "longUrl=#{CGI::escape(long_url)}"))
|
21
23
|
data = JSON.parse(http_response)
|
22
24
|
raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
|
23
25
|
data["results"][long_url]
|
24
26
|
end
|
25
27
|
|
26
28
|
def expand(short_url)
|
27
|
-
http_response =
|
29
|
+
http_response = @httpclient.get_content(build_url("expand", "shortUrl=#{short_url}"))
|
28
30
|
data = JSON.parse(http_response)
|
29
31
|
raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
|
30
32
|
data["results"][short_url]
|
31
33
|
end
|
32
34
|
|
33
35
|
def info(short_url)
|
34
|
-
http_response =
|
36
|
+
http_response = @httpclient.get_content(build_url("info", "shortUrl=#{short_url}"))
|
35
37
|
data = JSON.parse(http_response)
|
36
38
|
raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
|
37
39
|
data["results"][short_url.split(/\//)[-1]]
|
38
40
|
end
|
39
41
|
|
40
42
|
def stats(short_url)
|
41
|
-
http_response =
|
43
|
+
http_response = @httpclient.get_content(build_url("stats", "shortUrl=#{short_url}"))
|
42
44
|
data = JSON.parse(http_response)
|
43
45
|
raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
|
44
46
|
data["results"]
|
45
47
|
end
|
46
48
|
|
47
49
|
def errors
|
48
|
-
http_response =
|
50
|
+
http_response = @httpclient.get_content("http://api.bit.ly/errors?version=#{api_version}&login=#{login}&apiKey=#{api_key}")
|
49
51
|
data = JSON.parse(http_response)
|
50
52
|
raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
|
51
53
|
data["results"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Hoodow-bitly-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ole Riesenberg
|
@@ -32,6 +32,16 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.8.0
|
34
34
|
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: httpclient
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.1.5.2
|
44
|
+
version:
|
35
45
|
description: Small library to access bitly api
|
36
46
|
email:
|
37
47
|
- or@oleriesenberg.com
|