Class: GoogleAPIUrlShortener
- Inherits:
-
Object
- Object
- GoogleAPIUrlShortener
- Defined in:
- lib/google_api_url_shortener.rb,
lib/google_api_url_shortener/version.rb
Constant Summary collapse
- VERSION =
"1.0.2"
Instance Method Summary collapse
- #expand(short_url) ⇒ Object
-
#initialize(key) ⇒ GoogleAPIUrlShortener
constructor
A new instance of GoogleAPIUrlShortener.
- #result ⇒ Object
- #shorten(url) ⇒ Object
Constructor Details
#initialize(key) ⇒ GoogleAPIUrlShortener
Returns a new instance of GoogleAPIUrlShortener.
8 9 10 11 12 13 |
# File 'lib/google_api_url_shortener.rb', line 8 def initialize(key) @client = Google::APIClient.new @client.key = key @client. = nil @urlshortener = @client.discovered_api('urlshortener') end |
Instance Method Details
#expand(short_url) ⇒ Object
21 22 23 24 25 |
# File 'lib/google_api_url_shortener.rb', line 21 def (short_url) @result = @client.execute(:api_method => @urlshortener.url.get, :parameters => { 'shortUrl' => short_url }) body = JSON.parse(@result.body) body['longUrl'] end |
#result ⇒ Object
27 28 29 |
# File 'lib/google_api_url_shortener.rb', line 27 def result @result end |
#shorten(url) ⇒ Object
15 16 17 18 19 |
# File 'lib/google_api_url_shortener.rb', line 15 def shorten(url) @result = @client.execute(:api_method => @urlshortener.url.insert, :body_object => { 'longUrl' => url }) body = JSON.parse(@result.body) body['id'] end |