This open-source library allows you to integrate Ricoh Media Storage into your Swift app.
Learn more at http://docs.ricohapi.com/
- Swift 2.2+
- Xcode 7.3.1+
You'll also need
- Ricoh API Client Credentials (client_id & client_secret)
- Ricoh ID (user_id & password)
If you don't have them, please register yourself and your client from THETA Developers Website.
This section shows you two different methods to install Ricoh Media Storage for Swift in your application.
See Media Storage Sample to try out a sample of Ricoh Media Storage for Swift.
- If it is your first time to use CocoaPods, run the following commands to set it up.
$ gem install cocoapods
$ pod setup
- Go to your project directory.
- Create a Podfile by running
pod init
( if you do not have one yet ), and specifyRicohAPIMStorage
as follows:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target 'YourAppName' do
pod 'RicohAPIMStorage', '~> 2.0.0'
end
- Run
pod install
to installRicohAPIMStorage
. - Open your project's workspace.
- Choose your application scheme and run it to load the RicohAPIMStorage module.
- Install completed! See Sample Flow for a coding example.
- Clone Ricoh Media Storage for Swift by running the following commands:
$ git clone --recursive https://github.com/ricohapi/media-storage-swift.git
-
Open the new
media-storage-swift
directory, and dragRicohAPIMStorage.xcodeproj
into the Project Navigator of your project.It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.
-
Choose RicohAPIAuth scheme at the scheme menu of Xcode and run it.
-
Choose your application scheme and run it to load the RicohAPIMStorage module.
-
Install completed! See Sample Flow for a coding example.
// Import
import RicohAPIAuth
import RicohAPIMStorage
// Set your Ricoh API Client Credentials
var authClient = AuthClient(
clientId: "<your_client_id>",
clientSecret: "<your_client_secret>"
)
@IBAction func uploadButtonTapped(sender: AnyObject) {
// Set your resource owner credentials (Ricoh ID)
authClient.setResourceOwnerCreds(
userId: "<your_user_id>",
userPass: "<your_password>"
)
// Initialize a MediaStorage object with the AuthClient object
let mstorage = MediaStorage(authClient: authClient)
// Connect to the server
mstorage.connect(){result, error in
//Prepare an NSData object in your way
let mediaUrl = NSBundle.mainBundle().URLForResource("<your_media_name>", withExtension: "jpg")
let mediaData = NSData(contentsOfURL: mediaUrl!)!
// Upload
mstorage.upload(data: mediaData){result, error in
if !error.isEmpty() {
print("status code: \(error.statusCode)")
print("error message: \(error.message)")
} else {
print("media id : \(result.id)")
print("media contentType : \(result.contentType)")
print("media bytes : \(result.bytes)")
print("created at : \(result.createdAt)")
}
}
}
}
var authClient = AuthClient(
clientId: "<your_client_id>",
clientSecret: "<your_client_secret>"
)
authClient.setResourceOwnerCreds(
userId: "<your_user_id>",
userPass: "<your_password>"
)
var mstorage = MediaStorage(authClient: authClient)
mstorage.connect(){result, error in
if error.isEmpty() {
var accessToken: String = result.accessToken
// do something
}
}
let data: NSData = ...
mstorage.upload(data){result, error in
if error.isEmpty() {
var id: String = result.id
var contentType: String = result.contentType
var bytes: Int = result.bytes
var createdAt: String = result.createdAt
// do something
}
}
mstorage.download("<media_id>"){result, error in
if error.isEmpty() {
var data: NSData = result.data
// do something
}
}
- Without options
You'll get a default list if you set nothing or an empty Dictionary
object on the first parameter.
mstorage.list(){result, error in
if error.isEmpty() {
var mediaList: Array = result.mediaList
for media in mediaList {
var id: String = media.id
}
var pagingNext: String? = result.paging.next
var pagingPrevious: String? = result.paging.previous
// do something
}
}
- With options
You can also use a Dictionary
object for listing options as follows.
The available options are limit
, after
and before
.
mstorage.list(["limit": "25", "after": "<media_id>"]){result, error in
// do something
}
- Search
You can add another Dictionary
object with filter
key into the listing options to search by user metadata.
mstorage.list(["limit": "25", "after": "<media_id>",
"filter": ["meta.user.<key1>": "<value1>", "meta.user.<key2>": "<value2>"]]){result, error in
// do something
}
mstorage.delete("<media_id>"){error in
if error.isEmpty() {
// do something
}
}
mstorage.info("<media_id>"){result, error in
if error.isEmpty() {
var id: String = result.id
var contentType: String = result.contentType
var bytes: Int = result.bytes
var createdAt: String = result.createdAt
// do something
}
}
You can define your original metadata as a 'user metadata'. Existing metadata value for the same key will be overwritten. Up to 10 user metadata can be attached to a media data.
mstorage.addMeta("<media_id>", ["user.<key1>": "<value1>", "user.<key2>": "<value2>"]){error in
if error.isEmpty() {
// do something
}
}
- All
mstorage.meta("<media_id>"){result, error in
if error.isEmpty() {
var exif: [String: String] = result.exif
var gpano: [String: String] = result.gpano
var userMeta: [String: String] = result.userMeta
// do something
}
}
- Exif
mstorage.meta("<media_id>", "exif"){result, error in
if error.isEmpty() {
var exif: [String: String] = result
// do something
}
}
- Google Photo Sphere XMP
mstorage.meta("<media_id>", "gpano"){result, error in
if error.isEmpty() {
var gpano: [String: String] = result
// do something
}
}
- User metadata (all)
mstorage.meta("<media_id>", "user"){result, error in
if error.isEmpty() {
var userMeta: [String: String] = result
// do something
}
}
- User metadata (with a key)
mstorage.meta("<media_id>", "user.<key>"){result, error in
if error.isEmpty() {
var value: String = result["<key>"]
// do something
}
}
- User metadata (all)
mstorage.removeMeta("<media_id>", "user"){error in
if error.isEmpty() {
// do something
}
}
- User metadata (with a key)
mstorage.removeMeta("<media_id>", "user.<key>"){error in
if error.isEmpty() {
// do something
}
}