@@ -18,10 +18,13 @@ module Polly
18
18
#
19
19
class Presigner
20
20
21
- # @option options [required, Credentials] :credentials
22
- # You need provide an object that responds to `#credentials`
23
- # returning another object that responds to `#access_key_id`, `#secret_access_key`,
24
- # and `#session_token`.
21
+ # @option options [Client] :client Optionally provide an existing Polly
22
+ # client.
23
+ #
24
+ # @option options [Credentials] :credentials This option is deprecated,
25
+ # please use :client instead. Provide an object that responds to
26
+ # `#credentials` that returns another object that responds to
27
+ # `#access_key_id`, `#secret_access_key`, and `#session_token`.
25
28
#
26
29
# For example, you could provide an instance of following classes:
27
30
# * `Aws::Credentials`
@@ -30,35 +33,42 @@ class Presigner
30
33
# * `Aws::AssumeRoleCredentials`
31
34
# * `Aws::ECSCredentials`
32
35
#
33
- # @option options [required, string] :region
34
- # The region name, e.g. 'us-west-2'
36
+ # @option options [String] :region This option is deprecated, please use
37
+ # :client instead. The region name, e.g. 'us-west-2'.
38
+ #
35
39
def initialize ( options = { } )
36
- @credentials = options . fetch ( :credentials )
37
- @region = options . fetch ( :region )
40
+ if !( options . keys - [ :credentials , :region , :client ] ) . empty?
41
+ raise ArgumentError ,
42
+ ':options may only contain :client, :region, :credentials ' \
43
+ 'keys. Please use the :client option instead.'
44
+ end
45
+ @client = options [ :client ] || Aws ::Polly ::Client . new ( options )
38
46
end
39
47
40
- # @param [Hash] params parameter inputs for synthesize_speech operation
48
+ # @param [Hash] params Parameter inputs for {Client#synthesize_speech}
49
+ # operation.
41
50
def synthesize_speech_presigned_url ( params = { } )
42
- input_shape = Client . api . operation ( :synthesize_speech ) . input . shape
43
- sign_but_dont_send ( input_shape , params )
44
- end
51
+ req = @client . build_request ( :synthesize_speech , params )
45
52
46
- private
47
-
48
- def sign_but_dont_send ( input_shape , params )
49
53
parts = [ ]
50
- input_shape . members . each do |name , ref |
54
+ req . context . operation . input . shape . members . each do |name , ref |
51
55
parts << [ ref , params [ name ] ] unless params [ name ] . nil?
52
56
end
53
57
query = Aws ::Rest ::Request ::QuerystringBuilder . new . build ( parts )
54
58
55
59
signer = Aws ::Sigv4 ::Signer . new (
56
60
service : 'polly' ,
57
- region : @region ,
58
- credentials_provider : @credentials
61
+ region : req . context . config . region ,
62
+ credentials_provider : req . context . config . credentials
63
+ )
64
+
65
+ url = Aws ::Partitions ::EndpointProvider . resolve (
66
+ signer . region , 'polly' , 'regional' ,
67
+ {
68
+ dualstack : req . context . config . use_dualstack_endpoint ,
69
+ fips : req . context . config . use_fips_endpoint
70
+ }
59
71
)
60
- # TODO - use context so that dualstack can be used
61
- url = Aws ::Partitions ::EndpointProvider . resolve ( signer . region , 'polly' )
62
72
url += "/v1/speech?#{ query } "
63
73
pre_signed_url = signer . presign_url (
64
74
http_method : 'GET' ,
0 commit comments