sparqcode-waz-storage 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/CHANGELOG.rdoc +72 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +36 -0
- data/LICENSE +19 -0
- data/README.rdoc +299 -0
- data/lib/waz-blobs.rb +5 -0
- data/lib/waz-queues.rb +6 -0
- data/lib/waz-storage.rb +39 -0
- data/lib/waz-tables.rb +5 -0
- data/lib/waz/blobs/blob_object.rb +121 -0
- data/lib/waz/blobs/container.rb +160 -0
- data/lib/waz/blobs/exceptions.rb +11 -0
- data/lib/waz/blobs/service.rb +156 -0
- data/lib/waz/queues/exceptions.rb +29 -0
- data/lib/waz/queues/message.rb +65 -0
- data/lib/waz/queues/queue.rb +165 -0
- data/lib/waz/queues/service.rb +106 -0
- data/lib/waz/storage/base.rb +70 -0
- data/lib/waz/storage/core_service.rb +122 -0
- data/lib/waz/storage/exceptions.rb +33 -0
- data/lib/waz/storage/validation_rules.rb +26 -0
- data/lib/waz/storage/version.rb +11 -0
- data/lib/waz/tables/edm_type_helper.rb +45 -0
- data/lib/waz/tables/exceptions.rb +45 -0
- data/lib/waz/tables/service.rb +178 -0
- data/lib/waz/tables/table.rb +75 -0
- data/lib/waz/tables/table_array.rb +11 -0
- data/rakefile +23 -0
- data/tests/configuration.rb +14 -0
- data/tests/waz/blobs/blob_object_test.rb +80 -0
- data/tests/waz/blobs/container_test.rb +162 -0
- data/tests/waz/blobs/service_test.rb +282 -0
- data/tests/waz/queues/message_test.rb +33 -0
- data/tests/waz/queues/queue_test.rb +206 -0
- data/tests/waz/queues/service_test.rb +299 -0
- data/tests/waz/storage/base_tests.rb +81 -0
- data/tests/waz/storage/shared_key_core_service_test.rb +142 -0
- data/tests/waz/tables/service_test.rb +614 -0
- data/tests/waz/tables/table_test.rb +98 -0
- data/waz-storage.gemspec +29 -0
- metadata +187 -0
data/.gitignore
ADDED
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
= Revision History for Windows Azure Storage for Ruby
|
2
|
+
=== v1.1 - (smarx)
|
3
|
+
- Upload from stream, plus XML/URI escaping in various places, and a few other minor fixes
|
4
|
+
- Add upload method to container
|
5
|
+
- Add put_block_list to support upload
|
6
|
+
- Fix message canonicalization of ?comp= parameters for versions prior to 2009-09-19 (seems put_block was broken)
|
7
|
+
- Unescape query string parameters when constructing signatures (needed for put_block, since some base64-encoded names include non-URI-friendly characters)
|
8
|
+
- XML-escape property values for table entities (needed to insert things containing &, <, etc.)
|
9
|
+
- Remove Unicode characters from rakefile (was breaking something on Windows)
|
10
|
+
- Add tests for put_block_list and upload
|
11
|
+
- Fix tests for content type (typo, = instead of .should ==)
|
12
|
+
- Fix tests using RestClient.beautify_headers (expects an array, not a scalar)
|
13
|
+
|
14
|
+
=== v1.0.6 - (hermes.logicalbricks)
|
15
|
+
- Update tests to rspec 2.5.0
|
16
|
+
- Allow authorization using only SharedAccessSignature
|
17
|
+
|
18
|
+
=== v1.0.5 - (tomconte)
|
19
|
+
- Fixed for list_blobs as it wasn't fully merged to 2009-09-19. Now it works without 403 exceptions
|
20
|
+
|
21
|
+
=== v1.0.3 - (Johnny Halife)
|
22
|
+
- Merged with sriramk fix for loading path issues on some environments
|
23
|
+
|
24
|
+
=== v1.0.2 - (Johnny Halife)
|
25
|
+
- Completed Blobs API migration to 2009-09-19, _fully supporting_ what third-party tools does (e.g. Cerebrata) [thanks percent20]
|
26
|
+
|
27
|
+
=== v1.0.1 - (Johnny halife)
|
28
|
+
- Added syntax's sugar for ensuring a queue (get or create)
|
29
|
+
|
30
|
+
=== v1.0 - (Juan Pablo Garcia Dalolla)
|
31
|
+
- Added support for table service to query, get_one, insert, update, merge and delete entities.
|
32
|
+
- Added support for running against the Storage Developement Fabriq shipped with Microsoft SDK.
|
33
|
+
- Added signature support for Tables service according to msdn.microsoft.com/en-us/library/dd179428.aspx
|
34
|
+
- Added support to enumerate, create, and delete tables on give storage account.
|
35
|
+
- Improved support for stacked connection management.
|
36
|
+
|
37
|
+
=== v0.5.81 - (Johnny Halife)
|
38
|
+
- When simulating a container using a forward slash starting the blob name it crashed with 404, now it's fixed.
|
39
|
+
|
40
|
+
=== v0.5.8 - (Johnny Halife)
|
41
|
+
- Fixed an issue on the Queues Documentation (thanks @ezequielm)
|
42
|
+
- Added _naming validation for Containers_ according to http://msdn.microsoft.com/en-us/library/dd135715.aspx (thanks @panosjee)
|
43
|
+
- Added _naming validation for Queues_ according to http://msdn.microsoft.com/en-us/library/dd179349.aspx (thanks @panosjee)
|
44
|
+
- Added _support for Blob snapshots_
|
45
|
+
- Added support for rest-client 1.3.0. (thanks @jpgd)
|
46
|
+
|
47
|
+
=== v0.5.7 - (Johnny Halife)
|
48
|
+
- Fixes a critical bug on URL management that some time prevents message from being deleted, caused by a missing encoding on the URL parameters.
|
49
|
+
|
50
|
+
=== v0.5.6 - (Johnny Halife)
|
51
|
+
- Added signature support for 2009-09-19 Version of the Storage API
|
52
|
+
- Queues API has been migrated to the 2009-09-19 Version of the Storage API
|
53
|
+
- Added a new parameter for listing queues with metadata
|
54
|
+
- Added support for DequeueCount on messages being retrieved from the Queue
|
55
|
+
- <strong>Known Issue</strong>: Creating a queue multiple times with same metadata throws 409.
|
56
|
+
|
57
|
+
=== v0.5.5 - (Johnny Halife)
|
58
|
+
- Added a Change Log
|
59
|
+
- Added support for copy-blob [WAZ::Blobs::BlobObject.copy("container/blob_name")]
|
60
|
+
- Refactored out the whole request logic to an _execute_ method on the SharedKeyCoreService
|
61
|
+
- Added transparent support for block management (users don't know if their blob is being uploaded chunked or not)
|
62
|
+
- Added support for a blob to list its blocks
|
63
|
+
|
64
|
+
=== v0.5.4 - Sat Oct 17 19:35:48 2009 -0300 (Johnny Halife)
|
65
|
+
- Fixed method name for String.start_with? (previously starts_with?)
|
66
|
+
|
67
|
+
=== v0.5.3 - Sat Oct 17 18:20:51 2009 -0300 (Johnny Halife)
|
68
|
+
- Added the stack-based contextual connection handling (WAZ::Storage::Base.establish_connection {|block| }
|
69
|
+
- Added string extensions for non rails environments (and work to work on heroku) String.starts_with?
|
70
|
+
|
71
|
+
=== v0.5.2 - Thu Oct 15 22:08:01 2009 -0300 (Johnny Halife)
|
72
|
+
- Initial Version
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
waz-storage (1.1.1)
|
5
|
+
rest-client
|
6
|
+
ruby-hmac
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.1.3)
|
12
|
+
metaclass (0.0.1)
|
13
|
+
mime-types (1.18)
|
14
|
+
mocha (0.10.5)
|
15
|
+
metaclass (~> 0.0.1)
|
16
|
+
rcov (1.0.0)
|
17
|
+
rest-client (1.6.7)
|
18
|
+
mime-types (>= 1.16)
|
19
|
+
rspec (2.9.0)
|
20
|
+
rspec-core (~> 2.9.0)
|
21
|
+
rspec-expectations (~> 2.9.0)
|
22
|
+
rspec-mocks (~> 2.9.0)
|
23
|
+
rspec-core (2.9.0)
|
24
|
+
rspec-expectations (2.9.1)
|
25
|
+
diff-lcs (~> 1.1.3)
|
26
|
+
rspec-mocks (2.9.0)
|
27
|
+
ruby-hmac (0.4.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
mocha
|
34
|
+
rcov
|
35
|
+
rspec
|
36
|
+
waz-storage!
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Johnny G. Halife
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,299 @@
|
|
1
|
+
= Windows Azure Storage library — simple gem for accessing WAZ‘s Storage REST API
|
2
|
+
A simple implementation of Windows Azure Storage API for Ruby, inspired by the S3 gems and self experience of dealing with queues. The major
|
3
|
+
goal of the whole gem is to enable ruby developers [like me =)] to leverage Windows Azure Storage features and have another option
|
4
|
+
for cloud storage.
|
5
|
+
|
6
|
+
The whole gem is implemented based on Microsoft's specs from the communication and underlying service description and protocol (REST). The API
|
7
|
+
is for ruby developers built by a ruby developer. I'm trying to follow idioms, patterns and fluent type of doing APIs on Ruby.
|
8
|
+
|
9
|
+
This work isn't related at all with StorageClient Sample shipped with Microsoft SDK and written in .NET, the whole API is based on my own understanding,
|
10
|
+
experience and values of elegance and ruby development.
|
11
|
+
|
12
|
+
Full documentation for the gem is available at http://waz-storage.heroku.com
|
13
|
+
|
14
|
+
=== How does this differ from <em>waz-queues</em> and <em>waz-blobs</em> work?
|
15
|
+
Well, this is a sum up of the whole experience of writing those gems and getting them to work together to simplify
|
16
|
+
end user experience. Although there're some breaking changes, it's pretty backward compatible with existing gems.
|
17
|
+
|
18
|
+
=== What's new on the v1.1 version? [thanks to smarx]
|
19
|
+
- Upload from stream, plus XML/URI escaping in various places, and a few other minor fixes
|
20
|
+
- Add upload method to container
|
21
|
+
- Add put_block_list to support upload
|
22
|
+
- Fix message canonicalization of ?comp= parameters for versions prior to 2009-09-19 (seems put_block was broken)
|
23
|
+
- Unescape query string parameters when constructing signatures (needed for put_block, since some base64-encoded names include non-URI-friendly characters)
|
24
|
+
- XML-escape property values for table entities (needed to insert things containing &, <, etc.)
|
25
|
+
- Remove Unicode characters from rakefile (was breaking something on Windows)
|
26
|
+
- Add tests for put_block_list and upload
|
27
|
+
- Fix tests for content type (typo, = instead of .should ==)
|
28
|
+
- Fix tests using RestClient.beautify_headers (expects an array, not a scalar)
|
29
|
+
|
30
|
+
=== What's new on the v1.0.6 version? [thanks to hermes.logicalbricks]
|
31
|
+
- Update tests to rspec 2.5.0
|
32
|
+
- Allow authorization using only SharedAccessSignature
|
33
|
+
|
34
|
+
=== What's new on the version version?
|
35
|
+
- Fixed for list_blobs as it wasn't fully merged to 2009-09-19. Now it works without 403 exceptions [Thanks tomconte]
|
36
|
+
|
37
|
+
=== What's new on the v1.0.3 version?
|
38
|
+
- Merged with sriramk fix for loading path issues on some environments
|
39
|
+
|
40
|
+
=== What's new on the 1.0.2 version?
|
41
|
+
- Completed Blobs API migration to 2009-09-19, _fully supporting_ what third-party tools does (e.g. Cerebrata) [thanks percent20]
|
42
|
+
|
43
|
+
=== What's new on the 1.0.1 version?
|
44
|
+
- Added Syntax's sugar for ensuring a Queue (get or create)
|
45
|
+
|
46
|
+
=== What's new on the 1.0 version?
|
47
|
+
- Added support for table service to query, get_one, insert, update, merge and delete entities.
|
48
|
+
- Added support for running against the Storage Developement Fabriq shipped with Microsoft SDK.
|
49
|
+
- Added signature support for Tables service according to msdn.microsoft.com/en-us/library/dd179428.aspx
|
50
|
+
- Added support to enumerate, create, and delete tables on give storage account.
|
51
|
+
- Improved support for stacked connection management.
|
52
|
+
|
53
|
+
=== What's new on the 0.5.81 version?
|
54
|
+
- When simulating a container using a forward slash starting the blob name it crashed with 404, now it's fixed.
|
55
|
+
|
56
|
+
=== What's new on the 0.5.8 version?
|
57
|
+
- Fixed an issue on the Queues Documentation (thanks @ezequielm)
|
58
|
+
- Added <b>naming validation for Containers</b> according to http://msdn.microsoft.com/en-us/library/dd135715.aspx (thanks @panosjee)
|
59
|
+
- Added <b>naming validation for Queues</b> according to http://msdn.microsoft.com/en-us/library/dd179349.aspx (thanks @panosjee)
|
60
|
+
- Added <b>support for Blob snapshots</b>
|
61
|
+
- Added support for rest-client 1.3.0. (thanks @jpgd)
|
62
|
+
|
63
|
+
=== What's new on the 0.5.7 version?
|
64
|
+
- Fixes a critical bug on URL management that some time prevents messages from being deleted, caused by a missing encoding on the URL parameters.
|
65
|
+
|
66
|
+
=== What's new on the 0.5.6 version?
|
67
|
+
- Added new <b>shared key authentication support for 2009-09-19 Version of the Storage API</b>
|
68
|
+
- Queues API has been migrated to the <b>2009-09-19 Version of the Storage API</b>
|
69
|
+
- Added a new parameter for <b>listing queues with metadata</b>
|
70
|
+
- Added support for <b>DequeueCount</b> on messages being retrieved from the Queue
|
71
|
+
- <b>Known Issue</b>: Creating a queue multiple times with same metadata throws 409.
|
72
|
+
|
73
|
+
== Getting started
|
74
|
+
sudo gem install waz-storage --source http://gemcutter.org
|
75
|
+
|
76
|
+
== Basic Configuration
|
77
|
+
One of the major changes from the waz-queues and waz-blobs APIs was the ability to set a single storage account (99% of the cases) to be
|
78
|
+
used on your code just once. Since Windows Azure Storage Services are all related to a single account that includes Tables, Queues and Blobs,
|
79
|
+
I've changed the API in order to make ease that administration by requiring you to set the configuration just once:
|
80
|
+
|
81
|
+
require 'waz-queues' #=> if you want to use queues
|
82
|
+
require 'waz-blobs' #=> if you want to use blobs (or you can include both for using both)
|
83
|
+
|
84
|
+
WAZ::Storage::Base.establish_connection!(:account_name => account_name,
|
85
|
+
:access_key => access_key)
|
86
|
+
|
87
|
+
As you can see you, the way to get started it pretty simple, just include the establish_connection! call on your application bootstrapper, for example
|
88
|
+
if you are doing a sinatra-rb application it can be
|
89
|
+
|
90
|
+
configure :production do
|
91
|
+
# here is were you hook up with WAZ Storage Stuff.
|
92
|
+
end
|
93
|
+
|
94
|
+
That's all you need to get started and running your Windows Azure Code on a sinatra application.
|
95
|
+
|
96
|
+
== Usage: Queues
|
97
|
+
Windows Azure Queues are extremely powerful for asyc programming, they are very useful when you don’t need "always consistent"
|
98
|
+
data operations allowing you to enqueue and process on background. It’s important to mention that being WAZ-Queues a buffered
|
99
|
+
message system, you should design for idempotent operations given the fact that there’s no guarantee that a message can be repeated.
|
100
|
+
|
101
|
+
The implementation of the Windows Azure Queues REST API available online at http://msdn.microsoft.com/en-us/library/dd179363.aspx is fully
|
102
|
+
covered here.
|
103
|
+
|
104
|
+
Here's a quick getting started of the usage of the API:
|
105
|
+
|
106
|
+
WAZ::Storage::Base.establish_connection!(:account_name => account_name,
|
107
|
+
:access_key => access_key)
|
108
|
+
|
109
|
+
# NEW! Now you can do ensure and it will return the queue, first trying to retrieve it
|
110
|
+
# and then if it doesn't exist, will created it
|
111
|
+
queue = WAZ::Queues::Queue.ensure('my-queue')
|
112
|
+
|
113
|
+
# excepts that the metadata for the queue changes this method behaves as PUT (create/replace)
|
114
|
+
# remarks: it performs a validation whether metadata changed or not (if changed HTTP 409 conflict)
|
115
|
+
queue = WAZ::Queues::Queue.create('my-queue')
|
116
|
+
|
117
|
+
10.times do |m|
|
118
|
+
# enqueue a receives string. Message content can be anything up to 8KB
|
119
|
+
# you can serialize and send anything that serializes to UTF-8 string (JSON, XML, etc)
|
120
|
+
queue.enqueue!("message##{m}")
|
121
|
+
end
|
122
|
+
|
123
|
+
while(queue.size > 0) do
|
124
|
+
# Since WAZ implements the peek lock pattern we are locking messages (not dequeuing)
|
125
|
+
# it has two parameters how many messages and for how long they are locked
|
126
|
+
messages = queue.lock(10)
|
127
|
+
|
128
|
+
puts "dequeued message: #{messages.size}"
|
129
|
+
|
130
|
+
# deletes the message from the queue so other clients do not pick it after
|
131
|
+
# visibility time out expires
|
132
|
+
messages.each {|m| m.destroy!}
|
133
|
+
end
|
134
|
+
|
135
|
+
It's pretty intuitive, but full documentation (RDoc) is available for the API for further reference.
|
136
|
+
|
137
|
+
== Usage: Blobs
|
138
|
+
The blobs implementation inside this gem is fully compliant with the spec available at http://msdn.microsoft.com/en-us/library/dd135733.aspx. The Windows
|
139
|
+
Azure Blobs REST API isn't fully covered here (see TODO's for more information). It's pretty usable and stable right now,
|
140
|
+
I've been doing lot of testing around and it works seamlessly with the current Windows Azure implementation.
|
141
|
+
|
142
|
+
require 'waz-blobs'
|
143
|
+
|
144
|
+
WAZ::Storage::Base.establish_connection!(:account_name => account_name,
|
145
|
+
:access_key => access_key)
|
146
|
+
|
147
|
+
# creates a container
|
148
|
+
container = WAZ::Blobs::Container.create('my-container')
|
149
|
+
|
150
|
+
# stores a blob with custom properties (metadata)
|
151
|
+
blob = container.store('my_blob.txt',
|
152
|
+
'this is the content of my blob',
|
153
|
+
'plain/text',
|
154
|
+
{:x_ms_meta_Custom_Property => "custom_value" })
|
155
|
+
|
156
|
+
# return a specific blob from a container
|
157
|
+
blob = container['my_blob.txt']
|
158
|
+
|
159
|
+
# retrieves a blob value
|
160
|
+
blob.value
|
161
|
+
|
162
|
+
It's pretty intuitive, but full documentation (RDoc) is available for the API for further reference.
|
163
|
+
|
164
|
+
=== Using Blob with Shared Acess Signature
|
165
|
+
This feature allow to access a blob only with the information of the blob's name, the container, and the Shared Access Signature. If you don't have permission to perform an action (for example: list the blobs, create a new blob or something like that) you will receive an exception. If you want more details about this: http://msdn.microsoft.com/en-us/library/ee395415.aspx
|
166
|
+
|
167
|
+
require 'waz-blobs'
|
168
|
+
|
169
|
+
WAZ::Storage::Base.establish_connection!(:account_name=> 'mysharedblob',
|
170
|
+
:use_sas_auth_only=> true,
|
171
|
+
:sharedaccesssignature =>"?se=XXXXXX&sr=c&si=XXXXX&sig=XXXXXXXXXXXXXXXXXXXXX")
|
172
|
+
|
173
|
+
container = WAZ::Blobs::Container.new(:name=>'container')
|
174
|
+
|
175
|
+
blob = container.store('myfile.txt',File.read('fileofthecontent.txt'),'plain/text')
|
176
|
+
|
177
|
+
The feature was only tested storing a blob.
|
178
|
+
|
179
|
+
== Usage: Tables
|
180
|
+
The tables implementation inside this gem is fully compliant with the spec available at http://msdn.microsoft.com/en-us/library/dd179423.aspx. The Windows
|
181
|
+
Azure Tables REST API is fully covered here.
|
182
|
+
|
183
|
+
require 'waz-storage'
|
184
|
+
require 'waz-tables'
|
185
|
+
|
186
|
+
WAZ::Storage::Base.establish_connection!(:account_name => account_name,
|
187
|
+
:access_key => access_key)
|
188
|
+
|
189
|
+
# creates a new table
|
190
|
+
table = WAZ::Tables::Table.create('my-table')
|
191
|
+
|
192
|
+
# list available tables
|
193
|
+
# (returns a maximum of 1,000 items at one time (more details here: http://msdn.microsoft.com/en-us/library/dd135718.aspx)
|
194
|
+
tables = WAZ::Tables::Table.list
|
195
|
+
|
196
|
+
# more tables
|
197
|
+
WAZ::Tables::Table.list(tables.continuation_token)
|
198
|
+
|
199
|
+
# get a specific table, returning nil when the specified table is not found
|
200
|
+
my_table = WAZ::Tables::Table.find('my-table')
|
201
|
+
|
202
|
+
# table properties
|
203
|
+
my_table.name
|
204
|
+
my_table.url
|
205
|
+
|
206
|
+
# delete a table
|
207
|
+
my_table.destroy!
|
208
|
+
|
209
|
+
# Entity operations using the Table service
|
210
|
+
|
211
|
+
# get the existing service instance
|
212
|
+
service = WAZ::Tables::Table.service_instance
|
213
|
+
|
214
|
+
# define a new entity
|
215
|
+
entity = { :address => 'Mountain View',
|
216
|
+
:age => 23,
|
217
|
+
:amount_due => 200.23,
|
218
|
+
:binary_data => File.open(__FILE__),
|
219
|
+
:customer_code => 'aaaaaaaa-bbbb-cccc-dddd-aaaabbbbcccc',
|
220
|
+
:customer_since => Time.now.utc,
|
221
|
+
:is_active => true,
|
222
|
+
:num_of_orders => 255,
|
223
|
+
:partition_key => 'customer',
|
224
|
+
:row_key => "myRowKey#{rand(2000000).to_s}",
|
225
|
+
:Timestamp => Time.now.utc }
|
226
|
+
|
227
|
+
# inserts a new entity
|
228
|
+
service.insert_entity('customer_table', entity)
|
229
|
+
|
230
|
+
# retrieves all entities from a table
|
231
|
+
# (returns a maximum of 1,000 items at one time (more details here: http://msdn.microsoft.com/en-us/library/dd135718.aspx)
|
232
|
+
# Remarks on development storage it retrieves all items instead the first 1,000
|
233
|
+
entities = service.query('customer_table')
|
234
|
+
|
235
|
+
# retrieves more entities providing the obtained continuation_token
|
236
|
+
service.query('customer_table', {:continuation_token => entities.continuation_token} )
|
237
|
+
|
238
|
+
# retrieves all records that match with the specified query but only the first fifteen rows
|
239
|
+
service.query('customer_table', {:expression => "(PartitionKey eq 'customer') and (Age eq 23)", :top => 15} )
|
240
|
+
|
241
|
+
# get an existing entity by its partion_key and row_key
|
242
|
+
entity = service.get_entity('customer_table', 'customer', 'rowKey1')
|
243
|
+
|
244
|
+
# updates an entity
|
245
|
+
entity[:age] = 90
|
246
|
+
service.update_entity('customer_table', new_entity)
|
247
|
+
|
248
|
+
# merges an entity (more details here: http://msdn.microsoft.com/en-us/library/dd179392.aspx)
|
249
|
+
entity[:age] = 20
|
250
|
+
service.merge_entity('customer_table', new_entity)
|
251
|
+
|
252
|
+
# deletes an entity
|
253
|
+
service.delete_entity('customer_table', 'customer', 'rowKey1')
|
254
|
+
|
255
|
+
It's pretty intuitive, but full documentation (RDoc) is available for the API for further reference.
|
256
|
+
|
257
|
+
== Usage: Contextual Connection Handling
|
258
|
+
Sometimes while you are building a web application you may require handling different storage account but contextualized. The sample
|
259
|
+
that comes to my mind is something like a Storage Explorer or Account Monitor for WAZ.
|
260
|
+
|
261
|
+
That is why? I've added a new way of handling a stack-based contextual connection handling. The usage is pretty simple:
|
262
|
+
|
263
|
+
WAZ::Storage::Base.establish_connection(options) do
|
264
|
+
container = WAZ::Blobs::Container.find('container-name')
|
265
|
+
blob = container['blob-name']
|
266
|
+
blob.destroy!
|
267
|
+
end
|
268
|
+
|
269
|
+
As it is described on the example above, there's a new way of establishing a connection and use it on a given block. The whole implementation
|
270
|
+
is stack based, and will let you scope your context for some rare cases where you have another account.
|
271
|
+
|
272
|
+
*Disclaimer*: Moving objects across context isn't contemplated yet, and if you try to do changes among scopes you will get
|
273
|
+
to some wired Windows Azure Errors regarding objects that may not exist.
|
274
|
+
|
275
|
+
=== Remarks
|
276
|
+
Windows Azure Storage API works flawlessly from Heroku and custom ruby hosting deployments on EC2, as far as I tested it. You can leverage the storage
|
277
|
+
services without the need of having to write the application on .NET or hosting your application on Windows Azure.
|
278
|
+
|
279
|
+
The documentation and implementation exposed here is for the pre-release version and is subject to change on the future.
|
280
|
+
|
281
|
+
=== TODO's
|
282
|
+
As far as users start using it, I'll be building a backlog and probably handling a wish-list of features, but right now I've the following
|
283
|
+
TODO's already enqueued for further releases of the waz-storage API.
|
284
|
+
|
285
|
+
-Generate a sample application to better show the usage.
|
286
|
+
|
287
|
+
The things listed above do not represent any sort of priority, or the order they are going to be tackled. It's just a list.
|
288
|
+
|
289
|
+
== Meta
|
290
|
+
|
291
|
+
Written by Johnny G. Halife (johnny.halife at me dot com)
|
292
|
+
|
293
|
+
contributed by: Ezequiel Morito (http://twitter.com/ezequielm), Juan Pablo Garcia (http://twitter.com/jpgd), Steve Marx (http://twitter.com/smarx)
|
294
|
+
|
295
|
+
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
|
296
|
+
|
297
|
+
http://waz-storage.heroku.com
|
298
|
+
|
299
|
+
http://github.com/johnnyhalife/waz-storage
|