Skip to content
(Deprecated) A server side Swift SDK for Bluemix Object Storage Service
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Sources
Tests
.gitignore
.ruby-version
.slather.yml
.swift-version
.travis.yml
LICENSE
Package.swift
README.md
install-swiftenv.sh

README.md


This project has been deprecated and is no longer actively maintained. Proceed at your own risk!


BluemixObjectStorage

Bluemix server SDK for Object Storage in Swift

Swift Platform Build Status Codacy Badge Coverage Status

Installation

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/ibm-bluemix-mobile-services/bluemix-objectstorage-serversdk-swift.git", majorVersion: 0, minor: 7)
	]
)
  • 0.7.x releases were tested on OSX and Linux with Swift 3.0.2

Usage

Import the BluemixObjectStorage framework

import BluemixObjectStorage

Objectstorage

Use ObjectStorage instance to connect to IBM Object Storage service and manage containers.

Connect to the IBM Object Storage service using userId and password

let objstorage = ObjectStorage(projectId:"your-project-id")
objstorage.connect(	userId: "your-service-userId",
 					password: "your-service-password",
					region: ObjectStorage.REGION_DALLAS) { (error) in
	if let error = error {
		print("connect error :: \(error)")
	} else {
		print("connect success")
	}							
}

Create a new container

objstorage.createContainer(name: "container-name") { (error, container) in
	if let error = error {
		print("createContainer error :: \(error)")
	} else {
		print("createContainer success :: \(container?.name)")
	}
}

Retrieve an existing container

objstorage.retrieveContainer(name: "container-name") { (error, container) in
	if let error = error {
		print("retrieveContainer error :: \(error)")
	} else {
		print("retrieveContainer success :: \(container?.name)")
	}
}

Retrieve a list of existing containers

objstorage.retrieveContainersList { (error, containers) in
	if let error = error {
		print("retrieveContainersList error :: \(error)")
	} else {
		print("retrieveContainersList success :: \(containers?.description)")
	}
}

Delete an existing container

objstorage.deleteContainer(name: "container-name") { (error) in
	if let error = error {
		print("deleteContainer error :: \(error)")
	} else {
		print("deleteContainer success")
	}
}

Update account metadata

let metadata:Dictionary<String, String> = ["X-Account-Meta-SomeName":"SomeValue"]
objstorage.updateMetadata(metadata: metadata) { (error) in
	if let error = error {
		print("updateMetadata error :: \(error)")
	} else {
		print("updateMetadata success")
	}
}

Retrieve account metadata

objstorage.retrieveMetadata { (error, metadata) in
	if let error = error {
		print("retrieveMetadata error :: \(error)")
	} else {
		print("retrieveMetadata success :: \(metadata)")
	}
}

ObjectStorageContainer

Use ObjectStorageContainer instance to manage objects inside of particular container

Create a new object or update an existing one

#if os(Linux)
	let data = "testdata".dataUsingEncoding(NSUTF8StringEncoding)!
#else
	let data = "testdata".data(using: NSUTF8StringEncoding)!
#endif
let data = str.dataUsingEncoding(NSUTF8StringEncoding)
container.storeObject(name: "object-name", data: data) { (error, object) in
	if let error = error {
		print("storeObject error :: \(error)")
	} else {
		print("storeObject success :: \(object?.name)")
	}
}

Retrieve an existing object

container.retrieveObject(name: "object-name") { (error, object) in
	if let error = error {
		print("retrieveObject error :: \(error)")
	} else {
		print("retrieveObject success :: \(object?.name)")
	}
}

Retrieve a list of existing objects

container.retrieveObjectsList { (error, objects) in
	if let error = error {
		print("retrieveObjectsList error :: \(error)")
	} else {
		print("retrieveObjectsList success :: \(objects?.description)")
	}
}

Delete an existing object

container.deleteObject(name: "object-name") { (error) in
	if let error = error {
		print("deleteObject error :: \(error)")
	} else {
		print("deleteObject success")
	}
}

Delete the container

container.delete { (error) in
	if let error = error {
		print("deleteContainer error :: \(error)")
	} else {
		print("deleteContainer success")
	}
}

Update container metadata

let metadata:Dictionary<String, String> = ["X-Container-Meta-SomeName":"SomeValue"]
container.updateMetadata(metadata: metadata) { (error) in
	if let error = error {
		print("updateMetadata error :: \(error)")
	} else {
		print("updateMetadata success")
	}
}

Retrieve container metadata

container.retrieveMetadata { (error, metadata) in
	if let error = error {
		print("retrieveMetadata error :: \(error)")
	} else {
		print("retrieveMetadata success :: \(metadata)")
	}
}

ObjectStorageObject

Use ObjectStorageObject instance to load object content on demand

Load the object content

object.load(shouldCache: false) { (error, data) in
	if let error = error {
		print("load error :: \(error)")
	} else {
		print("load success :: \(data)")
	}
}

Delete the object

object.delete { (error) in
	if let error = error {
		print("deleteObject error :: \(error)")
	} else {
		print("deleteObject success")
	}
}

Update object metadata

let metadata:Dictionary<String, String> = ["X-Object-Meta-SomeName":"SomeValue"]
object.updateMetadata(metadata: metadata) { (error) in
	if let error = error {
		print("updateMetadata error :: \(error)")
	} else {
		print("updateMetadata success")
	}
}

Retrieve object metadata

object.retrieveMetadata { (error, metadata) in
	if let error = error {
		print("retrieveMetadata error :: \(error)")
	} else {
		print("retrieveMetadata success :: \(metadata)")
	}
}

ObjectStorageError

The ObjectStorageError is an enum with possible failure reasons

enum ObjectStorageError: ErrorType {
	case ConnectionFailure
	case NotFound
	case Unauthorized
	case ServerError
	case InvalidUri
	case FailedToRetrieveAuthToken
	case NotConnected
}

License

Copyright 2016 IBM Corp.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You can’t perform that action at this time.