netlify

package module
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2017 License: MIT Imports: 19 Imported by: 2

README

BitBallon API Client in Go

See the netlify package on godoc for full library documentation.

Quick Start

First go get github.com/netlify/netlify-go then use in your go project.

import "github.com/netlify/netlify-go"

client := netlify.NewClient(&netlify.Config{AccessToken: AccessToken})

// Create a new site
site, resp, err := client.Sites.Create(&SiteAttributes{
  Name: "site-subdomain",
  CustomDomain: "www.example.com",
  Password: "secret",
  NotificationEmail: "me@example.com",
})

// Deploy a directory
deploy, resp, err := site.Deploys.Create("/path/to/directory")

// Wait for the deploy to process
err := deploy.WaitForReady(0)

// Get a single site
site, resp, err := client.Sites.Get("my-site-id")

// Set the domain of the site
site.CustomDomain = "www.example.com"

// Update the site
resp, err := site.Update()

// Deploy a new version of the site from a zip file
deploy, resp, err := site.Deploys.Create("/path/to/file.zip")
deploy.WaitForReady(0)

// Delete the site
resp, err := site.Destroy()

Documentation

Overview

Package netlify provides a client for using the netlify API.

To work with the netlify API, start by instantiating a client:

client := netlify.NewClient(&netlify.Config{AccessToken: AccessToken})

// List sites
sites, resp, err := client.Sites.List(&netlify.ListOptions{Page: 1})

// Create a new site
site, resp, err := client.Sites.Create(&SiteAttributes{
  Name: "site-subdomain",
  CustomDomain: "www.example.com",
  Password: "secret",
  NotificationEmail: "me@example.com",
})

// Deploy a directory
deploy, resp, err := site.Deploys.Create("/path/to/directory")

// Wait for the deploy to process
err := deploy.WaitForReady(0)

// Get a single site
site, resp, err := client.Sites.Get("my-site-id")

// Set the domain of the site
site.CustomDomain = "www.example.com"

// Update the site
resp, err := site.Update()

// Deploy a new version of the site from a zip file
deploy, resp, err := site.Deploys.Create("/path/to/file.zip")
deploy.WaitForReady(0)

// Configure Continuous Deployment for a site

// First get a deploy key
deployKey, resp, err := site.DeployKeys.Create()
// Then make sure the public key (deployKey.PublicKey)
// has access to the repository

// Configure the repo
resp, err = site.ContinuousDeployment(&nefliy.RepoOptions{
  Repo: "netlify/netlify-home",
  Provider: "github",
  Dir: "_site",
  Cmd: "gulp build",
  Branch: "master",
  DeployKeyId: deployKey.Id
})
if err != nil {
  // Now make sure to add this URL as a POST webhook to your
  // repository:
  site.DeployHook
}

// Deleting a site
resp, err := site.Destroy()

Index

Constants

View Source
const (
	DefaultMaxConcurrentUploads = 10
)
View Source
const MaxFilesForSyncDeploy = 1000
View Source
const PreProcessingTimeout = time.Minute * 5

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildSettings

type BuildSettings struct {
	RepoType   string            `json:"repo_type"`
	RepoURL    string            `json:"repo_url"`
	RepoBranch string            `json:"repo_branch"`
	Cmd        string            `json:"cmd"`
	Dir        string            `json:"dir"`
	Env        map[string]string `json:"env"`

	CreatedAt Timestamp `json:"created_at"`
	UpdatedAt Timestamp `json:"updated_at"`
}

Settings for continuous deployment

type CertOptions

type CertOptions struct {
	Certificate    string   `json:"certificate"`
	Key            string   `json:"key"`
	CaCertificates []string `json:"ca_certificates"`
}

Attributes for site.ProvisionCert

type Client

type Client struct {
	BaseUrl   *url.URL
	UserAgent string

	Sites      *SitesService
	Deploys    *DeploysService
	DeployKeys *DeployKeysService

	MaxConcurrentUploads int
	// contains filtered or unexported fields
}

The netlify Client

func NewClient

func NewClient(config *Config) *Client

NewClient returns a new netlify API client

func (*Client) Request

func (c *Client) Request(method, path string, options *RequestOptions, decodeTo interface{}) (*Response, error)

Request sends an authenticated HTTP request to the netlify API

When error is nil, resp always contains a non-nil Response object

Generally methods on the various services should be used over raw API requests

func (*Client) SetLogger added in v0.1.5

func (c *Client) SetLogger(log *logrus.Entry)

type Config

