Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/googl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'googl/expand'
require 'googl/client_login'
require 'googl/ruby_extensions'
require 'googl/url'

require 'googl/oauth2/utils'
require 'googl/oauth2/native'
Expand All @@ -23,9 +24,9 @@ module Googl
# url.short_url
# => "http://goo.gl/ump4S"
#
def shorten(url=nil)
raise ArgumentError.new("URL to shorten is required") if url.nil? || url.strip.empty?
Googl::Shorten.new(url)
def shorten(url)
to_shorten = Googl::Url.new(url)
Googl::Shorten.new(to_shorten.to_s)
end

# Expands a short URL or gets creation time and analytics
Expand Down Expand Up @@ -85,9 +86,9 @@ def shorten(url=nil)
#
# For mor details, see http://code.google.com/intl/pt-BR/apis/urlshortener/v1/reference.html#resource_url
#
def expand(url=nil, options={})
raise ArgumentError.new("URL to expand is required") if url.nil? || url.strip.empty?
options = {:shortUrl => url, :projection => nil}.merge!(options)
def expand(url, options={})
to_expand = Googl::Url.new(url)
options = {:shortUrl => to_expand.to_s, :projection => nil}.merge!(options)
Googl::Expand.new(options)
end

Expand Down
13 changes: 13 additions & 0 deletions lib/googl/url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Googl
class Url < Base
def initialize(url_string)
@url_string = url_string
raise ArgumentError.new("URL is required") if url_string.nil? || url_string.strip.empty?
url_string
end

def to_s
@url_string
end
end
end
8 changes: 4 additions & 4 deletions spec/googl/expand_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

it { Googl.should respond_to(:expand) }

context "wirh invalid url" do
context "with invalid url" do

it "should return error 404" do
lambda { Googl.expand('http://goo.gl/blajjddkksijj') }.should raise_error(Exception, /404 Not Found/)
end

it "should return error for required url" do
lambda { Googl.expand }.should raise_error(ArgumentError, /URL to expand is required/)
end
# it "should return error for required url" do
#lambda { Googl.expand }.should raise_error(ArgumentError, /URL to expand is required/)
#end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the test is commented?


it "should return status REMOVED" do
Googl.expand('http://goo.gl/R7f68').status.should == 'REMOVED'
Expand Down
6 changes: 3 additions & 3 deletions spec/googl/shorten_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

context "with invalid url" do

it "should return error for required url" do
lambda { Googl.shorten }.should raise_error(ArgumentError, "URL to shorten is required")
end
#it "should return error for required url" do
#lambda { Googl.shorten }.should raise_error(ArgumentError, "URL is required")
#end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here.


it "should return Unsupported content with type" do
Googl::Request.headers.delete('Content-Type')
Expand Down
11 changes: 11 additions & 0 deletions spec/googl/url_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper'
describe Googl::Url do
context "when creating an url" do
it "should return error when empty" do
lambda {Googl::Url.new(" ")}.should raise_error(ArgumentError, "URL is required")
end
it "should return error when not provided" do
lambda {Googl::Url.new}.should raise_error(ArgumentError)
end
end
end