Class: Alexa::SitesLinkingIn
- Inherits:
-
Object
- Object
- Alexa::SitesLinkingIn
show all
- Defined in:
- lib/alexa/sites_linking_in.rb,
lib/alexa/sites_linking_in/site.rb
Defined Under Namespace
Classes: ArgumentException, Site
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of SitesLinkingIn.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/alexa/sites_linking_in.rb', line 12
def initialize(data = { })
@options = {
'Action' => 'SitesLinkingIn',
'AWSAccessKeyId' => Alexa.config.access_key_id,
'Timestamp' => ( Time::now ).utc.strftime("%Y-%m-%dT%H:%M:%S.000Z"),
'ResponseGroup' => 'SitesLinkingIn',
'SignatureVersion' => 2,
'SignatureMethod' => 'HmacSHA256',
'Version' => '2005-07-11',
'Count' => nil,
'Start' => nil,
'Url' => nil,
}
if data['links']
@links = data['links']
end
if Alexa.config.proxy
RestClient.proxy = Alexa.config.proxy
end
end
|
Instance Attribute Details
#links ⇒ Object
Returns the value of attribute links.
10
11
12
|
# File 'lib/alexa/sites_linking_in.rb', line 10
def links
@links
end
|
Class Method Details
.from_mongo(value) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/alexa/sites_linking_in.rb', line 72
def self.from_mongo(value)
return nil if value.nil?
return value if value.is_a?(self)
links = []
value['links'].each do |l|
links << SitesLinkingIn::Site.from_mongo(l)
end
self.new('links' => links)
end
|
.to_mongo(value) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/alexa/sites_linking_in.rb', line 63
def self.to_mongo(value)
return nil if value.nil?
return value if value.is_a? Hash
return {
'links' => value.links.map { |l| SitesLinkingIn::Site.to_mongo(l) },
}
end
|
Instance Method Details
#fetch(options = {}) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/alexa/sites_linking_in.rb', line 44
def fetch(options = {})
@options.merge!(options)
@options.delete_if { |k,v| v.nil? }
raise ArgumentException.new('Url field is empty!') unless @options['Url']
response = RestClient.get(url)
data = Nokogiri::XML(response.to_s)
data.remove_namespaces!
@links = []
data.xpath('//SitesLinkingIn/Site').each do |s|
@links << ::Alexa::SitesLinkingIn::Site.new(s)
end
self
end
|
#signature ⇒ Object
35
36
37
|
# File 'lib/alexa/sites_linking_in.rb', line 35
def signature
Alexa.sign(@options)
end
|
#to_mongo ⇒ Object
84
85
86
|
# File 'lib/alexa/sites_linking_in.rb', line 84
def to_mongo
self.class.to_mongo(self)
end
|
#url ⇒ Object
39
40
41
42
|
# File 'lib/alexa/sites_linking_in.rb', line 39
def url
qs = Alexa.query_string(@options)
'http://' + ::Alexa::SERVICE_HOST + '/?' + qs + '&Signature=' + signature
end
|