Class: Bitlyr::Url
- Inherits:
-
Object
- Object
- Bitlyr::Url
- Defined in:
- lib/bitlyr/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
-
#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.
-
#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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bitlyr/url.rb', line 9 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| Bitlyr::Referrer.new(referrer) } if ['referrers'] @countries = ['countries'].map{|country| Bitlyr::Country.new(country) } if ['countries'] if ['clicks'] && ['clicks'][0].is_a?(Hash) @clicks_by_day = ['clicks'].map{|day| Bitlyr::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
79 80 81 |
# File 'lib/bitlyr/url.rb', line 79 def countries @countries end |
#global_hash ⇒ Object (readonly)
Returns the value of attribute global_hash.
6 7 8 |
# File 'lib/bitlyr/url.rb', line 6 def global_hash @global_hash end |
#long_url ⇒ Object (readonly)
Returns the value of attribute long_url.
6 7 8 |
# File 'lib/bitlyr/url.rb', line 6 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
71 72 73 |
# File 'lib/bitlyr/url.rb', line 71 def referrers @referrers end |
#short_url ⇒ Object (readonly)
Returns the value of attribute short_url.
6 7 8 |
# File 'lib/bitlyr/url.rb', line 6 def short_url @short_url end |
#user_hash ⇒ Object (readonly)
Returns the value of attribute user_hash.
6 7 8 |
# File 'lib/bitlyr/url.rb', line 6 def user_hash @user_hash end |
Instance Method Details
#clicks_by_day(options = {}) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/bitlyr/url.rb', line 92 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
84 85 86 87 88 89 90 |
# File 'lib/bitlyr/url.rb', line 84 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
63 64 65 66 |
# File 'lib/bitlyr/url.rb', line 63 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
47 48 49 50 |
# File 'lib/bitlyr/url.rb', line 47 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
32 33 34 |
# File 'lib/bitlyr/url.rb', line 32 def new_hash? @new_hash 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
55 56 57 58 |
# File 'lib/bitlyr/url.rb', line 55 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
39 40 41 42 |
# File 'lib/bitlyr/url.rb', line 39 def user_clicks(={}) update_clicks_data if @user_clicks.nil? || [:force] @user_clicks end |