From 29b57a5008320d28e8cb4cff94f19c69caf2d3ff Mon Sep 17 00:00:00 2001 From: Jonathon Storer <jonathon.scott.storer@gmail.com> Date: Sun, 26 Aug 2012 22:56:48 -0400 Subject: [PATCH] small updates --- lib/bitly-oauth/client.rb | 20 ++++++++------------ lib/bitly-oauth/url.rb | 24 ------------------------ lib/bitly-oauth/user.rb | 4 ---- test/fixtures/9uX1TEinfo.json | 2 +- 4 files changed, 9 insertions(+), 41 deletions(-) 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..b52f635 100644 --- a/lib/bitly-oauth/url.rb +++ b/lib/bitly-oauth/url.rb @@ -1,9 +1,7 @@ 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 @new_hash = options['new_hash'] == 1 @@ -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 <tt>:force => true</tt> 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 <tt>:force => true</tt> 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 <tt>:force => true</tt> 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 <tt>:force => true</tt> 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 <tt>:force => true</tt> 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 <tt>:force => true</tt> 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 <tt>:force => true</tt> 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/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"}