ruby-aws 1.7.1 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/History.md +5 -0
  5. data/Manifest.txt +0 -28
  6. data/Rakefile +3 -4
  7. data/lib/ruby-aws.rb +2 -1
  8. data/lib/ruby-aws/version.rb +2 -2
  9. metadata +7 -49
  10. metadata.gz.sig +0 -0
  11. data/lib/amazon/util.rb +0 -10
  12. data/lib/amazon/util/binder.rb +0 -48
  13. data/lib/amazon/util/data_reader.rb +0 -169
  14. data/lib/amazon/util/filter_chain.rb +0 -79
  15. data/lib/amazon/util/hash_nesting.rb +0 -93
  16. data/lib/amazon/util/lazy_results.rb +0 -59
  17. data/lib/amazon/util/logging.rb +0 -23
  18. data/lib/amazon/util/paginated_iterator.rb +0 -70
  19. data/lib/amazon/util/proactive_results.rb +0 -116
  20. data/lib/amazon/util/threadpool.rb +0 -129
  21. data/lib/amazon/util/user_data_store.rb +0 -100
  22. data/lib/amazon/webservices/mechanical_turk.rb +0 -123
  23. data/lib/amazon/webservices/mechanical_turk_requester.rb +0 -285
  24. data/lib/amazon/webservices/mturk/mechanical_turk_error_handler.rb +0 -153
  25. data/lib/amazon/webservices/mturk/question_generator.rb +0 -58
  26. data/lib/amazon/webservices/util/amazon_authentication_relay.rb +0 -72
  27. data/lib/amazon/webservices/util/command_line.rb +0 -157
  28. data/lib/amazon/webservices/util/convenience_wrapper.rb +0 -90
  29. data/lib/amazon/webservices/util/filter_proxy.rb +0 -45
  30. data/lib/amazon/webservices/util/mock_transport.rb +0 -70
  31. data/lib/amazon/webservices/util/request_signer.rb +0 -42
  32. data/lib/amazon/webservices/util/rest_transport.rb +0 -120
  33. data/lib/amazon/webservices/util/soap_simplifier.rb +0 -48
  34. data/lib/amazon/webservices/util/soap_transport.rb +0 -20
  35. data/lib/amazon/webservices/util/soap_transport_header_handler.rb +0 -27
  36. data/lib/amazon/webservices/util/unknown_result_exception.rb +0 -27
  37. data/lib/amazon/webservices/util/validation_exception.rb +0 -55
  38. data/lib/amazon/webservices/util/xml_simplifier.rb +0 -61
