Class: Bitlyr::Client
- Inherits:
-
Object
- Object
- Bitlyr::Client
- Extended by:
- Forwardable
- Defined in:
- lib/bitlyr/client.rb
Overview
The client is the main part of this gem. You need to initialize the client with your username and API key and then you will be able to use the client to perform all the rest of the actions available through the API.
Instance Method Summary collapse
-
#bitly_pro_domain(domain) ⇒ Object
(also: #pro?)
Checks whether a domain is a Bitly Pro Domain.
-
#clicks(input) ⇒ Object
Expands either a hash, short url or array of either and gets click data too.
-
#clicks_by_day(input, options = {}) ⇒ Object
Takes a short url, hash or array of either and gets the clicks by day.
-
#clicks_by_minute(input) ⇒ Object
Takes a short url, hash or array of either and gets the clicks by minute of each of the last hour.
-
#countries(input) ⇒ Object
Expands either a short link or hash and gets the country data for that link.
-
#expand(input) ⇒ Object
Expands either a hash, short url or array of either.
-
#info(input) ⇒ Object
Like expand, but gets the title of the page and who created it.
-
#initialize(strategy) ⇒ Client
constructor
Requires a Bitlyr::Strategy.
-
#lookup(input) ⇒ Object
Looks up the short url and global hash of a url or array of urls.
-
#referrers(input) ⇒ Object
Expands either a short link or hash and gets the referrer data for that link.
- #referring_domains(link, options = {}) ⇒ Object
-
#shorten(long_url, options = {}) ⇒ Object
Shortens a long url.
Constructor Details
Instance Method Details
#bitly_pro_domain(domain) ⇒ Object Also known as: pro?
Checks whether a domain is a Bitly Pro Domain
19 20 21 22 |
# File 'lib/bitlyr/client.rb', line 19 def bitly_pro_domain(domain) response = get(:bitly_pro_domain, :domain => domain) return response['bitly_pro_domain'] end |
#clicks(input) ⇒ Object
Expands either a hash, short url or array of either and gets click data too.
Returns the results in the order they were entered
48 49 50 |
# File 'lib/bitlyr/client.rb', line 48 def clicks(input) get_method(:clicks, input) end |
#clicks_by_day(input, options = {}) ⇒ Object
Takes a short url, hash or array of either and gets the clicks by day
105 106 107 108 |
# File 'lib/bitlyr/client.rb', line 105 def clicks_by_day(input, ={}) .reject! { |k, v| k.to_s != 'days' } get_method(:clicks_by_day, input, ) end |
#clicks_by_minute(input) ⇒ Object
Takes a short url, hash or array of either and gets the clicks by minute of each of the last hour
100 101 102 |
# File 'lib/bitlyr/client.rb', line 100 def clicks_by_minute(input) get_method(:clicks_by_minute, input) end |
#countries(input) ⇒ Object
Expands either a short link or hash and gets the country data for that link
This method does not take an array as an input
95 96 97 |
# File 'lib/bitlyr/client.rb', line 95 def countries(input) get_single_method(:countries, input) end |
#expand(input) ⇒ Object
Expands either a hash, short url or array of either.
Returns the results in the order they were entered
41 42 43 |
# File 'lib/bitlyr/client.rb', line 41 def (input) get_method(:expand, input) end |
#info(input) ⇒ Object
Like expand, but gets the title of the page and who created it
53 54 55 |
# File 'lib/bitlyr/client.rb', line 53 def info(input) get_method(:info, input) end |
#lookup(input) ⇒ Object
Looks up the short url and global hash of a url or array of urls
Returns the results in the order they were entered
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/bitlyr/client.rb', line 60 def lookup(input) input = input.to_a response = get(:lookup, :url => input) results = response['lookup'].inject([]) do |results, url| url['long_url'] = url.delete('url') if url['error'].nil? # builds the results array in the same order as the input results[input.index(url['long_url'])] = Bitlyr::Url.new(self, url) else results[input.index(url['long_url'])] = Bitlyr::MissingUrl.new(url) end # remove the key from the original array, in case the same hash/url was entered twice input[input.index(url['long_url'])] = nil results end return results.length > 1 ? results : results[0] end |
#referrers(input) ⇒ Object
Expands either a short link or hash and gets the referrer data for that link
This method does not take an array as an input
81 82 83 |
# File 'lib/bitlyr/client.rb', line 81 def referrers(input) get_single_method(:referrers, input) end |
#referring_domains(link, options = {}) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/bitlyr/client.rb', line 85 def referring_domains(link, ={}) response = get('link/referring_domains', {:link => link}.merge()) response['referring_domains'].map do |referring_domain| Bitlyr::ReferringDomain.new(referring_domain) end end |
#shorten(long_url, options = {}) ⇒ Object
Shortens a long url
Options can be:
- domain
-
choose bit.ly or j.mp (bit.ly is default)
- x_login and x_apiKey
-
add this link to another user’s history (both required)
33 34 35 36 |
# File 'lib/bitlyr/client.rb', line 33 def shorten(long_url, ={}) response = get(:shorten, { :longUrl => long_url }.merge()) return Bitlyr::Url.new(self, response) end |