Skip to content

Commit

Permalink
[ADD] bingo! initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bagwanpankaj committed Jan 14, 2011
1 parent c361f16 commit 529b9fe
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 26 deletions.
12 changes: 1 addition & 11 deletions Gemfile
@@ -1,13 +1,3 @@
source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"

# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "rspec", "~> 2.1.0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.1"
gem "rcov", ">= 0"
end
gem "httparty"
2 changes: 1 addition & 1 deletion LICENSE.txt
@@ -1,4 +1,4 @@
Copyright (c) 2011 bagwanpankaj
Copyright (c) 2011 Bagwan Pankaj

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
36 changes: 29 additions & 7 deletions README.rdoc → README.textile
@@ -1,8 +1,32 @@
= shortly
h1. Shortly

Description goes here.
A Ruby wrapper for various url shortener services

== Contributing to shortly
h2. Getting Started

create a dependency in your Gemfile

@gem 'shortly'@

then run

@bundle install@

and shortly will be up and running.

h2. Uses

Coming Shortly(or see the code)

h2. More Info

For detailed info visit my blog "http://BagwanPankaj.com":http://bagwanpankaj.com

For more info write me at bagwanpankaj[at]gmail.com or me[at]bagwanpankaj.com

Copyright (c) 2010 Bagwan Pankaj: http://bagwanpankaj.com, released under the MIT license

h2. Contributing to shortly

* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
Expand All @@ -12,8 +36,6 @@ Description goes here.
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

== Copyright

Copyright (c) 2011 bagwanpankaj. See LICENSE.txt for
further details.
h2. Copyright

Copyright (c) 2010 [Bagwan Pankaj]. See LICENSE.txt for further details.
11 changes: 4 additions & 7 deletions Rakefile
Expand Up @@ -15,14 +15,11 @@ Jeweler::Tasks.new do |gem|
gem.name = "shortly"
gem.homepage = "http://github.com/bagwanpankaj/shortly"
gem.license = "MIT"
gem.summary = %Q{TODO: one-line summary of your gem}
gem.description = %Q{TODO: longer description of your gem}
gem.summary = %Q{Url Shortner Services Ruby Wrapper}
gem.description = %Q{Ruby Wrapper for different Url Shortner Services Ruby Wrapper}
gem.email = "bagwanpankaj@gmail.com"
gem.authors = ["bagwanpankaj"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
# gem.add_development_dependency 'rspec', '> 1.2.3'
gem.authors = ["Bagwan Pankaj"]
gem.files = Dir.glob('lib/**/**/*.rb')
end
Jeweler::RubygemsDotOrgTasks.new

Expand Down
10 changes: 10 additions & 0 deletions lib/shortly.rb
@@ -0,0 +1,10 @@
require 'uri'
require 'ostruct'
require 'httparty'
require 'shortly'
require 'shortly/helper'
require 'shortly/errors'
require 'shortly/client'
require 'shortly/clients/bitly'
require 'shortly/clients/googl'
require 'shortly/clients/isgd'
51 changes: 51 additions & 0 deletions lib/shortly/client.rb
@@ -0,0 +1,51 @@
# Copyright (c) 2011 Bagwan Pankaj
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

module Shortly

class Client

include HTTParty
include Shortly::Errors
include Shortly::Helper

base_uri ''

def self.shorten(url, options ={})
raise MethodNotAvailableError.new("Sorry. This method is not available for given service.")
end

def self.expand(url, options ={})
raise MethodNotAvailableError.new("Sorry. This method is not available for given service.")
end

def self.validate(options = {})
raise MethodNotAvailableError.new("Sorry. This method is not available for given service.")
end

protected

def self.valid_uri?(url)
!!(url =~ URI::regexp)
end

end
end
62 changes: 62 additions & 0 deletions lib/shortly/clients/bitly.rb
@@ -0,0 +1,62 @@
# Copyright (c) 2011 Bagwan Pankaj
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

module Shortly

module Clients

class Bitly < Client

class << self
#apiKey = "<your apiKey>"
#login = "<your login>"
attr_accessor :login, :apiKey
end

base_uri 'api.bit.ly'

#shorts provided url by making call to bitly api with given options.
def self.shorten(url, options = {})
raise InvalidURIError.new("provided URI is invalid.") unless valid_uri?(url)
options = {:login => self.login, :apiKey => self.apiKey, :longUrl => url, :format => "json"}.merge(options)
response = get("/v3/shorten", {:query => options})
OpenStruct.new(response["data"])
end

#expands provided url by making call to bitly api with given options.
def self.expand(short_url, options ={})
raise InvalidURIError.new("provided URI is invalid.") unless valid_uri?(short_url)
options = {:login => self.login, :apiKey => self.apiKey, :shortUrl => short_url, :format => "json"}.merge(options)
response = get("/v3/expand", {:query => options})
OpenStruct.new(response["data"]["expand"].first)
end

#validates given login(as x_login) and apiKey (as x_api_key)
#options = {:x_login => xlogin, :x_api_key => x_api_key, :apiKey => apiKey, :login => login, :format => "json"}
def self.validate(options = {})
response = get("/v3/validate", {:query => options})
OpenStruct.new(response["data"])
end

end

end
end
41 changes: 41 additions & 0 deletions lib/shortly/clients/googl.rb
@@ -0,0 +1,41 @@
# Copyright (c) 2011 Bagwan Pankaj
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

module Shortly

module Clients

class Googl < Client

base_uri 'goo.gl'

#shorts provided url by making call to goo.gl api with given options.
def self.shorten(url, options = {})
raise InvalidURIError.new("provided URI is invalid.") unless valid_uri?(url)
response = post("/api/shorten", {:body => {:url => url}})
OpenStruct.new(response)
end

end

end

end
40 changes: 40 additions & 0 deletions lib/shortly/clients/isgd.rb
@@ -0,0 +1,40 @@
# Copyright (c) 2011 Bagwan Pankaj
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

module Shortly

module Clients

class Isgd < Client

base_uri 'is.gd'

#shorts provided url by making call to is.gd api with given options.
def self.shorten(url, options = {})
raise InvalidURIError.new("provided URI is invalid.") unless valid_uri?(url)
options = {:format => "json", :url => url}.merge(options)
response = get("/create.php", {:query => options})
OpenStruct.new(response)
end

end
end
end
37 changes: 37 additions & 0 deletions lib/shortly/clients/rubyurl.rb
@@ -0,0 +1,37 @@
# Copyright (c) 2011 Bagwan Pankaj
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

module Shortly

module Clients

class RubyUrl < Client

base_uri 'rubyurl.com'

def self.shorten(url)
post('/api/links.json', :query => { :link => { :website_url => url } })
end
end

end

end
40 changes: 40 additions & 0 deletions lib/shortly/errors.rb
@@ -0,0 +1,40 @@
# Copyright (c) 2011 Bagwan Pankaj
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

module Shortly

module Errors

class ShortlyError < StandardError

def initialize(msg)
super("ShortlyError - #{msg}")
end

end

class ShortlyArgumentError < ArgumentError; end
class InvalidURIError < ShortlyError; end
class NotAuthorizedError < ShortlyArgumentError; end
class MethodNotAvailableError < ShortlyError; end
end

end

0 comments on commit 529b9fe

Please sign in to comment.