Git Product home page Git Product logo

bluemix-objectstorage-clientsdk-swift's Introduction


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


[BluemixObjectStorageSDK]

Object Storage

Bluemix Client SDK for Object Storage in Swift

Build Status Platform Codacy Badge Coverage Status

Table of Contents

Summary

Object Storage provides an unstructured cloud data store to build and deliver cloud applications and services with lowered cost, reliability, and speed to market. Bluemix developers and users can access and store unstructured data content and can interactively compose and connect to applications and services. The Object Storage service also provides programmatic access via API, SDKs and a consumable UI for object management.

You can use this client SDK to store and retrieve binary data on your Object Storage service instance on Bluemix from your iOS application.

Read the official documentation for information about getting started with Object Storage.

Requirements

  • iOS 8.0+
  • Xcode 8+
  • Swift 3.0

Installation

The Bluemix Mobile Services Swift SDKs are available via Cocoapods and Carthage.

Cocoapods

To install BluemixObjectStorage using Cocoapods, add it to your Podfile:

use_frameworks!

target 'MyApp' do
    pod 'BluemixObjectStorage'
end

Make sure you have Cocoapods version 1.1.0.rc.2 (or later) installed. Then run the pod install command. To update to a newer release of BluemixObjectStorage, use pod update BluemixObjectStorage.

Carthage

To install BMSAnalytics with Carthage, follow the instructions here.

Add this line to your Cartfile:

github "ibm-bluemix-mobile-services/bluemix-objectstorage-clientdsk-swift"

Then run the carthage update command. Once the build is finished, add BluemixObjectStorage.framework, BMSCore.framework and BMSAnalyticsAPI.framework to your project.

Example Usage

View the complete API reference here.

--

Importing module

Adding the framework
import BluemixObjectStorage

View examples

--

Connecting to Object Storage

Use ObjectStorage instance to connect to IBM Object Storage service.

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")
	}							
}
Connect to the IBM Object Storage service using explicit authToken
let objstorage = ObjectStorage(projectId: "your-project-id")
objstorage.connect(authToken: "your-auth-token",
		   		   region: ObjectStorage.Region.Dallas) { (error) in
	if let error = error {
		print("connect error :: \(error)")
	} else {
		print("connect success")
	}							
}

View examples

--

Managing containers

Use ObjectStorage instance to manage containers.

Create a new container
objstorage.create(container: "container-name") { (error, container) in
	if let error = error {
		print("create container error :: \(error)")
	} else {
		print("create container success :: \(container?.name)")
	}
}
Retrieve an existing container
objstorage.retrieve(container: "container-name") { (error, container) in
	if let error = error {
		print("retrieve container error :: \(error)")
	} else {
		print("retrieve container success :: \(container?.name)")
	}
}
Retrieve a list of existing containers
objstorage.retrieveContainersList { (error, containers) in
	if let error = error {
		print("retrieve containers list error :: \(error)")
	} else {
		print("retrieve containers list success :: \(containers?.description)")
	}
}
Delete an existing container
objstorage.delete(container: "container-name") { (error) in
	if let error = error {
		print("delete container error :: \(error)")
	} else {
		print("delete container success")
	}
}

You can also use ObjectStorageContainer instance to manage containers

Delete the container
container.delete { (error) in
	if let error = error {
		print("delete container error :: \(error)")
	} else {
		print("delete container success")
	}
}
Update container metadata
let metadata = ["X-Container-Meta-SomeName": "SomeValue"]
container.update(metadata: metadata) { (error) in
	if let error = error {
		print("update metadata error :: \(error)")
	} else {
		print("update metadata success")
	}
}
Retrieve container metadata
container.retrieveMetadata { (error, metadata) in
	if let error = error {
		print("retrieveMetadata error :: \(error)")
	} else {
		print("retrieveMetadata success :: \(metadata)")
	}
}

View examples

--

Managing Objects

Use ObjectStorageContainer instance to manage objects inside of particular container

Create a new object or update an existing one
let data = "testdata".data(using: .utf8)!
container.store(object: "object-name", data: data) { (error, object) in
	if let error = error {
		print("store object error :: \(error)")
	} else {
		print("store object success :: \(object?.name)")
	}
}
Retrieve an existing object
container.retrieve(object: "object-name") { (error, object) in
	if let error = error {
		print("retrieve object error :: \(error)")
	} else {
		print("retrieve object 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.delete(object: "object-name") { (error) in
	if let error = error {
		print("delete object error :: \(error)")
	} else {
		print("delete object success")
	}
}

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)")
	}
}
Update object metadata
let metadata = ["X-Object-Meta-SomeName": "SomeValue"]
object.update(metadata: metadata) { (error) in
	if let error = error {
		print("update metadata error :: \(error)")
	} else {
		print("update metadata success")
	}
}
Retrieve object metadata
object.retrieveMetadata { (error, metadata) in
	if let error = error {
		print("retrieve metadata error :: \(error)")
	} else {
		print("retrieve metadata success :: \(metadata)")
	}
}

View examples

--

Account metadata

Update account metadata
let metadata = ["X-Account-Meta-SomeName": "SomeValue"]
objstorage.update(metadata: metadata) { (error) in
	if let error = error {
		print("update metadata error :: \(error)")
	} else {
		print("update metadata success")
	}
}
Retrieve account metadata
objstorage.retrieveMetadata { (error, metadata) in
	if let error = error {
		print("retrieve metadata error :: \(error)")
	} else {
		print("retrieve metadata success :: \(metadata)")
	}
}

View examples

--

Types of errors

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
	case cannotRefreshAuthToken
}

View examples

--

License

This package contains code licensed under the Apache License, Version 2.0 (the "License"). You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 and may also view the License in the LICENSE file within this package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.