Skip to content

Commit

Permalink
Reimplement all other APIs on Call2 and GetIter2
Browse files Browse the repository at this point in the history
  • Loading branch information
brandur committed Jun 13, 2018
1 parent d382d20 commit 7c389d7
Show file tree
Hide file tree
Showing 44 changed files with 454 additions and 1,569 deletions.
1 change: 1 addition & 0 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,5 +444,6 @@ type PayoutSchedule struct {

// AccountRejectParams is the structure for the Reject function.
type AccountRejectParams struct {
Params `form:"*"`
Reason *string `form:"reason"`
}
81 changes: 13 additions & 68 deletions account/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,8 @@ func New(params *stripe.AccountParams) (*stripe.Account, error) {
}

func (c Client) New(params *stripe.AccountParams) (*stripe.Account, error) {
body := &form.Values{}

// Type is now required on creation and not allowed on update
// It can't be passed if you pass `from_recipient` though
if params.FromRecipient != nil {
body.Add("type", stripe.StringValue(params.Type))
}

form.AppendTo(body, params)

acct := &stripe.Account{}
err := c.B.Call("POST", "/accounts", c.Key, body, &params.Params, acct)

err := c.B.Call2("POST", "/accounts", c.Key, params, acct)
return acct, err
}

Expand All @@ -40,8 +29,7 @@ func Get() (*stripe.Account, error) {

func (c Client) Get() (*stripe.Account, error) {
account := &stripe.Account{}
err := c.B.Call("GET", "/account", c.Key, nil, nil, account)

err := c.B.Call2("GET", "/account", c.Key, nil, account)
return account, err
}

Expand All @@ -51,18 +39,9 @@ func GetByID(id string, params *stripe.AccountParams) (*stripe.Account, error) {
}

func (c Client) GetByID(id string, params *stripe.AccountParams) (*stripe.Account, error) {
var body *form.Values
var commonParams *stripe.Params

if params != nil {
commonParams = &params.Params
body = &form.Values{}
form.AppendTo(body, params)
}

path := stripe.FormatURLPath("/accounts/%s", id)
account := &stripe.Account{}
err := c.B.Call("GET", stripe.FormatURLPath("/accounts/%s", id), c.Key, body, commonParams, account)

err := c.B.Call2("GET", path, c.Key, params, account)
return account, err
}

Expand All @@ -72,18 +51,9 @@ func Update(id string, params *stripe.AccountParams) (*stripe.Account, error) {
}

func (c Client) Update(id string, params *stripe.AccountParams) (*stripe.Account, error) {
var body *form.Values
var commonParams *stripe.Params

if params != nil {
commonParams = &params.Params
body = &form.Values{}
form.AppendTo(body, params)
}

path := stripe.FormatURLPath("/accounts/%s", id)
acct := &stripe.Account{}
err := c.B.Call("POST", stripe.FormatURLPath("/accounts/%s", id), c.Key, body, commonParams, acct)

err := c.B.Call2("POST", path, c.Key, params, acct)
return acct, err
}

Expand All @@ -93,18 +63,9 @@ func Del(id string, params *stripe.AccountParams) (*stripe.Account, error) {
}

func (c Client) Del(id string, params *stripe.AccountParams) (*stripe.Account, error) {
var body *form.Values
var commonParams *stripe.Params

if params != nil {
body = &form.Values{}
form.AppendTo(body, params)
commonParams = &params.Params
}

path := stripe.FormatURLPath("/accounts/%s", id)
acct := &stripe.Account{}
err := c.B.Call("DELETE", stripe.FormatURLPath("/accounts/%s", id), c.Key, body, commonParams, acct)

err := c.B.Call2("DELETE", path, c.Key, params, acct)
return acct, err
}

Expand All @@ -114,13 +75,9 @@ func Reject(id string, params *stripe.AccountRejectParams) (*stripe.Account, err
}

func (c Client) Reject(id string, params *stripe.AccountRejectParams) (*stripe.Account, error) {
body := &form.Values{}
if params.Reason != nil {
body.Add("reason", stripe.StringValue(params.Reason))
}
path := stripe.FormatURLPath("/accounts/%s/reject", id)
acct := &stripe.Account{}
err := c.B.Call("POST", stripe.FormatURLPath("/accounts/%s/reject", id), c.Key, body, nil, acct)

err := c.B.Call2("POST", path, c.Key, params, acct)
return acct, err
}

Expand All @@ -129,22 +86,10 @@ func List(params *stripe.AccountListParams) *Iter {
return getC().List(params)
}

func (c Client) List(params *stripe.AccountListParams) *Iter {
var body *form.Values
var lp *stripe.ListParams
var p *stripe.Params

if params != nil {
body = &form.Values{}

form.AppendTo(body, params)
lp = &params.ListParams
p = params.ToParams()
}

return &Iter{stripe.GetIter(lp, body, func(b *form.Values) ([]interface{}, stripe.ListMeta, error) {
func (c Client) List(listParams *stripe.AccountListParams) *Iter {
return &Iter{stripe.GetIter2(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.AccountList{}
err := c.B.Call("GET", "/accounts", c.Key, b, p, list)
err := c.B.CallRaw("GET", "/accounts", c.Key, b, p, list)

ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
Expand Down
48 changes: 8 additions & 40 deletions applepaydomain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ func New(params *stripe.ApplePayDomainParams) (*stripe.ApplePayDomain, error) {
}

func (c Client) New(params *stripe.ApplePayDomainParams) (*stripe.ApplePayDomain, error) {
body := &form.Values{}
form.AppendTo(body, params)

domain := &stripe.ApplePayDomain{}
err := c.B.Call("POST", "/apple_pay/domains", c.Key, body, &params.Params, domain)
err := c.B.Call2("POST", "/apple_pay/domains", c.Key, params, domain)
return domain, err
}

Expand All @@ -32,18 +29,9 @@ func Get(id string, params *stripe.ApplePayDomainParams) (*stripe.ApplePayDomain
}

func (c Client) Get(id string, params *stripe.ApplePayDomainParams) (*stripe.ApplePayDomain, error) {
var body *form.Values
var commonParams *stripe.Params

if params != nil {
body = &form.Values{}
commonParams = &params.Params
form.AppendTo(body, params)
}

path := stripe.FormatURLPath("/apple_pay/domains/%s", id)
domain := &stripe.ApplePayDomain{}
err := c.B.Call("GET", stripe.FormatURLPath("/apple_pay/domains/%s", id), c.Key, body, commonParams, domain)

err := c.B.Call2("GET", path, c.Key, params, domain)
return domain, err
}

Expand All @@ -53,18 +41,9 @@ func Del(id string, params *stripe.ApplePayDomainParams) (*stripe.ApplePayDomain
}

func (c Client) Del(id string, params *stripe.ApplePayDomainParams) (*stripe.ApplePayDomain, error) {
var body *form.Values
var commonParams *stripe.Params

if params != nil {
body = &form.Values{}
form.AppendTo(body, params)
commonParams = &params.Params
}

path := stripe.FormatURLPath("/apple_pay/domains/%s", id)
domain := &stripe.ApplePayDomain{}
err := c.B.Call("DELETE", stripe.FormatURLPath("/apple_pay/domains/%s", id), c.Key, body, commonParams, domain)

err := c.B.Call2("DELETE", path, c.Key, params, domain)
return domain, err
}

Expand All @@ -73,21 +52,10 @@ func List(params *stripe.ApplePayDomainListParams) *Iter {
return getC().List(params)
}

func (c Client) List(params *stripe.ApplePayDomainListParams) *Iter {
var body *form.Values
var lp *stripe.ListParams
var p *stripe.Params

if params != nil {
body = &form.Values{}
form.AppendTo(body, params)
lp = &params.ListParams
p = params.ToParams()
}

return &Iter{stripe.GetIter(lp, body, func(b *form.Values) ([]interface{}, stripe.ListMeta, error) {
func (c Client) List(listParams *stripe.ApplePayDomainListParams) *Iter {
return &Iter{stripe.GetIter2(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.ApplePayDomainList{}
err := c.B.Call("GET", "/apple_pay/domains", c.Key, b, p, list)
err := c.B.CallRaw("GET", "/apple_pay/domains", c.Key, b, p, list)

ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
Expand Down
42 changes: 6 additions & 36 deletions balance/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,8 @@ func Get(params *stripe.BalanceParams) (*stripe.Balance, error) {
}

func (c Client) Get(params *stripe.BalanceParams) (*stripe.Balance, error) {
var body *form.Values
var commonParams *stripe.Params

if params != nil {
commonParams = &params.Params
body = &form.Values{}
form.AppendTo(body, params)
}

balance := &stripe.Balance{}
err := c.B.Call("GET", "/balance", c.Key, body, commonParams, balance)

err := c.B.Call2("GET", "/balance", c.Key, params, balance)
return balance, err
}

Expand All @@ -41,18 +31,9 @@ func GetBalanceTransaction(id string, params *stripe.BalanceTransactionParams) (
}

func (c Client) GetBalanceTransaction(id string, params *stripe.BalanceTransactionParams) (*stripe.BalanceTransaction, error) {
var body *form.Values
var commonParams *stripe.Params

if params != nil {
commonParams = &params.Params
body = &form.Values{}
form.AppendTo(body, params)
}

path := stripe.FormatURLPath("/balance/history/%s", id)
balance := &stripe.BalanceTransaction{}
err := c.B.Call("GET", stripe.FormatURLPath("/balance/history/%s", id), c.Key, body, commonParams, balance)

err := c.B.Call2("GET", path, c.Key, params, balance)
return balance, err
}

Expand All @@ -62,21 +43,10 @@ func List(params *stripe.BalanceTransactionListParams) *Iter {
return getC().List(params)
}

func (c Client) List(params *stripe.BalanceTransactionListParams) *Iter {
var body *form.Values
var lp *stripe.ListParams
var p *stripe.Params

if params != nil {
body = &form.Values{}
form.AppendTo(body, params)
lp = &params.ListParams
p = params.ToParams()
}

return &Iter{stripe.GetIter(lp, body, func(b *form.Values) ([]interface{}, stripe.ListMeta, error) {
func (c Client) List(listParams *stripe.BalanceTransactionListParams) *Iter {
return &Iter{stripe.GetIter2(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) {
list := &stripe.BalanceTransactionList{}
err := c.B.Call("GET", "/balance/history", c.Key, b, p, list)
err := c.B.CallRaw("GET", "/balance/history", c.Key, b, p, list)

ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
Expand Down
Loading

0 comments on commit 7c389d7

Please sign in to comment.