jwplatform

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

README

Go JW Platform

GoDoc Build Status

The official Go client library for accessing the JW Platform API.

Requirements

Go 1.13+

Installation

Install jwplatform-go with:

go get -u github.com/jwplayer/jwplatform-go
Using Go modules
module github.com/my/package

require (
    github.com/jwplayer/jwplatform-go v0.2.0
)

Usage

import (
  "github.com/jwplayer/jwplatform-go"
)

client := jwplatform.NewClient("API_KEY", "API_SECRET")
Example: Get video metadata
package main

import (
  "context"
  "fmt"
  "log"
  "net/http"
  "net/url"
  "os"

  "github.com/jwplayer/jwplatform-go"
)

func main() {
  ctx, cancel := context.WithCancel(context.Background())
  defer cancel()

  apiKey := os.Getenv("JWPLATFORM_API_KEY")
  apiSecret := os.Getenv("JWPLATFORM_API_SECRET")

  client := jwplatform.NewClient(apiKey, apiSecret)

  // set URL params
  params := url.Values{}
  params.Set("video_key", "VIDEO_KEY")  // some video key, e.g. gIRtMhYM

  // declare an empty interface
  var result map[string]interface{}

  err := client.MakeRequest(ctx, http.MethodGet, "/videos/show/", params, &result)

  if err != nil {
  	log.Fatal(err)
  }

  fmt.Println(result["status"])  // ok
}
Example: Upload video
package main

import (
  "context"
  "fmt"
  "log"
  "net/url"
  "os"

  "github.com/jwplayer/jwplatform-go"
)

func main() {
  filepath := "path/to/your/video.mp4"

  ctx, cancel := context.WithCancel(context.Background())
  defer cancel()

  // set URL params
  params := url.Values{}
  params.Set("title", "Your video title")
  params.Set("description", "Your video description")

  apiKey := os.Getenv("JWPLATFORM_API_KEY")
  apiSecret := os.Getenv("JWPLATFORM_API_SECRET")

  client := jwplatform.NewClient(apiKey, apiSecret)

  // declare an empty interface
  var result map[string]interface{}

  // upload video using direct upload method
  err := client.Upload(ctx, filepath, params, &result)

  if err != nil {
  	log.Fatal(err)
  }

  fmt.Println(result["status"])  // ok
}

Supported operations

All API methods documentated on the API are available in this client. Please refer to our api documentation.

Test

Before running the tests, make sure to grab all of the package's dependencies:

go get -t -v

Run all tests:

make test

For any requests, bug or comments, please [open an issue][issues] or [submit a pull request][pulls].

License

JW Platform API Go library is distributed under the Apache v2.0 license.

Documentation

Overview

Package jwplatform provides a client to talk to the JW Platform API.

import (
  "github.com/jwplayer/jwplatform-go"
)

client := jwplatform.NewClient("API_KEY", "API_SECRET")

Index

Constants

View Source
const (
	APIVersion = "v1"
	APIHost    = "api.jwplatform.com"
	Version    = "0.2.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	APIVersion string
	BaseURL    *url.URL
	UserAgent  string
	Version    string
	// contains filtered or unexported fields
}

Client represents the JWPlatform client object.

func NewClient

func NewClient(apiKey string, apiSecret string) *Client

NewClient creates a new client object.

func (*Client) MakeRequest

func (c *Client) MakeRequest(ctx context.Context, method, pathPart string, params url.Values, v interface{}) error

MakeRequest requests with api signature and decodes json result.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, filepath string, params url.Values, v interface{}) error

Upload posts a file using the direct upload method.

Jump to

Keyboard shortcuts

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