Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jonstorer committed Aug 27, 2012
1 parent 309d63f commit 29b57a5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 41 deletions.
20 changes: 8 additions & 12 deletions lib/bitly-oauth/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand All @@ -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
24 changes: 0 additions & 24 deletions lib/bitly-oauth/url.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -81,19 +63,13 @@ 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)
end
@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)
Expand Down
4 changes: 0 additions & 4 deletions lib/bitly-oauth/user.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/9uX1TEinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"status_code": 200, "data": {"info": [{"global_hash": "18H1ET", "hash": "9uX1TE", "user_hash": "9uX1TE", "created_by": "philnash", "title": "A title"}]}, "status_txt": "OK"}
{"status_code": 200, "data": {"info": [{"global_hash": "18H1ET", "hash": "9uX1TE", "user_hash": "9uX1TE", "created_by": "philnash", "title": "A title"}]}, "status_txt": "OK"}

0 comments on commit 29b57a5

Please sign in to comment.