hackerdude-aws 2.3.25 → 2.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/aws.rb +1 -1
- data/lib/awsbase/support.rb +0 -34
- metadata +9 -15
- data/lib/alexa/alexa.rb +0 -239
- data/test/alexa/test_alexa.rb +0 -53
- data/test/alexa/test_helper.rb +0 -2
data/lib/aws.rb
CHANGED
data/lib/awsbase/support.rb
CHANGED
@@ -51,40 +51,6 @@ unless defined? ActiveSupport
|
|
51
51
|
constant
|
52
52
|
end
|
53
53
|
|
54
|
-
# By default, +camelize+ converts strings to UpperCamelCase. If the argument to +camelize+
|
55
|
-
# is set to <tt>:lower</tt> then +camelize+ produces lowerCamelCase.
|
56
|
-
#
|
57
|
-
# +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
|
58
|
-
#
|
59
|
-
# Examples:
|
60
|
-
# "active_record".camelize # => "ActiveRecord"
|
61
|
-
# "active_record".camelize(:lower) # => "activeRecord"
|
62
|
-
# "active_record/errors".camelize # => "ActiveRecord::Errors"
|
63
|
-
# "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
|
64
|
-
def camelize(lower_case_and_underscored_word=self, first_letter_in_uppercase = true)
|
65
|
-
if first_letter_in_uppercase
|
66
|
-
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
67
|
-
else
|
68
|
-
lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
|
73
|
-
#
|
74
|
-
# Changes '::' to '/' to convert namespaces to paths.
|
75
|
-
#
|
76
|
-
# Examples:
|
77
|
-
# "ActiveRecord".underscore # => "active_record"
|
78
|
-
# "ActiveRecord::Errors".underscore # => active_record/errors
|
79
|
-
def underscore
|
80
|
-
self.to_s.gsub(/::/, '/').
|
81
|
-
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
82
|
-
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
83
|
-
tr("-", "_").
|
84
|
-
downcase
|
85
|
-
end
|
86
|
-
|
87
|
-
|
88
54
|
end
|
89
55
|
|
90
56
|
|
metadata
CHANGED
@@ -1,24 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hackerdude-aws
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 55
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 2.3.
|
9
|
+
- 26
|
10
|
+
version: 2.3.26
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Reeder
|
14
14
|
- Chad Arimura
|
15
15
|
- RightScale
|
16
|
-
- David Martinez
|
17
16
|
autorequire:
|
18
17
|
bindir: bin
|
19
18
|
cert_chain: []
|
20
19
|
|
21
|
-
date: 2010-
|
20
|
+
date: 2010-12-13 00:00:00 -08:00
|
22
21
|
default_executable:
|
23
22
|
dependencies:
|
24
23
|
- !ruby/object:Gem::Dependency
|
@@ -77,7 +76,7 @@ dependencies:
|
|
77
76
|
version: "0"
|
78
77
|
type: :runtime
|
79
78
|
version_requirements: *id004
|
80
|
-
description: AWS Ruby Library for interfacing with Amazon Web Services.
|
79
|
+
description: AWS Ruby Library for interfacing with Amazon Web Services.
|
81
80
|
email: travis@appoxy.com
|
82
81
|
executables: []
|
83
82
|
|
@@ -87,7 +86,6 @@ extra_rdoc_files:
|
|
87
86
|
- README.markdown
|
88
87
|
files:
|
89
88
|
- lib/acf/right_acf_interface.rb
|
90
|
-
- lib/alexa/alexa.rb
|
91
89
|
- lib/aws.rb
|
92
90
|
- lib/awsbase/aws_response_array.rb
|
93
91
|
- lib/awsbase/benchmark_fix.rb
|
@@ -107,8 +105,6 @@ files:
|
|
107
105
|
- README.markdown
|
108
106
|
- test/acf/test_acf.rb
|
109
107
|
- test/acf/test_helper.rb
|
110
|
-
- test/alexa/test_alexa.rb
|
111
|
-
- test/alexa/test_helper.rb
|
112
108
|
- test/ec2/test_ec2.rb
|
113
109
|
- test/ec2/test_helper.rb
|
114
110
|
- test/ec2/test_mon.rb
|
@@ -126,12 +122,12 @@ files:
|
|
126
122
|
- test/test_credentials.rb
|
127
123
|
- test/ts_right_aws.rb
|
128
124
|
has_rdoc: true
|
129
|
-
homepage: http://github.com/
|
125
|
+
homepage: http://github.com/appoxy/aws/
|
130
126
|
licenses: []
|
131
127
|
|
132
128
|
post_install_message:
|
133
|
-
rdoc_options:
|
134
|
-
|
129
|
+
rdoc_options: []
|
130
|
+
|
135
131
|
require_paths:
|
136
132
|
- lib
|
137
133
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -158,12 +154,10 @@ rubyforge_project:
|
|
158
154
|
rubygems_version: 1.3.7
|
159
155
|
signing_key:
|
160
156
|
specification_version: 3
|
161
|
-
summary: AWS Ruby Library for interfacing with Amazon Web Services.
|
157
|
+
summary: AWS Ruby Library for interfacing with Amazon Web Services.
|
162
158
|
test_files:
|
163
159
|
- test/acf/test_acf.rb
|
164
160
|
- test/acf/test_helper.rb
|
165
|
-
- test/alexa/test_alexa.rb
|
166
|
-
- test/alexa/test_helper.rb
|
167
161
|
- test/ec2/test_ec2.rb
|
168
162
|
- test/ec2/test_helper.rb
|
169
163
|
- test/ec2/test_mon.rb
|
data/lib/alexa/alexa.rb
DELETED
@@ -1,239 +0,0 @@
|
|
1
|
-
module Aws
|
2
|
-
class Alexa
|
3
|
-
include AwsBaseInterface
|
4
|
-
DEFAULT_HOST = "awis.amazonaws.com"
|
5
|
-
DEFAULT_PATH = "/"
|
6
|
-
API_VERSION = "2005-07-11"
|
7
|
-
DEFAULT_PROTOCOL = 'http'
|
8
|
-
DEFAULT_PORT = 80
|
9
|
-
|
10
|
-
VALID_URLINFO_RESPONSE_GROUPS = [
|
11
|
-
:related_links,
|
12
|
-
:categories,
|
13
|
-
:rank,
|
14
|
-
:rank_by_country,
|
15
|
-
:rank_by_city,
|
16
|
-
:usage_stats,
|
17
|
-
:contact_info,
|
18
|
-
:adult_content,
|
19
|
-
:speed,
|
20
|
-
:language,
|
21
|
-
:keywords,
|
22
|
-
:owned_domains,
|
23
|
-
:links_in_count,
|
24
|
-
:site_data
|
25
|
-
]
|
26
|
-
# TODO - the docs mentions :popups on the meta groups, but it's not on the response group. Oversight? Check to see if that kind of info is being passed
|
27
|
-
|
28
|
-
VALID_CATEGORY_BROWSE_RESPONSE_GROUPS = [ :categories,
|
29
|
-
:related_categories,
|
30
|
-
:language_categories,
|
31
|
-
:letter_bars
|
32
|
-
]
|
33
|
-
|
34
|
-
META_GROUPS = {
|
35
|
-
:related=>[:related_links, :categories],
|
36
|
-
:traffic_data=>[:rank, :usage_stats],
|
37
|
-
:content_data=>[:site_data, :adult_content, :popups, :speed, :language]
|
38
|
-
}
|
39
|
-
@@bench = AwsBenchmarkingBlock.new
|
40
|
-
def self.bench_xml
|
41
|
-
@@bench.xml
|
42
|
-
end
|
43
|
-
def self.bench_ec2
|
44
|
-
@@bench.service
|
45
|
-
end
|
46
|
-
|
47
|
-
@@api = ENV['ALEXA_API_VERSION'] || API_VERSION
|
48
|
-
def initialize(aws_access_key_id=nil, aws_secret_access_key=nil, params={})
|
49
|
-
init({ :name => 'ALEXA',
|
50
|
-
:default_host => ENV['ALEXA_URL'] ? URI.parse(ENV['ALEXA_URL']).host : DEFAULT_HOST,
|
51
|
-
:default_port => ENV['ALEXA_URL'] ? URI.parse(ENV['ALEXA_URL']).port : DEFAULT_PORT,
|
52
|
-
:default_service => ENV['ALEXA_URL'] ? URI.parse(ENV['ALEXA_URL']).path : DEFAULT_PATH,
|
53
|
-
:default_protocol => ENV['ALEXA_URL'] ? URI.parse(ENV['ALEXA_URL']).scheme : DEFAULT_PROTOCOL,
|
54
|
-
:api_version => API_VERSION },
|
55
|
-
aws_access_key_id || ENV['AWS_ACCESS_KEY_ID'] ,
|
56
|
-
aws_secret_access_key|| ENV['AWS_SECRET_ACCESS_KEY'],
|
57
|
-
params)
|
58
|
-
# EC2 doesn't really define any transient errors to retry, and in fact,
|
59
|
-
# when they return a 503 it is usually for 'request limit exceeded' which
|
60
|
-
# we most certainly should not retry. So let's pare down the list of
|
61
|
-
# retryable errors to InternalError only (see AwsBase for the default
|
62
|
-
# list)
|
63
|
-
amazon_problems = ['InternalError']
|
64
|
-
end
|
65
|
-
|
66
|
-
def generate_request(action, params={}) #:nodoc:
|
67
|
-
service_hash = {"Action" => action,
|
68
|
-
"AWSAccessKeyId" => @aws_access_key_id,
|
69
|
-
"Version" => @@api }
|
70
|
-
service_hash.update(params)
|
71
|
-
service_params = signed_service_params(@aws_secret_access_key, service_hash, :get, @params[:server], @params[:service])
|
72
|
-
|
73
|
-
# use POST method if the length of the query string is too large
|
74
|
-
if service_params.size > 2000
|
75
|
-
if signature_version == '2'
|
76
|
-
# resign the request because HTTP verb is included into signature
|
77
|
-
service_params = signed_service_params(@aws_secret_access_key, service_hash, :post, @params[:server], @params[:service])
|
78
|
-
end
|
79
|
-
request = Net::HTTP::Post.new(@params[:service])
|
80
|
-
request.body = service_params
|
81
|
-
request['Content-Type'] = 'application/x-www-form-urlencoded'
|
82
|
-
else
|
83
|
-
request = Net::HTTP::Get.new("#{@params[:service]}?#{service_params}")
|
84
|
-
end
|
85
|
-
# prepare output hash
|
86
|
-
{ :request => request,
|
87
|
-
:server => @params[:server],
|
88
|
-
:port => @params[:port],
|
89
|
-
:protocol => @params[:protocol] }
|
90
|
-
end
|
91
|
-
|
92
|
-
def request_info(request, parser) #:nodoc:
|
93
|
-
thread = @params[:multi_thread] ? Thread.current : Thread.main
|
94
|
-
thread[:ec2_connection] ||= Rightscale::HttpConnection.new(:exception => AwsError, :logger => @logger)
|
95
|
-
request_info_impl(thread[:ec2_connection], @@bench, request, parser)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Quickly return the alexa URL info, (rank only)
|
99
|
-
#
|
100
|
-
# Example:
|
101
|
-
# alexa_rank("http://www.yahoo.com")[:rank][:text] # 4
|
102
|
-
def alexa_rank(url, params={}, cache_for = nil)
|
103
|
-
result = alexa_url_info(url, {:response_groups=>:rank})
|
104
|
-
return result[:url_info_response][:response][:url_info_result][:alexa][:traffic_data]
|
105
|
-
end
|
106
|
-
|
107
|
-
# Retrieves the Alexa URL info for a URL.
|
108
|
-
# By default it returns every response group.
|
109
|
-
# Override response_groups to set your own.
|
110
|
-
#
|
111
|
-
# Example:
|
112
|
-
# alexa_url_info("http://www.google.com")[:url_info_response]..
|
113
|
-
def alexa_url_info(url, opts={}, cache_for=nil, parser = QAlexaUrlInfoParser)
|
114
|
-
options = {:response_groups=>VALID_URLINFO_RESPONSE_GROUPS}.merge(opts)
|
115
|
-
request_hash = {}
|
116
|
-
request_hash['Url'] = url
|
117
|
-
request_hash['ResponseGroup'] = response_groups_to_param(options[:response_groups])
|
118
|
-
params.each do |key, val|
|
119
|
-
request_hash.merge! hash_params(key, (val.is_a?(Array) ? val : [val]))
|
120
|
-
end
|
121
|
-
link = generate_request('UrlInfo', request_hash)
|
122
|
-
request_cache_or_info(cache_for, link, parser, @@bench, cache_for)
|
123
|
-
rescue Exception
|
124
|
-
on_exception
|
125
|
-
end
|
126
|
-
|
127
|
-
# Returns a list of subcategories inside a category
|
128
|
-
#
|
129
|
-
def alexa_category_browse(path, opts={}, cache_for=nil, parser = QAlexaUrlInfoParser)
|
130
|
-
options = {:response_groups=>VALID_CATEGORY_BROWSE_RESPONSE_GROUPS}.merge(opts)
|
131
|
-
request_hash = {}
|
132
|
-
request_hash['Path'] = path
|
133
|
-
request_hash['ResponseGroup'] = response_groups_to_param(options[:response_groups])
|
134
|
-
params.each do |key, val|
|
135
|
-
request_hash.merge! hash_params(key, (val.is_a?(Array) ? val : [val]))
|
136
|
-
end
|
137
|
-
link = generate_request('CategoryBrowse', request_hash)
|
138
|
-
request_cache_or_info(cache_for, link, parser, @@bench, cache_for)
|
139
|
-
rescue Exception
|
140
|
-
on_exception
|
141
|
-
end
|
142
|
-
|
143
|
-
# Returns a list of category listings
|
144
|
-
def alexa_category_listings(path, cache_for=nil, parser = QAlexaUrlInfoParser)
|
145
|
-
request_hash = {}
|
146
|
-
request_hash['Path'] = path
|
147
|
-
request_hash['ResponseGroup'] = "Listings"
|
148
|
-
params.each do |key, val|
|
149
|
-
request_hash.merge! hash_params(key, (val.is_a?(Array) ? val : [val]))
|
150
|
-
end
|
151
|
-
link = generate_request('CategoryListings', request_hash)
|
152
|
-
request_cache_or_info(cache_for, link, parser, @@bench, cache_for)
|
153
|
-
rescue Exception
|
154
|
-
on_exception
|
155
|
-
end
|
156
|
-
|
157
|
-
def alexa_sites_linking_in(path, cache_for, parser = QAlexaUrlInfoParser)
|
158
|
-
request_hash = {}
|
159
|
-
request_hash['Path'] = path
|
160
|
-
request_hash['ResponseGroup'] = "SitesLinkingIn"
|
161
|
-
params.each do |key, val|
|
162
|
-
request_hash.merge! hash_params(key, (val.is_a?(Array) ? val : [val]))
|
163
|
-
end
|
164
|
-
link = generate_request('CategoryListings', request_hash)
|
165
|
-
request_cache_or_info(cache_for, link, parser, @@bench, cache_for)
|
166
|
-
rescue Exception
|
167
|
-
on_exception
|
168
|
-
end
|
169
|
-
|
170
|
-
def alexa_traffic_history
|
171
|
-
throw ArgumentError.new("Not Implemented. Sorry!")
|
172
|
-
end
|
173
|
-
|
174
|
-
private
|
175
|
-
|
176
|
-
def response_groups_to_param(groups)
|
177
|
-
actual_groups = groups.is_a?(Array) ? groups : [groups]
|
178
|
-
actual_groups.collect{|g| g.to_s.camelize }.join(",")
|
179
|
-
end
|
180
|
-
|
181
|
-
end
|
182
|
-
|
183
|
-
class QAlexaElementHash < Hash
|
184
|
-
attr_accessor :finalized
|
185
|
-
def last
|
186
|
-
self
|
187
|
-
end
|
188
|
-
def to_s
|
189
|
-
return has_key?(:text) ? self[:text] : super.to_s
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
class QAlexaUrlInfoParser < AwsParser
|
194
|
-
|
195
|
-
def initialize(args)
|
196
|
-
super(args)
|
197
|
-
@result = {}
|
198
|
-
end
|
199
|
-
|
200
|
-
def tagstart(name, attr)
|
201
|
-
item = current_item(name)
|
202
|
-
_attr = attr.dup
|
203
|
-
_attr.delete("xmlns:aws")
|
204
|
-
item.merge!(_attr)
|
205
|
-
end
|
206
|
-
|
207
|
-
def tagend(name)
|
208
|
-
element = current_item(name)
|
209
|
-
element[:text] = @text.strip
|
210
|
-
element.finalized = true
|
211
|
-
end
|
212
|
-
|
213
|
-
def current_item(name)
|
214
|
-
outer = @result
|
215
|
-
inner = nil
|
216
|
-
path_array = @xmlpath.split('/')
|
217
|
-
path_array << name
|
218
|
-
path_array.collect{|s| s.sub('aws:','')}.each{|_xpath_element|
|
219
|
-
name_sym = symbol_for(_xpath_element)
|
220
|
-
inner = outer[name_sym] || QAlexaElementHash.new
|
221
|
-
inner = inner.last # Sometimes we may get an array.
|
222
|
-
if inner.finalized
|
223
|
-
old_inner = inner
|
224
|
-
inner = QAlexaElementHash.new
|
225
|
-
outer[name_sym] = [old_inner, inner]
|
226
|
-
end
|
227
|
-
outer[name_sym] = inner if ! outer.has_key?(name_sym)
|
228
|
-
outer = inner
|
229
|
-
}
|
230
|
-
return inner.nil? ? outer : inner
|
231
|
-
end
|
232
|
-
|
233
|
-
def symbol_for(name)
|
234
|
-
sym_name = name.sub('aws:','').underscore.to_sym
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
end
|
data/test/alexa/test_alexa.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
require 'pp'
|
3
|
-
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
4
|
-
|
5
|
-
require 'ruby-debug'
|
6
|
-
Debugger.start
|
7
|
-
|
8
|
-
# Tests the Alexa AWS implementation
|
9
|
-
# Note this is very preliminary code. The code just spits back hashes
|
10
|
-
# and it has no concept of types just yet. The parser can
|
11
|
-
# be overriden on the calls if you need stronger types and must
|
12
|
-
# have something right away.
|
13
|
-
class TestAlexa < Test::Unit::TestCase
|
14
|
-
|
15
|
-
def setup
|
16
|
-
TestCredentials.get_credentials
|
17
|
-
@alexa = Aws::Alexa.new(TestCredentials.aws_access_key_id,
|
18
|
-
TestCredentials.aws_secret_access_key)
|
19
|
-
end
|
20
|
-
|
21
|
-
# Quick rank request
|
22
|
-
def test_rank
|
23
|
-
return
|
24
|
-
TestCredentials.get_credentials
|
25
|
-
rank = @alexa.alexa_rank("http://www.youtube.com")
|
26
|
-
assert ! rank.empty?
|
27
|
-
assert ! rank[:rank][:text].blank?
|
28
|
-
assert rank[:rank][:text].to_i > 0
|
29
|
-
assert ! rank[:data_url][:text].blank?
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_alexa_urlinfo
|
33
|
-
TestCredentials.get_credentials
|
34
|
-
result = @alexa.alexa_url_info("http://www.yahoo.com")
|
35
|
-
assert result[:url_info_response][:response][:url_info_result][:alexa][:contact_info][:company_stock_ticker][:text] == "YHOO"
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_alexa_category_browse
|
39
|
-
TestCredentials.get_credentials
|
40
|
-
category_browse = @alexa.alexa_category_browse("Top/Computers/Software/Operating_Systems")
|
41
|
-
assert ! category_browse.empty?
|
42
|
-
assert ! category_browse[:category_browse_response][:response][:category_browse_result][:alexa][:category_browse][:categories][:category].first[:path][:text].blank?
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_alexa_category_listings
|
47
|
-
TestCredentials.get_credentials
|
48
|
-
category_browse = @alexa.alexa_category_listings("Top/Computers/Software/Operating_Systems")
|
49
|
-
assert ! category_browse.empty?
|
50
|
-
assert category_browse[:category_listings_response][:response][:category_listings_result][:alexa][:category_listings][:listings][:listing].length > 0
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
data/test/alexa/test_helper.rb
DELETED