Class: Googl::Expand

Inherits:
Base show all
Includes:
Utils
Defined in:
lib/googl/expand.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(options = {}) ⇒ Expand

Expands a short URL or gets creation time and analytics. See Googl.expand


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/googl/expand.rb', line 11

def initialize(options={})

  options.delete_if {|key, value| value.nil?}

  resp = get(API_URL, :query => options)
  if resp.code == 200
    self.created    = resp['created'] if resp.has_key?('created')
    self.long_url   = resp['longUrl']
    self.analytics  = resp['analytics'].to_openstruct if resp.has_key?('analytics')
    self.status     = resp['status']
    self.short_url  = resp['id']
  else
    raise exception("#{resp.code} #{resp.message}")
  end
end

Instance Attribute Details

#analyticsObject

Returns the value of attribute analytics


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

def analytics
  @analytics
end

#createdObject

Returns the value of attribute created


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

def created
  @created
end

#long_urlObject

Returns the value of attribute long_url


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

def long_url
  @long_url
end

#short_urlObject

Returns the value of attribute short_url


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

def short_url
  @short_url
end

#statusObject

Returns the value of attribute status


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

def status
  @status
end