google_storage 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,12 +1,35 @@
1
1
  h1. Google Storage using API v2
2
2
 
3
- I wrote this gem because the only google storage gems I could find already written were either written a while ago and only set up to use the old
3
+ I wrote this gem because the only google storage gems I could find already written were either written a while ago and only set up to use the original
4
4
  version of Google's API or they were dependent on Gems that don't run properly on... dare I say it... windows.. :) Apologies, I'm without choice
5
5
  at the moment, but anyways, this gem should run fine on all platforms and I've tried to keep dependencies to a minimum. Let me know if you find
6
6
  any bugs though ok and feel free to contribute.
7
7
 
8
- Google Storage is still a little experimental at the moment and the responses back from google differ quite a bit from each other.
9
- I've tried to parse all of these different responses and turn them into a fairly common type of response object though.
8
+ h2. Response Object
9
+
10
+ A lot of the responses from GS on the backend are a little bit inconsistent, sometimes returning response codes, sometimes returning heavily
11
+ nested xml data and sometimes just returning information in the response header. I've tried to parse all responses that are returned from GS into a fairly
12
+ consistent type of response Hash object. Usually this is in the form of something like this:
13
+
14
+ <pre>
15
+ #successful responses will always include a :success => true key/value pair
16
+
17
+ client.list_buckets
18
+ => {:success=>true,
19
+ :buckets=>[ {"Name"=>"bucket_1_example", "CreationDate"=>"2011-06-07T07:11:18.480Z"},
20
+ {"Name"=>"bucket_2_example", "CreationDate"=>"2011-05-31T10:58:08.097Z"},
21
+ {"Name"=>"bucket_3_example", "CreationDate"=>"2011-06-06T22:47:10.728Z"}],
22
+ :raw=>{ THIS :raw FIELD WILL RETURN A HASH OF THE UNPARSED RESPONSE IN CASE YOU NEED IT }
23
+ }
24
+
25
+ #Unsuccessful responses will return an "Error" Hash
26
+
27
+ client.get_bucket("bucket_4_example")
28
+ => {"Error"=>{
29
+ "Code"=>"NoSuchBucket",
30
+ "Message"=>"The specified bucket does not exist."
31
+ }}
32
+ </pre>
10
33
 
11
34
  h2. Setup Guide
12
35
 
@@ -22,7 +45,7 @@ But it's also possible to run this gem from the command line if you want.
22
45
  h2. Install the google_storage Gem
23
46
 
24
47
  Include the google_storage gem in your Gemfile and install config files
25
- <pre>gem "google_storage"
48
+ <pre>gem 'google_storage'
26
49
  bundle install
27
50
  </pre>
28
51
  Then in your Rails application directory run:
@@ -107,4 +130,65 @@ web_applications:
107
130
  # Google Storage API
108
131
  </pre>
109
132
 
110
- Once you've acquired your refresh_token you can now make calls to the API. Refer to the examples dir on how to use.
133
+ Once you've acquired your refresh_token you can now make calls to the API.
134
+
135
+
136
+ h2. Examples
137
+
138
+ h3. Configuration
139
+
140
+ <pre>require 'google_storage'</pre>
141
+
142
+ The following will look for google_storage.yml in your rails config directory
143
+ <pre>client = GoogleStorage::Client.new</pre>
144
+
145
+ Otherwise you can pass in the path to the google_storage.yml
146
+ <pre>client = GoogleStorage::Client.new(:config_yml => 'C:/github/highvoltage/config/google_storage.yml')
147
+ </pre>
148
+
149
+ h3. Service Requests
150
+
151
+ GET Service
152
+ <pre>client.list_buckets</pre>
153
+
154
+ h3. Bucket Requests
155
+
156
+ GET Access Control List for Bucket
157
+ <pre>client.bucket_acls('bucket_name')</pre>
158
+
159
+ PUT Bucket
160
+ <pre>client.create_bucket('bucket_name') # < private bucket
161
+ client.create_bucket('bucket_name', :x_goog_acl => 'public-read') # < public bucket </pre>
162
+
163
+ GET Bucket
164
+ <pre>client.get_bucket('bucket_name')</pre>
165
+
166
+ DELETE Bucket
167
+ <pre>client.delete_bucket('bucket_name')</pre>
168
+
169
+ h3. Object Requests
170
+
171
+ GET Access Control List for Object
172
+ <pre>client.object_acls('bucket_name', 'filename.jpg')</pre>
173
+
174
+ GET Object
175
+ <pre>client.get_object('bucket_name', 'filename.jpg')
176
+ client.get_object('bucket_name', 'filename.jpg', :write_to_file => 'c:/temp/new_file_name.jpg')</pre>
177
+
178
+ POST Object
179
+ <pre>Sorry, not including a 'post' object method as it still requires use of the old legacy access,
180
+ Please use the 'put' object method below instead to upload files to a bucket.</pre>
181
+
182
+ PUT Object
183
+ <pre>client.put_object('bucket_name', 'filename.jpg', :data => File.read('c:/temp/file.jpg'), :x_goog_acl => 'public-read')
184
+ client.upload_object('bucket_name', 'filename.jpg', :path_to_file => 'c:/temp/file.jpg')</pre>
185
+
186
+ HEAD Object
187
+ <pre>client.object_head('bucket_name', 'filename.jpg')</pre>
188
+
189
+ DELETE Object
190
+ <pre>client.delete_object('bucket_name', 'filename.jpg')</pre>
191
+
192
+
193
+
194
+
@@ -971,18 +971,18 @@ Example:
971
971
  <pre class="lines">
