-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Reporting resources #690
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Package reportrun provides API functions related to report runs. | ||
// | ||
// For more details, see: https://stripe.com/docs/api/go#reporting_report_run | ||
package reportrun | ||
|
||
import ( | ||
"net/http" | ||
|
||
stripe "github.com/stripe/stripe-go" | ||
"github.com/stripe/stripe-go/form" | ||
) | ||
|
||
// Client is used to invoke /reporting/report_runs APIs. | ||
type Client struct { | ||
B stripe.Backend | ||
Key string | ||
} | ||
|
||
// New creates a new report run. | ||
func New(params *stripe.ReportRunParams) (*stripe.ReportRun, error) { | ||
return getC().New(params) | ||
} | ||
|
||
// New creates a new report run. | ||
func (c Client) New(params *stripe.ReportRunParams) (*stripe.ReportRun, error) { | ||
reportrun := &stripe.ReportRun{} | ||
err := c.B.Call(http.MethodPost, "/reporting/report_runs", c.Key, params, reportrun) | ||
return reportrun, err | ||
} | ||
|
||
// Get returns the details of a report run. | ||
func Get(id string, params *stripe.ReportRunParams) (*stripe.ReportRun, error) { | ||
return getC().Get(id, params) | ||
} | ||
|
||
// Get returns the details of a report run. | ||
func (c Client) Get(id string, params *stripe.ReportRunParams) (*stripe.ReportRun, error) { | ||
path := stripe.FormatURLPath("/reporting/report_runs/%s", id) | ||
reportrun := &stripe.ReportRun{} | ||
err := c.B.Call(http.MethodGet, path, c.Key, params, reportrun) | ||
return reportrun, err | ||
} | ||
|
||
// List returns a list of report runs. | ||
func List(params *stripe.ReportRunListParams) *Iter { | ||
return getC().List(params) | ||
} | ||
|
||
// List returns a list of report runs. | ||
func (c Client) List(listParams *stripe.ReportRunListParams) *Iter { | ||
return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) { | ||
list := &stripe.ReportRunList{} | ||
err := c.B.CallRaw(http.MethodGet, "/reporting/report_runs", c.Key, b, p, list) | ||
|
||
ret := make([]interface{}, len(list.Data)) | ||
for i, v := range list.Data { | ||
ret[i] = v | ||
} | ||
|
||
return ret, list.ListMeta, err | ||
})} | ||
} | ||
|
||
// Iter is an iterator for report runs. | ||
type Iter struct { | ||
*stripe.Iter | ||
} | ||
|
||
// ReportRun returns the report run which the iterator is currently pointing to. | ||
func (i *Iter) ReportRun() *stripe.ReportRun { | ||
return i.Current().(*stripe.ReportRun) | ||
} | ||
|
||
func getC() Client { | ||
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package reportrun | ||
|
||
import ( | ||
"testing" | ||
|
||
assert "github.com/stretchr/testify/require" | ||
stripe "github.com/stripe/stripe-go" | ||
_ "github.com/stripe/stripe-go/testing" | ||
) | ||
|
||
func TestReportRunGet(t *testing.T) { | ||
reportrun, err := Get("frr_123", nil) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, reportrun) | ||
assert.Equal(t, "reporting.report_run", reportrun.Object) | ||
} | ||
|
||
func TestReportRunList(t *testing.T) { | ||
i := List(&stripe.ReportRunListParams{}) | ||
|
||
// Verify that we can get at least one reportrun | ||
assert.True(t, i.Next()) | ||
assert.Nil(t, i.Err()) | ||
assert.NotNil(t, i.ReportRun()) | ||
assert.Equal(t, "reporting.report_run", i.ReportRun().Object) | ||
} | ||
|
||
func TestReportRunNew(t *testing.T) { | ||
reportrun, err := New(&stripe.ReportRunParams{ | ||
Parameters: &stripe.ReportRunParametersParams{ | ||
ConnectedAccount: stripe.String("acct_123"), | ||
}, | ||
ReportType: stripe.String("activity.summary.1"), | ||
}) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, reportrun) | ||
assert.Equal(t, "reporting.report_run", reportrun.Object) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Package reporttype provides API functions related to report types. | ||
// | ||
// For more details, see: https://stripe.com/docs/api/go#reporting_report_type | ||
package reporttype | ||
|
||
import ( | ||
"net/http" | ||
|
||
stripe "github.com/stripe/stripe-go" | ||
"github.com/stripe/stripe-go/form" | ||
) | ||
|
||
// Client is used to invoke /reporting/report_types APIs. | ||
type Client struct { | ||
B stripe.Backend | ||
Key string | ||
} | ||
|
||
// Get returns the details of a report type. | ||
func Get(id string, params *stripe.ReportTypeParams) (*stripe.ReportType, error) { | ||
return getC().Get(id, params) | ||
} | ||
|
||
// Get returns the details of a report type. | ||
func (c Client) Get(id string, params *stripe.ReportTypeParams) (*stripe.ReportType, error) { | ||
path := stripe.FormatURLPath("/reporting/report_types/%s", id) | ||
reporttype := &stripe.ReportType{} | ||
err := c.B.Call(http.MethodGet, path, c.Key, params, reporttype) | ||
return reporttype, err | ||
} | ||
|
||
// List returns a list of report types. | ||
func List(params *stripe.ReportTypeListParams) *Iter { | ||
return getC().List(params) | ||
} | ||
|
||
// List returns a list of report types. | ||
func (c Client) List(listParams *stripe.ReportTypeListParams) *Iter { | ||
return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) { | ||
list := &stripe.ReportTypeList{} | ||
err := c.B.CallRaw(http.MethodGet, "/reporting/report_types", c.Key, b, p, list) | ||
|
||
ret := make([]interface{}, len(list.Data)) | ||
for i, v := range list.Data { | ||
ret[i] = v | ||
} | ||
|
||
return ret, list.ListMeta, err | ||
})} | ||
} | ||
|
||
// Iter is an iterator for report types. | ||
type Iter struct { | ||
*stripe.Iter | ||
} | ||
|
||
// ReportType returns the report type which the iterator is currently pointing to. | ||
func (i *Iter) ReportType() *stripe.ReportType { | ||
return i.Current().(*stripe.ReportType) | ||
} | ||
|
||
func getC() Client { | ||
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package reporttype | ||
|
||
import ( | ||
"testing" | ||
|
||
assert "github.com/stretchr/testify/require" | ||
stripe "github.com/stripe/stripe-go" | ||
_ "github.com/stripe/stripe-go/testing" | ||
) | ||
|
||
func TestReportTestGet(t *testing.T) { | ||
reporttype, err := Get("activity.summary.1", nil) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, reporttype) | ||
assert.Equal(t, "reporting.report_type", reporttype.Object) | ||
} | ||
|
||
func TestReportTestList(t *testing.T) { | ||
i := List(&stripe.ReportTypeListParams{}) | ||
|
||
// Verify that we can get at least one reporttype | ||
assert.True(t, i.Next()) | ||
assert.Nil(t, i.Err()) | ||
assert.NotNil(t, i.ReportType()) | ||
assert.Equal(t, "reporting.report_type", i.ReportType().Object) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package stripe | ||
|
||
// ReportRunStatus is the possible values for status on a report run. | ||
type ReportRunStatus string | ||
|
||
// List of values that ReportRunStatus can take. | ||
const ( | ||
ReportRunStatusFailed ReportRunStatus = "failed" | ||
ReportRunStatusPending ReportRunStatus = "pending" | ||
ReportRunStatusSucceeded ReportRunStatus = "succeeded" | ||
) | ||
|
||
// ReportRunParametersParams is the set of parameters that can be used when creating a report run. | ||
type ReportRunParametersParams struct { | ||
ConnectedAccount *string `form:"connected_account"` | ||
Currency *string `form:"currency"` | ||
IntervalEnd *int64 `form:"interval_end"` | ||
IntervalStart *int64 `form:"interval_start"` | ||
Payout *string `form:"payout"` | ||
ReportingCategory *string `form:"reporting_category"` | ||
} | ||
|
||
// ReportRunParams is the set of parameters that can be used when creating a report run. | ||
type ReportRunParams struct { | ||
Params `form:"*"` | ||
Parameters *ReportRunParametersParams `form:"parameters"` | ||
ReportType *string `form:"report_type"` | ||
} | ||
|
||
// ReportRunListParams is the set of parameters that can be used when listing report runs. | ||
type ReportRunListParams struct { | ||
ListParams `form:"*"` | ||
Created *int64 `form:"created"` | ||
CreatedRange *RangeQueryParams `form:"created"` | ||
} | ||
|
||
// ReportRunParameters describes the parameters hash on a report run. | ||
type ReportRunParameters struct { | ||
ConnectedAccount string `json:"connected_account"` | ||
Currency Currency `json:"currency"` | ||
IntervalEnd int64 `json:"interval_end"` | ||
IntervalStart int64 `json:"interval_start"` | ||
Payout string `json:"payout"` | ||
ReportingCategory string `json:"reporting_category"` | ||
} | ||
|
||
// ReportRun is the resource representing a report run. | ||
type ReportRun struct { | ||
Created int64 `json:"created"` | ||
Error string `json:"error"` | ||
ID string `json:"id"` | ||
Livemode bool `json:"livemode"` | ||
Object string `json:"object"` | ||
Parameters *ReportRunParameters `json:"parameters"` | ||
ReportType string `json:"report_type"` | ||
Result *FileUpload `json:"result"` | ||
Status ReportRunStatus `json:"status"` | ||
SucceededAt int64 `json:"succeeded_at"` | ||
} | ||
|
||
// ReportRunList is a list of report runs as retrieved from a list endpoint. | ||
type ReportRunList struct { | ||
ListMeta | ||
Data []*ReportRun `json:"data"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package stripe | ||
|
||
// ReportTypeListParams is the set of parameters that can be used when listing report types. | ||
type ReportTypeListParams struct { | ||
ListParams `form:"*"` | ||
} | ||
|
||
// ReportTypeParams is the set of parameters that can be used when retrieving a report type. | ||
type ReportTypeParams struct { | ||
Params `form:"*"` | ||
} | ||
|
||
// ReportType is the resource representing a report type. | ||
type ReportType struct { | ||
Created int64 `json:"created"` | ||
DataAvailableEnd int64 `json:"data_available_end"` | ||
DataAvailableStart int64 `json:"data_available_start"` | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
Object string `json:"object"` | ||
Updated int64 `json:"updated"` | ||
Version int64 `json:"version"` | ||
} | ||
|
||
// ReportTypeList is a list of report types as retrieved from a list endpoint. | ||
type ReportTypeList struct { | ||
ListMeta | ||
Data []*ReportType `json:"data"` | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided not to prefix everything with
Reporting
in this case because it felt redundant and unlikely we'd have a conflict in the future.Let me know if you think it's cleaner to keep the prefix though like we do for Issuing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes sense in this situation.