Class: Bitlyr::User
- Inherits:
-
Object
- Object
- Bitlyr::User
- Defined in:
- lib/bitlyr/user.rb
Overview
A user requires an oauth access token. The flow is as follows:
o = Bitlyr::Strategy::OAuth.new(consumer_token, consumer_secret)
o.(redirect_url)
#=> "https://bit.ly/oauth/authorize?client_id=#{consumer_token}&type=web_server&redirect_uri=http%3A%2F%2Ftest.local%2Fbitlyr%2Fauth"
Redirect your users to this url, when they authorize your application they will be redirected to the url you provided with a code parameter. Use that parameter, and the exact same redirect url as follows:
o.get_access_token_from_code(params[:code], redirect_url)
#=> #<Bitlyr::AccessToken ...>
Then use that access token to create your user object.
u=Bitlyr::User.new(o.access_token)
Instance Method Summary collapse
-
#clicks(options = {}) ⇒ Object
OAuth 2 endpoint that provides the total clicks per day on a user’s bit.ly links.
-
#client ⇒ Object
Returns a Bitly Client using the credentials of the user.
-
#countries(options = {}) ⇒ Object
OAuth 2 endpoint that provides a list of countries from which clicks on a given user’s bit.ly links are originating, and the number of clicks per country.
-
#initialize(access_token) ⇒ User
constructor
A new instance of User.
-
#realtime_links(options = {}) ⇒ Object
OAuth 2 endpoint that provides a given user’s 100 most popular links based on click traffic in the past hour, and the number of clicks per link.
-
#referrers(options = {}) ⇒ Object
OAuth 2 endpoint that provides a list of top referrers (up to 500 per day) for a given user’s bit.ly links, and the number of clicks per referrer.
-
#total_clicks(options = {}) ⇒ Object
Displays the total clicks returned from the clicks method.
Constructor Details
#initialize(access_token) ⇒ User
Returns a new instance of User.
20 21 22 |
# File 'lib/bitlyr/user.rb', line 20 def initialize(access_token) @access_token = access_token end |
Instance Method Details
#clicks(options = {}) ⇒ Object
OAuth 2 endpoint that provides the total clicks per day on a user’s bit.ly links.
code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/user/clicks
61 62 63 64 |
# File 'lib/bitlyr/user.rb', line 61 def clicks(={}) get_clicks() @clicks end |
#client ⇒ Object
Returns a Bitly Client using the credentials of the user.
73 74 75 |
# File 'lib/bitlyr/user.rb', line 73 def client @client ||= Bitlyr::Client.new(@access_token) end |
#countries(options = {}) ⇒ Object
OAuth 2 endpoint that provides a list of countries from which clicks on a given user’s bit.ly links are originating, and the number of clicks per country.
code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/user/countries
39 40 41 42 43 44 |
# File 'lib/bitlyr/user.rb', line 39 def countries(={}) if @countries.nil? || .delete(:force) @countries = get_method(:countries, Bitlyr::Country, ) end @countries end |
#realtime_links(options = {}) ⇒ Object
OAuth 2 endpoint that provides a given user’s 100 most popular links based on click traffic in the past hour, and the number of clicks per link.
code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/user/realtime_links
50 51 52 53 54 55 56 |
# File 'lib/bitlyr/user.rb', line 50 def realtime_links(={}) if @realtime_links.nil? || .delete(:force) result = get(:realtime_links, ) @realtime_links = result['realtime_links'].map { |rs| Bitlyr::RealtimeLink.new(rs) } end @realtime_links end |
#referrers(options = {}) ⇒ Object
OAuth 2 endpoint that provides a list of top referrers (up to 500 per day) for a given user’s bit.ly links, and the number of clicks per referrer.
code.google.com/p/bitly-api/wiki/ApiDocumentation#/v3/user/referrers
28 29 30 31 32 33 |
# File 'lib/bitlyr/user.rb', line 28 def referrers(={}) if @referrers.nil? || .delete(:force) @referrers = get_method(:referrers, Bitlyr::Referrer, ) end @referrers end |
#total_clicks(options = {}) ⇒ Object
Displays the total clicks returned from the clicks method.
67 68 69 70 |
# File 'lib/bitlyr/user.rb', line 67 def total_clicks(={}) get_clicks() @total_clicks end |