grim/paytreon

A ton more work
draft
2018-05-27, Gary Kramlich
cbc5ce1664ff
Parents f7be7a3d2116
Children 9f7ddaadd565
A ton more work
  • +1 -1
    client.go
  • +71 -73
    types.go
  • +114 -5
    types_test.go
  • --- a/client.go Sun May 27 00:14:40 2018 -0500
    +++ b/client.go Sun May 27 01:38:02 2018 -0500
    @@ -1,5 +1,5 @@
    package paytreon
    import (
    - "net/http"
    +// "net/http"
    )
    --- a/types.go Sun May 27 00:14:40 2018 -0500
    +++ b/types.go Sun May 27 01:38:02 2018 -0500
    @@ -1,8 +1,6 @@
    package paytreon
    -import (
    - "time"
    -)
    +import ()
    // Address represents a Patreon's address.
    type Address struct {
    @@ -21,26 +19,26 @@
    type User struct {
    ID string `jsonapi:"primary,user"`
    - FirstName string `jsonapi:"attr,first_name"`
    - LastName string `jsonapi:"attr,last_name"`
    - FullName string `jsonapi:"attr,full_name"`
    - Vanity string `jsonapi:"attr,vanity"`
    - Email string `jsonapi:"attr,email"`
    - About string `jsonapi:"attr,about"`
    - FacebookId string `jsonapi:"attr,facebook_id"`
    - Gender int `jsonapi:"attr,gender"`
    - HasPassword bool `jsonapi:"attr,has_password"`
    - ImageURL string `jsonapi:"attr,image_url"`
    - ThumbURL string `jsonapi:"attr,thumb_url"`
    - YouTube string `jsonapi:"attr,youtube"`
    - Twitter string `jsonapi:"attr,twitter"`
    - Facebook string `jsonapi:"attr,facebook"`
    - IsEmailVerified bool `jsonapi:"attr,is_email_verified"`
    - IsSuspended bool `jsonapi:"attr,is_suspended"`
    - IsDeleted bool `jsonapi:"attr,is_deleted"`
    - IsNuked bool `jsonapi:"attr,is_nuked"`
    - Created time.Time `jsonapi:"attr,created"`
    - URL string `jsonapi:"attr,url"`
    + FirstName string `jsonapi:"attr,first_name"`
    + LastName string `jsonapi:"attr,last_name"`
    + FullName string `jsonapi:"attr,full_name"`
    + Vanity string `jsonapi:"attr,vanity"`
    + Email string `jsonapi:"attr,email"`
    + About string `jsonapi:"attr,about"`
    + FacebookId string `jsonapi:"attr,facebook_id"`
    + Gender int `jsonapi:"attr,gender"`
    + HasPassword bool `jsonapi:"attr,has_password"`
    + ImageURL string `jsonapi:"attr,image_url"`
    + ThumbURL string `jsonapi:"attr,thumb_url"`
    + YouTube string `jsonapi:"attr,youtube"`
    + Twitter string `jsonapi:"attr,twitter"`
    + Facebook string `jsonapi:"attr,facebook"`
    + IsEmailVerified bool `jsonapi:"attr,is_email_verified"`
    + IsSuspended bool `jsonapi:"attr,is_suspended"`
    + IsDeleted bool `jsonapi:"attr,is_deleted"`
    + IsNuked bool `jsonapi:"attr,is_nuked"`
    + Created string `jsonapi:"attr,created"`
    + URL string `jsonapi:"attr,url"`
    Pledges *Pledge `jsonapi:"relation,pledges"`
    }
    @@ -48,11 +46,11 @@
    type Pledge struct {
    ID string `jsonapi:"primary,pledge"`
    - AmountCents int `jsonapi:"attr,amount_cents"`
    - CreatedAt time.Time `jsonapi:"attr,created_at"`
    - DeclinedSince time.Time `jsonapi:"attr,declined_since"`
    - PledgeCapCents int `jsonapi:"attr,pledge_cap_cents"`
    - PatronPaysFees bool `jsonapi:"attr,patron_pays_fees"`
    + AmountCents int `jsonapi:"attr,amount_cents"`
    + CreatedAt string `jsonapi:"attr,created_at"`
    + DeclinedSince string `jsonapi:"attr,declined_since"`
    + PledgeCapCents int `jsonapi:"attr,pledge_cap_cents"`
    + PatronPaysFees bool `jsonapi:"attr,patron_pays_fees"`
    TotalHistoricalAmountCents *int `jsonapi:"attr,total_historical_amount_cents,omitempty"`
    IsPaused *bool `jsonapi:"attr,is_paused,omitempty"`
    @@ -68,49 +66,49 @@
    type Reward struct {
    ID string `jsonapi:"primary,reward"`
    - Amount int `jsonapi:"attr,amount"`
    - AmountCents int `jsonapi:"attr,amount_cents"`
    - CreatedAt time.Time `jsonapi:"attr,created_at"`
    - DeletedAt time.Time `jsonapi:"attr,deleted_at"`
    - EditedAt time.Time `jsonapi:"attr,edited_at"`
    - Description string `jsonapi:"attr,description"`
    - ImageURL string `jsonapi:"attr,image_url"`
    - PatronCount int `jsonapi:"attr,patron_count"`
    - PostCount int `jsonapi:"attr,post_count"`
    - Published bool `jsonapi:"attr,published"`
    - PublishedAt time.Time `jsonapi:"attr,published_at"`
    - RequiresShipping bool `jsonapi:"attr,requires_shipping"`
    - Title string `jsonapi:"attr,title"`
    - UnpublishedAt time.Time `jsonapi:"attr,unpublished_at"`
    - URL string `jsonapi:"attr,url"`
    + Amount int `jsonapi:"attr,amount"`
    + AmountCents int `jsonapi:"attr,amount_cents"`
    + CreatedAt string `jsonapi:"attr,created_at,iso8601"`
    + DeletedAt string `jsonapi:"attr,deleted_at,iso8601,omitempty"`
    + EditedAt string `jsonapi:"attr,edited_at,iso8601"`
    + Description string `jsonapi:"attr,description"`
    + ImageURL string `jsonapi:"attr,image_url"`
    + PatronCount int `jsonapi:"attr,patron_count"`
    + PostCount int `jsonapi:"attr,post_count"`
    + Published bool `jsonapi:"attr,published"`
    + PublishedAt string `jsonapi:"attr,published_at,iso8601"`
    + RequiresShipping bool `jsonapi:"attr,requires_shipping"`
    + Title string `jsonapi:"attr,title"`
    + UnpublishedAt string `jsonapi:"attr,unpublished_at,iso8601,omitempty"`
    + URL string `jsonapi:"attr,url"`
    }
    type Campaign struct {
    ID string `jsonapi:"primary,campaign"`
    - Summary string `jsonapi:"attr,summary"`
    - CreationName string `jsonapi:"attr,creation_name"`
    - DisplayPatronGoals bool `jsonapi:"attr,display_patron_goals"`
    - PayPerName string `jsonapi:"attr,pay_per_name"`
    - OneLiner string `jsonapi:"attr,one_liner"`
    - MainVideoEmbed string `jsonapi:"attr,main_video_embed"`
    - MainVideoURL string `jsonapi:"attr,main_video_url"`
    - ImageSmallURL string `jsonapi:"attr,image_small_url"`
    - ImageURL string `jsonapi:"attr,image_url"`
    - ThanksVideoURL string `jsonapi:"attr,thanks_video_url"`
    - ThanksEmbed string `jsonapi:"attr,thanks_embed"`
    - ThanksMsg string `jsonapi:"attr,thanks_msg"`
    - IsChargedImmediately bool `jsonapi:"attr,is_charged_immediately"`
    - IsMonthly bool `jsonapi:"attr,is_monthly"`
    - IsNsfw bool `jsonapi:"attr,is_nsfw"`
    - IsPlural bool `jsonapi:"attr,is_plural"`
    - CreatedAt time.Time `jsonapi:"attr,created_at"`
    - PublishedAt time.Time `jsonapi:"attr,published_at"`
    - PledgeURL string `jsonapi:"attr,pledge_url"`
    - PledgeSum int `jsonapi:"attr,pledge_sum"`
    - PatronCount int `jsonapi:"attr,patron_count"`
    - CreationCount int `jsonapi:"attr,creation_count"`
    - OutstandingPaymentAmountCents int `jsonapi:"attr,outstanding_payment_amount_cents"`
    + Summary string `jsonapi:"attr,summary"`
    + CreationName string `jsonapi:"attr,creation_name"`
    + DisplayPatronGoals bool `jsonapi:"attr,display_patron_goals"`
    + PayPerName string `jsonapi:"attr,pay_per_name"`
    + OneLiner string `jsonapi:"attr,one_liner"`
    + MainVideoEmbed string `jsonapi:"attr,main_video_embed"`
    + MainVideoURL string `jsonapi:"attr,main_video_url"`
    + ImageSmallURL string `jsonapi:"attr,image_small_url"`
    + ImageURL string `jsonapi:"attr,image_url"`
    + ThanksVideoURL string `jsonapi:"attr,thanks_video_url"`
    + ThanksEmbed string `jsonapi:"attr,thanks_embed"`
    + ThanksMsg string `jsonapi:"attr,thanks_msg"`
    + IsChargedImmediately bool `jsonapi:"attr,is_charged_immediately"`
    + IsMonthly bool `jsonapi:"attr,is_monthly"`
    + IsNsfw bool `jsonapi:"attr,is_nsfw"`
    + IsPlural bool `jsonapi:"attr,is_plural"`
    + CreatedAt string `jsonapi:"attr,created_at"`
    + PublishedAt string `jsonapi:"attr,published_at"`
    + PledgeURL string `jsonapi:"attr,pledge_url"`
    + PledgeSum int `jsonapi:"attr,pledge_sum"`
    + PatronCount int `jsonapi:"attr,patron_count"`
    + CreationCount int `jsonapi:"attr,creation_count"`
    + OutstandingPaymentAmountCents int `jsonapi:"attr,outstanding_payment_amount_cents"`
    // Categories *CategoriesRelationship `jsonapi:"relation,categories,omitempty"`
    Creator *User `jsonapi:"relation,creator,omitempty"`
    @@ -123,11 +121,11 @@
    type Goal struct {
    ID string `jsonapi:"primary,goal"`
    - Amount int `jsonapi:"attr,amount"`
    - AmountCents int `jsonapi:"attr,amount_cents"`
    - CompletedPercentage int `jsonapi:"attr,completed_percentage"`
    - CreatedAt time.Time `jsonapi:"attr,created_at"`
    - ReachedAt time.Time `jsonapi:"attr,reached_at"`
    - Title string `jsonapi:"attr,title"`
    - Description string `jsonapi:"attr,description"`
    + Amount int `jsonapi:"attr,amount"`
    + AmountCents int `jsonapi:"attr,amount_cents"`
    + CompletedPercentage int `jsonapi:"attr,completed_percentage"`
    + CreatedAt string `jsonapi:"attr,created_at"`
    + ReachedAt string `jsonapi:"attr,reached_at"`
    + Title string `jsonapi:"attr,title"`
    + Description string `jsonapi:"attr,description"`
    }
    --- a/types_test.go Sun May 27 00:14:40 2018 -0500
    +++ b/types_test.go Sun May 27 01:38:02 2018 -0500
    @@ -1,13 +1,15 @@
    package paytreon
    import (
    + "reflect"
    + "strings"
    "testing"
    "github.com/google/jsonapi"
    )
    func TestAddressUnmarshal(t *testing.T) {
    - data = `{"data": [{
    + data := `{"data": {
    "attributes": {
    "addressee": "somebody",
    "city": "somecity",
    @@ -20,12 +22,119 @@
    },
    "id": "someid",
    "type": "address"
    - }]}
    - `
    +}}`
    - var addr Address
    - err := jsonapi.UnmarshalPayload(data, &addr)
    + exp := Address{
    + ID: "someid",
    + Addressee: "somebody",
    + City: "somecity",
    + Country: "somecountry",
    + Line1: "someline1",
    + Line2: "someline2",
    + PhoneNumber: "",
    + PostalCode: "somepostalcode",
    + State: "somestate",
    + }
    +
    + var address Address
    + err := jsonapi.UnmarshalPayload(strings.NewReader(data), &address)
    if err != nil {
    t.Errorf("unexpected error: %s", err)
    }
    +
    + if !reflect.DeepEqual(address, exp) {
    + t.Errorf("value mismatch\n%#v\nis not equal to\n%#v", address, exp)
    + }
    }
    +
    +func TestRewardUnmarshal(t *testing.T) {
    + data := `{"data": {
    + "attributes": {
    + "amount": 100,
    + "amount_cents": 50,
    + "created_at": "2018-05-23T21:27:59.077755+00:00",
    + "deleted_at": null,
    + "edited_at": "2018-05-23T21:27:59.077755+00:00",
    + "description": "somedescription",
    + "image_url": "http://some.img",
    + "patron_count": 100,
    + "post_count": 50,
    + "published": true,
    + "published_at": "2018-05-23T21:27:59.077755+00:00",
    + "requires_shipping": true,
    + "title": "sometitle",
    + "unpublished_at": null,
    + "url": "http://some.reward"
    + },
    + "id": "someid",
    + "type": "reward"
    +}}`
    +
    + expDate := "2018-05-23T21:27:59.077755+00:00"
    +
    + exp := Reward{
    + ID: "someid",
    + Amount: 100,
    + AmountCents: 50,
    + CreatedAt: expDate,
    + EditedAt: expDate,
    + Description: "somedescription",
    + ImageURL: "http://some.img",
    + PatronCount: 100,
    + PostCount: 50,
    + Published: true,
    + PublishedAt: expDate,
    + RequiresShipping: true,
    + Title: "sometitle",
    + URL: "http://some.reward",
    + }
    +
    + var act Reward
    + err := jsonapi.UnmarshalPayload(strings.NewReader(data), &act)
    + if err != nil {
    + t.Errorf("unexpected error: %s", err)
    + }
    +
    + if !reflect.DeepEqual(act, exp) {
    + t.Errorf("value mismatch\n%#v\nis not equal to\n%#v", act, exp)
    + }
    +}
    +
    +func TestGoalUnmarshal(t *testing.T) {
    + data := `{"data": {
    + "attributes": {
    + "amount": 100,
    + "amount_cents": 50,
    + "completed_percentage": 75,
    + "created_at": "2018-05-23T21:27:59.077755+00:00",
    + "reached_at": null,
    + "title": "sometitle",
    + "description": "somedescription"
    + },
    + "id": "someid",
    + "type": "goal"
    +}}`
    +
    + expDate := "2018-05-23T21:27:59.077755+00:00"
    +
    + exp := Goal{
    + ID: "someid",
    + Amount: 100,
    + AmountCents: 50,
    + CompletedPercentage: 75,
    + CreatedAt: expDate,
    + ReachedAt: "",
    + Title: "sometitle",
    + Description: "somedescription",
    + }
    +
    + var act Goal
    + err := jsonapi.UnmarshalPayload(strings.NewReader(data), &act)
    + if err != nil {
    + t.Errorf("unexpected error: %s", err)
    + }
    +
    + if !reflect.DeepEqual(act, exp) {
    + t.Errorf("value mismatch\n%#v\nis not equal to\n%#v", act, exp)
    + }
    +}