Class: Bitly::Url

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/bitly/url.rb

Constant Summary collapse

VARIABLES =
['long_url', 'short_url', 'hash', 'user_hash', 'short_keyword_url']

Instance Method Summary collapse

Constructor Details

#initialize(login, api_key, obj = nil) ⇒ Url

Returns a new instance of Url.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/bitly/url.rb', line 8

def initialize(,api_key,obj=nil)
  unless obj.nil?
    
    raise BitlyError.new(obj['errorMessage'],obj['errorCode'],'expand') if obj['statusCode'] == "ERROR"
    
    instance_variablise(obj, VARIABLES)
    @info = obj[:info] if obj[:info]
    @stats = obj[:stats] if obj[:stats]
  end
  @login = 
  @api_key = api_key
end

Instance Method Details

#infoObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bitly/url.rb', line 21

def info
  if @info.nil?
    if @hash
      request = create_url "info", :hash => @hash
      result = get_result(request)[@hash]
      instance_variablise(result, VARIABLES)
      @info = result
    elsif @short_url
      hash = @short_url.gsub(/^.*bit.ly\//,'')
      request = create_url "info", :hash => hash
      result = get_result(request)[hash]
      instance_variablise(result, VARIABLES)
      @info = result
    else
      nil
    end
  else
    @info
  end
end

#statsObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bitly/url.rb', line 42

def stats
  if @stats.nil?
    if @hash
      request = create_url "stats", :hash => @hash
    elsif @short_url
      request = create_url "stats", :shortUrl => @short_url
    end
    @stats = get_result(request)
  else
    @stats
  end
end