lib/bitly/v3/url.rb in bitly-0.5.2 vs lib/bitly/v3/url.rb in bitly-0.5.3

- old
+ new

@@ -14,10 +14,12 @@ @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 # Returns true if the user hash was created first for this call @@ -38,16 +40,38 @@ # updates the stats and returns the global clicks def global_clicks(opts={}) update_clicks_data if @global_clicks.nil? || opts[:force] @global_clicks end + + # If the url already has the title, return it. + # IF there is no title or <tt>:force => true</tt> is passed, + # updates the info and returns the title + def title(opts={}) + update_info if @title.nil? || opts[:force] + @title + end + + # If the url already has the creator, return it. + # IF there is no creator or <tt>:force => true</tt> is passed, + # updates the info and returns the creator + def created_by(opts={}) + update_info if @created_by.nil? || opts[:force] + @created_by + end private def update_clicks_data full_url = @client.clicks(@user_hash || @short_url) @global_clicks = full_url.global_clicks @user_clicks = full_url.user_clicks + end + + def update_info + full_url = @client.info(@user_hash || @short_url) + @created_by = full_url.created_by + @title = full_url.title end end end end \ No newline at end of file