TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2015 |
SPMSupports SPM | ✗ |
Maintained by xoyip.
Depends on: | |
AFNetworking | ~> 2.5 |
CryptoSwift | ~> 0.0 |
XMLDictionary | ~> 1.4 |
Regex | ~> 0.2 |
AzureStorageApiClient is api client library for Microsost Azure Storage in Swift. This library only supports MS Azure Queue Storage.
API with
import AzureStorageApiClient
class FooBar {
private let client = AzureBlob.Client(accoutName: "account", useHTTPS: true, hostName: nil)
func handleResponse<T>(response: Response<T>) {
switch response {
case .Success(let wrapper):
println(wrapper.value)
case .Failure(let wrapper):
println(wrapper.value)
}
}
// Lists all of the containers in a storage account.
func listContainers() {
let request = AzureBlob.ListContainersRequest()
blobClient?.call(request, handler: handleResponse)
}
// Creates a new container in a storage account.
func createContainer() {
let request = AzureBlob.CreateContainerRequest(container: "containername")
blobClient?.call(request, handler: handleResponse)
}
// Deletes the container and any blobs that it contains.
func deleteContainer() {
let request = AzureBlob.DeleteContainerRequest(container: "containername")
blobClient?.call(request, handler: handleResponse)
}
// Creates a new blob or replaces an existing blob within a container.
func putBlob() {
if let url = NSURL(string: "https://avatars2.githubusercontent.com/u/3599510?v=3&s=10") {
let data = NSData(contentsOfURL: url)!
let request = AzureBlob.PutBlobRequest(container: "containername", name: "file.png", data: data, mimetype: "image/png")
blobClient?.call(request, handler: handleResponse)
}
}
// Reads or downloads a blob from the Blob service, including its user-defined metadata and system properties.
func getBlob() {
let request = AzureBlob.GetBlobRequest(container: "containername", name: "file.png", mimetype: "image/png")
blobClient?.call(request, handler: handleResponse)
}
// Returns all system properties and user-defined metadata on the blob.
func getBlobProperties() {
let request = AzureBlob.GetBlobPropertiesRequest(container: "containername", name: "file.png")
blobClient?.call(request, handler: handleResponse)
}
}
import AzureStorageApiClient
class FooBar {
private let client = AzureQueue.Client(accoutName: "account", accessKey: "key", useHTTPS: true, hostName: nil)
func handleResponse<T>(response: Response<T>) {
switch response {
case .Success(let wrapper):
println(wrapper.value)
case .Failure(let wrapper):
println(wrapper.value)
}
}
// lists all of the queues in a given storage account
func listQueues() {
let request = AzureStorage.ListQueuesRequest()
client?.call(request, handler: handleResponse)
}
// creates a queue under the given account
func createQueue() {
let request = AzureStorage.CreateQueueRequest(queue: "queuename")
client?.call(request, handler: handleResponse)
}
// permanently deletes the specified queue
func deleteQueue() {
let request = AzureStorage.DeleteQueueRequest(queue: "queuename")
client?.call(request, handler: handleResponse)
}
// adds a new message to the back of the message queue
func putMessage() {
let request = AzureStorage.PutMessagesRequest(queue: "queuename", message: "a message", messageTTL: 3600, visibilityTimeout: 600)
client?.call(request, handler: handleResponse)
}
// retrieves one or more messages from the front of the queue
func getMessages() {
let request = AzureStorage.GetMessagesRequest(queue: "queuename", visibilityTimeout: 600, numberOfMessages: 32)
client?.call(request, handler: handleResponse)
}
// retrieves one or more messages from the front of the queue, but does not alter the visibility of the message
func peekMessage() {
let request = AzureStorage.PeekMessagesRequest(queue: "queuename", numberOfMessages: 32)
client?.call(request, handler: handleResponse)
}
// deletes the specified message
func deleteMessage() {
let request = AzureStorage.DeleteMessageRequest(queue: "queuename", messageId: "message-id(UUID)", popReceipt: "pop-receipt")
client?.call(request, handler: handleResponse)
}
// deletes all messages from the specified queue
func clearMessage() {
let request = AzureStorage.ClearMessagesRequest(queue: "queuename")
client?.call(request, handler: handleResponse)
}
// updates the visibility timeout of a message, the contents of a message
func updateMessage() {
let request = AzureStorage.UpdateMessageRequest(queue: "queuename", message: "new message", messageId: "message-id(UUID)", popReceipt: "pop-receipt", visibilityTimeout: 3600)
client?.call(request, handler: handleResponse)
}
}
Example/AzureStorageApiClient_Example/Config.sample.swift
to Example/AzureStorageApiClient_Example/Config.swift
Example/AzureStorageApiClient_Example/Config.swift
. -> Microsoft Azure Portal Example/AzureStorageApiClient.xcworkspace
and run application.Hiromasa OHno
AzureStorageApiClient is available under the MIT license. See the LICENSE file for more info.