lib/bitly/client.rb
# Looks up the short url and global hash of a url or array of urls
#
# Returns the results in the order they were entered
Looks up the short url and global hash of a url or array of urls
Returns the results in the order they were entered
Looks up the short url and global hash of a url or array of urls Returns the results in the order they were entered
def lookup(input)
      input = arrayize(input)
      query = input.inject([]) { |q, i| q << "url=#{CGI.escape(i)}" }
      query = "/lookup?" + query.join('&')
      response = get(query)
      results = response['data']['lookup'].inject([]) do |rs, url|
        url['long_url'] = url['url']
        url['url'] = nil
        if url['error'].nil?
          rs[input.index(url['long_url'])] = Bitly::Url.new(self, url)
          input[input.index(url['long_url'])] = nil
        else
          rs[input.index(url['long_url'])] = Bitly::MissingUrl.new(url)
          input[input.index(url['long_url'])] = nil
        end
        rs
      end
      return results.length > 1 ? results : results[0]
    end
def lookup ( input ) input = arrayize ( input ) query = input . inject ( [ ] ) { | q , i | q << "url=#{CGI.escape(i)}" } query = "/lookup?" + query . join ( '&' ) response = get ( query ) results = response [ 'data' ] [ 'lookup' ] . inject ( [ ] ) do | rs , url | url [ 'long_url' ] = url [ 'url' ] url [ 'url' ] = nil if url [ 'error' ] . nil? rs [ input . index ( url [ 'long_url' ] ) ] = Bitly :: Url . new ( self , url ) input [ input . index ( url [ 'long_url' ] ) ] = nil else rs [ input . index ( url [ 'long_url' ] ) ] = Bitly :: MissingUrl . new ( url ) input [ input . index ( url [ 'long_url' ] ) ] = nil end rs end return results . length > 1 ? results : results [ 0 ] end
Looks up the short url and global hash of a url or array of urls
Returns the results in the order they were entered
Looks up the short url and global hash of a url or array of urls Returns the results in the order they were entered
# builds the results array in the same order as the input # remove the key from the original array, in case the same hash/url was entered twice
input
<not_specific>