Class: BitlyOAuth::Url
- Inherits:
-
Object
- Object
- BitlyOAuth::Url
- Defined in:
- lib/bitly_oauth/url.rb
Instance Attribute Summary collapse
-
#countries(options = {}) ⇒ Object
readonly
If the url already has country data, return it.
-
#global_hash ⇒ Object
readonly
Returns the value of attribute global_hash.
-
#long_url ⇒ Object
readonly
Returns the value of attribute long_url.
-
#referrers(options = {}) ⇒ Object
readonly
If the url already has referrer data, return it.
-
#short_url ⇒ Object
readonly
Returns the value of attribute short_url.
-
#user_hash ⇒ Object
readonly
Returns the value of attribute user_hash.
Instance Method Summary collapse
- #clicks_by_day(options = {}) ⇒ Object
- #clicks_by_minute(options = {}) ⇒ Object
-
#created_by(options = {}) ⇒ Object
If the url already has the creator, return it.
-
#global_clicks(options = {}) ⇒ Object
If the url already has click statistics, returns the global clicks.
-
#initialize(client, options = {}) ⇒ Url
constructor
Initialize with a bitly client and optional hash to fill in the details for the url.
-
#new_hash? ⇒ Boolean
Returns true if the user hash was created first for this call.
-
#referring_domains(options = {}) ⇒ Object
If the url already has referring_domains data, return it.
-
#title(options = {}) ⇒ Object
If the url already has the title, return it.
-
#user_clicks(options = {}) ⇒ Object
If the url already has click statistics, returns the user clicks.
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, = {}) @client = client @title = ['title'] || '' if .key?('title') @new_hash = (['new_hash'] == 1) @long_url = ['long_url'] @user_hash = ['hash'] || ['user_hash'] @short_url = ['url'] || ['short_url'] || "http://bit.ly/#{@user_hash}" @created_by = ['created_by'] @global_hash = ['global_hash'] @user_clicks = ['user_clicks'] @global_clicks = ['global_clicks'] @referrers = ['referrers'].map{|referrer| BitlyOAuth::Referrer.new(referrer) } if ['referrers'] @countries = ['countries'].map{|country| BitlyOAuth::Country.new(country) } if ['countries'] if ['clicks'] && ['clicks'][0].is_a?(Hash) @clicks_by_day = ['clicks'].map{|day| BitlyOAuth::Day.new(day)} else @clicks_by_minute = ['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_hash ⇒ Object (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_url ⇒ Object (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_url ⇒ Object (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_hash ⇒ Object (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(={}) if @clicks_by_day.nil? || [: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(={}) if @clicks_by_minute.nil? || [: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(={}) update_info if @created_by.nil? || [: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(={}) update_clicks_data if @global_clicks.nil? || [:force] @global_clicks end |
#new_hash? ⇒ Boolean
Returns true if the user hash was created first for this call
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(={}) if @referring_domains.nil? || [: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(={}) update_info if @title.nil? || [: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(={}) update_clicks_data if @user_clicks.nil? || [:force] @user_clicks end |