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
-
#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.
-
#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 |
# File 'lib/bitly/v3/url.rb', line 9 def initialize(client, opts={}) @client = client if opts @short_url = opts['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'] 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
#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
39 40 41 42 |
# File 'lib/bitly/v3/url.rb', line 39 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
24 25 26 |
# File 'lib/bitly/v3/url.rb', line 24 def new_hash? @new_hash 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
31 32 33 34 |
# File 'lib/bitly/v3/url.rb', line 31 def user_clicks(opts={}) update_clicks_data if @global_clicks.nil? || opts[:force] @user_clicks end |