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
-
#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
-
#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.
-
#new_hash? ⇒ Boolean
Returns true if the user hash was created first for this call.
-
#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 |
# 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'] end @short_url = "http://bit.ly/#{@user_hash}" unless @short_url end |
Instance Attribute Details
#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
#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
57 58 59 60 |
# File 'lib/bitly/v3/url.rb', line 57 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
41 42 43 44 |
# File 'lib/bitly/v3/url.rb', line 41 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
26 27 28 |
# File 'lib/bitly/v3/url.rb', line 26 def new_hash? @new_hash 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
49 50 51 52 |
# File 'lib/bitly/v3/url.rb', line 49 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
33 34 35 36 |
# File 'lib/bitly/v3/url.rb', line 33 def user_clicks(opts={}) update_clicks_data if @global_clicks.nil? || opts[:force] @user_clicks end |