s33r 0.4.2 → 0.5

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.
Files changed (114) hide show
  1. data/examples/cli/instant_download_server.rb +88 -0
  2. data/examples/cli/s3cli.rb +31 -52
  3. data/examples/cli/simple.rb +16 -6
  4. data/examples/fores33r/app/controllers/browser_controller.rb +12 -10
  5. data/examples/fores33r/app/helpers/application_helper.rb +2 -1
  6. data/examples/fores33r/app/views/browser/_upload.rhtml +1 -1
  7. data/examples/fores33r/app/views/browser/index.rhtml +4 -4
  8. data/examples/fores33r/config/environment.rb +5 -3
  9. data/examples/fores33r/log/development.log +2259 -0
  10. data/examples/fores33r/log/mongrel.log +59 -0
  11. data/examples/s3.yaml +2 -6
  12. data/lib/s33r/bucket.rb +103 -0
  13. data/lib/s33r/bucket_listing.rb +33 -76
  14. data/lib/s33r/client.rb +305 -446
  15. data/lib/s33r/networking.rb +197 -0
  16. data/lib/s33r/s33r_exception.rb +29 -18
  17. data/lib/s33r/s33r_http.rb +36 -18
  18. data/lib/s33r/s3_acl.rb +32 -52
  19. data/lib/s33r/s3_logging.rb +117 -0
  20. data/lib/s33r/s3_obj.rb +124 -69
  21. data/lib/s33r/utility.rb +447 -0
  22. data/test/cases/spec_acl.rb +10 -40
  23. data/test/cases/spec_bucket_listing.rb +12 -32
  24. data/test/cases/spec_logging.rb +47 -0
  25. data/test/cases/spec_networking.rb +11 -0
  26. data/test/cases/spec_s3_object.rb +44 -5
  27. data/test/cases/spec_utility.rb +264 -0
  28. data/test/files/acl.xml +0 -6
  29. data/test/files/config.yaml +5 -0
  30. data/test/files/logging_status_disabled.xml +3 -0
  31. data/test/files/logging_status_enabled.xml +7 -0
  32. data/test/test_setup.rb +7 -2
  33. metadata +16 -94
  34. data/examples/cli/acl_x.rb +0 -41
  35. data/examples/cli/logging_x.rb +0 -20
  36. data/examples/fores33r/README +0 -183
  37. data/html/classes/MIME.html +0 -120
  38. data/html/classes/MIME/InvalidContentType.html +0 -119
  39. data/html/classes/MIME/Type.html +0 -1173
  40. data/html/classes/MIME/Types.html +0 -566
  41. data/html/classes/Net.html +0 -108
  42. data/html/classes/Net/HTTPGenericRequest.html +0 -233
  43. data/html/classes/Net/HTTPResponse.html +0 -271
  44. data/html/classes/S33r.html +0 -986
  45. data/html/classes/S33r/BucketListing.html +0 -434
  46. data/html/classes/S33r/Client.html +0 -1575
  47. data/html/classes/S33r/LoggingResource.html +0 -222
  48. data/html/classes/S33r/NamedBucket.html +0 -693
  49. data/html/classes/S33r/OrderlyXmlMarkup.html +0 -165
  50. data/html/classes/S33r/S33rException.html +0 -124
  51. data/html/classes/S33r/S33rException/BucketListingMaxKeysError.html +0 -111
  52. data/html/classes/S33r/S33rException/BucketNotLogTargetable.html +0 -119
  53. data/html/classes/S33r/S33rException/InvalidBucketListing.html +0 -111
  54. data/html/classes/S33r/S33rException/InvalidPermission.html +0 -111
  55. data/html/classes/S33r/S33rException/InvalidS3GroupType.html +0 -111
  56. data/html/classes/S33r/S33rException/MalformedBucketName.html +0 -111
  57. data/html/classes/S33r/S33rException/MethodNotAvailable.html +0 -111
  58. data/html/classes/S33r/S33rException/MissingBucketName.html +0 -111
  59. data/html/classes/S33r/S33rException/MissingRequiredHeaders.html +0 -111
  60. data/html/classes/S33r/S33rException/MissingResource.html +0 -111
  61. data/html/classes/S33r/S33rException/S3FallenOver.html +0 -111
  62. data/html/classes/S33r/S33rException/TryingToPutEmptyResource.html +0 -117
  63. data/html/classes/S33r/S33rException/UnsupportedCannedACL.html +0 -111
  64. data/html/classes/S33r/S33rException/UnsupportedHTTPMethod.html +0 -111
  65. data/html/classes/S33r/S3ACL.html +0 -125
  66. data/html/classes/S33r/S3ACL/ACLDoc.html +0 -521
  67. data/html/classes/S33r/S3ACL/AmazonCustomer.html +0 -168
  68. data/html/classes/S33r/S3ACL/CanonicalUser.html +0 -212
  69. data/html/classes/S33r/S3ACL/Grant.html +0 -403
  70. data/html/classes/S33r/S3ACL/Grantee.html +0 -239
  71. data/html/classes/S33r/S3ACL/Group.html +0 -178
  72. data/html/classes/S33r/S3Object.html +0 -618
  73. data/html/classes/S33r/Sync.html +0 -152
  74. data/html/classes/XML.html +0 -202
  75. data/html/classes/XML/Document.html +0 -125
  76. data/html/classes/XML/Node.html +0 -124
  77. data/html/created.rid +0 -1
  78. data/html/files/CHANGELOG.html +0 -107
  79. data/html/files/MIT-LICENSE.html +0 -129
  80. data/html/files/README_txt.html +0 -259
  81. data/html/files/lib/s33r/bucket_listing_rb.html +0 -101
  82. data/html/files/lib/s33r/builder_rb.html +0 -108
  83. data/html/files/lib/s33r/client_rb.html +0 -111
  84. data/html/files/lib/s33r/core_rb.html +0 -113
  85. data/html/files/lib/s33r/libxml_extensions_rb.html +0 -101
  86. data/html/files/lib/s33r/libxml_loader_rb.html +0 -109
  87. data/html/files/lib/s33r/logging_rb.html +0 -108
  88. data/html/files/lib/s33r/mimetypes_rb.html +0 -120
  89. data/html/files/lib/s33r/named_bucket_rb.html +0 -101
  90. data/html/files/lib/s33r/s33r_exception_rb.html +0 -101
  91. data/html/files/lib/s33r/s33r_http_rb.html +0 -108
  92. data/html/files/lib/s33r/s3_acl_rb.html +0 -108
  93. data/html/files/lib/s33r/s3_obj_rb.html +0 -108
  94. data/html/files/lib/s33r/sync_rb.html +0 -101
  95. data/html/files/lib/s33r_rb.html +0 -101
  96. data/html/fr_class_index.html +0 -66
  97. data/html/fr_file_index.html +0 -44
  98. data/html/fr_method_index.html +0 -183
  99. data/html/index.html +0 -24
  100. data/html/rdoc-style.css +0 -208
  101. data/lib/s33r/core.rb +0 -296
  102. data/lib/s33r/logging.rb +0 -43
  103. data/lib/s33r/named_bucket.rb +0 -148
  104. data/lib/s33r/sync.rb +0 -13
  105. data/test/cases/spec_all_buckets.rb +0 -28
  106. data/test/cases/spec_client.rb +0 -101
  107. data/test/cases/spec_core.rb +0 -128
  108. data/test/cases/spec_namedbucket.rb +0 -46
  109. data/test/cases/spec_sync.rb +0 -34
  110. data/test/files/all_buckets.xml +0 -21
  111. data/test/files/client_config.yml +0 -5
  112. data/test/files/namedbucket_config.yml +0 -8
  113. data/test/files/namedbucket_config2.yml +0 -8
  114. data/test/test_bucket_setup.rb +0 -41
