Class: Googl::Shorten
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
-
#long_url ⇒ Object
Returns the value of attribute long_url.
-
#short_url ⇒ Object
Returns the value of attribute short_url.
Instance Method Summary collapse
-
#initialize(long_url, user_ip = nil, api_key = nil) ⇒ Shorten
constructor
Creates a new short URL, see Googl.shorten.
Methods inherited from Base
Constructor Details
#initialize(long_url, user_ip = nil, api_key = nil) ⇒ Shorten
Creates a new short URL, see Googl.shorten
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/googl/shorten.rb', line 11 def initialize(long_url, user_ip = nil, api_key = nil) modify_headers('Content-Type' => 'application/json') = {"longUrl" => long_url} shorten_url = API_URL if (user_ip != nil && !user_ip.empty?) ["userIp"] = user_ip end if (api_key != nil && !api_key.empty?) shorten_url += "?key=#{api_key}" end = .to_json resp = post(shorten_url, :body => ) if resp.code == 200 self.short_url = resp['id'] self.long_url = resp['longUrl'] else raise exception(resp.parsed_response) end end |