Class: Googl::Shorten

Inherits:
Base show all
Includes:
Utils
Defined in:
lib/googl/shorten.rb

Constant Summary

Constants included from Utils

Utils::API_CLIENT_LOGIN_URL, Utils::API_HISTORY_URL, Utils::API_URL, Utils::SCOPE_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#info, #qr_code

Constructor Details

#initialize(long_url) ⇒ Shorten

Creates a new short URL, see Googl.shorten



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/googl/shorten.rb', line 11

def initialize(long_url)
  modify_headers('Content-Type' => 'application/json')
  options = {"longUrl" => long_url}.to_json
  resp = post(API_URL, :body => options)
  if resp.code == 200
    self.short_url  = resp['id']
    self.long_url   = resp['longUrl']
  else
    raise exception(resp.parsed_response)
  end
end

Instance Attribute Details

#long_urlObject

Returns the value of attribute long_url.



7
8
9
# File 'lib/googl/shorten.rb', line 7

def long_url
  @long_url
end

#short_urlObject

Returns the value of attribute short_url.



7
8
9
# File 'lib/googl/shorten.rb', line 7

def short_url
  @short_url
end