Class: Bitly::V3::Url
- Inherits:
-
Object
- Object
- Bitly::V3::Url
- 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
-
#aggregate_link ⇒ Object
readonly
Returns the value of attribute aggregate_link.
-
#global_hash ⇒ Object
readonly
Returns the value of attribute global_hash.
-
#long_url ⇒ Object
readonly
Returns the value of attribute long_url.
-
#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(opts = {}) ⇒ Object
- #clicks_by_minute(opts = {}) ⇒ Object
-
#countries(opts = {}) ⇒ Object
If the url already has country data, return it.
-
#created_at(opts = {}) ⇒ Object
If the url already has created at data, return it.
-
#created_by(opts = {}) ⇒ Object
If the url already has the creator, return it.
-
#global_clicks(opts = {}) ⇒ Object
If the url already has click statistics, returns the global clicks.
-
#initialize(client, opts = {}) ⇒ Url
constructor
Initialize with a bitly client and optional hash to fill in the details for the url.
- #jmp_url ⇒ Object
-
#new_hash? ⇒ Boolean
Returns true if the user hash was created first for this call.
-
#qrcode_url(opts = {}) ⇒ Object
QR code is automatically created and can be incorporated into mobile applications.
-
#referrers(opts = {}) ⇒ Object
If the url already has referrer data, return it.
-
#title(opts = {}) ⇒ Object
If the url already has the title, return it.
-
#user_clicks(opts = {}) ⇒ Object
If the url already has click statistics, returns the user clicks.
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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bitly/v3/url.rb', line 9 def initialize(client, opts={}) @client = client if opts @short_url = opts['url'] || opts['short_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'] @title = opts['title'] @created_by = opts['created_by'] @created_at = Time.at opts['created_at'] if opts['created_at'] @aggregate_link = opts['aggregate_link'] @referrers = opts['referrers'].inject([]) do |results, referrer| results << Bitly::V3::Referrer.new(referrer) end if opts['referrers'] @countries = opts['countries'].inject([]) do |results, country| results << Bitly::V3::Country.new(country) end if opts['countries'] if opts['clicks'] && opts['clicks'][0].is_a?(Hash) @clicks_by_day = opts['clicks'].inject([]) do |results, day| results << Bitly::V3::Day.new(day) end else @clicks_by_minute = opts['clicks'] end end @short_url = "http://bit.ly/#{@user_hash}" unless @short_url end |
Instance Attribute Details
#aggregate_link ⇒ Object (readonly)
Returns the value of attribute aggregate_link.
6 7 8 |
# File 'lib/bitly/v3/url.rb', line 6 def aggregate_link @aggregate_link end |
#global_hash ⇒ Object (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_url ⇒ Object (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_url ⇒ Object (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_hash ⇒ Object (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
#clicks_by_day(opts = {}) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/bitly/v3/url.rb', line 109 def clicks_by_day(opts={}) if @clicks_by_day.nil? || opts[: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(opts = {}) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/bitly/v3/url.rb', line 101 def clicks_by_minute(opts={}) if @clicks_by_minute.nil? || opts[:force] full_url = @client.clicks_by_minute(@user_hash || @short_url) @clicks_by_minute = full_url.clicks_by_minute end @clicks_by_minute end |
#countries(opts = {}) ⇒ Object
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
88 89 90 91 |
# File 'lib/bitly/v3/url.rb', line 88 def countries(opts={}) update_countries if @countries.nil? || opts[:force] @countries end |
#created_at(opts = {}) ⇒ Object
If the url already has created at data, return it. If there is no created at data or :force => true
is passed, updates the info and returns it
96 97 98 99 |
# File 'lib/bitly/v3/url.rb', line 96 def created_at(opts={}) update_info if @created_at.nil? || opts[:force] @created_at end |
#created_by(opts = {}) ⇒ 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
72 73 74 75 |
# File 'lib/bitly/v3/url.rb', line 72 def created_by(opts={}) update_info if @created_by.nil? || opts[:force] @created_by end |
#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
56 57 58 59 |
# File 'lib/bitly/v3/url.rb', line 56 def global_clicks(opts={}) update_clicks_data if @global_clicks.nil? || opts[:force] @global_clicks end |
#jmp_url ⇒ Object
117 118 119 |
# File 'lib/bitly/v3/url.rb', line 117 def jmp_url @short_url.nil? ? nil : @short_url.gsub(/bit\.ly/,'j.mp') end |
#new_hash? ⇒ Boolean
Returns true if the user hash was created first for this call
41 42 43 |
# File 'lib/bitly/v3/url.rb', line 41 def new_hash? @new_hash end |
#qrcode_url(opts = {}) ⇒ Object
QR code is automatically created and can be incorporated into mobile applications.
123 124 125 126 |
# File 'lib/bitly/v3/url.rb', line 123 def qrcode_url(opts={}) qrcode = opts.has_key?(:s) ? ".qrcode?s=#{opts[:s]}" : ".qrcode" @short_url + qrcode end |
#referrers(opts = {}) ⇒ Object
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
80 81 82 83 |
# File 'lib/bitly/v3/url.rb', line 80 def referrers(opts={}) update_referrers if @referrers.nil? || opts[:force] @referrers end |
#title(opts = {}) ⇒ 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
64 65 66 67 |
# File 'lib/bitly/v3/url.rb', line 64 def title(opts={}) update_info if @title.nil? || opts[:force] @title 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
48 49 50 51 |
# File 'lib/bitly/v3/url.rb', line 48 def user_clicks(opts={}) update_clicks_data if @global_clicks.nil? || opts[:force] @user_clicks end |