type Config struct {
	AccessToken string

	ClientId     string
	ClientSecret string

	BaseUrl   string
	UserAgent string

	HttpClient     *http.Client
	RequestTimeout time.Duration

	MaxConcurrentUploads int
}

Config is used to configure the netlify client. Typically you'll just want to set an AccessToken

func (*Config) Token

func (c *Config) Token() (*oauth.Token, error)

type Deploy

type Deploy struct {
	Id     string `json:"id"`
	SiteId string `json:"site_id"`
	UserId string `json:"user_id"`

	// State of the deploy (uploading/uploaded/processing/ready/error)
	State string `json:"state"`

	// Cause of error if State is "error"
	ErrorMessage string `json:"error_message"`

	// Shas of files that needs to be uploaded before the deploy is ready
	Required []string `json:"required"`

	DeployUrl     string `json:"deploy_url"`
	SiteUrl       string `json:"url"`
	ScreenshotUrl string `json:"screenshot_url"`

	CreatedAt Timestamp `json:"created_at"`
	UpdatedAt Timestamp `json:"updated_at"`

	Branch    string `json:"branch,omitempty"`
	CommitRef string `json:"commit_ref,omitempty"`
	// contains filtered or unexported fields
}

Deploy represents a specific deploy of a site

func (*Deploy) Deploy

func (deploy *Deploy) Deploy(dirOrZip string) (*Response, error)

func (*Deploy) DeployDirWithGitInfo added in v0.1.3

func (deploy *Deploy) DeployDirWithGitInfo(dir, branch, commitRef string) (*Response, error)

DeployDirWithGitInfo scans the given directory and deploys the files that have changed on Netlify.

This function allows you to supply git information about the deploy when it hasn't been set previously be a Continuous Deployment process.

func (*Deploy) Publish

func (deploy *Deploy) Publish() (*Response, error)

Alias for restore. Published a specific deploy.

func (*Deploy) Reload

func (deploy *Deploy) Reload() (*Response, error)

Reload a deploy from the API

func (*Deploy) Restore

func (deploy *Deploy) Restore() (*Response, error)

Restore an old deploy. Sets the deploy as the active deploy for a site

func (*Deploy) WaitForReady

func (deploy *Deploy) WaitForReady(timeout time.Duration) error

type DeployInfo

type DeployInfo struct {
	Id       string   `json:"id"`
	DeployId string   `json:"deploy_id"`
	Required []string `json:"required"`
}

Info returned when creating a new deploy

type DeployKey

type DeployKey struct {
	Id        string `json:"id"`
	PublicKey string `json:"public_key"`

	CreatedAt Timestamp `json:"created_at"`
}

DeployKey for use with continuous deployment setups

type DeployKeysService

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

DeployKeysService is used to access all DeployKey related API methods

func (*DeployKeysService) Create

func (d *DeployKeysService) Create() (*DeployKey, *Response, error)

Create a new deploy key for use with continuous deployment

type DeploysService

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

DeploysService is used to access all Deploy related API methods

func (*DeploysService) Create

func (s *DeploysService) Create(dirOrZip string) (*Deploy, *Response, error)

Create a new deploy

Example: site.Deploys.Create("/path/to/site-dir", true) If the target is a zip file, it must have the extension .zip

func (*DeploysService) CreateDraft

func (s *DeploysService) CreateDraft(dirOrZip string) (*Deploy, *Response, error)

CreateDraft a new draft deploy. Draft deploys will be uploaded and processed, but won't affect the active deploy for a site.

func (*DeploysService) Get

func (d *DeploysService) Get(id string) (*Deploy, *Response, error)

Get a specific deploy.

func (*DeploysService) List

func (s *DeploysService) List(options *ListOptions) ([]Deploy, *Response, error)

List all deploys. Takes ListOptions to control pagination.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response
	Message  string
}

ErrorResponse is returned when a request to the API fails

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type ListOptions

type ListOptions struct {
	Page    int
	PerPage int
}

All List methods takes a ListOptions object controlling pagination

type ProcessingSettings

type ProcessingSettings struct {
	CSS struct {
		Minify bool `json:"minify"`
		Bundle bool `json:"bundle"`
	} `json:"css"`
	JS struct {
		Minify bool `json:"minify"`
		Bundle bool `json:"bundle"`
	} `json:"js"`
	HTML struct {
		PrettyURLs bool `json:"pretty_urls"`
	} `json:"html"`
	Images struct {
		Optimize bool `json:"optimize"`
	} `json:"images"`
	Skip bool `json:"skip"`
}

