Class: Alexa::UrlInfo
- Inherits:
-
Object
- Object
- Alexa::UrlInfo
- Defined in:
- lib/alexa/url_info.rb,
lib/alexa/url_info/usage.rb,
lib/alexa/url_info/related.rb,
lib/alexa/url_info/categories.rb,
lib/alexa/url_info/contact_info.rb,
lib/alexa/url_info/content_data.rb,
lib/alexa/url_info/traffic_data.rb,
lib/alexa/url_info/contributing_subdomains.rb
Defined Under Namespace
Classes: ArgumentException, Categories, ContactInfo, ContentData, ContributingSubdomains, Related, TrafficData, Usage
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#contact_info ⇒ Object
readonly
Returns the value of attribute contact_info.
-
#content_data ⇒ Object
readonly
Returns the value of attribute content_data.
-
#contributing_subdomains ⇒ Object
readonly
Returns the value of attribute contributing_subdomains.
-
#related ⇒ Object
readonly
Returns the value of attribute related.
-
#traffic_data ⇒ Object
readonly
Returns the value of attribute traffic_data.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Class Method Summary collapse
Instance Method Summary collapse
- #fetch(options = {}) ⇒ Object
-
#initialize(data = { }) ⇒ UrlInfo
constructor
A new instance of UrlInfo.
- #signature ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(data = { }) ⇒ UrlInfo
Returns a new instance of UrlInfo.
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 |
# File 'lib/alexa/url_info.rb', line 19 def initialize(data = { }) @options = { 'Action' => 'UrlInfo', 'AWSAccessKeyId' => Alexa.config.access_key_id, 'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.000Z"), 'ResponseGroup' => 'RelatedLinks,Categories,Rank,RankByCountry,RankByCity,UsageStats,ContactInfo,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData', 'SignatureVersion' => 2, 'SignatureMethod' => 'HmacSHA256', 'Version' => '2005-07-11', 'Url' => nil, } if data['contact_info'] @contact_info = data['contact_info'] end if data['content_data'] @content_data = data['content_data'] end if data['related'] @related = data['related'] end if data['traffic_data'] @traffic_data = data['traffic_data'] end if data['usage'] @usage = data['usage'] end if data['contributing_subdomains'] @contributing_subdomains = data['contributing_subdomains'] end if data['categories'] @categories = data['categories'] end if Alexa.config.proxy RestClient.proxy = Alexa.config.proxy end end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
17 18 19 |
# File 'lib/alexa/url_info.rb', line 17 def categories @categories end |
#contact_info ⇒ Object (readonly)
Returns the value of attribute contact_info.
17 18 19 |
# File 'lib/alexa/url_info.rb', line 17 def contact_info @contact_info end |
#content_data ⇒ Object (readonly)
Returns the value of attribute content_data.
17 18 19 |
# File 'lib/alexa/url_info.rb', line 17 def content_data @content_data end |
#contributing_subdomains ⇒ Object (readonly)
Returns the value of attribute contributing_subdomains.
17 18 19 |
# File 'lib/alexa/url_info.rb', line 17 def contributing_subdomains @contributing_subdomains end |
#related ⇒ Object (readonly)
Returns the value of attribute related.
17 18 19 |
# File 'lib/alexa/url_info.rb', line 17 def @related end |
#traffic_data ⇒ Object (readonly)
Returns the value of attribute traffic_data.
17 18 19 |
# File 'lib/alexa/url_info.rb', line 17 def traffic_data @traffic_data end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
17 18 19 |
# File 'lib/alexa/url_info.rb', line 17 def usage @usage end |
Class Method Details
.from_mongo(value) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/alexa/url_info.rb', line 108 def self.from_mongo(value) return nil if value.nil? return value if value.is_a?(self) self.new( 'contact_info' => ContactInfo.from_mongo(value['contact_info']), 'content_data' => ContentData.from_mongo(value['content_data']), 'related' => Related.from_mongo(value['related']), 'categories' => Categories.from_mongo(value['categories']), 'traffic_data' => TrafficData.from_mongo(value['traffic_data']), 'usage' => Usage.from_mongo(value['usage']), 'contributing_subdomains' => ContributingSubdomains.from_mongo(value['contributing_subdomains']) ) end |
.to_mongo(value) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/alexa/url_info.rb', line 93 def self.to_mongo(value) return nil if value.nil? return value if value.is_a? Hash return { 'contact_info' => ContactInfo.to_mongo(value.contact_info), 'content_data' => ContentData.to_mongo(value.content_data), 'related' => Related.to_mongo(value.), 'categories' => Categories.to_mongo(value.categories), 'traffic_data' => TrafficData.to_mongo(value.traffic_data), 'usage' => Usage.to_mongo(value.usage), 'contributing_subdomains' => ContributingSubdomains.to_mongo(value.contributing_subdomains), } end |
Instance Method Details
#fetch(options = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/alexa/url_info.rb', line 74 def fetch( = {}) @options.merge!() @options.delete_if { |k,v| v.nil? } response = RestClient.get(url) data = Nokogiri::XML(response.to_s) data.remove_namespaces! @contact_info = ContactInfo.new(data.xpath('//ContactInfo').first) @content_data = ContentData.new(data.xpath('//ContentData').first) @related = Related.new(data.xpath('//Related').first) @categories = Categories.new(data.xpath('//Categories').first) @traffic_data = TrafficData.new(data.xpath('//TrafficData').first) @usage = Usage.new(data.xpath('//UsageStatistics').first) @contributing_subdomains = ContributingSubdomains.new(data.xpath('//ContributingSubdomains').first) self end |
#signature ⇒ Object
64 65 66 |
# File 'lib/alexa/url_info.rb', line 64 def signature Alexa.sign(@options) end |
#url ⇒ Object
68 69 70 71 72 |
# File 'lib/alexa/url_info.rb', line 68 def url qs = Alexa.query_string(@options) sign = signature 'http://' + ::Alexa::SERVICE_HOST + '/?' + qs + '&Signature=' + sign end |