Class: Bitly::V3::Url

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

Overview

Url objects should only be created by the client object as it collects the correct information from the API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, opts = {}) ⇒ Url

Initialize with a bitly client and optional hash to fill in the details for the url.



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

def initialize(client, opts={})
  @client = client
  if opts
    @short_url = opts['url']
    @long_url = opts['long_url']
    @user_hash = opts['hash'] || opts['user_hash']
    @global_hash = opts['global_hash']
    @new_hash = (opts['new_hash'] == 1)
    @user_clicks = opts['user_clicks']
    @global_clicks = opts['global_clicks']
  end
  @short_url = "http://bit.ly/#{@user_hash}" unless @short_url
end

Instance Attribute Details

#global_hashObject (readonly)

Returns the value of attribute global_hash.



6
7
8
# File 'lib/bitly/v3/url.rb', line 6

def global_hash
  @global_hash
end

#long_urlObject (readonly)

Returns the value of attribute long_url.



6
7
8
# File 'lib/bitly/v3/url.rb', line 6

def long_url
  @long_url
end

#short_urlObject (readonly)

Returns the value of attribute short_url.



6
7
8
# File 'lib/bitly/v3/url.rb', line 6

def short_url
  @short_url
end

#user_hashObject (readonly)

Returns the value of attribute user_hash.



6
7
8
# File 'lib/bitly/v3/url.rb', line 6

def user_hash
  @user_hash
end

Instance Method Details

#global_clicks(opts = {}) ⇒ Object

If the url already has click statistics, returns the global clicks. IF there are no click statistics or :force => true is passed, updates the stats and returns the global clicks



39
40
41
42
# File 'lib/bitly/v3/url.rb', line 39

def global_clicks(opts={})
  update_clicks_data if @global_clicks.nil? || opts[:force]
  @global_clicks
end

#new_hash?Boolean

Returns true if the user hash was created first for this call

Returns:

  • (Boolean)


24
25
26
# File 'lib/bitly/v3/url.rb', line 24

def new_hash?
  @new_hash
end

#user_clicks(opts = {}) ⇒ Object

If the url already has click statistics, returns the user clicks. IF there are no click statistics or :force => true is passed, updates the stats and returns the user clicks



31
32
33
34
# File 'lib/bitly/v3/url.rb', line 31

def user_clicks(opts={})
  update_clicks_data if @global_clicks.nil? || opts[:force]
  @user_clicks
end