look-bitly-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,8 @@
1
+ == 0.1.0 2009-07-07
2
+
3
+ * Covering all api methods
4
+
5
+
6
+ == 0.0.1 2009-07-05
7
+
8
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,12 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bitly-api.gemspec
6
+ lib/bitly-api.rb
7
+ lib/bitly-api/bitly-api.rb
8
+ script/console
9
+ script/destroy
10
+ script/generate
11
+ test/test_bitly-api.rb
12
+ test/test_helper.rb
data/README.rdoc ADDED
@@ -0,0 +1,43 @@
1
+ = bitly-api
2
+
3
+ * http://github.com/Hoodow/bitly-api
4
+
5
+ == DESCRIPTION:
6
+
7
+ Small library to access bitly api
8
+
9
+ == USAGE:
10
+
11
+ api = BitlyApi:Bitly(:login => BITLY_LOGIN, :api_key => BITLY_API_KEY)
12
+ api.shorten("http://pickhost.eu")
13
+ api.expand("zNgN6")
14
+
15
+ == INSTALL:
16
+
17
+ gem sources -a http://gems.github.com
18
+ gem install Hoodow-bitly-api
19
+
20
+ == LICENSE:
21
+
22
+ (The MIT License)
23
+
24
+ Copyright (c) 2009 Ole Riesenberg
25
+
26
+ Permission is hereby granted, free of charge, to any person obtaining
27
+ a copy of this software and associated documentation files (the
28
+ 'Software'), to deal in the Software without restriction, including
29
+ without limitation the rights to use, copy, modify, merge, publish,
30
+ distribute, sublicense, and/or sell copies of the Software, and to
31
+ permit persons to whom the Software is furnished to do so, subject to
32
+ the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be
35
+ included in all copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
38
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
39
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
40
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
41
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
42
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
43
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
2
+ %w[rake rake/clean fileutils newgem rubigen].each { |f| require f }
3
+ require File.dirname(__FILE__) + '/lib/bitly-api'
4
+
5
+ # Generate all the Rake tasks
6
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
7
+ $hoe = Hoe.new('bitly-api', BitlyApi::VERSION) do |p|
8
+ p.developer('Ole Riesenberg', 'or@oleriesenberg.com')
9
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
10
+ p.rubyforge_name = p.name # TODO this is default value
11
+ # p.extra_deps = [
12
+ # ['activesupport','>= 2.0.2'],
13
+ # ]
14
+ p.extra_dev_deps = [
15
+ ['newgem', ">= #{::Newgem::VERSION}"]
16
+ ]
17
+
18
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
19
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
20
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
+ p.rsync_args = '-av --delete --ignore-errors'
22
+ end
23
+
24
+ require 'newgem/tasks' # load /tasks/*.rake
25
+ Dir['tasks/**/*.rake'].each { |t| load t }
26
+
27
+ # TODO - want other tests/tasks run by default? Add them to the list
28
+ # task :default => [:spec, :features]
data/bitly-api.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{bitly-api}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Ole Riesenberg"]
9
+ s.date = %q{2009-07-09}
10
+ s.description = %q{Small library to access bitly api}
11
+ s.email = ["or@oleriesenberg.com"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
13
+ s.files = ["History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "bitly-api.gemspec", "lib/bitly-api.rb", "lib/bitly-api/bitly-api.rb", "script/console", "script/destroy", "script/generate", "test/test_bitly-api.rb", "test/test_helper.rb"]
14
+ s.homepage = %q{http://github.com/Hoodow/bitly-api}
15
+ s.rdoc_options = ["--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{bitly-api}
18
+ s.rubygems_version = %q{1.3.4}
19
+ s.summary = %q{Small library to access bitly api}
20
+ s.test_files = ["test/test_helper.rb", "test/test_bitly-api.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<newgem>, [">= 1.4.1"])
28
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
29
+ else
30
+ s.add_dependency(%q<newgem>, [">= 1.4.1"])
31
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<newgem>, [">= 1.4.1"])
35
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
36
+ end
37
+
38
+ s.add_dependency(%q<httpclient>, [">= 2.1.5.2"])
39
+ end
data/lib/bitly-api.rb ADDED
@@ -0,0 +1,11 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rubygems'
5
+ require 'httpclient'
6
+ require 'json'
7
+ require 'bitly-api/bitly-api'
8
+
9
+ module BitlyApi
10
+ VERSION = '0.1.0'
11
+ end
@@ -0,0 +1,60 @@
1
+ module BitlyApi
2
+ class BitlyError < StandardError
3
+ end
4
+
5
+ class Bitly
6
+ attr_accessor :login
7
+ attr_accessor :api_key
8
+ attr_accessor :api_version
9
+
10
+ def initialize(options = {})
11
+ raise ArgumentError.new(":login and :api_key are required") if (options[:login].nil? or options[:api_key].nil?)
12
+ options[:version] = "2.0.1" if options[:version].nil?
13
+
14
+ self.login = options[:login]
15
+ self.api_key = options[:api_key]
16
+ self.api_version = options[:version]
17
+ @httpclient = HTTPClient.new
18
+ end
19
+
20
+ def shorten(long_url)
21
+ http_response = @httpclient.get_content(build_url("shorten", "longUrl=#{long_url}"))
22
+ data = JSON.parse(http_response)
23
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
24
+ data["results"][long_url]
25
+ end
26
+
27
+ def expand(short_url)
28
+ http_response = @httpclient.get_content(build_url("expand", "shortUrl=#{short_url}"))
29
+ data = JSON.parse(http_response)
30
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
31
+ data["results"][short_url]
32
+ end
33
+
34
+ def info(short_url)
35
+ http_response = @httpclient.get_content(build_url("info", "shortUrl=#{short_url}"))
36
+ data = JSON.parse(http_response)
37
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
38
+ data["results"][short_url.split(/\//)[-1]]
39
+ end
40
+
41
+ def stats(short_url)
42
+ http_response = @httpclient.get_content(build_url("stats", "shortUrl=#{short_url}"))
43
+ data = JSON.parse(http_response)
44
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
45
+ data["results"]
46
+ end
47
+
48
+ def errors
49
+ http_response = @httpclient.get_content("http://api.bit.ly/errors?version=#{api_version}&login=#{login}&apiKey=#{api_key}")
50
+ data = JSON.parse(http_response)
51
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
52
+ data["results"]
53
+ end
54
+
55
+ private
56
+ def build_url(api_method, api_ressource)
57
+ "http://api.bit.ly/#{api_method}?version=#{api_version}&login=#{login}&apiKey=#{api_key}&#{api_ressource}"
58
+ end
59
+ end
60
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/bitly-api.rb'}"
9
+ puts "Loading bitly-api gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestBitlyApi < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/bitly-api'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: look-bitly-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ole Riesenberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-09 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newgem
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
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:
45
+ description: Small library to access bitly api
46
+ email:
47
+ - or@oleriesenberg.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - README.rdoc
56
+ files:
57
+ - History.txt
58
+ - Manifest.txt
59
+ - README.rdoc
60
+ - Rakefile
61
+ - bitly-api.gemspec
62
+ - lib/bitly-api.rb
63
+ - lib/bitly-api/bitly-api.rb
64
+ - script/console
65
+ - script/destroy
66
+ - script/generate
67
+ - test/test_bitly-api.rb
68
+ - test/test_helper.rb
69
+ has_rdoc: false
70
+ homepage: http://github.com/Hoodow/bitly-api
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --main
74
+ - README.rdoc
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project: bitly-api
92
+ rubygems_version: 1.2.0
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Small library to access bitly api
96
+ test_files:
97
+ - test/test_helper.rb
98
+ - test/test_bitly-api.rb