Class: Googlus::Expand
- Inherits:
-
Object
- Object
- Googlus::Expand
- Defined in:
- lib/googlus/expand.rb
Overview
Expands Google shorten URLs
Instance Attribute Summary collapse
-
#short_url ⇒ Object
readonly
Returns the value of attribute short_url.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url) ⇒ Expand
constructor
Short URL to expand.
Constructor Details
#initialize(url) ⇒ Expand
Short URL to expand
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/googlus/expand.rb', line 7 def initialize(url) http = Net::HTTP.new("www.googleapis.com", 443) http.use_ssl = true resp, body = http.get("/urlshortener/v1/url?shortUrl=#{url}") body = JSON.parse(body) if resp.code.to_i == 200 @short_url = body["id"] @url = body["longUrl"] @kind = body["kind"] @status = body["status"] else error = body["error"] raise "Expanding error: #{error["code"]} - #{error["message"]}" end end |
Instance Attribute Details
#short_url ⇒ Object (readonly)
Returns the value of attribute short_url.
4 5 6 |
# File 'lib/googlus/expand.rb', line 4 def short_url @short_url end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/googlus/expand.rb', line 4 def url @url end |