@@ -1,986 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Module: S33r</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Module</strong></td>
53
- <td class="class-name-in-header">S33r</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../files/lib/s33r/bucket_listing_rb.html">
59
- lib/s33r/bucket_listing.rb
60
- </a>
61
- <br />
62
- <a href="../files/lib/s33r/client_rb.html">
63
- lib/s33r/client.rb
64
- </a>
65
- <br />
66
- <a href="../files/lib/s33r/named_bucket_rb.html">
67
- lib/s33r/named_bucket.rb
68
- </a>
69
- <br />
70
- <a href="../files/lib/s33r/s3_acl_rb.html">
71
- lib/s33r/s3_acl.rb
72
- </a>
73
- <br />
74
- <a href="../files/lib/s33r/s3_obj_rb.html">
75
- lib/s33r/s3_obj.rb
76
- </a>
77
- <br />
78
- <a href="../files/lib/s33r/builder_rb.html">
79
- lib/s33r/builder.rb
80
- </a>
81
- <br />
82
- <a href="../files/lib/s33r/logging_rb.html">
83
- lib/s33r/logging.rb
84
- </a>
85
- <br />
86
- <a href="../files/lib/s33r/core_rb.html">
87
- lib/s33r/core.rb
88
- </a>
89
- <br />
90
- <a href="../files/lib/s33r/s33r_exception_rb.html">
91
- lib/s33r/s33r_exception.rb
92
- </a>
93
- <br />
94
- <a href="../files/lib/s33r/sync_rb.html">
95
- lib/s33r/sync.rb
96
- </a>
97
- <br />
98
- </td>
99
- </tr>
100
-
101
- </table>
102
- </div>
103
- <!-- banner header -->
104
-
105
- <div id="bodyContent">
106
-
107
-
108
-
109
- <div id="contextContent">
110
-
111
- <div id="description">
112
- <p>
113
- Module to handle S3 operations which don&#8217;t require an internet
114
- connection, i.e. data validation and request-building operations; also
115
- holds all the constants relating to S3.
116
- </p>
117
- <p>
118
- Parts of this code are heavily based on Amazon&#8217;s code. Here&#8217;s
119
- their license:
120
- </p>
121
- <pre>
122
- This software code is made available &quot;AS IS&quot; without warranties of any
123
- kind. You may copy, display, modify and redistribute the software
124
- code either by itself or as incorporated into your code; provided that
125
- you do not remove any proprietary notices. Your use of this software
126
- code is at your own risk and you waive any claim against Amazon
127
- Digital Services, Inc. or its affiliates with respect to your use of
128
- this software code. (c) 2006 Amazon Digital Services, Inc. or its
129
- affiliates.
130
- </pre>
131
-
132
- </div>
133
-
134
-
135
- </div>
136
-
137
- <div id="method-list">
138
- <h3 class="section-bar">Methods</h3>
139
-
140
- <div class="name-list">
141
- <a href="#M000044">add_default_headers</a>&nbsp;&nbsp;
142
- <a href="#M000048">bucket_name_valid?</a>&nbsp;&nbsp;
143
- <a href="#M000046">canned_acl_header</a>&nbsp;&nbsp;
144
- <a href="#M000042">generate_auth_header_value</a>&nbsp;&nbsp;
145
- <a href="#M000041">generate_canonical_string</a>&nbsp;&nbsp;
146
- <a href="#M000049">generate_querystring</a>&nbsp;&nbsp;
147
- <a href="#M000043">generate_signature</a>&nbsp;&nbsp;
148
- <a href="#M000047">guess_mime_type</a>&nbsp;&nbsp;
149
- <a href="#M000056">keys_to_symbols</a>&nbsp;&nbsp;
150
- <a href="#M000045">metadata_headers</a>&nbsp;&nbsp;
151
- <a href="#M000057">parse_expiry</a>&nbsp;&nbsp;
152
- <a href="#M000058">remove_namespace</a>&nbsp;&nbsp;
153
- <a href="#M000050">s3_acl_path</a>&nbsp;&nbsp;
154
- <a href="#M000055">s3_authenticated_url</a>&nbsp;&nbsp;
155
- <a href="#M000051">s3_logging_path</a>&nbsp;&nbsp;
156
- <a href="#M000054">s3_path</a>&nbsp;&nbsp;
157
- <a href="#M000053">s3_public_url</a>&nbsp;&nbsp;
158
- <a href="#M000052">s3_url</a>&nbsp;&nbsp;
159
- </div>
160
- </div>
161
-
162
- </div>
163
-
164
-
165
- <!-- if includes -->
166
- <div id="includes">
167
- <h3 class="section-bar">Included Modules</h3>
168
-
169
- <div id="includes-list">
170
- <span class="include-name"><a href="Net.html">Net</a></span>
171
- </div>
172
- </div>
173
-
174
- <div id="section">
175
-
176
- <div id="class-list">
177
- <h3 class="section-bar">Classes and Modules</h3>
178
-
179
- Module <a href="S33r/S33rException.html" class="link">S33r::S33rException</a><br />
180
- Module <a href="S33r/S3ACL.html" class="link">S33r::S3ACL</a><br />
181
- Module <a href="S33r/Sync.html" class="link">S33r::Sync</a><br />
182
- Class <a href="S33r/BucketListing.html" class="link">S33r::BucketListing</a><br />
183
- Class <a href="S33r/Client.html" class="link">S33r::Client</a><br />
184
- Class <a href="S33r/LoggingResource.html" class="link">S33r::LoggingResource</a><br />
185
- Class <a href="S33r/NamedBucket.html" class="link">S33r::NamedBucket</a><br />
186
- Class <a href="S33r/OrderlyXmlMarkup.html" class="link">S33r::OrderlyXmlMarkup</a><br />
187
- Class <a href="S33r/S3Object.html" class="link">S33r::S3Object</a><br />
188
-
189
- </div>
190
-
191
- <div id="constants-list">
192
- <h3 class="section-bar">Constants</h3>
193
-
194
- <div class="name-list">
195
- <table summary="Constants">
196
- <tr class="top-aligned-row context-row">
197
- <td class="context-item-name">HOST</td>
198
- <td>=</td>
199
- <td class="context-item-value">'s3.amazonaws.com'</td>
200
- </tr>
201
- <tr class="top-aligned-row context-row">
202
- <td class="context-item-name">PORT</td>
203
- <td>=</td>
204
- <td class="context-item-value">443</td>
205
- </tr>
206
- <tr class="top-aligned-row context-row">
207
- <td class="context-item-name">NON_SSL_PORT</td>
208
- <td>=</td>
209
- <td class="context-item-value">80</td>
210
- </tr>
211
- <tr class="top-aligned-row context-row">
212
- <td class="context-item-name">METADATA_PREFIX</td>
213
- <td>=</td>
214
- <td class="context-item-value">'x-amz-meta-'</td>
215
- </tr>
216
- <tr class="top-aligned-row context-row">
217
- <td class="context-item-name">DEFAULT_CHUNK_SIZE</td>
218
- <td>=</td>
219
- <td class="context-item-value">1048576</td>
220
- <td width="3em">&nbsp;</td>
221
- <td class="context-item-desc">
222
- Size of each chunk (in bytes) to be sent per request when putting files
223
- (1Mb).
224
-
225
- </td>
226
- </tr>
227
- <tr class="top-aligned-row context-row">
228
- <td class="context-item-name">AWS_HEADER_PREFIX</td>
229
- <td>=</td>
230
- <td class="context-item-value">'x-amz-'</td>
231
- </tr>
232
- <tr class="top-aligned-row context-row">
233
- <td class="context-item-name">AWS_AUTH_HEADER_VALUE</td>
234
- <td>=</td>
235
- <td class="context-item-value">&quot;AWS %s:%s&quot;</td>
236
- </tr>
237
- <tr class="top-aligned-row context-row">
238
- <td class="context-item-name">INTERESTING_HEADERS</td>
239
- <td>=</td>
240
- <td class="context-item-value">['content-md5', 'content-type', 'date']</td>
241
- </tr>
242
- <tr class="top-aligned-row context-row">
243
- <td class="context-item-name">REQUIRED_HEADERS</td>
244
- <td>=</td>
245
- <td class="context-item-value">['Content-Type', 'Date']</td>
246
- <td width="3em">&nbsp;</td>
247
- <td class="context-item-desc">
248
- Headers which must be included with every request to S3.
249
-
250
- </td>
251
- </tr>
252
- <tr class="top-aligned-row context-row">
253
- <td class="context-item-name">CANNED_ACLS</td>
254
- <td>=</td>
255
- <td class="context-item-value">['private', 'public-read', 'public-read-write', 'authenticated-read']</td>
256
- <td width="3em">&nbsp;</td>
257
- <td class="context-item-desc">
258
- Canned ACLs made available by S3.
259
-
260
- </td>
261
- </tr>
262
- <tr class="top-aligned-row context-row">
263
- <td class="context-item-name">METHOD_VERBS</td>
264
- <td>=</td>
265
- <td class="context-item-value">['GET', 'PUT', 'HEAD', 'POST', 'DELETE']</td>
266
- <td width="3em">&nbsp;</td>
267
- <td class="context-item-desc">
268
- HTTP methods which S3 will respond to.
269
-
270
- </td>
271
- </tr>
272
- <tr class="top-aligned-row context-row">
273
- <td class="context-item-name">BUCKET_LIST_MAX_MAX_KEYS</td>
274
- <td>=</td>
275
- <td class="context-item-value">1000</td>
276
- <td width="3em">&nbsp;</td>
277
- <td class="context-item-desc">
278
- Maximum number which can be passed in max-keys parameter when GETting
279
- bucket list.
280
-
281
- </td>
282
- </tr>
283
- <tr class="top-aligned-row context-row">
284
- <td class="context-item-name">DEFAULT_EXPIRY_SECS</td>
285
- <td>=</td>
286
- <td class="context-item-value">60 * 15</td>
287
- <td width="3em">&nbsp;</td>
288
- <td class="context-item-desc">
289
- Default number of seconds an authenticated URL will last for (15 minutes).
290
-
291
- </td>
292
- </tr>
293
- <tr class="top-aligned-row context-row">
294
- <td class="context-item-name">RESPONSE_NAMESPACE_URI</td>
295
- <td>=</td>
296
- <td class="context-item-value">&quot;http://s3.amazonaws.com/doc/2006-03-01/&quot;</td>
297
- <td width="3em">&nbsp;</td>
298
- <td class="context-item-desc">
299
- The namespace used for response body <a href="XML.html">XML</a> documents.
300
-
301
- </td>
302
- </tr>
303
- <tr class="top-aligned-row context-row">
304
- <td class="context-item-name">PERMISSIONS</td>
305
- <td>=</td>
306
- <td class="context-item-value">{ :read =&gt; 'READ', # permission to read :write =&gt; 'WRITE', # permission to write :read_acl =&gt; 'READ_ACP', # permission to read ACL settings :all =&gt; 'FULL_CONTROL'</td>
307
- <td width="3em">&nbsp;</td>
308
- <td class="context-item-desc">
309
- Permissions which can be set within a &lt;Grant&gt; (see <a
310
- href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/UsingPermissions.html">docs.amazonwebservices.com/AmazonS3/2006-03-01/UsingPermissions.html</a>).
311
-
312
- <p>
313
- NB I&#8217;ve missed out the WRITE_ACP permission as this is functionally
314
- equivalent to FULL_CONTROL.
315
- </p>
316
- </td>
317
- </tr>
318
- <tr class="top-aligned-row context-row">
319
- <td class="context-item-name">NAMESPACE</td>
320
- <td>=</td>
321
- <td class="context-item-value">'xsi'</td>
322
- <td width="3em">&nbsp;</td>
323
- <td class="context-item-desc">
324
- Used for generating ACL <a href="XML.html">XML</a> documents.
325
-
326
- </td>
327
- </tr>
328
- <tr class="top-aligned-row context-row">
329
- <td class="context-item-name">NAMESPACE_URI</td>
330
- <td>=</td>
331
- <td class="context-item-value">'http://www.w3.org/2001/XMLSchema-instance'</td>
332
- </tr>
333
- <tr class="top-aligned-row context-row">
334
- <td class="context-item-name">GRANTEE_TYPES</td>
335
- <td>=</td>
336
- <td class="context-item-value">{ :amazon_customer =&gt; 'AmazonCustomerByEmail', :canonical_user =&gt; 'CanonicalUser', :group =&gt; 'Group'</td>
337
- </tr>
338
- <tr class="top-aligned-row context-row">
339
- <td class="context-item-name">S3_GROUP_TYPES</td>
340
- <td>=</td>
341
- <td class="context-item-value">{ :all_users =&gt; 'global/AllUsers', :authenticated_users =&gt; 'global/AuthenticatedUsers', :log_delivery =&gt; 's3/LogDelivery'</td>
342
- </tr>
343
- <tr class="top-aligned-row context-row">
344
- <td class="context-item-name">GROUP_ACL_URI_BASE</td>
345
- <td>=</td>
346
- <td class="context-item-value">'http://acs.amazonaws.com/groups/'</td>
347
- </tr>
348
- </table>
349
- </div>
350
- </div>
351
-
352
-
353
-
354
-
355
-
356
-
357
- <!-- if method_list -->
358
- <div id="methods">
359
- <h3 class="section-bar">Public Class methods</h3>
360
-
361
- <div id="method-M000056" class="method-detail">
362
- <a name="M000056"></a>
363
-
364
- <div class="method-heading">
365
- <a href="#M000056" class="method-signature">
366
- <span class="method-name">keys_to_symbols</span><span class="method-args">(hsh)</span>
367
- </a>
368
- </div>
369
-
370
- <div class="method-description">
371
- <p>
372
- Turn keys in a hash <tt>hsh</tt> into symbols.
373
- </p>
374
- <p>
375
- Returns a hash with &#8216;symbolised&#8217; keys.
376
- </p>
377
- <p><a class="source-toggle" href="#"
378
- onclick="toggleCode('M000056-source');return false;">[Source]</a></p>
379
- <div class="method-source-code" id="M000056-source">
380
- <pre>
381
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 260</span>
382
- 260: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">S33r</span>.<span class="ruby-identifier">keys_to_symbols</span>(<span class="ruby-identifier">hsh</span>)
383
- 261: <span class="ruby-identifier">symbolised</span> = <span class="ruby-identifier">hsh</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">symbolised</span>, <span class="ruby-identifier">key_value</span><span class="ruby-operator">|</span>
384
- 262: <span class="ruby-identifier">symbolised</span>.<span class="ruby-identifier">merge</span>({<span class="ruby-identifier">key_value</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">to_sym</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">key_value</span>[<span class="ruby-value">1</span>]})
385
- 263: <span class="ruby-keyword kw">end</span>
386
- 264: <span class="ruby-identifier">symbolised</span>
387
- 265: <span class="ruby-keyword kw">end</span>
388
- </pre>
389
- </div>
390
- </div>
391
- </div>
392
-
393
- <div id="method-M000057" class="method-detail">
394
- <a name="M000057"></a>
395
-
396
- <div class="method-heading">
397
- <a href="#M000057" class="method-signature">
398
- <span class="method-name">parse_expiry</span><span class="method-args">(expires)</span>
399
- </a>
400
- </div>
401
-
402
- <div class="method-description">
403
- <p>
404
- Parse an expiry date to seconds since the epoch.
405
- </p>
406
- <p>
407
- <tt>expires</tt> can be set to &#8216;forever&#8217; to get a time 20 years
408
- in the future; &#8216;default&#8217; to use the current time +
409
- DEFAULT_EXPIRY_SECS; or to a specific date (parseable by ParseDate); or to
410
- an integer representing seconds since the epoch.
411
- </p>
412
- <p>
413
- TODO: testing for this
414
- </p>
415
- <p><a class="source-toggle" href="#"
416
- onclick="toggleCode('M000057-source');return false;">[Source]</a></p>
417
- <div class="method-source-code" id="M000057-source">
418
- <pre>
419
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 275</span>
420
- 275: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">S33r</span>.<span class="ruby-identifier">parse_expiry</span>(<span class="ruby-identifier">expires</span>)
421
- 276: <span class="ruby-identifier">base_expires</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">to_i</span>
422
- 277: <span class="ruby-keyword kw">if</span> <span class="ruby-value str">'forever'</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">expires</span>
423
- 278: <span class="ruby-comment cmt"># 20 years (same as forever in computer terms)</span>
424
- 279: <span class="ruby-identifier">expires</span> = <span class="ruby-identifier">base_expires</span> <span class="ruby-operator">+</span> (<span class="ruby-value">60</span> <span class="ruby-operator">*</span> <span class="ruby-value">60</span> <span class="ruby-operator">*</span> <span class="ruby-value">24</span> <span class="ruby-operator">*</span> <span class="ruby-value">365.25</span> <span class="ruby-operator">*</span> <span class="ruby-value">20</span>).<span class="ruby-identifier">to_i</span>
425
- 280: <span class="ruby-keyword kw">elsif</span> <span class="ruby-value str">'default'</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">expires</span>
426
- 281: <span class="ruby-comment cmt"># default to DEFAULT_EXPIRY_SECS seconds from now if expires not set</span>
427
- 282: <span class="ruby-identifier">expires</span> = <span class="ruby-identifier">base_expires</span> <span class="ruby-operator">+</span> <span class="ruby-constant">DEFAULT_EXPIRY_SECS</span>
428
- 283: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">expires</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
429
- 284: <span class="ruby-identifier">datetime_parts</span> = <span class="ruby-constant">ParseDate</span>.<span class="ruby-identifier">parsedate</span>(<span class="ruby-identifier">expires</span>)
430
- 285: <span class="ruby-identifier">expires</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">gm</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">datetime_parts</span>).<span class="ruby-identifier">to_i</span>
431
- 286: <span class="ruby-keyword kw">end</span>
432
- 287: <span class="ruby-identifier">expires</span>
433
- 288: <span class="ruby-keyword kw">end</span>
434
- </pre>
435
- </div>
436
- </div>
437
- </div>
438
-
439
- <div id="method-M000058" class="method-detail">
440
- <a name="M000058"></a>
441
-
442
- <div class="method-heading">
443
- <a href="#M000058" class="method-signature">
444
- <span class="method-name">remove_namespace</span><span class="method-args">(xml_in)</span>
445
- </a>
446
- </div>
447
-
448
- <div class="method-description">
449
- <p>
450
- Remove the namespace declaration from S3 <a href="XML.html">XML</a>
451
- response bodies (libxml isn&#8217;t fond of it).
452
- </p>
453
- <p><a class="source-toggle" href="#"
454
- onclick="toggleCode('M000058-source');return false;">[Source]</a></p>
455
- <div class="method-source-code" id="M000058-source">
456
- <pre>
457
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 292</span>
458
- 292: <span class="ruby-keyword kw">def</span> <span class="ruby-constant">S33r</span>.<span class="ruby-identifier">remove_namespace</span>(<span class="ruby-identifier">xml_in</span>)
459
- 293: <span class="ruby-identifier">namespace</span> = <span class="ruby-constant">S33r</span><span class="ruby-operator">::</span><span class="ruby-constant">RESPONSE_NAMESPACE_URI</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">'/'</span>, <span class="ruby-value str">'\/'</span>)
460
- 294: <span class="ruby-identifier">xml_in</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-node">/ xmlns=&quot;#{namespace}&quot;/</span>, <span class="ruby-value str">''</span>)
461
- 295: <span class="ruby-keyword kw">end</span>
462
- </pre>
463
- </div>
464
- </div>
465
- </div>
466
-
467
- <h3 class="section-bar">Public Instance methods</h3>
468
-
469
- <div id="method-M000044" class="method-detail">
470
- <a name="M000044"></a>
471
-
472
- <div class="method-heading">
473
- <a href="#M000044" class="method-signature">
474
- <span class="method-name">add_default_headers</span><span class="method-args">(headers, options={})</span>
475
- </a>
476
- </div>
477
-
478
- <div class="method-description">
479
- <p>
480
- Build the headers required with every S3 request (Date and Content-Type);
481
- options hash can contain extra header settings; +:date+ and +:content_type+
482
- are required headers, and set to defaults if not supplied
483
- </p>
484
- <p><a class="source-toggle" href="#"
485
- onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
486
- <div class="method-source-code" id="M000044-source">
487
- <pre>
488
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 144</span>
489
- 144: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_default_headers</span>(<span class="ruby-identifier">headers</span>, <span class="ruby-identifier">options</span>={})
490
- 145: <span class="ruby-comment cmt"># set the default headers required by AWS</span>
491
- 146: <span class="ruby-identifier">missing_headers</span> = <span class="ruby-constant">REQUIRED_HEADERS</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">keys</span>
492
- 147:
493
- 148: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">missing_headers</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'Content-Type'</span>)
494
- 149: <span class="ruby-identifier">headers</span>[<span class="ruby-value str">'Content-Type'</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:content_type</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">''</span>
495
- 150: <span class="ruby-keyword kw">end</span>
496
- 151:
497
- 152: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">missing_headers</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value str">'Date'</span>)
498
- 153: <span class="ruby-identifier">date</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:date</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
499
- 154: <span class="ruby-identifier">headers</span>[<span class="ruby-value str">'Date'</span>] = <span class="ruby-identifier">date</span>.<span class="ruby-identifier">httpdate</span>
500
- 155: <span class="ruby-keyword kw">end</span>
501
- 156:
502
- 157: <span class="ruby-identifier">headers</span>
503
- 158: <span class="ruby-keyword kw">end</span>
504
- </pre>
505
- </div>
506
- </div>
507
- </div>
508
-
509
- <div id="method-M000048" class="method-detail">
510
- <a name="M000048"></a>
511
-
512
- <div class="method-heading">
513
- <a href="#M000048" class="method-signature">
514
- <span class="method-name">bucket_name_valid?</span><span class="method-args">(bucket_name)</span>
515
- </a>
516
- </div>
517
-
518
- <div class="method-description">
519
- <p>
520
- Ensure that a bucket_name is well-formed (no leading or trailing slash).
521
- </p>
522
- <p><a class="source-toggle" href="#"
523
- onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
524
- <div class="method-source-code" id="M000048-source">
525
- <pre>
526
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 195</span>
527
- 195: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">bucket_name_valid?</span>(<span class="ruby-identifier">bucket_name</span>)
528
- 196: <span class="ruby-keyword kw">if</span> (<span class="ruby-value str">'/'</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">bucket_name</span>[<span class="ruby-value">0</span>,<span class="ruby-value">1</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">'/'</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">bucket_name</span>[<span class="ruby-value">-1</span>,<span class="ruby-value">1</span>])
529
- 197: <span class="ruby-identifier">raise</span> <span class="ruby-constant">S33rException</span><span class="ruby-operator">::</span><span class="ruby-constant">MalformedBucketName</span>, <span class="ruby-value str">&quot;Bucket name cannot have a leading or trailing slash&quot;</span>
530
- 198: <span class="ruby-keyword kw">end</span>
531
- 199: <span class="ruby-keyword kw">end</span>
532
- </pre>
533
- </div>
534
- </div>
535
- </div>
536
-
537
- <div id="method-M000046" class="method-detail">
538
- <a name="M000046"></a>
539
-
540
- <div class="method-heading">
541
- <a href="#M000046" class="method-signature">
542
- <span class="method-name">canned_acl_header</span><span class="method-args">(canned_acl, headers={})</span>
543
- </a>
544
- </div>
545
-
546
- <div class="method-description">
547
- <p>
548
- Add a canned ACL setter header.
549
- </p>
550
- <p><a class="source-toggle" href="#"
551
- onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
552
- <div class="method-source-code" id="M000046-source">
553
- <pre>
554
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 176</span>
555
- 176: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">canned_acl_header</span>(<span class="ruby-identifier">canned_acl</span>, <span class="ruby-identifier">headers</span>={})
556
- 177: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">canned_acl</span>.<span class="ruby-identifier">nil?</span>
557
- 178: <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">CANNED_ACLS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">canned_acl</span>)
558
- 179: <span class="ruby-identifier">raise</span> <span class="ruby-constant">S33rException</span><span class="ruby-operator">::</span><span class="ruby-constant">UnsupportedCannedACL</span>, <span class="ruby-node">&quot;The canned ACL #{canned_acl} is not supported&quot;</span>
559
- 180: <span class="ruby-keyword kw">end</span>
560
- 181: <span class="ruby-identifier">headers</span>[<span class="ruby-constant">AWS_HEADER_PREFIX</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'acl'</span>] = <span class="ruby-identifier">canned_acl</span>
561
- 182: <span class="ruby-keyword kw">end</span>
562
- 183: <span class="ruby-identifier">headers</span>
563
- 184: <span class="ruby-keyword kw">end</span>
564
- </pre>
565
- </div>
566
- </div>
567
- </div>
568
-
569
- <div id="method-M000042" class="method-detail">
570
- <a name="M000042"></a>
571
-
572
- <div class="method-heading">
573
- <a href="#M000042" class="method-signature">
574
- <span class="method-name">generate_auth_header_value</span><span class="method-args">(method, path, headers, aws_access_key, aws_secret_access_key)</span>
575
- </a>
576
- </div>
577
-
578
- <div class="method-description">
579
- <p>
580
- Get the value for the AWS authentication header.
581
- </p>
582
- <p><a class="source-toggle" href="#"
583
- onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
584
- <div class="method-source-code" id="M000042-source">
585
- <pre>
586
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 118</span>
587
- 118: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate_auth_header_value</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">headers</span>, <span class="ruby-identifier">aws_access_key</span>, <span class="ruby-identifier">aws_secret_access_key</span>)
588
- 119: <span class="ruby-identifier">raise</span> <span class="ruby-constant">S33rException</span><span class="ruby-operator">::</span><span class="ruby-constant">MethodNotAvailable</span>, <span class="ruby-value str">&quot;Method %s not available&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">method</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">METHOD_VERBS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">method</span>)
589
- 120:
590
- 121: <span class="ruby-comment cmt"># check the headers needed for authentication have been set</span>
591
- 122: <span class="ruby-identifier">missing_headers</span> = <span class="ruby-constant">REQUIRED_HEADERS</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">keys</span>
592
- 123: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">missing_headers</span>.<span class="ruby-identifier">empty?</span>)
593
- 124: <span class="ruby-identifier">raise</span> <span class="ruby-constant">S33rException</span><span class="ruby-operator">::</span><span class="ruby-constant">MissingRequiredHeaders</span>,
594
- 125: <span class="ruby-value str">&quot;Headers required for AWS auth value are missing: &quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">missing_headers</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">', '</span>)
595
- 126: <span class="ruby-keyword kw">end</span>
596
- 127:
597
- 128: <span class="ruby-comment cmt"># get the AWS header</span>
598
- 129: <span class="ruby-identifier">canonical_string</span> = <span class="ruby-identifier">generate_canonical_string</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">headers</span>)
599
- 130: <span class="ruby-identifier">signature</span> = <span class="ruby-identifier">generate_signature</span>(<span class="ruby-identifier">aws_secret_access_key</span>, <span class="ruby-identifier">canonical_string</span>)
600
- 131: <span class="ruby-constant">AWS_AUTH_HEADER_VALUE</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">aws_access_key</span>, <span class="ruby-identifier">signature</span>]
601
- 132: <span class="ruby-keyword kw">end</span>
602
- </pre>
603
- </div>
604
- </div>
605
- </div>
606
-
607
- <div id="method-M000041" class="method-detail">
608
- <a name="M000041"></a>
609
-
610
- <div class="method-heading">
611
- <a href="#M000041" class="method-signature">
612
- <span class="method-name">generate_canonical_string</span><span class="method-args">(method, path, headers={}, expires=nil)</span>
613
- </a>
614
- </div>
615
-
616
- <div class="method-description">
617
- <p>
618
- Build canonical string for signing; modified (slightly) from the Amazon
619
- sample code.
620
- </p>
621
- <p><a class="source-toggle" href="#"
622
- onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
623
- <div class="method-source-code" id="M000041-source">
624
- <pre>
625
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 75</span>
626
- 75: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate_canonical_string</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">headers</span>={}, <span class="ruby-identifier">expires</span>=<span class="ruby-keyword kw">nil</span>)
627
- 76: <span class="ruby-identifier">interesting_headers</span> = {}
628
- 77: <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
629
- 78: <span class="ruby-identifier">lk</span> = <span class="ruby-identifier">key</span>.<span class="ruby-identifier">downcase</span>
630
- 79: <span class="ruby-keyword kw">if</span> (<span class="ruby-constant">INTERESTING_HEADERS</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">lk</span>) <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">lk</span> <span class="ruby-operator">=~</span> <span class="ruby-node">/^#{AWS_HEADER_PREFIX}/o</span>)
631
- 80: <span class="ruby-identifier">interesting_headers</span>[<span class="ruby-identifier">lk</span>] = <span class="ruby-identifier">value</span>
632
- 81: <span class="ruby-keyword kw">end</span>
633
- 82: <span class="ruby-keyword kw">end</span>
634
- 83:
635
- 84: <span class="ruby-comment cmt"># These fields get empty strings if they don't exist.</span>
636
- 85: <span class="ruby-identifier">interesting_headers</span>[<span class="ruby-value str">'content-type'</span>] <span class="ruby-operator">||=</span> <span class="ruby-value str">''</span>
637
- 86: <span class="ruby-identifier">interesting_headers</span>[<span class="ruby-value str">'content-md5'</span>] <span class="ruby-operator">||=</span> <span class="ruby-value str">''</span>
638
- 87:
639
- 88: <span class="ruby-comment cmt"># If you're using expires for query string auth, then it trumps date.</span>
640
- 89: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">expires</span>.<span class="ruby-identifier">nil?</span>
641
- 90: <span class="ruby-identifier">interesting_headers</span>[<span class="ruby-value str">'date'</span>] = <span class="ruby-identifier">expires</span>
642
- 91: <span class="ruby-keyword kw">end</span>
643
- 92:
644
- 93: <span class="ruby-identifier">buf</span> = <span class="ruby-node">&quot;#{method}\n&quot;</span>
645
- 94: <span class="ruby-identifier">interesting_headers</span>.<span class="ruby-identifier">sort</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">b</span>[<span class="ruby-value">0</span>] }.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
646
- 95: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">=~</span> <span class="ruby-node">/^#{AWS_HEADER_PREFIX}/o</span>
647
- 96: <span class="ruby-identifier">buf</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{key}:#{value}\n&quot;</span>
648
- 97: <span class="ruby-keyword kw">else</span>
649
- 98: <span class="ruby-identifier">buf</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{value}\n&quot;</span>
650
- 99: <span class="ruby-keyword kw">end</span>
651
- 100: <span class="ruby-keyword kw">end</span>
652
- 101:
653
- 102: <span class="ruby-comment cmt"># Ignore everything after the question mark...</span>
654
- 103: <span class="ruby-identifier">buf</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">path</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/\?.*$/</span>, <span class="ruby-value str">''</span>)
655
- 104:
656
- 105: <span class="ruby-comment cmt"># ...unless there is an acl, logging or torrent parameter</span>
657
- 106: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">path</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/[&amp;?]acl($|&amp;|=)/</span>
658
- 107: <span class="ruby-identifier">buf</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'?acl'</span>
659
- 108: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">path</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/[&amp;?]torrent($|&amp;|=)/</span>
660
- 109: <span class="ruby-identifier">buf</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'?torrent'</span>
661
- 110: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">path</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/[&amp;?]logging($|&amp;|=)/</span>
662
- 111: <span class="ruby-identifier">buf</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'?logging'</span>
663
- 112: <span class="ruby-keyword kw">end</span>
664
- 113:
665
- 114: <span class="ruby-identifier">buf</span>
666
- 115: <span class="ruby-keyword kw">end</span>
667
- </pre>
668
- </div>
669
- </div>
670
- </div>
671
-
672
- <div id="method-M000049" class="method-detail">
673
- <a name="M000049"></a>
674
-
675
- <div class="method-heading">
676
- <a href="#M000049" class="method-signature">
677
- <span class="method-name">generate_querystring</span><span class="method-args">(pairs={})</span>
678
- </a>
679
- </div>
680
-
681
- <div class="method-description">
682
- <p>
683
- Convert a hash of name/value pairs to querystring variables. Name for a
684
- variable can be a string or symbol.
685
- </p>
686
- <p><a class="source-toggle" href="#"
687
- onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
688
- <div class="method-source-code" id="M000049-source">
689
- <pre>
690
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 203</span>
691
- 203: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate_querystring</span>(<span class="ruby-identifier">pairs</span>={})
692
- 204: <span class="ruby-identifier">str</span> = <span class="ruby-value str">''</span>
693
- 205: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pairs</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
694
- 206: <span class="ruby-identifier">str</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">&quot;?&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">pairs</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-node">&quot;#{key}=#{CGI::escape(value.to_s)}&quot;</span> }.<span class="ruby-identifier">join</span>(<span class="ruby-value str">'&amp;'</span>)
695
- 207: <span class="ruby-keyword kw">end</span>
696
- 208: <span class="ruby-identifier">str</span>
697
- 209: <span class="ruby-keyword kw">end</span>
698
- </pre>
699
- </div>
700
- </div>
701
- </div>
702
-
703
- <div id="method-M000043" class="method-detail">
704
- <a name="M000043"></a>
705
-
706
- <div class="method-heading">
707
- <a href="#M000043" class="method-signature">
708
- <span class="method-name">generate_signature</span><span class="method-args">(aws_secret_access_key, str)</span>
709
- </a>
710
- </div>
711
-
712
- <div class="method-description">
713
- <p>
714
- Encode the given string with the aws_secret_access_key, by taking the hmac
715
- sha1 sum, and then base64 encoding it.
716
- </p>
717
- <p><a class="source-toggle" href="#"
718
- onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
719
- <div class="method-source-code" id="M000043-source">
720
- <pre>
721
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 136</span>
722
- 136: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate_signature</span>(<span class="ruby-identifier">aws_secret_access_key</span>, <span class="ruby-identifier">str</span>)
723
- 137: <span class="ruby-identifier">digest</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">HMAC</span><span class="ruby-operator">::</span><span class="ruby-identifier">digest</span>(<span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Digest</span><span class="ruby-operator">::</span><span class="ruby-constant">Digest</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;SHA1&quot;</span>), <span class="ruby-identifier">aws_secret_access_key</span>, <span class="ruby-identifier">str</span>)
724
- 138: <span class="ruby-constant">Base64</span>.<span class="ruby-identifier">encode64</span>(<span class="ruby-identifier">digest</span>).<span class="ruby-identifier">strip</span>
725
- 139: <span class="ruby-keyword kw">end</span>
726
- </pre>
727
- </div>
728
- </div>
729
- </div>
730
-
731
- <div id="method-M000047" class="method-detail">
732
- <a name="M000047"></a>
733
-
734
- <div class="method-heading">
735
- <a href="#M000047" class="method-signature">
736
- <span class="method-name">guess_mime_type</span><span class="method-args">(file_name)</span>
737
- </a>
738
- </div>
739
-
740
- <div class="method-description">
741
- <p>
742
- Guess a file&#8217;s mime type. If the mime_type for a file cannot be
743
- guessed, &quot;text/plain&quot; is used.
744
- </p>
745
- <p><a class="source-toggle" href="#"
746
- onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
747
- <div class="method-source-code" id="M000047-source">
748
- <pre>
749
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 188</span>
750
- 188: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">guess_mime_type</span>(<span class="ruby-identifier">file_name</span>)
751
- 189: <span class="ruby-identifier">mime_type</span> = <span class="ruby-constant">MIME</span><span class="ruby-operator">::</span><span class="ruby-constant">Types</span>.<span class="ruby-identifier">type_for</span>(<span class="ruby-identifier">file_name</span>)[<span class="ruby-value">0</span>]
752
- 190: <span class="ruby-identifier">mime_type</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">MIME</span><span class="ruby-operator">::</span><span class="ruby-constant">Types</span>[<span class="ruby-value str">'text/plain'</span>][<span class="ruby-value">0</span>]
753
- 191: <span class="ruby-identifier">mime_type</span>
754
- 192: <span class="ruby-keyword kw">end</span>
755
- </pre>
756
- </div>
757
- </div>
758
- </div>
759
-
760
- <div id="method-M000045" class="method-detail">
761
- <a name="M000045"></a>
762
-
763
- <div class="method-heading">
764
- <a href="#M000045" class="method-signature">
765
- <span class="method-name">metadata_headers</span><span class="method-args">(headers, metadata={})</span>
766
- </a>
767
- </div>
768
-
769
- <div class="method-description">
770
- <p>
771
- Add metadata headers, correctly prefixing them first, e.g. you might do <a
772
- href="S33r.html#M000045">metadata_headers</a>({}, {&#8216;myname&#8217;
773
- =&gt; &#8216;elliot&#8217;, &#8216;myage&#8217; =&gt; 36}) to add two
774
- headers to the request:
775
- </p>
776
- <pre>
777
- x-amz-meta-myname: elliot
778
- x-amz-meta-myage: 36
779
- </pre>
780
- <p>
781
- Returns headers with the metadata headers appended.
782
- </p>
783
- <p><a class="source-toggle" href="#"
784
- onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
785
- <div class="method-source-code" id="M000045-source">
786
- <pre>
787
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 168</span>
788
- 168: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">metadata_headers</span>(<span class="ruby-identifier">headers</span>, <span class="ruby-identifier">metadata</span>={})
789
- 169: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">metadata</span>.<span class="ruby-identifier">empty?</span>
790
- 170: <span class="ruby-identifier">metadata</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">headers</span>[<span class="ruby-constant">METADATA_PREFIX</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span> }
791
- 171: <span class="ruby-keyword kw">end</span>
792
- 172: <span class="ruby-identifier">headers</span>
793
- 173: <span class="ruby-keyword kw">end</span>
794
- </pre>
795
- </div>
796
- </div>
797
- </div>
798
-
799
- <div id="method-M000050" class="method-detail">
800
- <a name="M000050"></a>
801
-
802
- <div class="method-heading">
803
- <a href="#M000050" class="method-signature">
804
- <span class="method-name">s3_acl_path</span><span class="method-args">(bucket_name, resource_key)</span>
805
- </a>
806
- </div>
807
-
808
- <div class="method-description">
809
- <p>
810
- Return the location of the ACL for a resource.
811
- </p>
812
- <p><a class="source-toggle" href="#"
813
- onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
814
- <div class="method-source-code" id="M000050-source">
815
- <pre>
816
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 212</span>
817
- 212: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_acl_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>)
818
- 213: <span class="ruby-identifier">s3_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;?acl&quot;</span>
819
- 214: <span class="ruby-keyword kw">end</span>
820
- </pre>
821
- </div>
822
- </div>
823
- </div>
824
-
825
- <div id="method-M000055" class="method-detail">
826
- <a name="M000055"></a>
827
-
828
- <div class="method-heading">
829
- <a href="#M000055" class="method-signature">
830
- <span class="method-name">s3_authenticated_url</span><span class="method-args">(aws_access_key, aws_secret_access_key, bucket_name, resource_key, expires=nil)</span>
831
- </a>
832
- </div>
833
-
834
- <div class="method-description">
835
- <p>
836
- Generate a get-able URL for an S3 resource key which passes authentication
837
- in querystring.
838
- </p>
839
- <p>
840
- int <tt>expires</tt>: when the URL expires (seconds since the epoch); NB
841
- you can use <a href="S33r.html#M000057">S33r.parse_expiry</a> to generate a
842
- suitable value from a string.
843
- </p>
844
- <p><a class="source-toggle" href="#"
845
- onclick="toggleCode('M000055-source');return false;">[Source]</a></p>
846
- <div class="method-source-code" id="M000055-source">
847
- <pre>
848
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 243</span>
849
- 243: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_authenticated_url</span>(<span class="ruby-identifier">aws_access_key</span>, <span class="ruby-identifier">aws_secret_access_key</span>, <span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>,
850
- 244: <span class="ruby-identifier">expires</span>=<span class="ruby-keyword kw">nil</span>)
851
- 245: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">s3_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>)
852
- 246: <span class="ruby-identifier">expires</span> = <span class="ruby-constant">S33r</span>.<span class="ruby-identifier">parse_expiry</span>(<span class="ruby-identifier">expires</span>)
853
- 247:
854
- 248: <span class="ruby-identifier">canonical_string</span> = <span class="ruby-identifier">generate_canonical_string</span>(<span class="ruby-value str">'GET'</span>, <span class="ruby-identifier">path</span>, {}, <span class="ruby-identifier">expires</span>)
855
- 249: <span class="ruby-identifier">signature</span> = <span class="ruby-identifier">generate_signature</span>(<span class="ruby-identifier">aws_secret_access_key</span>, <span class="ruby-identifier">canonical_string</span>)
856
- 250:
857
- 251: <span class="ruby-identifier">querystring</span> = <span class="ruby-identifier">generate_querystring</span>({ <span class="ruby-value str">'Signature'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">signature</span>, <span class="ruby-value str">'Expires'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">expires</span>,
858
- 252: <span class="ruby-value str">'AWSAccessKeyId'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">aws_access_key</span> })
859
- 253:
860
- 254: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">s3_url</span>(<span class="ruby-identifier">path</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">querystring</span>
861
- 255: <span class="ruby-keyword kw">end</span>
862
- </pre>
863
- </div>
864
- </div>
865
- </div>
866
-
867
- <div id="method-M000051" class="method-detail">
868
- <a name="M000051"></a>
869
-
870
- <div class="method-heading">
871
- <a href="#M000051" class="method-signature">
872
- <span class="method-name">s3_logging_path</span><span class="method-args">(bucket_name, resource_key)</span>
873
- </a>
874
- </div>
875
-
876
- <div class="method-description">
877
- <p>
878
- Return the location of the logging definition for a resource.
879
- </p>
880
- <p><a class="source-toggle" href="#"
881
- onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
882
- <div class="method-source-code" id="M000051-source">
883
- <pre>
884
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 217</span>
885
- 217: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_logging_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>)
886
- 218: <span class="ruby-identifier">s3_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>) <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;?logging&quot;</span>
887
- 219: <span class="ruby-keyword kw">end</span>
888
- </pre>
889
- </div>
890
- </div>
891
- </div>
892
-
893
- <div id="method-M000054" class="method-detail">
894
- <a name="M000054"></a>
895
-
896
- <div class="method-heading">
897
- <a href="#M000054" class="method-signature">
898
- <span class="method-name">s3_path</span><span class="method-args">(bucket_name, resource_key)</span>
899
- </a>
900
- </div>
901
-
902
- <div class="method-description">
903
- <p>
904
- Returns the path for this bucket and key.
905
- </p>
906
- <p><a class="source-toggle" href="#"
907
- onclick="toggleCode('M000054-source');return false;">[Source]</a></p>
908
- <div class="method-source-code" id="M000054-source">
909
- <pre>
910
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 233</span>
911
- 233: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>)
912
- 234: <span class="ruby-identifier">path</span> = <span class="ruby-value str">'/'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">bucket_name</span>
913
- 235: <span class="ruby-identifier">path</span> <span class="ruby-operator">+=</span> <span class="ruby-value str">'/'</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">resource_key</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-value str">''</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">resource_key</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">resource_key</span>.<span class="ruby-identifier">nil?</span>
914
- 236: <span class="ruby-identifier">path</span>
915
- 237: <span class="ruby-keyword kw">end</span>
916
- </pre>
917
- </div>
918
- </div>
919
- </div>
920
-
921
- <div id="method-M000053" class="method-detail">
922
- <a name="M000053"></a>
923
-
924
- <div class="method-heading">
925
- <a href="#M000053" class="method-signature">
926
- <span class="method-name">s3_public_url</span><span class="method-args">(bucket_name, resource_key='')</span>
927
- </a>
928
- </div>
929
-
930
- <div class="method-description">
931
- <p>
932
- Public readable URL for a bucket and resource.
933
- </p>
934
- <p><a class="source-toggle" href="#"
935
- onclick="toggleCode('M000053-source');return false;">[Source]</a></p>
936
- <div class="method-source-code" id="M000053-source">
937
- <pre>
938
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 227</span>
939
- 227: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_public_url</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>=<span class="ruby-value str">''</span>)
940
- 228: <span class="ruby-identifier">path</span> = <span class="ruby-identifier">s3_path</span>(<span class="ruby-identifier">bucket_name</span>, <span class="ruby-identifier">resource_key</span>)
941
- 229: <span class="ruby-identifier">s3_url</span>(<span class="ruby-identifier">path</span>)
942
- 230: <span class="ruby-keyword kw">end</span>
943
- </pre>
944
- </div>
945
- </div>
946
- </div>
947
-
948
- <div id="method-M000052" class="method-detail">
949
- <a name="M000052"></a>
950
-
951
- <div class="method-heading">
952
- <a href="#M000052" class="method-signature">
953
- <span class="method-name">s3_url</span><span class="method-args">(path)</span>
954
- </a>
955
- </div>
956
-
957
- <div class="method-description">
958
- <p>
959
- Prepend scheme and HOST to path.
960
- </p>
961
- <p><a class="source-toggle" href="#"
962
- onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
963
- <div class="method-source-code" id="M000052-source">
964
- <pre>
965
- <span class="ruby-comment cmt"># File lib/s33r/core.rb, line 222</span>
966
- 222: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">s3_url</span>(<span class="ruby-identifier">path</span>)
967
- 223: <span class="ruby-value str">&quot;http://&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-constant">HOST</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">path</span>
968
- 224: <span class="ruby-keyword kw">end</span>
969
- </pre>
970
- </div>
971
- </div>
972
- </div>
973
-
974
-
975
- </div>
976
-
977
-
978
- </div>
979
-
980
-
981
- <div id="validator-badges">
982
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
983
- </div>
984
-
985
- </body>
986
- </html>