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) ⇒ Shorten
constructor
Creates a new short URL, see Googl.shorten.
Methods inherited from Base
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') = {"longUrl" => long_url}.to_json resp = post(API_URL, :body => ) if resp.code == 200 self.short_url = resp['id'] self.long_url = resp['longUrl'] else raise exception(resp.parsed_response) end end |