Class: BitlyOAuth::Url

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bitly_oauth/url.rb', line 7

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

  @referrers = options['referrers'].map{|referrer| BitlyOAuth::Referrer.new(referrer) } if options['referrers']
  @countries = options['countries'].map{|country| BitlyOAuth::Country.new(country) } if options['countries']

  if options['clicks'] && options['clicks'][0].is_a?(Hash)
    @clicks_by_day = options['clicks'].map{|day| BitlyOAuth::Day.new(day)}
  else
    @clicks_by_minute = options['clicks']
  end
end

Instance Attribute Details

#countries(options = {}) ⇒ Object (readonly)

If the url already has country data, return it. IF there is no country or :force => true is passed, updates the countries and returns them



90
91
92
# File 'lib/bitly_oauth/url.rb', line 90

def countries
  @countries
end

#global_hashObject (readonly)

Returns the value of attribute global_hash.



4
5
6
# File 'lib/bitly_oauth/url.rb', line 4

def global_hash
  @global_hash
end

#long_urlObject (readonly)

Returns the value of attribute long_url.



4
5
6
# File 'lib/bitly_oauth/url.rb', line 4

def long_url
  @long_url
end

#referrers(options = {}) ⇒ Object (readonly)

If the url already has referrer data, return it. IF there is no referrer or :force => true is passed, updates the referrers and returns them



69
70
71
# File 'lib/bitly_oauth/url.rb', line 69

def referrers
  @referrers
end

#short_urlObject (readonly)

Returns the value of attribute short_url.



4
5
6
# File 'lib/bitly_oauth/url.rb', line 4

def short_url
  @short_url
end

#user_hashObject (readonly)

Returns the value of attribute user_hash.



4
5
6
# File 'lib/bitly_oauth/url.rb', line 4

def user_hash
  @user_hash
end

Instance Method Details

#clicks_by_day(options = {}) ⇒ Object



106
107
108
109
110
111
112
# File 'lib/bitly_oauth/url.rb', line 106

def clicks_by_day(options={})
  if @clicks_by_day.nil? || options[:force]
    full_url = @client.clicks_by_day(@user_hash || @short_url)
    @clicks_by_day = full_url.clicks_by_day
  end
  @clicks_by_day
end

#clicks_by_minute(options = {}) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/bitly_oauth/url.rb', line 98

def clicks_by_minute(options={})
  if @clicks_by_minute.nil? || options[:force]
    full_url = @client.clicks_by_minute(@user_hash || @short_url)
    @clicks_by_minute = full_url.clicks_by_minute
  end
  @clicks_by_minute
end

#created_by(options = {}) ⇒ Object

If the url already has the creator, return it. IF there is no creator or :force => true is passed, updates the info and returns the creator



61
62
63
64
# File 'lib/bitly_oauth/url.rb', line 61

def created_by(options={})
  update_info if @created_by.nil? || options[:force]
  @created_by
end

#global_clicks(options = {}) ⇒ 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



45
46
47
48
# File 'lib/bitly_oauth/url.rb', line 45

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

#new_hash?Boolean

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

Returns:

  • (Boolean)


30
31
32
# File 'lib/bitly_oauth/url.rb', line 30

def new_hash?
  @new_hash
end

#referring_domains(options = {}) ⇒ Object

If the url already has referring_domains data, return it. IF there is no referring_domains or :force => true is passed, updates the referring_domains and returns them



80
81
82
83
84
85
# File 'lib/bitly_oauth/url.rb', line 80

def referring_domains(options={})
  if @referring_domains.nil? || options[:force]
    @referring_domains = @client.referring_domains(@short_url)
  end
  @referring_domains
end

#title(options = {}) ⇒ Object

If the url already has the title, return it. IF there is no title or :force => true is passed, updates the info and returns the title



53
54
55
56
# File 'lib/bitly_oauth/url.rb', line 53

def title(options={})
  update_info if @title.nil? || options[:force]
  @title
end

#user_clicks(options = {}) ⇒ 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



37
38
39
40
# File 'lib/bitly_oauth/url.rb', line 37

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