Class: BitlyOAuth::User
- Inherits:
-
Object
- Object
- BitlyOAuth::User
- Defined in:
- lib/bitly_oauth/user.rb
Overview
A user requires a BitlyOAuth::AccessToken. The flow is as follows:
client = BitlyOAuth::Client.new(consumer_token, consumer_secret)
client.(redirect_url)
#=> "https://bitly.com/oauth/authorize?client_id=id&type=code&redirect_uri=http%3A%2F%2Ftest.local%2Fbitly-oauth%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:
token = o.get_access_token_from_code(params[:code], redirect_url)
#=> #<BitlyOAuth::AccessToken ...>
Then use that access token to create your user object.
user = BitlyOAuth::User.new(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.
21 22 23 |
# File 'lib/bitly_oauth/user.rb', line 21 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
62 63 64 65 |
# File 'lib/bitly_oauth/user.rb', line 62 def clicks(={}) get_clicks() @clicks end |
#client ⇒ Object
Returns a Bitly Client using the credentials of the user.
74 75 76 77 78 79 80 |
# File 'lib/bitly_oauth/user.rb', line 74 def client @client ||= begin client = BitlyOAuth::Client.new(@access_token.client.id, @access_token.client.secret) client.set_access_token_from_token(@access_token.token) client end 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
40 41 42 43 44 45 |
# File 'lib/bitly_oauth/user.rb', line 40 def countries(={}) if @countries.nil? || .delete(:force) @countries = get_method(:countries, BitlyOAuth::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
51 52 53 54 55 56 57 |
# File 'lib/bitly_oauth/user.rb', line 51 def realtime_links(={}) if @realtime_links.nil? || .delete(:force) result = get(:realtime_links, ) @realtime_links = result['realtime_links'].map { |rs| BitlyOAuth::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
29 30 31 32 33 34 |
# File 'lib/bitly_oauth/user.rb', line 29 def referrers(={}) if @referrers.nil? || .delete(:force) @referrers = get_method(:referrers, BitlyOAuth::Referrer, ) end @referrers end |
#total_clicks(options = {}) ⇒ Object
Displays the total clicks returned from the clicks method.
68 69 70 71 |
# File 'lib/bitly_oauth/user.rb', line 68 def total_clicks(={}) get_clicks() @total_clicks end |