api

package
v0.0.0-...-d02524b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2019 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package that contains the models of the JSON objects used in the requests and responses and the methods to create new objects that describes the API actions, like the Upload or the AtTokenScraper

Index

Constants

View Source
const (
	// NewUploadURL : Url to which send the request to get a new url to upload a new image
	NewUploadURL = "https://photos.google.com/_/upload/uploadmedia/rupio/interactive?authuser=2"

	// Url to which send the request to enable an uploaded image
	//EnablePhotoUrl = "https://photos.google.com/_/PhotosUi/mutate"
	EnablePhotoUrl = "https://photos.google.com/u/2/_/PhotosUi/data/batchexecute"

	// Url to move an enabled photo into a specific album
	MoveToAlbumUrl = "https://photos.google.com/u/2/_/PhotosUi/data/batchexecute"

	// Url to move an enabled photo into a specific album
	CreateAlbumUrl = "https://photos.google.com/u/2/_/PhotosUi/data/batchexecute"
)
View Source
const (
	GooglePhotoUrl = "https://photos.google.com/"
)

Variables

View Source
var (
	RegexUploadedImageURL = regexp.MustCompile("^https:\\/\\/lh3\\.googleusercontent\\.com\\/([\\w-]+)$")
)

Functions

This section is empty.

Types

type ApiTokenContainer

type ApiTokenContainer struct {
	Token string `json:"SNlM0e"`
}

type AtTokenScraper

type AtTokenScraper struct {
	// contains filtered or unexported fields
}

AtTokenScraper used to scape tokens to upload images

func NewAtTokenScraper

func NewAtTokenScraper(credentials auth.CookieCredentials) *AtTokenScraper

Create a new scraper for the at token. This token is user-dependent, so you need to create a new token scraper for each Credentials object.

func (*AtTokenScraper) ScrapeNewAtToken

func (ts *AtTokenScraper) ScrapeNewAtToken() (string, error)

Use this method to get a new at token. The method makes an http request to Google and uses the user credentials

type CreateSessionRequest

type CreateSessionRequest struct {
	// The fields array is a slice that should contain only ExternalField or InternalField structs
	Fields []interface{} `json:"fields"`
}

Inner object of the request to get a new url to upload a photo.

type ExternalField

type ExternalField struct {
	External ExternalFieldObject `json:"external"`
}

Possible field for the Fields slice in the CreateSessionRequest struct

type ExternalFieldObject

type ExternalFieldObject struct {
	Name     string `json:"name"`
	Filename string `json:"filename"`
	Size     int64  `json:"size"`
}

Describes the file that need to be uploaded. This objects should be contained in a ExternalField

type InlinedField

type InlinedField struct {
	Inlined InlinedFieldObject `json:"inlined"`
}

Possible field for the Fields slice in the CreateSessionRequest struct

type InlinedFieldObject

type InlinedFieldObject struct {
	Name        string `json:"name"`
	Content     string `json:"contentType"`
	ContentType string `json:"contentType"`
}

Used to define parameters of the upload. This object should be contained in a InternalField

type RequestUploadURL

type RequestUploadURL struct {
	ProtocolVersion      string               `json:"protocolVersion"`
	CreateSessionRequest CreateSessionRequest `json:"createSessionRequest"`
}

Structure of the JSON object that it's sent to request a new url to upload a new photo

type Upload

type Upload struct {
	// Options of the upload
	Options *UploadOptions

	// Credentials to used to send the requests
	Credentials auth.CookieCredentials
	// contains filtered or unexported fields
}

Upload represents an upload, generated by an UploadOptions

func NewUpload

func NewUpload(options *UploadOptions, credentials auth.CookieCredentials) (*Upload, error)

NewUpload creates a new Upload given an UploadOptions and a Credentials implementation. This method return an error if the upload options struct it's not usable to create a new upload

func (*Upload) Upload

func (u *Upload) Upload() (*UploadResult, error)

Upload tries to upload an image, making multiple http requests. It returns a response event if there is an error

type UploadOptions

type UploadOptions struct {
	// Required field, a stream from which read the image.
	// You need to close the stream when the image is uploaded
	Stream io.Reader

	// Required field, size of the photo
	FileSize int64

	// Name of the photo (optional)
	Name string

	// UNIX timestamp of the photo (optional)
	Timestamp int64

	// Optional album id
	AlbumId string

	// Optional album name
	AlbumName string
}

UploadOptions contains the Upload options

func NewUploadOptionsFromFile

func NewUploadOptionsFromFile(file *os.File) (*UploadOptions, error)

NewUploadOptionsFromFile creates a new UploadOptions from a file

type UploadResult

type UploadResult struct {
	Uploaded bool
	ImageID  string
	ImageUrl string
	AlbumID  string
}

func (*UploadResult) URLString

func (ur *UploadResult) URLString() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL