Hoodow-bitly-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2009-07-05
2
+
3
+ * 1 major enhancement:
4
+ * 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,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 FIXME full name
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.
@@ -0,0 +1,28 @@
1
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
2
+ %w[rake rake/clean fileutils hoe 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,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{bitly-api}
5
+ s.version = "0.0.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-05}
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
+ 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 'net/http'
6
+ require 'open-uri'
7
+ require 'json'
8
+ require 'bitly-api/bitly-api'
9
+
10
+ module BitlyApi
11
+ VERSION = '0.0.1'
12
+ end
@@ -0,0 +1,40 @@
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
+ end
18
+
19
+ def shorten(long_url)
20
+ http_response = open(build_url("shorten", "longUrl=#{long_url}")).read
21
+ data = JSON.parse(http_response)
22
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
23
+ results = data["results"][long_url]
24
+ results
25
+ end
26
+
27
+ def expand(short_url)
28
+ http_response = open(build_url("expand", "shortUrl=#{short_url}")).read
29
+ data = JSON.parse(http_response)
30
+ raise BitlyError.new(data["errorMessage"]) unless data["statusCode"] == "OK"
31
+ results = data["results"][short_url]
32
+ results
33
+ end
34
+
35
+ private
36
+ def build_url(api_method, api_ressource)
37
+ "http://api.bit.ly/#{api_method}?version=#{api_version}&login=#{login}&apiKey=#{api_key}&#{api_ressource}"
38
+ end
39
+ end
40
+ 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,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Hoodow-bitly-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ole Riesenberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-05 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
+ description: Small library to access bitly api
36
+ email:
37
+ - or@oleriesenberg.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - History.txt
44
+ - Manifest.txt
45
+ - README.rdoc
46
+ files:
47
+ - History.txt
48
+ - Manifest.txt
49
+ - README.rdoc
50
+ - Rakefile
51
+ - bitly-api.gemspec
52
+ - lib/bitly-api.rb
53
+ - lib/bitly-api/bitly-api.rb
54
+ - script/console
55
+ - script/destroy
56
+ - script/generate
57
+ - test/test_bitly-api.rb
58
+ - test/test_helper.rb
59
+ has_rdoc: false
60
+ homepage: http://github.com/Hoodow/bitly-api
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --main
64
+ - README.rdoc
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project: bitly-api
82
+ rubygems_version: 1.2.0
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Small library to access bitly api
86
+ test_files:
87
+ - test/test_helper.rb
88
+ - test/test_bitly-api.rb