Exemplo n.º 1
0
func NewClient() *media.Client {
	settings := &models.OAuth2ClientSettings{
		ClientID:     DefaultConfig.ClientID,
		ClientSecret: DefaultConfig.ClientSecret,
		TokenType:    gphotoTokenType,
		RefreshToken: DefaultConfig.RefreshToken,
		Expiry:       time.Now(),
		AuthURL:      gphotoAuthURL,
		TokenURL:     gphotoTokenURL,
		Scopes:       []string{gphotoScopes},
	}
	return media.NewClient(settings.GenClient(oauth2.NoContext))
}
Exemplo n.º 2
0
func newMediaClient(req *wcg.Request) (*media.Client, error) {
	const fallbackServer = "speedland-ng-dev.appspot.com"
	kind := entities.OAuth2ClientSettings
	if lib.IsOnLocalGAE() || req.IsTest() {
		kind = kind.NewRemote(fallbackServer)
	}
	_, settings, err := kind.Get().Key(OAuth2ClientKey).One(req)
	if err != nil {
		return nil, err
	}
	if settings == nil {
		if lib.IsOnLocalGAE() || req.IsTest() {
			return nil, fmt.Errorf("OAuthClient `%s` is not configured on %s", OAuth2ClientKey, fallbackServer)
		}
		return nil, fmt.Errorf("OAuthClient `%s` is not configured", OAuth2ClientKey)
	}
	return media.NewClient(
		settings.(*models.OAuth2ClientSettings).GenClient(urlfetch.NewContext(req)),
	), nil
}