972
972
 
973
973
 
974
- 172
975
- 173
976
- 174
977
974
  175
978
975
  176
979
976
  177
980
977
  178
981
978
  179
982
- 180</pre>
979
+ 180
980
+ 181
981
+ 182
982
+ 183</pre>
983
983
  </td>
984
984
  <td>
985
- <pre class="code"><span class="info file"># File 'lib/google_storage/object.rb', line 172</span>
985
+ <pre class="code"><span class="info file"># File 'lib/google_storage/object.rb', line 175</span>
986
986
 
987
987
  <span class='kw'>def</span> <span class='id delete_object'>delete_object</span><span class='lparen'>(</span><span class='id bucket_name'>bucket_name</span><span class='comma'>,</span> <span class='id filename'>filename</span><span class='comma'>,</span> <span class='id options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
988
988
  <span class='id filename'>filename</span><span class='period'>.</span><span class='id gsub!'>gsub!</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^\/</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
@@ -1133,7 +1133,10 @@ Example:
1133
1133
  44
1134
1134
  45
1135
1135
  46
1136
- 47</pre>
1136
+ 47
1137
+ 48
1138
+ 49
1139
+ 50</pre>
1137
1140
  </td>
1138
1141
  <td>
1139
1142
  <pre class="code"><span class="info file"># File 'lib/google_storage/object.rb', line 23</span>
@@ -1147,7 +1150,7 @@ Example:
1147
1150
  <span class='kw'>begin</span>
1148
1151
  <span class='const'>File</span><span class='period'>.</span><span class='id open'>open</span><span class='lparen'>(</span><span class='id options'>options</span><span class='lbracket'>[</span><span class='symbol'>:write_to_file</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>wb</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id f'>f</span><span class='op'>|</span> <span class='id f'>f</span><span class='period'>.</span><span class='id write'>write</span><span class='lparen'>(</span><span class='id resp'>resp</span><span class='period'>.</span><span class='id body'>body</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
1149
1152
  <span class='kw'>rescue</span> <span class='const'>Exception</span> <span class='op'>=&gt;</span> <span class='id msg'>msg</span>
1150
- <span class='kw'>return</span> <span class='lbrace'>{</span><span class='symbol'>:error</span> <span class='op'>=&gt;</span> <span class='id msg'>msg</span><span class='rbrace'>}</span>
1153
+ <span class='kw'>return</span> <span class='lbrace'>{</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Error</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='id msg'>msg</span><span class='rbrace'>}</span>
1151
1154
  <span class='kw'>end</span>
1152
1155
  <span class='id resp_obj'>resp_obj</span><span class='period'>.</span><span class='id clear'>clear</span>
1153
1156
  <span class='id resp_obj'>resp_obj</span><span class='lbracket'>[</span><span class='symbol'>:success</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='kw'>true</span>
@@ -1162,6 +1165,9 @@ Example:
1162
1165
  <span class='id resp_obj'>resp_obj</span><span class='lbracket'>[</span><span class='symbol'>:size</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id resp'>resp</span><span class='period'>.</span><span class='id header'>header</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>content-length</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span>
1163
1166
 
1164
1167
  <span class='kw'>return</span> <span class='id resp_obj'>resp_obj</span>
1168
+
1169
+
1170
+
1165
1171
  <span class='kw'>end</span></pre>
1166
1172
  </td>
1167
1173
  </tr>
@@ -1264,9 +1270,6 @@ Example:
1264
1270
  <pre class="lines">
1265
1271
 
1266
1272
 
1267
- 118
1268
- 119
1269
- 120
1270
1273
  121
1271
1274
  122
1272
1275
  123
@@ -1276,10 +1279,13 @@ Example:
1276
1279
  127
1277
1280
  128
1278
1281
  129
1279
- 130</pre>
1282
+ 130
1283
+ 131
1284
+ 132
1285
+ 133</pre>
1280
1286
  </td>
1281
1287
  <td>
1282
- <pre class="code"><span class="info file"># File 'lib/google_storage/object.rb', line 118</span>
1288
+ <pre class="code"><span class="info file"># File 'lib/google_storage/object.rb', line 121</span>
1283
1289
 
1284
1290
  <span class='kw'>def</span> <span class='id object_acls'>object_acls</span><span class='lparen'>(</span><span class='id bucket_name'>bucket_name</span><span class='comma'>,</span> <span class='id filename'>filename</span><span class='comma'>,</span> <span class='id options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
1285
1291
  <span class='id filename'>filename</span><span class='period'>.</span><span class='id gsub!'>gsub!</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^\/</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
@@ -1332,9 +1338,6 @@ Example:
1332
1338
  <pre class="lines">
1333
1339
 
1334
1340
 
1335
- 144
1336
- 145
1337
- 146
1338
1341
  147
1339
1342
  148
1340
1343
  149
@@ -1346,10 +1349,13 @@ Example:
1346
1349
  155
1347
1350
  156
1348
1351
  157
1349
- 158</pre>
1352
+ 158
1353
+ 159
1354
+ 160
1355
+ 161</pre>
1350
1356
  </td>
1351
1357
  <td>
1352
- <pre class="code"><span class="info file"># File 'lib/google_storage/object.rb', line 144</span>
1358
+ <pre class="code"><span class="info file"># File 'lib/google_storage/object.rb', line 147</span>
1353
1359
 
1354
1360
  <span class='kw'>def</span> <span class='id object_head'>object_head</span><span class='lparen'>(</span><span class='id bucket_name'>bucket_name</span><span class='comma'>,</span> <span class='id filename'>filename</span><span class='comma'>,</span> <span class='id options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
1355
1361
  <span class='id filename'>filename</span><span class='period'>.</span><span class='id gsub!'>gsub!</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^\/</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
@@ -1427,9 +1433,6 @@ Available Options:
1427
1433
  <pre class="lines">
1428
1434
 
1429
1435
 
1430
- 74
1431
- 75
1432
- 76
1433
1436
  77
1434
1437
  78
1435
1438
  79
@@ -1455,10 +1458,13 @@ Available Options:
1455
1458
  99
1456
1459
  100
1457
1460
  101
1458
- 102</pre>
1461
+ 102
1462
+ 103
1463
+ 104
1464
+ 105</pre>
1459
1465
  </td>
1460
1466
  <td>
1461
- <pre class="code"><span class="info file"># File 'lib/google_storage/object.rb', line 74</span>
1467
+ <pre class="code"><span class="info file"># File 'lib/google_storage/object.rb', line 77</span>
1462
1468
 
1463
1469
  <span class='kw'>def</span> <span class='id put_object'>put_object</span><span class='lparen'>(</span><span class='id bucket_name'>bucket_name</span><span class='comma'>,</span> <span class='id filename'>filename</span><span class='comma'>,</span> <span class='id options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span>
1464
1470
  <span class='id filename'>filename</span><span class='period'>.</span><span class='id gsub!'>gsub!</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^\/</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
@@ -1472,7 +1478,7 @@ Available Options:
1472
1478
  <span class='ivar'>@data</span> <span class='op'>=</span> <span class='id uploaded_file'>uploaded_file</span><span class='period'>.</span><span class='id read'>read</span>
1473
1479
  <span class='kw'>end</span>
1474
1480
  <span class='kw'>rescue</span> <span class='const'>Exception</span> <span class='op'>=&gt;</span> <span class='id msg'>msg</span>
1475
- <span class='kw'>return</span> <span class='lbrace'>{</span><span class='symbol'>:error</span> <span class='op'>=&gt;</span> <span class='id msg'>msg</span><span class='rbrace'>}</span>
1481
+ <span class='kw'>return</span> <span class='lbrace'>{</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Error</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='id msg'>msg</span><span class='rbrace'>}</span>
1476
1482
  <span class='kw'>end</span>
1477
1483
  <span class='id options'>options</span><span class='lbracket'>[</span><span class='symbol'>:data</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='ivar'>@data</span>
1478
1484
  <span class='kw'>end</span>
@@ -1499,7 +1505,7 @@ Available Options:
1499
1505
  </div>
1500
1506
 
1501
1507
  <div id="footer">
1502
- Generated on Tue Jun 28 10:28:04 2011 by
1508
+ Generated on Fri Jul 1 12:07:25 2011 by
1503
1509
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1504
1510
  0.7.2 (ruby-1.9.2).
1505
1511
  </div>
@@ -211,7 +211,7 @@ Example:
211
211
  </div>
212
212
 
213
213
  <div id="footer">
214
- Generated on Tue Jun 28 10:28:04 2011 by
214
+ Generated on Fri Jul 1 12:07:25 2011 by
215
215
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
216
216
  0.7.2 (ruby-1.9.2).
217
217
  </div>
@@ -97,7 +97,7 @@
97
97
  <dt id="VERSION-constant" class="">VERSION =
98
98
 
99
99
  </dt>
100
- <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.0.4</span><span class='tstring_end'>&quot;</span></span></pre></dd>
100
+ <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>0.1.1</span><span class='tstring_end'>&quot;</span></span></pre></dd>
101
101
 
102
102
  </dl>
103
103
 
@@ -111,7 +111,7 @@
111
111
  </div>
112
112
 
113
113
  <div id="footer">
114
- Generated on Tue Jun 28 10:28:04 2011 by
114
+ Generated on Fri Jul 1 12:07:25 2011 by
115
115
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
116
116
  0.7.2 (ruby-1.9.2).
117
117
  </div>
data/doc/_index.html CHANGED
@@ -127,7 +127,7 @@
127
127
  </div>
128
128
 
129
129
  <div id="footer">
130
- Generated on Tue Jun 28 10:28:04 2011 by
130
+ Generated on Fri Jul 1 12:07:24 2011 by
131
131
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
132
132
  0.7.2 (ruby-1.9.2).
133
133
  </div>
data/doc/file.README.html CHANGED
@@ -55,12 +55,33 @@
55
55
  <iframe id="search_frame"></iframe>
56
56
 
57
57
  <div id="content"><div id='filecontents'><h1>Google Storage using <span class="caps">API</span> v2</h1>
58
- <p>I wrote this gem because the only google storage gems I could find already written were either written a while ago and only set up to use the old
58
+ <p>I wrote this gem because the only google storage gems I could find already written were either written a while ago and only set up to use the original
59
59
  version of Google&#8217;s <span class="caps">API</span> or they were dependent on Gems that don&#8217;t run properly on&#8230; dare I say it&#8230; windows.. :) Apologies, I&#8217;m without choice
60
60
  at the moment, but anyways, this gem should run fine on all platforms and I&#8217;ve tried to keep dependencies to a minimum. Let me know if you find
61
61
  any bugs though ok and feel free to contribute.</p>
62
- <p>Google Storage is still a little experimental at the moment and the responses back from google differ quite a bit from each other.
63
- I&#8217;ve tried to parse all of these different responses and turn them into a fairly common type of response object though.</p>
62
+ <h2>Response Object</h2>
63
+ <p>A lot of the responses from GS on the backend are a little bit inconsistent, sometimes returning response codes, sometimes returning heavily
64
+ nested xml data and sometimes just returning information in the response header. I&#8217;ve tried to parse all responses that are returned from GS into a fairly
65
+ consistent type of response Hash object. Usually this is in the form of something like this:</p>
66
+ <pre class="code">
67
+ #successful responses will always include a :success =&gt; true key/value pair
68
+
69
+ client.list_buckets
70
+ =&gt; {:success=&gt;true,
71
+ :buckets=&gt;[ {&quot;Name&quot;=&gt;&quot;bucket_1_example&quot;, &quot;CreationDate&quot;=&gt;&quot;2011-06-07T07:11:18.480Z&quot;},
72
+ {&quot;Name&quot;=&gt;&quot;bucket_2_example&quot;, &quot;CreationDate&quot;=&gt;&quot;2011-05-31T10:58:08.097Z&quot;},
73
+ {&quot;Name&quot;=&gt;&quot;bucket_3_example&quot;, &quot;CreationDate&quot;=&gt;&quot;2011-06-06T22:47:10.728Z&quot;}],
74
+ :raw=&gt;{ THIS :raw FIELD WILL RETURN A HASH OF THE UNPARSED RESPONSE IN CASE YOU NEED IT }
75
+ }
76
+
77
+ #Unsuccessful responses will return an &quot;Error&quot; Hash
78
+
79
+ client.get_bucket(&quot;bucket_4_example&quot;)
80
+ =&gt; {&quot;Error&quot;=&gt;{
81
+ &quot;Code&quot;=&gt;&quot;NoSuchBucket&quot;,
82
+ &quot;Message&quot;=&gt;&quot;The specified bucket does not exist.&quot;
83
+ }}
84
+ </pre>
64
85
  <h2>Setup Guide</h2>
65
86
  <p>There&#8217;s a couple of steps to follow in order to setup this gem. The new Google Storage APIv2 uses OAuth 2.0 to authenticate requests, you can read up
66
87
  more on the nitty gritty if you like here: <a href="http://code.google.com/apis/accounts/docs/OAuth2.html">Google&#8217;s OAuth2 Guide</a></p>
@@ -141,10 +162,47 @@ web_applications:
141
162
  # 7. Copy and paste the refresh_token into this file. Your application should now be able to make calls to your
142
163
  # Google Storage API
143
164
  </pre>
144
- <p>Once you&#8217;ve acquired your refresh_token you can now make calls to the <span class="caps">API</span>. Refer to the examples dir on how to use.</p></div></div>
165
+ <p>Once you&#8217;ve acquired your refresh_token you can now make calls to the <span class="caps">API</span>.</p>
166
+ <h2>Examples</h2>
167
+ <h3>Configuration</h3>
168
+ <pre class="code"><span class='id require'>require</span> <span class='id “google_storage”'>“google_storage”</span></pre>
169
+ The following will look for google_storage.yml in your rails config directory
170
+ <pre class="code"><span class='id client'>client</span> <span class='op'>=</span> <span class='const'>GoogleStorage</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id new'>new</span></pre>
171
+ Otherwise you can pass in the path to the google_storage.yml
172
+ <pre class="code">client = GoogleStorage::Client.new(:config_yml =&gt; ‘C:/github/highvoltage/config/google_storage.yml’)
173
+ </pre>
174
+ <h3>Service Requests</h3>
175
+ <span class="caps">GET</span> Service
176
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id list_buckets'>list_buckets</span></pre>
177
+ <h3>Bucket Requests</h3>
178
+ <span class="caps">GET</span> Access Control List for Bucket
179
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id bucket_acls'>bucket_acls</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='rparen'>)</span></pre>
180
+ <span class="caps">PUT</span> Bucket
181
+ <pre class="code">client.create_bucket(‘bucket_name’) &lt;— private bucket
182
+ client.create_bucket(‘bucket_name’, :x_goog_acl =&gt; ‘public-read’) &lt;— public bucket </pre>
183
+ <span class="caps">GET</span> Bucket
184
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id get_bucket'>get_bucket</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='rparen'>)</span></pre>
185
+ <span class="caps">DELETE</span> Bucket
186
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id delete_bucket'>delete_bucket</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='rparen'>)</span></pre>
187
+ <h3>Object Requests</h3>
188
+ <span class="caps">GET</span> Access Control List for Object
189
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id object_acls'>object_acls</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='comma'>,</span> <span class='id ‘filename'>‘filename</span><span class='period'>.</span><span class='id jpg’'>jpg’</span><span class='rparen'>)</span></pre>
190
+ <span class="caps">GET</span> Object
191
+ <pre class="code">client.get_object(‘bucket_name’, ‘filename.jpg’)
192
+ client.get_object(‘bucket_name’, ‘filename.jpg’, :write_to_file =&gt; ‘c:/temp/new_file_name.jpg’)</pre>
193
+ <span class="caps">POST</span> Object
194
+ <pre class="code">Sorry, not including a ‘post’ object method as it still requires use of the old legacy access,
195
+ Please use the ‘put’ object method below instead to upload files to a bucket.</pre>
196
+ <span class="caps">PUT</span> Object
197
+ <pre class="code">client.put_object(‘bucket_name’, ‘filename.jpg’, :data =&gt; File.read(‘c:/temp/file.jpg’), :x_goog_acl =&gt; ‘public-read’)
198
+ client.upload_object(‘bucket_name’, ‘filename.jpg’, :path_to_file =&gt; ‘c:/temp/file.jpg’)</pre>
199
+ <span class="caps">HEAD</span> Object
200
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id object_head'>object_head</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='comma'>,</span> <span class='id ‘filename'>‘filename</span><span class='period'>.</span><span class='id jpg’'>jpg’</span><span class='rparen'>)</span></pre>
201
+ <span class="caps">DELETE</span> Object
202
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id delete_object'>delete_object</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='comma'>,</span> <span class='id ‘filename'>‘filename</span><span class='period'>.</span><span class='id jpg’'>jpg’</span><span class='rparen'>)</span></pre></div></div>
145
203
 
146
204
  <div id="footer">
147
- Generated on Tue Jun 28 10:28:04 2011 by
205
+ Generated on Fri Jul 1 12:07:25 2011 by
148
206
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
149
207
  0.7.2 (ruby-1.9.2).
150
208
  </div>
data/doc/index.html CHANGED
@@ -55,12 +55,33 @@
55
55
  <iframe id="search_frame"></iframe>
56
56
 
57
57
  <div id="content"><div id='filecontents'><h1>Google Storage using <span class="caps">API</span> v2</h1>
58
- <p>I wrote this gem because the only google storage gems I could find already written were either written a while ago and only set up to use the old
58
+ <p>I wrote this gem because the only google storage gems I could find already written were either written a while ago and only set up to use the original
59
59
  version of Google&#8217;s <span class="caps">API</span> or they were dependent on Gems that don&#8217;t run properly on&#8230; dare I say it&#8230; windows.. :) Apologies, I&#8217;m without choice
60
60
  at the moment, but anyways, this gem should run fine on all platforms and I&#8217;ve tried to keep dependencies to a minimum. Let me know if you find
61
61
  any bugs though ok and feel free to contribute.</p>
62
- <p>Google Storage is still a little experimental at the moment and the responses back from google differ quite a bit from each other.
63
- I&#8217;ve tried to parse all of these different responses and turn them into a fairly common type of response object though.</p>
62
+ <h2>Response Object</h2>
63
+ <p>A lot of the responses from GS on the backend are a little bit inconsistent, sometimes returning response codes, sometimes returning heavily
64
+ nested xml data and sometimes just returning information in the response header. I&#8217;ve tried to parse all responses that are returned from GS into a fairly
65
+ consistent type of response Hash object. Usually this is in the form of something like this:</p>
66
+ <pre class="code">
67
+ #successful responses will always include a :success =&gt; true key/value pair
68
+
69
+ client.list_buckets
70
+ =&gt; {:success=&gt;true,
71
+ :buckets=&gt;[ {&quot;Name&quot;=&gt;&quot;bucket_1_example&quot;, &quot;CreationDate&quot;=&gt;&quot;2011-06-07T07:11:18.480Z&quot;},
72
+ {&quot;Name&quot;=&gt;&quot;bucket_2_example&quot;, &quot;CreationDate&quot;=&gt;&quot;2011-05-31T10:58:08.097Z&quot;},
73
+ {&quot;Name&quot;=&gt;&quot;bucket_3_example&quot;, &quot;CreationDate&quot;=&gt;&quot;2011-06-06T22:47:10.728Z&quot;}],
74
+ :raw=&gt;{ THIS :raw FIELD WILL RETURN A HASH OF THE UNPARSED RESPONSE IN CASE YOU NEED IT }
75
+ }
76
+
77
+ #Unsuccessful responses will return an &quot;Error&quot; Hash
78
+
79
+ client.get_bucket(&quot;bucket_4_example&quot;)
80
+ =&gt; {&quot;Error&quot;=&gt;{
81
+ &quot;Code&quot;=&gt;&quot;NoSuchBucket&quot;,
82
+ &quot;Message&quot;=&gt;&quot;The specified bucket does not exist.&quot;
83
+ }}
84
+ </pre>
64
85
  <h2>Setup Guide</h2>
65
86
  <p>There&#8217;s a couple of steps to follow in order to setup this gem. The new Google Storage APIv2 uses OAuth 2.0 to authenticate requests, you can read up
66
87
  more on the nitty gritty if you like here: <a href="http://code.google.com/apis/accounts/docs/OAuth2.html">Google&#8217;s OAuth2 Guide</a></p>
@@ -141,10 +162,47 @@ web_applications:
141
162
  # 7. Copy and paste the refresh_token into this file. Your application should now be able to make calls to your
142
163
  # Google Storage API
143
164
  </pre>
144
- <p>Once you&#8217;ve acquired your refresh_token you can now make calls to the <span class="caps">API</span>. Refer to the examples dir on how to use.</p></div></div>
165
+ <p>Once you&#8217;ve acquired your refresh_token you can now make calls to the <span class="caps">API</span>.</p>
166
+ <h2>Examples</h2>
167
+ <h3>Configuration</h3>
168
+ <pre class="code"><span class='id require'>require</span> <span class='id “google_storage”'>“google_storage”</span></pre>
169
+ The following will look for google_storage.yml in your rails config directory
170
+ <pre class="code"><span class='id client'>client</span> <span class='op'>=</span> <span class='const'>GoogleStorage</span><span class='op'>::</span><span class='const'>Client</span><span class='period'>.</span><span class='id new'>new</span></pre>
171
+ Otherwise you can pass in the path to the google_storage.yml
172
+ <pre class="code">client = GoogleStorage::Client.new(:config_yml =&gt; ‘C:/github/highvoltage/config/google_storage.yml’)
173
+ </pre>
174
+ <h3>Service Requests</h3>
175
+ <span class="caps">GET</span> Service
176
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id list_buckets'>list_buckets</span></pre>
177
+ <h3>Bucket Requests</h3>
178
+ <span class="caps">GET</span> Access Control List for Bucket
179
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id bucket_acls'>bucket_acls</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='rparen'>)</span></pre>
180
+ <span class="caps">PUT</span> Bucket
181
+ <pre class="code">client.create_bucket(‘bucket_name’) &lt;— private bucket
182
+ client.create_bucket(‘bucket_name’, :x_goog_acl =&gt; ‘public-read’) &lt;— public bucket </pre>
183
+ <span class="caps">GET</span> Bucket
184
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id get_bucket'>get_bucket</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='rparen'>)</span></pre>
185
+ <span class="caps">DELETE</span> Bucket
186
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id delete_bucket'>delete_bucket</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='rparen'>)</span></pre>
187
+ <h3>Object Requests</h3>
188
+ <span class="caps">GET</span> Access Control List for Object
189
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id object_acls'>object_acls</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='comma'>,</span> <span class='id ‘filename'>‘filename</span><span class='period'>.</span><span class='id jpg’'>jpg’</span><span class='rparen'>)</span></pre>
190
+ <span class="caps">GET</span> Object
191
+ <pre class="code">client.get_object(‘bucket_name’, ‘filename.jpg’)
192
+ client.get_object(‘bucket_name’, ‘filename.jpg’, :write_to_file =&gt; ‘c:/temp/new_file_name.jpg’)</pre>
193
+ <span class="caps">POST</span> Object
194
+ <pre class="code">Sorry, not including a ‘post’ object method as it still requires use of the old legacy access,
195
+ Please use the ‘put’ object method below instead to upload files to a bucket.</pre>
196
+ <span class="caps">PUT</span> Object
197
+ <pre class="code">client.put_object(‘bucket_name’, ‘filename.jpg’, :data =&gt; File.read(‘c:/temp/file.jpg’), :x_goog_acl =&gt; ‘public-read’)
198
+ client.upload_object(‘bucket_name’, ‘filename.jpg’, :path_to_file =&gt; ‘c:/temp/file.jpg’)</pre>
199
+ <span class="caps">HEAD</span> Object
200
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id object_head'>object_head</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='comma'>,</span> <span class='id ‘filename'>‘filename</span><span class='period'>.</span><span class='id jpg’'>jpg’</span><span class='rparen'>)</span></pre>
201
+ <span class="caps">DELETE</span> Object
202
+ <pre class="code"><span class='id client'>client</span><span class='period'>.</span><span class='id delete_object'>delete_object</span><span class='lparen'>(</span><span class='id ‘bucket_name’'>‘bucket_name’</span><span class='comma'>,</span> <span class='id ‘filename'>‘filename</span><span class='period'>.</span><span class='id jpg’'>jpg’</span><span class='rparen'>)</span></pre></div></div>
145
203
 
146
204
  <div id="footer">
147
- Generated on Tue Jun 28 10:28:04 2011 by
205
+ Generated on Fri Jul 1 12:07:25 2011 by
148
206
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
149
207
  0.7.2 (ruby-1.9.2).
150
208
  </div>
@@ -94,7 +94,7 @@
94
94
  </div>
95
95
 
96
96
  <div id="footer">
97
- Generated on Tue Jun 28 10:28:04 2011 by
97
+ Generated on Fri Jul 1 12:07:25 2011 by
98
98
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
99
99
  0.7.2 (ruby-1.9.2).
100
100
  </div>
data/examples/examples.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # client = GoogleStorage::Client.new
7
7
  #
8
8
  # Otherwise you can pass in the path to the google_storage.yml
9
- # client = GoogleStorage::Client.new(:config_yml => 'C:/example_path/config/google_storage.yml')
9
+ # client = GoogleStorage::Client.new(:config_yml => 'C:/github/highvoltage/config/google_storage.yml')
10
10
  #
11
11
  ### Service Requests ###
12
12
  #
@@ -82,7 +82,7 @@ Example: GoogleStorage::Client.new(:config_yml => 'path to your google storage y
82
82
 
83
83
  @client_id = config_yml['web_applications']['client_id']
84
84
  @client_secret = config_yml['web_applications']['client_secret']
85
- @client_secret.force_encoding("UTF-8")
85
+ @client_secret.force_encoding("UTF-8") if @client_secret.respond_to?(:force_encoding)
86
86
  @refresh_token = config_yml['refresh_token'] if config_yml['refresh_token']
87
87
 
88
88
  #TODO Add support for individual permission types
@@ -29,7 +29,7 @@ module GoogleStorage
29
29
  begin
30
30
  File.open(options[:write_to_file], 'wb') {|f| f.write(resp.body) }
31
31
  rescue Exception => msg
32
- return {:error => msg}
32
+ return {"Error" => msg}
33
33
  end
34
34
  resp_obj.clear
35
35
  resp_obj[:success] = true
@@ -44,6 +44,9 @@ module GoogleStorage
44
44
  resp_obj[:size] = resp.header["content-length"]
45
45
 
46
46
  return resp_obj
47
+
48
+
49
+
47
50
  end
48
51
 
49
52
  ###
@@ -83,7 +86,7 @@ module GoogleStorage
83
86
  @data = uploaded_file.read
84
87
  end
85
88
  rescue Exception => msg
86
- return {:error => msg}
89
+ return {"Error" => msg}
87
90
  end
88
91
  options[:data] = @data
89
92
  end
@@ -1,3 +1,3 @@
1
1
  module GoogleStorage
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-28 00:00:00.000000000Z
12
+ date: 2011-07-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: crack
16
- requirement: &10204272 !ruby/object:Gem::Requirement
16
+ requirement: &10174068 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *10204272
24
+ version_requirements: *10174068
25
25
  description: A Ruby client library for using the new Google Storage API v2 using OAuth2.0
26
26
  email:
27
27
  - lucas@lucashills.com