bitly-api 0.1.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.
@@ -0,0 +1,14 @@
1
+ == 0.1.1 2009-07-21 (by Luke Francl)
2
+
3
+ * Use HTTPClient instead of Net::HTTP
4
+ * make sure long_url is CGI escaped before submitting it to Bit.ly
5
+
6
+
7
+ == 0.1.0 2009-07-07
8
+
9
+ * Covering all api methods
10
+
11
+
12
+ == 0.0.1 2009-07-05
13
+
14
+ * Initial release
@@ -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
@@ -0,0 +1,47 @@
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
+ == CONTRIBUTORS:
21
+
22
+ * Luke Francl ( http://github.com/look )
23
+
24
+ == LICENSE:
25
+
26
+ (The MIT License)
27
+
28
+ Copyright (c) 2009 Ole Riesenberg
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining
31
+ a copy of this software and associated documentation files (the
32
+ 'Software'), to deal in the Software without restriction, including
33
+ without limitation the rights to use, copy, modify, merge, publish,
34
+ distribute, sublicense, and/or sell copies of the Software, and to
35
+ permit persons to whom the Software is furnished to do so, subject to
36
+ the following conditions:
37
+
38
+ The above copyright notice and this permission notice shall be
39
+ included in all copies or substantial portions of the Software.
40
+
41
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
42
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
44
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
45
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
46
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
47
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -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]
@@ -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.1"
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
@@ -0,0 +1,12 @@
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 'cgi'
8
+ require 'bitly-api/bitly-api'
9
+
10
+ module BitlyApi
11
+ VERSION = '0.1.1'
12
+ end
@@ -0,0 +1,61 @@
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
+ # shorten +long_url+. +long_url+ is CGI escaped, so you shouldn't escape it yourself.
21
+ def shorten(long_url)
22
+ http_response = @httpclient.get_content(build_url("shorten", "longUrl=#{CGI::escape(long_url)}"))
23
+ data = JSON.parse(http_response)
24
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
25
+ data["results"][long_url]
26
+ end
27
+
28
+ def expand(short_url)
29
+ http_response = @httpclient.get_content(build_url("expand", "shortUrl=#{short_url}"))
30
+ data = JSON.parse(http_response)
31
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
32
+ data["results"][short_url]
33
+ end
34
+
35
+ def info(short_url)
36
+ http_response = @httpclient.get_content(build_url("info", "shortUrl=#{short_url}"))
37
+ data = JSON.parse(http_response)
38
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
39
+ data["results"][short_url.split(/\//)[-1]]
40
+ end
41
+
42
+ def stats(short_url)
43
+ http_response = @httpclient.get_content(build_url("stats", "shortUrl=#{short_url}"))
44
+ data = JSON.parse(http_response)
45
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
46
+ data["results"]
47
+ end
48
+
49
+ def errors
50
+ http_response = @httpclient.get_content("http://api.bit.ly/errors?version=#{api_version}&login=#{login}&apiKey=#{api_key}")
51
+ data = JSON.parse(http_response)
52
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
53
+ data["results"]
54
+ end
55
+
56
+ private
57
+ def build_url(api_method, api_ressource)
58
+ "http://api.bit.ly/#{api_method}?version=#{api_version}&login=#{login}&apiKey=#{api_key}&#{api_ressource}"
59
+ end
60
+ end
61
+ end
@@ -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"
@@ -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)
@@ -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,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitly-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ole Riesenberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2009-07-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: newgem
16
+ requirement: &7990840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.4.1
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *7990840
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ requirement: &7990340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.8.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *7990340
36
+ - !ruby/object:Gem::Dependency
37
+ name: httpclient
38
+ requirement: &7989840 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 2.1.5.2
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *7989840
47
+ description: Small library to access bitly api
48
+ email:
49
+ - or@oleriesenberg.com
50
+ executables: []
51
+ extensions: []
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
+ homepage: http://github.com/Hoodow/bitly-api
70
+ licenses: []
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
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project: bitly-api
91
+ rubygems_version: 1.8.5
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Small library to access bitly api
95
+ test_files:
96
+ - test/test_helper.rb
97
+ - test/test_bitly-api.rb