This repository was archived by the owner on Jan 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Writing a Client Implementation
Matt Holt edited this page Jan 10, 2017
·
4 revisions
By implementing a client to a cloud service, you can enable Photobak to work with that service. Pull requests welcome!
Create a new package. Here's a template:
// Package providername implements Provider Name access for photobak.
package providername
import (
"encoding/gob"
"flag"
"github.com/mholt/photobak"
)
const (
name = "providername"
title = "Provider Name"
)
func init() {
// Allow accounts for this service to be configured from the command line
var accounts photobak.StringFlagList
flag.Var(&accounts, name, "Add a "+title+" account to the repository")
photobak.RegisterProvider(photobak.Provider{
Name: name,
Title: title,
Accounts: func() []string { return accounts },
Credentials: /* function to get credentials */,
NewClient: /* function to get new client */,
})
// Register the type(s) used to implement the photobak.Item
// and photobak.Collection interfaces. They can actually be
// the same concrete type if that works better with the API.
// This is very important so your type can be stored in the DB.
gob.Register(AlbumType{})
gob.Register(PhotoType{})
}
As you can see, we've registered the provider type with Photobak. You'll need to write functions that return credentials for a given username and return an API client given some credentials.
Then, you'll just have to:
- Implement the photobak.Client interface. This is the type that will be used to interact with the cloud provider's API.
- Implement the photobak.Collection and photobak.Item interfaces. These are mainly used for storage.
Be sure to test thoroughly that your implementation is working. Have fun!