ducky/subscriptions

Paddy 2015-07-13 Child:2c8250237566

7:9e138933e4ce Go to Latest

ducky/subscriptions/client/subscription.go

Create a client for working with subscriptions. We mostly copied our code.secondbit.org/auth.hg/client package to create a simple client library for communicating with our Subscriptions API. Right now, the client only has support for creating a subscription. It remains untested, but it builds.

History
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/client/subscription.go	Mon Jul 13 23:32:57 2015 -0400
     1.3 @@ -0,0 +1,19 @@
     1.4 +package client
     1.5 +
     1.6 +import (
     1.7 +	"code.secondbit.org/auth.hg"
     1.8 +
     1.9 +	"code.secondbit.org/ducky/subscriptions.hg"
    1.10 +	"code.secondbit.org/ducky/subscriptions.hg/api"
    1.11 +)
    1.12 +
    1.13 +func (c *Client) CreateSubscription(change subscriptions.SubscriptionChange) (subscriptions.Subscription, error) {
    1.14 +	resp, err := c.Post("/subscriptions/", change, auth.Scopes{api.ScopeSubscription, api.ScopeSubscriptionAdmin}.Strings(), change.UserID)
    1.15 +	if err != nil {
    1.16 +		return subscriptions.Subscription{}, err
    1.17 +	}
    1.18 +	if len(resp.Subscriptions) < 1 {
    1.19 +		return subscriptions.Subscription{}, subscriptions.ErrSubscriptionNotFound
    1.20 +	}
    1.21 +	return resp.Subscriptions[0], nil
    1.22 +}