medium-sdk-go: github.com/Medium/medium-sdk-go Index | Files

package medium

import "github.com/Medium/medium-sdk-go"

Package medium provides a client for Medium's OAuth2 API.

Index

Package Files

medium.go

Constants

const (
    ScopeBasicProfile     Scope = "basicProfile"
    ScopePublishPost            = "publishPost"
    ScopeUploadImage            = "uploadImage"
    ScopeListPublications       = "listPublications"
)

Available scope options when requesting access to a user's Medium account.

const (
    PublishStatusDraft    PublishStatus = "draft"
    PublishStatusUnlisted               = "unlisted"
    PublishStatusPublic                 = "public"
)

Publish statuses that are available when creating a post on Medium.

const (
    LicenseAllRightsReserved License = "all-rights-reserved"
    LicenseCC40By                    = "cc-40-by"
    LicenseCC40BySA                  = "cc-40-by-sa"
    LicenseCC40ByND                  = "cc-40-by-nd"
    LicenseCC40ByNC                  = "cc-40-by-nc"
    LicenseCC40ByNCND                = "cc-40-by-nc-nd"
    LicenseCC40ByNCSA                = "cc-40-by-nc-sa"
    LicenseCC40Zero                  = "cc-40-zero"
    LicensePublicDomain              = "public-domain"
)

Licenses that are available when creating a post on Medium.

type AccessToken Uses

type AccessToken struct {
    TokenType    string   `json:"token_type"`
    AccessToken  string   `json:"access_token"`
    RefreshToken string   `json:"refresh_token"`
    Scope        []string `json:"scope"`
    ExpiresAt    int64    `json:"expires_at"`
}

AccessToken defines credentials with which Medium's API may be accessed.

type ContentFormat Uses

type ContentFormat string
const (
    ContentFormatHTML     ContentFormat = "html"
    ContentFormatMarkdown               = "markdown"
)

Content formats that are available when creating a post on Medium.

type Contributor Uses

type Contributor struct {
    PublicationID string `json:"publicationID"`
    UserID        string `json:"userID"`
    Role          string `json:"role"`
}

Contributor defines a Medium publication contributor

type Contributors Uses

type Contributors struct {
    Data []Contributor `json:"data"`
}

Contributors inherit all Medium publication contributors

type CreatePostOptions Uses

type CreatePostOptions struct {
    UserID        string        `json:"-"`
    Title         string        `json:"title"`
    Content       string        `json:"content"`
    ContentFormat ContentFormat `json:"contentFormat"`
    Tags          []string      `json:"tags,omitempty"`
    CanonicalURL  string        `json:"canonicalUrl,omitempty"`
    PublishStatus PublishStatus `json:"publishStatus,omitempty"`
    License       License       `json:"license,omitempty"`
}

CreatePostOptions defines the options for creating a post on Medium.

type Error Uses

type Error struct {
    Message string `json:"message"`
    Code    int    `json:"code"`
}

Error defines an error received when making a request to the API.

func (Error) Error Uses

func (e Error) Error() string

Error returns a string representing the error, satisfying the error interface.

type Image Uses

type Image struct {
    URL string `json:"url"`
    MD5 string `json:"md5"`
}

Image defines a Medium image

type License Uses

type License string

type Medium Uses

type Medium struct {
    ApplicationID     string
    ApplicationSecret string
    AccessToken       string
    Host              string
    Timeout           time.Duration
    Transport         http.RoundTripper
    // contains filtered or unexported fields
}

Medium defines the Medium client.

func NewClient Uses

func NewClient(id, secret string) *Medium

NewClient returns a new Medium API client which can be used to make RPC requests.

func NewClientWithAccessToken Uses

func NewClientWithAccessToken(accessToken string) *Medium

NewClientWithAccessToken returns a new Medium API client which can be used to make RPC requests.

func (*Medium) CreatePost Uses

func (m *Medium) CreatePost(o CreatePostOptions) (*Post, error)

CreatePost creates a post on the profile identified by the current AccessToken. This requires m.AccessToken to have the PublishPost scope.

func (*Medium) ExchangeAuthorizationCode Uses

func (m *Medium) ExchangeAuthorizationCode(code, redirectURL string) (AccessToken, error)

ExchangeAuthorizationCode exchanges the supplied code for a long-lived access token.

func (*Medium) ExchangeRefreshToken Uses

func (m *Medium) ExchangeRefreshToken(rt string) (AccessToken, error)

ExchangeRefreshToken exchanges the supplied refresh token for a new access token.

func (*Medium) GetAuthorizationURL Uses

func (m *Medium) GetAuthorizationURL(state, redirectURL string, scopes ...Scope) string

GetAuthorizationURL returns the URL to which an application may send a user in order to acquire authorization.

func (*Medium) GetPublicationContributors Uses

func (m *Medium) GetPublicationContributors(publicationID string) (*Contributors, error)

GetPublicationContributors gets contributors for givaen a publication by the current AccessToken. This requires m.AccessToken to have the BasicPublications scope.

func (*Medium) GetUser Uses

func (m *Medium) GetUser(userID string) (*User, error)

GetUser gets the profile identified by the current AccessToken. It will get the specified user or the current user if userID is empty. This requires m.AccessToken to have the BasicProfile scope.

func (*Medium) GetUserPublications Uses

func (m *Medium) GetUserPublications(userID string) (*Publications, error)

GetUserPublications gets user publications by the current AccessToken. This requires m.AccessToken to have the BasicPublications scope.

func (*Medium) UploadImage Uses

func (m *Medium) UploadImage(o UploadOptions) (*Image, error)

UploadImage uploads an image to Medium. This requires m.AccessToken to have the UploadImage scope.

type Post Uses

type Post struct {
    ID           string        `json:"id"`
    Title        string        `json:"title"`
    AuthorID     string        `json:"authorId"`
    Tags         []string      `json:"tags"`
    URL          string        `json:"url"`
    CanonicalURL string        `json:"canonicalUrl"`
    PublishState PublishStatus `json:"publishStatus"`
    License      License       `json:"license"`
    LicenseURL   string        `json:"licenseUrl"`
}

Post defines a Medium post

type Publication Uses

type Publication struct {
    ID          string `json:"id"`
    Name        string `json:"name"`
    Description string `json:"description"`
    URL         string `json:"url"`
    ImageURL    string `json:"imageUrl"`
}

Publication defines a Medium user publication

type Publications Uses

type Publications struct {
    Data []Publication `json:"data"`
}

Publications inherit all Medium user publications

type PublishStatus Uses

type PublishStatus string

type Scope Uses

type Scope string

type UploadOptions Uses

type UploadOptions struct {
    FilePath    string
    ContentType string
    // contains filtered or unexported fields
}

UploadOptions defines the options for uploading files to Medium.

type User Uses

type User struct {
    ID       string `json:"id"`
    Username string `json:"username"`
    Name     string `json:"name"`
    URL      string `json:"url"`
    ImageURL string `json:"imageUrl"`
}

User defines a Medium user

Package medium imports 13 packages (graph) and is imported by 1 packages. Updated 2019-02-18. Refresh now. Tools for package owners.