Skip to content
This repository has been archived by the owner on Jan 21, 2019. It is now read-only.

Writing a Client Implementation

Matt Holt edited this page Jan 11, 2017 · 4 revisions

By implementing a client to a cloud service, you can enable Photobak to work with that service. It's not hard. 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. A collection is like an album, and an item is like a photo or video.

You must ensure that all items can be accessed through a collection, even if the collection is fake. In other words, all photos/videos must belong to a collection in order for Photobak to archive them successfully.

PLEASE please please read the godoc for what is required of each method you implement. It's not much to ask, but each service might have its own caveats. Document those caveats when you submit a pull request.

Be sure to test thoroughly that your implementation is working.

Have fun!

Note

Although Photobak is designed to work with multimedia (by extracting EXIF data, etc), I don't think it will fail if used with other types of cloud storage. So technically, I think other kinds of cloud storage providers like S3 could be implemented if desired.

Clone this wiki locally