class GooglApi
Attributes
api_key[RW]
Public Class Methods
new(api_key)
click to toggle source
# File lib/goo-gl.rb, line 13 def initialize(api_key) self.api_key = api_key end
Public Instance Methods
shorten(long_url)
click to toggle source
# File lib/goo-gl.rb, line 17 def shorten(long_url) req = Net::HTTP::Post.new(URI('https://www.googleapis.com/urlshortener/v1/url') + "?key=#{self.api_key}") req.body = {longUrl: long_url}.to_json req.content_type = 'application/json' response = @@http.request(req).body JSON.parse(response)['id'] end