api

package
v2.1.5+incompatible Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package implements access to Upwork API

Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author:: Maksym Novozhylov (mnovozhilov@upwork.com) Copyright:: Copyright 2018(c) Upwork.com License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html

Package implements access to Upwork API

Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author:: Maksym Novozhylov (mnovozhilov@upwork.com) Copyright:: Copyright 2018(c) Upwork.com License:: See LICENSE.txt and TOS - https://developers.upwork.com/api-tos.html

Index

Constants

View Source
const (
	// oauth2 and api flow
	BaseHost                  = "https://www.upwork.com/"
	DefaultEpoint             = "api"
	GqlEndpoint               = "https://api.upwork.com/graphql"
	AuthorizationEP           = BaseHost + "ab/account-security/oauth2/authorize"
	AccessTokenEP             = BaseHost + DefaultEpoint + "/v3/oauth2/token"
	DataFormat                = "json"
	OverloadParam             = "http_method"
	UPWORK_LIBRARY_USER_AGENT = "Github Upwork API Golang Library"

	// response types
	ByteResponse  = "[]byte"
	ErrorResponse = "error"
)

Define end points

View Source
const (
	TIMEFORMAT = "2006-01-02T15:04:05.000Z" // NOTE: time.RFC3339 does not work for unclear reason?
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiClient

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

Api client

func Setup

func Setup(config *Config) (client ApiClient)

Setup client using specific config

func (*ApiClient) Delete

func (c *ApiClient) Delete(uri string, params map[string]string) (r *http.Response, re interface{})

DELETE method for client

func (*ApiClient) Get

func (c *ApiClient) Get(uri string, params map[string]string) (r *http.Response, re interface{})

GET method for client

func (*ApiClient) GetAuthorizationUrl

func (c *ApiClient) GetAuthorizationUrl(stateString string) (authzUrl string)

Receive an authorization URL

func (*ApiClient) GetToken

func (c *ApiClient) GetToken(ctx context.Context, authzCode string) *oauth2.Token

Get access token using a specific authorization code

func (*ApiClient) HasAccessToken

func (c *ApiClient) HasAccessToken(ctx context.Context) bool

Check if client contains already a access/refresh token pair

func (*ApiClient) Post

func (c *ApiClient) Post(uri string, params map[string]string) (r *http.Response, re interface{})

POST method for client

func (*ApiClient) Put

func (c *ApiClient) Put(uri string, params map[string]string) (r *http.Response, re interface{})

PUT method for client

func (*ApiClient) SetApiResponseType

func (c *ApiClient) SetApiResponseType(t string)

Set API response type

func (*ApiClient) SetEntryPoint

func (c *ApiClient) SetEntryPoint(ep string)

Set entry point, e.g requested from a router

func (*ApiClient) SetOrgUidHeader

func (c *ApiClient) SetOrgUidHeader(ctx context.Context, tenantId string)

setup X-Upwork-API-TenantId header

func (*ApiClient) SetPostAsJson

func (c *ApiClient) SetPostAsJson(t bool)

Set request type for non-Get requests

func (*ApiClient) SetRefreshTokenNotifyFunc

func (c *ApiClient) SetRefreshTokenNotifyFunc(f TokenNotifyFunc)

Set refresh token notify function

type Config

type Config struct {
	ClientId            string
	ClientSecret        string
	AccessToken         string
	RefreshToken        string
	RedirectUri         string
	ExpiresIn           string
	ExpiresAt           time.Time
	State               string
	Debug               bool
	HasCustomHttpClient bool
	TenantIdHeader      string // X-Upwork-API-TenantId required for GraphQL requests
}

Config

func NewConfig

func NewConfig(data map[string]string) (settings *Config)

Create a new config

func ReadConfig

func ReadConfig(fn string) (settings *Config)

Read a specific configuration (json) file

func (*Config) Print

func (cfg *Config) Print()

Test print of found/assigned key

func (*Config) SetCustomHttpClient

func (cfg *Config) SetCustomHttpClient(ctx context.Context, httpClient *http.Client) context.Context

Configure a context with the custom http client

func (*Config) SetOrgUidHeader

func (cfg *Config) SetOrgUidHeader(tenantId string)

Configure X-Upwork-API-TenantId header for OwnHttpClient

func (*Config) SetOwnHttpClient

func (cfg *Config) SetOwnHttpClient(ctx context.Context) context.Context

Configure a context with the own http client over RoundTripper

type HeadersTransport

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

func (*HeadersTransport) RoundTrip

func (t *HeadersTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip for the RoundTripper interface

type NotifyingTokenSource

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

NotifyingTokenSource is an oauth2.TokenSource that calls a function when a new token is obtained.

func NewNotifyingTokenSource

func NewNotifyingTokenSource(src oauth2.TokenSource, f TokenNotifyFunc) *NotifyingTokenSource

NewNotifyingTokenSource creates a NotifyingTokenSource from an underlying src and calls f when a new token is obtained.

func (*NotifyingTokenSource) Token

func (s *NotifyingTokenSource) Token() (*oauth2.Token, error)

Token fetches a new token from the underlying source.

type TokenNotifyFunc

type TokenNotifyFunc func(*oauth2.Token) error

TokenNotifyFunc is a function that accepts an oauth2 Token upon refresh, and returns an error if it should not be used.

Directories

Path Synopsis
routers
activities/engagement
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
activities/team
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
auth
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
freelancers/profile
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
freelancers/search
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
graphql
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/clients/applications
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/clients/offers
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/contracts
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/engagements
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/freelancers/applications
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/freelancers/offers
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/interviews
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/jobs
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/milestones
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/roles
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
hr/submissions
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
jobs/profile
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
jobs/search
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
messages
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
metadata
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
organization/companies
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
organization/teams
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
organization/users
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
payments
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
reports/finance/accounts
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
reports/finance/billings
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
reports/finance/earnings
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
reports/time
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
snapshot
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
workdays
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
workdiary
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.
Router for Upwork API Licensed under the Upwork's API Terms of Use; you may not use this file except in compliance with the Terms.

Jump to

Keyboard shortcuts

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