apiVideo

package module
v0.0.0-...-ead00f2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2018 License: MIT Imports: 6 Imported by: 0

README

Api.video golang sdk Build Status Go Report Card

Golang sdk for the api of api.video, maintained by Fris.

Documentations

GoDocs.

Example

NOTICE: Make you sure to edit the login credentials with yours when using the example code !

package main

import (
   "fmt"
   "github.com/OGFris/api.video"
)

func main() {
   c := &apiVideo.Client{
	    Username: "youremail@example.com",
	    Password: "12345678",
       BaseUri:  apiVideo.BaseUri,
   }

   // Authenticate to get the tokens.
   err := c.Authenticate()
   if err != nil {
	    panic(err)
   }
   
   video, err := c.CreateVideo(&apiVideo.UploadVideo{Title: "test", Source: "https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_10mb.mp4"}, true)
   if err != nil {
   	panic(err)
   }
   
   fmt.Println(video)
}

License

GoStats is under the MIT License.

MIT License

Copyright (c) 2018 Fris

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Documentation

Index

Constants

View Source
const (
	// BaseUri is the main url to the api.
	BaseUri = "https://ws.api.video"

	// ApiKeyPath is the path for the authentication.
	ApiKeyPath = "/auth/api-key"

	// RefreshPath is the path for the token refresh.
	RefreshPath = "/auth/refresh"
)
View Source
const (
	// VideosPath is the path for creating videos.
	VideosPath = "/videos"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthResponse

type AuthResponse struct {
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

AuthResponse is the model of the authentication and refresh responses.

type Client

type Client struct {
	// Username stands for the email you used to register your account.
	Username string

	// Password stands for the api token you received in the registration email.
	Password string

	// BaseUri should always be the constant BaseUrl.
	BaseUri string

	// TokenType is provided inside the response to the authentication.
	TokenType string

	// ExpiresIn is provided inside the response to the authentication, it is the timeout for the AccessToken.
	ExpiresIn time.Time

	// AccessToken is provided inside the response to the authentication, it is used to make requests to the api.
	AccessToken string

	// RefreshToken is provided inside the response to the authentication, it is used to update the AccessToken when-
	// expired.
	RefreshToken string
}

Client is the instance that is used to communicate with the api.

func LoadClientFromEnv

func LoadClientFromEnv() *Client

LoadClientFromEnv creates a Client instance with input from env.

func (*Client) Authenticate

func (c *Client) Authenticate() error

Authenticate has to be executed in order to use the api, it authenticates the client to get the token.

func (*Client) CreateVideo

func (c *Client) CreateVideo(u *UploadVideo, fromSource bool) (*Video, error)

CreateVideo creates a new video using the client.

func (*Client) Refresh

func (c *Client) Refresh() error

Refresh is used to update the access token using the refresh token on the api

type UploadVideo

type UploadVideo struct {
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Tags        []string `json:"tags"`
	Metadata    []struct {
		Key   string `json:"key"`
		Value string `json:""`
	} `json:"metadata"`
	Public   bool   `json:"public"`
	Source   string `json:"source"`
	PlayerId string `json:"playerId"`
}

UploadVideo is the model of the post form that is sent to the api when creating a new video.

func (*UploadVideo) ToJson

func (u *UploadVideo) ToJson() (string, error)

ToJson converts the UploadVideo type to a json encoded string.

type Video

type Video struct {
	VideoId     string   `json:"videoId"`
	PlayerId    string   `json:"playerId"`
	Title       string   `json:"title"`
	Description string   `json:"description"`
	Public      bool     `json:"public"`
	Tags        []string `json:"tags"`
	Metadata    []struct {
		Key   string `json:"key"`
		Value string `json:""`
	} `json:"metadata"`
	PublishedAt string `json:"publishedAt"`
	Source      struct {
		Uri string `json:"uri"`
	} `json:"source"`
	Assets struct {
		Iframe    string `json:"iframe"`
		Player    string `json:"player"`
		Hls       string `json:"hls"`
		Thumbnail string `json:"thumbnail"`
	} `json:"assets"`
}

Video is the model for the response received from the api.

Jump to

Keyboard shortcuts

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