@@ -1,153 +0,0 @@
1
- # Copyright:: Copyright (c) 2007-2014 Amazon Technologies, Inc.
2
- # License:: Apache License, Version 2.0
3
-
4
- require 'amazon/util/logging'
5
- require 'amazon/webservices/util/validation_exception'
6
- require 'amazon/webservices/util/unknown_result_exception'
7
-
8
- module Amazon
9
- module WebServices
10
- module MTurk
11
-
12
- class MechanicalTurkErrorHandler
13
- include Amazon::Util::Logging
14
-
15
- REQUIRED_PARAMETERS = [:Relay]
16
-
17
- # Commands with these prefixes can be retried if we are unsure of success
18
- RETRY_PRE = %w( search get register update disable assign set dispose )
19
-
20
- # Max number of times to retry a call
21
- MAX_RETRY = 6
22
-
23
- # Base used in Exponential Backoff retry delay
24
- BACKOFF_BASE = 2
25
- # Scale factor for Exponential Backoff retry delay
26
- BACKOFF_INITIAL = 0.1
27
-
28
- # Matching pattern to find a 'Results' element in the Response
29
- RESULT_PATTERN = /Result/
30
- # Additional elements to be considered a 'Result' despite not matching RESULT_PATTERN
31
- ACCEPTABLE_RESULTS = %w( HIT Qualification QualificationType QualificationRequest Information )
32
-
33
- def initialize( args )
34
- missing_parameters = REQUIRED_PARAMETERS - args.keys
35
- raise "Missing paramters: #{missing_parameters.join(',')}" unless missing_parameters.empty?
36
- @relay = args[:Relay]
37
- end
38
-
39
- def dispatch(method, *args)
40
- try = 0
41
- begin
42
- try += 1
43
- log "Dispatching call to #{method} (try #{try})"
44
- response = @relay.send(method,*args)
45
- validateResponse( response )
46
- return response
47
- rescue Exception => error
48
- case handleError( error,method,args )
49
- when :RetryWithBackoff
50
- retry if doBackoff( try )
51
- when :RetryImmediate
52
- retry if canRetry( try )
53
- when :Ignore
54
- return :IgnoredError => error
55
- when :Unknown
56
- raise Util::UnknownResultException.new( error, method, args )
57
- when :Fail
58
- raise error
59
- else
60
- raise "Unknown error handling method: #{handleError( error,method )}"
61
- end
62
- raise error
63
- end
64
- end
65
-
66
- def methodRetryable( method )
67
- RETRY_PRE.each do |pre|
68
- return true if method.to_s =~ /^#{pre}/i
69
- end
70
- return false
71
- end
72
-
73
- def handleError( error, method, args )
74
- log "Handling error: #{error.inspect}"
75
- idempotent = args.none? {|params| params[:UniqueRequestToken].nil? || params[:UniqueRequestToken].empty? }
76
- retryable = methodRetryable( method ) || idempotent
77
-
78
- case error.class.to_s
79
- when 'Timeout::Error','SOAP::HTTPStreamError','Errno::ECONNRESET','Errno::EPIPE'
80
- if retryable
81
- return :RetryImmediate
82
- else
83
- return :Unknown
84
- end
85
- when 'SOAP::FaultError'
86
- case error.faultcode.data
87
- when "aws:Server.ServiceUnavailable"
88
- return :RetryWithBackoff
89
- else
90
- return :Unknown
91
- end
92
- when 'Amazon::WebServices::Util::ValidationException'
93
- case error.message
94
- when 'AWS.ServiceUnavailable'
95
- return :RetryWithBackoff if retryable
96
- end
97
- return :Fail
98
- when 'RuntimeError'
99
- case error.message
100
- when 'Throttled'
101
- return :RetryWithBackoff
102
- else
103
- return :RetryImmediate
104
- end
105
- else
106
- return :Unknown
107
- end
108
- end
109
-
110
- def canRetry( try )
111
- try <= MAX_RETRY
112
- end
113
-
114
- def doBackoff( try )
115
- return false unless canRetry(try)
116
- delay = BACKOFF_INITIAL * ( BACKOFF_BASE ** try )
117
- sleep delay
118
- return true
119
- end
120
-
121
- def isResultTag( tag )
122
- tag.to_s =~ RESULT_PATTERN or ACCEPTABLE_RESULTS.include?( tag.to_s )
123
- end
124
-
125
- def validateResponse(response)
126
- log "Validating response: #{response.inspect}"
127
- if response[:Errors] and response[:Errors][:Error]
128
- if response[:Errors][:Error][:Code] == "ServiceUnavailable"
129
- raise 'Throttled'
130
- else
131
- raise Util::ValidationException.new(response)
132
- end
133
- end
134
- if response[:OperationRequest] and response[:OperationRequest][:Errors]
135
- raise Util::ValidationException.new(response)
136
- end
137
- resultTags = response.keys.find_all {|r| isResultTag( r ) }
138
- raise Util::ValidationException.new(response, "Didn't get back an acceptable result tag (got back #{response.keys.join(',')})") if resultTags.empty?
139
- resultTags.each do |resultTag|
140
- log "using result tag <#{resultTag}>"
141
- result = response[resultTag]
142
- if result[:Request] and result[:Request][:Errors]
143
- raise Util::ValidationException.new(result)
144
- end
145
- end
146
- response
147
- end
148
-
149
- end # MechanicalTurkErrorHandler
150
-
151
- end # Amazon::WebServices::MTurk
152
- end # Amazon::WebServices
153
- end # Amazon
@@ -1,58 +0,0 @@
1
- # Copyright:: Copyright (c) 2007 Amazon Technologies, Inc.
2
- # License:: Apache License, Version 2.0
3
-
4
- require 'rexml/element'
5
-
6
- module Amazon
7
- module WebServices
8
- module MTurk
9
-
10
- class QuestionGenerator
11
-
12
- def self.build(type=:Basic)
13
- question = self.new(type)
14
- yield question
15
- return question.to_xml
16
- end
17
-
18
- def initialize(type=:Basic)
19
- @overview = nil
20
- @questions = []
21
- @type = type
22
- end
23
-
24
- def ask(*args)
25
- case @type
26
- when :Basic
27
- askBasic( args.join )
28
- end
29
- end
30
-
31
- def askBasic(text)
32
- id = "BasicQuestion#{@questions.size+1}"
33
- question = REXML::Element.new 'Text'
34
- question.text = text
35
- answerSpec = "<FreeTextAnswer/>"
36
- @questions << { :Id => id, :Question => question.to_s, :AnswerSpec => answerSpec }
37
- end
38
-
39
- def to_xml
40
- components = [PREAMBLE]
41
- components << OVERVIEW % @overview unless @overview.nil?
42
- for question in @questions
43
- components << QUESTION % [ question[:Id], question[:Question], question[:AnswerSpec] ]
44
- end
45
- components << [TAIL]
46
- return components.join
47
- end
48
-
49
- PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>'+"\n"+'<QuestionForm xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd">'
50
- OVERVIEW = '<Overview>%s</Overview>'
51
- QUESTION = '<Question><QuestionIdentifier>%s</QuestionIdentifier><QuestionContent>%s</QuestionContent><AnswerSpecification>%s</AnswerSpecification></Question>'
52
- TAIL = '</QuestionForm>'
53
-
54
- end # QuestionGenerator
55
-
56
- end # Amazon::WebServices::MTurk
57
- end # Amazon::WebServices
58
- end # Amazon
@@ -1,72 +0,0 @@
1
- # Copyright:: Copyright (c) 2007 Amazon Technologies, Inc.
2
- # License:: Apache License, Version 2.0
3
-
4
- require 'amazon/webservices/util/command_line'
5
- require 'amazon/webservices/util/request_signer'
6
-
7
- module Amazon
8
- module WebServices
9
- module Util
10
-
11
- class AmazonAuthenticationRelay
12
-
13
- REQUIRED_PARAMETERS = [:Name,:Transport]
14
-
15
- def initialize( args )
16
- missing_parameters = REQUIRED_PARAMETERS - args.keys
17
- raise "Missing paramters: #{missing_parameters.join(',')}" unless missing_parameters.empty?
18
- @name = args[:Name]
19
- @transport = args[:Transport]
20
- @keyId, @key = findAuthInfo( args )
21
- end
22
-
23
- def withCredential(credential,method,*request)
24
- time = Time.now.gmtime.strftime('%Y-%m-%dT%H:%M:%S.123Z')
25
- request[0] ||= {}
26
- args = { :AWSAccessKeyId => @keyId,
27
- :Timestamp => time,
28
- :Signature => RequestSigner.sign(@name,method,time,@key),
29
- :Credential => credential,
30
- :Request => request }
31
- @transport.send( method, args )
32
- end
33
-
34
- def method_missing(method, *request)
35
- time = Time.now.gmtime.strftime('%Y-%m-%dT%H:%M:%S.321Z')
36
- request[0] ||= {}
37
- args = { :AWSAccessKeyId => @keyId,
38
- :Timestamp => time,
39
- :Signature => RequestSigner.sign(@name,method,time,@key),
40
- :Request => request }
41
- @transport.send( method, args )
42
- end
43
-
44
- def to_s
45
- "AmazonAuthenticationRelay[name:#{@name} transport:#{@transport}]>"
46
- end
47
-
48
- def inspect
49
- "#<Amazon::WebServices::Util::AmazonAuthenticationRelay:#{object_id} name:#{@name} transport:#{@transport.inspect}>"
50
- end
51
-
52
- private
53
-
54
- def findAuthInfo( args )
55
- if args.has_key? :AWSAccessKey or args.has_key? :AWSAccessKeyId
56
- # user tried to pass authentication information in, so just use that
57
- raise "Missing AWSAccessKeyId" if args[:AWSAccessKeyId].nil?
58
- raise "Missing AWSAccessKey" if args[:AWSAccessKey].nil?
59
- return args[:AWSAccessKeyId], args[:AWSAccessKey]
60
- else
61
- # didn't get passed in, so load from config or go interactive
62
- cmd = CommandLine.new
63
- cmd.checkAuthConfig
64
- return cmd.authId, cmd.authKey
65
- end
66
- end
67
-
68
- end # AmazonAuthenticationRelay
69
-
70
- end # Amazon::WebServices::Util
71
- end # Amazon::WebServices
72
- end # Amazon
@@ -1,157 +0,0 @@
1
- # Copyright:: Copyright (c) 2007 Amazon Technologies, Inc.
2
- # License:: Apache License, Version 2.0
3
-
4
- require 'optparse'
5
- require 'highline'
6
- require 'amazon/util/user_data_store'
7
-
8
- module Amazon
9
- module WebServices
10
- module Util
11
-
12
- class CommandLine
13
-
14
- SDKS = ['Mechanical Turk']
15
-
16
- MISSING_AUTH = "You are missing authentication information required to utilize Amazon Web Services. You will now be prompted for your <%= color('Access Key ID',BOLD) %> and your <%= color('Secret Access Key',BOLD) %>. If you do not have this information, please log into http://www.amazonaws.com/ \n\n"
17
- RESUME_AUTH = "Authentication information has been initialized. Continuing... \n\n"
18
-
19
- MAIN_HELP = <<EOF
20
-
21
- This is the <%= color('RubyAWS', RED, BOLD) %> Command Line Application's Interactive mode.
22
- You got here by typing:
23
-
24
- <%= color('$ ruby-aws',GREEN) %>
25
-
26
- This application currently supports the following functionality:
27
-
28
- <%= list( ['Amazon Web Services Authentication Configuration'] ) %>
29
- You can also invoke this tool with commandline parameters. For more information:
30
-
31
- <%= color('$ ruby-aws --help',GREEN) %>
32
-
33
- Thanks for using Amazon Web Services!
34
-
35
- EOF
36
-
37
- def initialize( interactive = true )
38
- @interactive = interactive
39
- @h = HighLine.new
40
- @h.wrap_at = :auto
41
- @store = Amazon::Util::UserDataStore.new :AWS
42
- HighLine.use_color = useColor?
43
- HighLine.track_eof = false # disabling because it misbehaves
44
- end
45
-
46
- def checkAuthConfig
47
- if @store.get(:Auth,:AccessKeyId).nil? or @store.get(:Auth,:SecretAccessKey).nil?
48
- @h.say MISSING_AUTH
49
- getAuthConfig
50
- @h.say RESUME_AUTH
51
- end
52
- end
53
-
54
- def getAuthConfig( default={} )
55
- id = @h.ask( 'What is your Access Key ID?' ) {|q| q.validate = /^[A-Z0-9]{20}$/ ; q.default = authId.to_s ; q.first_answer = default[:ID] }
56
- key = @h.ask( 'What is your Secret Access Key?' ) {|q| q.validate = /^[\w\/+]{40}$/ ; q.default = authKey.to_s ; q.first_answer = default[:Key] }
57
-
58
- @store.set(:Auth,:AccessKeyId,id)
59
- @store.set(:Auth,:SecretAccessKey,key)
60
-
61
- should_save = @h.agree( 'Would you like to save your authentication information?' )
62
- @store.save if should_save
63
- rescue
64
- raise "Unable to retrieve authentication information from the Console"
65
- end
66
-
67
- def authKey
68
- @store.get(:Auth,:SecretAccessKey)
69
- end
70
- def authId
71
- @store.get(:Auth,:AccessKeyId)
72
- end
73
-
74
- def useColor?
75
- if @store.get(:Misc,:ColorTerminal).nil?
76
- if @interactive and @h.agree( "Should the console application use color? (y/n)" )
77
- @store.set(:Misc,:ColorTerminal,true)
78
- else
79
- @store.set(:Misc,:ColorTerminal,false)
80
- end
81
- @store.save
82
- end
83
- return @store.get(:Misc,:ColorTerminal)
84
- end
85
-
86
- def toggleColor
87
- value = !useColor?
88
- @store.set(:Misc,:ColorTerminal,value)
89
- HighLine.use_color = value
90
- end
91
-
92
- def default_menu
93
- loop do
94
- @h.choose do |menu|
95
- menu.header = "\n" + @h.color('RubyAWS',HighLine::BOLD,HighLine::RED) + " " + @h.color('Command Line Application',HighLine::BOLD) + " " + @h.color('[Interactive Mode]',HighLine::GREEN,HighLine::BOLD)
96
- menu.select_by = :index
97
- menu.choice( 'Configure Amazon Web Services Authentication' ) do
98
- if @h.agree( "\nCurrent ID: #{@h.color(authId,HighLine::BOLD)}\nCurrent Key: #{@h.color(authKey,HighLine::BOLD)}\nDo you want to change?" )
99
- getAuthConfig
100
- end
101
- end
102
- menu.choice( 'Toggle Color' ) { toggleColor }
103
- menu.choice( :help ) do
104
- @h.say MAIN_HELP
105
- end
106
- menu.choice( 'Save and Quit' ) { @store.save ; exit }
107
- menu.prompt = "\nWhat would you like to do? "
108
- end
109
- end
110
- end
111
-
112
- def parseOptions
113
- res = {}
114
- opts = OptionParser.new
115
-
116
- opts.on( '-i', '--interactive', 'Load Interactive Mode' ) { res[:Interactive] = true }
117
- opts.on( '-a', '--authenticate', 'Configure Authentication Options' ) { res[:Auth] = true }
118
- opts.on( '--id=ID', 'Set Access Key ID (requires "-a")' ) { |id| res[:ID] = id }
119
- opts.on( '--key=KEY', 'Set Secret Access Key (requires "-a")' ) { |key| res[:Key] = key }
120
-
121
- begin
122
- opts.parse(ARGV)
123
- raise "-i and -a are exclusive options. Please pick one." if res[:Interactive] and res[:Auth]
124
- raise "--id requires -a" if res[:ID] and !res[:Auth]
125
- raise "--key requires -a" if res[:Key] and !res[:Auth]
126
- res[:Mode] = res[:Auth] ? :Auth : :Interactive
127
- rescue => e
128
- p e.message
129
- end
130
- res
131
- end
132
-
133
- def run
134
-
135
- opts = parseOptions
136
-
137
- case opts[:Mode]
138
- when :Interactive
139
-
140
- @h.say "\n<%= color('Welcome to',BOLD) %> <%= color('RubyAWS #{RubyAWS::VERSION}',BOLD,RED) %>"
141
- @h.say "This version includes SDK extensions for: <%= list (#{SDKS.inspect}.collect {|a| color(a,BOLD)}), :inline, ' and ' %>\n\n"
142
-
143
- checkAuthConfig
144
-
145
- default_menu
146
- when :Auth
147
-
148
- getAuthConfig( :Key => opts[:Key], :ID => opts[:ID] )
149
-
150
- end
151
- end
152
-
153
- end
154
-
155
- end # Amazon::WebServices::Util
156
- end # Amazon::WebServices
157
- end # Amazon::WebServices
@@ -1,90 +0,0 @@
1
- # Copyright:: Copyright (c) 2007 Amazon Technologies, Inc.
2
- # License:: Apache License, Version 2.0
3
-
4
- require 'amazon/util'
5
-
6
- module Amazon
7
- module WebServices
8
- module Util
9
-
10
- class ConvenienceWrapper
11
- include Amazon::Util::Logging
12
-
13
- REQUIRED_PARAMETERS = [:ServiceClass]
14
-
15
- def initialize(args)
16
- missing_parameters = REQUIRED_PARAMETERS - args.keys
17
- raise "Missing paramters: #{missing_parameters.join(',')}" unless missing_parameters.empty?
18
- @service = args[:ServiceClass].new( args )
19
- end
20
-
21
- def callService( method, *args )
22
- @service.send( method, *args )
23
- end
24
-
25
- def method_missing( method, *args )
26
- if @service.respond_to? method
27
- callService( method, *args )
28
- else
29
- callService( ConvenienceWrapper.real_method( method ), *args )
30
- end
31
- end
32
-
33
- def self.serviceCall( method, responseTag, defaultArgs={} )
34
- method = method.to_s
35
- name = ( method[0..0].downcase + method[1..-1] ).to_sym
36
- rawName = ( name.to_s + "Raw" ).to_sym
37
- method = real_method( method )
38
-
39
- raise 'Stop redifining service methods!' if self.instance_methods.include? name.to_s
40
-
41
- define_method( rawName ) do |args|
42
- log "Sending service request '#{name}' with args: #{args.inspect}"
43
- result = callService( method, args )
44
- return result[responseTag]
45
- end
46
-
47
- define_method( name ) do |*params|
48
- userArgs = params[0] || {}
49
- args = defaultArgs.merge( userArgs )
50
- self.send rawName, args
51
- end
52
- end
53
-
54
- def self.paginate( method, elementTag, pageSize=25 )
55
- method = method.to_s
56
- all_name = ( method[0..0].downcase + method[1..-1] + "All" ).to_sym
57
- iterator_name = ( method[0..0].downcase + method[1..-1] + "Iterator" ).to_sym
58
- proactive_name = ( method[0..0].downcase + method[1..-1] + "AllProactive" ).to_sym
59
- method = ( method[0..0].downcase + method[1..-1] ).to_sym
60
-
61
- raise 'Stop redifining service methods!' if self.instance_methods.include? name.to_s
62
-
63
- processors = { all_name => Amazon::Util::LazyResults,
64
- iterator_name => Amazon::Util::PaginatedIterator,
65
- proactive_name => Amazon::Util::ProactiveResults }
66
-
67
- processors.each do |name,processor|
68
- define_method( name ) do |*params|
69
- userArgs = params[0] || {}
70
- args = {:PageSize => pageSize}.merge( userArgs ) # allow user to override page size
71
- return processor.new do |pageNumber|
72
- pageArgs = args.merge({:PageNumber => pageNumber}) # don't allow override of page number
73
- res = self.send( method, pageArgs)[elementTag]
74
- res.nil? ? nil : [res].flatten
75
- end
76
- end
77
- end
78
-
79
- end
80
-
81
- def self.real_method( method )
82
- method = method.to_s
83
- method = ( method[0..0].upcase + method[1..-1] ).to_sym
84
- end
85
-
86
- end # ConvenienceWrapper
87
-
88
- end # Amazon::WebServices::Util
89
- end # Amazon::WebServices
90
- end # Amazon