Settings for post processing

type RepoOptions

type RepoOptions struct {
	// GitHub API ID or similar unique repo ID
	Id string `json:"id"`

	// Repo path. Full ssh based path for manual repos,
	// username/reponame for GitHub or BitBucket
	Repo string `json:"repo"`

	// Currently "github", "bitbucket" or "manual"
	Provider string `json:"provider"`

	// Directory to deploy after building
	Dir string `json:"dir"`

	// Build command
	Cmd string `json:"cmd"`

	// Branch to pull from
	Branch string `json:"branch"`

	// Build environment variables
	Env *map[string]string `json:"env"`

	// ID of a netlify deploy key used to access the repo
	DeployKeyID string `json:"deploy_key_id"`
}

Attributes for setting up continuous deployment

type RequestOptions

type RequestOptions struct {
	JsonBody      interface{}
	RawBody       io.Reader
	RawBodyLength int64
	QueryParams   *url.Values
	Headers       *map[string]string
}

RequestOptions for doing raw requests to the netlify API

type Response

type Response struct {
	*http.Response

	NextPage  int
	PrevPage  int
	FirstPage int
	LastPage  int
}

netlify API Response. All API methods on the different client services will return a Response object. For any list operation this object will hold pagination information

type Site

type Site struct {
	Id     string `json:"id"`
	UserId string `json:"user_id"`

	// These fields can be updated through the API
	Name              string   `json:"name"`
	CustomDomain      string   `json:"custom_domain"`
	DomainAliases     []string `json:"domain_aliases"`
	Password          string   `json:"password"`
	NotificationEmail string   `json:"notification_email"`

	State   string `json:"state"`
	Plan    string `json:"plan"`
	SSLPlan string `json:"ssl_plan"`
	Premium bool   `json:"premium"`
	Claimed bool   `json:"claimed"`

	Url           string `json:"url"`
	AdminUrl      string `json:"admin_url"`
	DeployUrl     string `json:"deploy_url"`
	ScreenshotUrl string `json:"screenshot_url"`

	SSL      bool `json:"ssl"`
	ForceSSL bool `json:"force_ssl"`

	BuildSettings      *BuildSettings      `json:"build_settings"`
	ProcessingSettings *ProcessingSettings `json:"processing_settings"`

	DeployHook string `json:"deploy_hook"`

	CreatedAt Timestamp `json:"created_at"`
	UpdatedAt Timestamp `json:"updated_at"`

	// Access deploys for this site
	Deploys *DeploysService
	// contains filtered or unexported fields
}

Site represents a netlify Site

func (*Site) ContinuousDeployment

func (site *Site) ContinuousDeployment(repoOptions *RepoOptions) (*Response, error)

Configure Continuous Deployment for a site

func (*Site) Destroy

func (site *Site) Destroy() (*Response, error)

Destroy deletes a site permanently

func (*Site) ProvisionCert

func (site *Site) ProvisionCert(certOptions *CertOptions) (*Response, error)

Provision SSL Certificate for a site. Takes optional CertOptions to set a custom cert/chain/key. Without this netlify will generate the certificate automatically.

func (*Site) Reload

func (site *Site) Reload() (*Response, error)

func (*Site) Update

func (site *Site) Update() (*Response, error)

Update will update the fields that can be updated through the API

type SiteAttributes

type SiteAttributes struct {
	Name              string `json:"name"`
	CustomDomain      string `json:"custom_domain"`
	Password          string `json:"password"`
	NotificationEmail string `json:"notification_email"`

	ForceSSL bool `json:"force_ssl"`

	ProcessingSettings bool `json:"processing_options"`

	Repo *RepoOptions `json:"repo"`
}

Attributes for Sites.Create

type SitesService

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

SitesService is used to access all Site related API methods

func (*SitesService) Create

func (s *SitesService) Create(attributes *SiteAttributes) (*Site, *Response, error)

Create a new empty site.

func (*SitesService) Get

func (s *SitesService) Get(id string) (*Site, *Response, error)

Get a single Site from the API. The id can be either a site Id or the domain of a site (ie. site.Get("mysite.netlify.com"))

func (*SitesService) List

func (s *SitesService) List(options *ListOptions) ([]Site, *Response, error)

List all sites you have access to. Takes ListOptions to control pagination.

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. This is necessary for some fields since the GitHub API is inconsistent in how it represents times. All exported methods of time.Time can be called on Timestamp.

func (Timestamp) Equal

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal

func (Timestamp) String

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

Jump to

Keyboard shortcuts

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