Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 681817a2d7
Fetching contributors…

Cannot retrieve contributors at this time

file 69 lines (61 sloc) 2.172 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
module UrlShortener
  
  # All elements within doc are available as instance method calls.
  # such as; info_response_instance.htmlMetaDescription or info_response_instance.htmlTitle
  # if you don't like using camelised method names then you can use underscores like
  # info_response_instance.html_meta_description or info_response_instance.html_title and it should work fine
  #
  # e.g. xml response
  # <bitly>
  # <errorCode>0</errorCode>
  # <errorMessage/>
  # <results>
  # <doc>
  # <urlFetched>http://www.cnn.com/</urlFetched>
  # <shortenedByUser>bitly</shortenedByUser>
  # <keywords/>
  # <hash>31IqMl</hash>
  # <exif/>
  # <longUrl>http://cnn.com/</longUrl>
  # <htmlMetaDescription>
  # CNN.com delivers the latest breaking news and information on the latest top stories, weather, business, entertainment, politics, and more. For in-depth coverage, CNN.com provides special reports, video, audio, photo galleries, and interactive guides.
  # </htmlMetaDescription>
  # <indexed>1253643458</indexed>
  # <htmlTitle>
  # CNN.com - Breaking News, U.S., World, Weather, Entertainment &amp; Video News
  # </htmlTitle>
  # <htmlMetaKeywords>
  # <item>CNN</item>
  # <item>CNN news</item>
  # <item>CNN.com</item>
  # <item>CNN TV</item>
  # <item>news</item>
  # </htmlMetaKeywords>
  # <mirrorUrl/>
  # <keyword/>
  # <contentLegth>99195.0</contentLegth>
  # <fileExtension/>
  # </doc>
  # </results>
  # <statusCode>OK</statusCode>
  # </bitly>
  
  class Response::Info < UrlShortener::Response
    
    def initialize(response)
      super
    end
    
    # Just to override the hash method provided by hashie
    # that adds some other hash value
    def hash
      return unless doc_value?
      result['doc']['hash']
    end
    
    private
    
    def doc_value?
      return unless result['doc']
      return if result['doc'].empty?
      true
    end
    
    def base_element
      attributes.doc
    end
    
  end
end
Something went wrong with that request. Please try again.