diff --git a/Rakefile b/Rakefile index 2574288..a219fca 100644 --- a/Rakefile +++ b/Rakefile @@ -10,7 +10,7 @@ Rake::TestTask.new(:test) do |test| test.verbose = true end -require 'rake/rdoctask' +require 'rdoc/task' Rake::RDocTask.new do |rdoc| version = BitlyOAuth::VERSION diff --git a/lib/bitly-oauth/client.rb b/lib/bitly-oauth/client.rb index 5884fe3..86b3d91 100644 --- a/lib/bitly-oauth/client.rb +++ b/lib/bitly-oauth/client.rb @@ -76,6 +76,13 @@ def lookup(input) private + def get_single_method(method, input) + raise ArgumentError.new("This method only takes a hash or url input") unless input.is_a? String + + response = v3(method, key_for(input) => input.to_a) + BitlyOAuth::Url.new(self, response) + end + def get_method(method, input, options={}) options = ParamsHash[ options ] options.symbolize_keys! @@ -101,17 +108,6 @@ def get_method(method, input, options={}) results.length > 1 ? results : results[0] end - def get_single_method(method, input) - raise ArgumentError.new("This method only takes a hash or url input") unless input.is_a? String - - response = v3(method, key_for(input) => input.to_a) - BitlyOAuth::Url.new(self, response) - end - - def access_token - @access_token - end - def key_for(input) input.match(/^http:\/\//) ? :shortUrl : :hash end @@ -132,7 +128,7 @@ def get(path, params = {}) end def query(params) - { :query => ParamsHash[ { :access_token => access_token }.merge(params) ].to_query } + { :query => ParamsHash[ { :access_token => @access_token }.merge(params) ].to_query } end end end diff --git a/lib/bitly-oauth/url.rb b/lib/bitly-oauth/url.rb index 4417a6a..05c4262 100644 --- a/lib/bitly-oauth/url.rb +++ b/lib/bitly-oauth/url.rb @@ -1,20 +1,18 @@ module BitlyOAuth - class Url attr_reader :short_url, :long_url, :user_hash, :global_hash, :referrers, :countries - # Initialize with a bitly client and optional hash to fill in the details for the url. def initialize(client, options = {}) @client = client + @short_url = options['url'] || options['short_url'] || "http://bit.ly/#{@user_hash}" + @user_hash = options['hash'] || options['user_hash'] + @title = options['title'] @new_hash = options['new_hash'] == 1 @long_url = options['long_url'] @created_by = options['created_by'] @global_hash = options['global_hash'] @user_clicks = options['user_clicks'] @global_clicks = options['global_clicks'] - @title = options['title'] - @user_hash = options['hash'] || options['user_hash'] - @short_url = options['url'] || options['short_url'] || "http://bit.ly/#{@user_hash}" @referrers = options['referrers'].map do |referrer| BitlyOAuth::Referrer.new(referrer) @@ -33,46 +31,30 @@ def initialize(client, options = {}) end end - # Returns true if the user hash was created first for this call def new_hash? @new_hash end - # 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 def user_clicks(options={}) update_clicks_data if @user_clicks.nil? || options[:force] @user_clicks end - # 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 def global_clicks(options={}) update_clicks_data if @global_clicks.nil? || options[:force] @global_clicks end - # If the url already has the title, return it. - # IF there is no title or :force => true is passed, - # updates the info and returns the title def title(options={}) update_info if @title.nil? || options[:force] @title end - # If the url already has the creator, return it. - # IF there is no creator or :force => true is passed, - # updates the info and returns the creator def created_by(options={}) update_info if @created_by.nil? || options[:force] @created_by end - # If the url already has referrer data, return it. - # IF there is no referrer or :force => true is passed, - # updates the referrers and returns them def referrers(options={}) if @referrers.nil? || options[:force] full_url = @client.referrers(@user_hash || @short_url) @@ -81,9 +63,6 @@ def referrers(options={}) @referrers end - # If the url already has referring_domains data, return it. - # IF there is no referring_domains or :force => true is passed, - # updates the referring_domains and returns them def referring_domains(options={}) if @referring_domains.nil? || options[:force] @referring_domains = @client.referring_domains(@short_url) @@ -91,9 +70,6 @@ def referring_domains(options={}) @referring_domains end - # If the url already has country data, return it. - # IF there is no country or :force => true is passed, - # updates the countries and returns them def countries(options={}) if @countries.nil? || options[:force] full_url = @client.countries(@user_hash || @short_url) diff --git a/lib/bitly-oauth/user.rb b/lib/bitly-oauth/user.rb index 6a35bd7..2f37031 100644 --- a/lib/bitly-oauth/user.rb +++ b/lib/bitly-oauth/user.rb @@ -1,9 +1,5 @@ module BitlyOAuth - class User - include HTTParty - base_uri 'https://api-ssl.bit.ly/v3/' - def initialize(access_token) @access_token = access_token end diff --git a/lib/bitly_oauth.rb b/lib/bitly_oauth.rb deleted file mode 100644 index 11fffee..0000000 --- a/lib/bitly_oauth.rb +++ /dev/null @@ -1,2 +0,0 @@ -warn "[DEPRECATION] `bitly_oauth.rb' has been replaced with `bitly-oauth.rb` to match autoloading specs" -require 'bitly-oauth' diff --git a/test/fixtures/9uX1TEinfo.json b/test/fixtures/9uX1TEinfo.json index daf57fe..78e6583 100644 --- a/test/fixtures/9uX1TEinfo.json +++ b/test/fixtures/9uX1TEinfo.json @@ -1 +1 @@ -{"status_code": 200, "data": {"info": [{"global_hash": "18H1ET", "hash": "9uX1TE", "user_hash": "9uX1TE", "created_by": "philnash", "title": "A title"}]}, "status_txt": "OK"} \ No newline at end of file +{"status_code": 200, "data": {"info": [{"global_hash": "18H1ET", "hash": "9uX1TE", "user_hash": "9uX1TE", "created_by": "philnash", "title": "A title"}]}, "status_txt": "OK"} diff --git a/test/test_helper.rb b/test/test_helper.rb index 7a566dc..ef5b250 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) -require 'bitly_oauth' +require 'bitly-oauth' FakeWeb.allow_net_connect = false