-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d99956
commit 6def002
Showing
5 changed files
with
160 additions
and
0 deletions.
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
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 scheduledqueryrun provides API functions related to scheduled query runs. | ||
// | ||
// For more details, see: https://stripe.com/docs/api#scheduled_queries | ||
package scheduledqueryrun | ||
|
||
import ( | ||
"net/http" | ||
|
||
stripe "github.com/stripe/stripe-go" | ||
"github.com/stripe/stripe-go/form" | ||
) | ||
|
||
// Client is used to invoke /sigma/scheduled_query_runs APIs. | ||
type Client struct { | ||
B stripe.Backend | ||
Key string | ||
} | ||
|
||
// Get returns the details of an scheduled query run. | ||
func Get(id string, params *stripe.SigmaScheduledQueryRunParams) (*stripe.SigmaScheduledQueryRun, error) { | ||
return getC().Get(id, params) | ||
} | ||
|
||
// Get returns the details of an scheduled query run. | ||
func (c Client) Get(id string, params *stripe.SigmaScheduledQueryRunParams) (*stripe.SigmaScheduledQueryRun, error) { | ||
path := stripe.FormatURLPath("/sigma/scheduled_query_runs/%s", id) | ||
run := &stripe.SigmaScheduledQueryRun{} | ||
err := c.B.Call(http.MethodGet, path, c.Key, params, run) | ||
return run, err | ||
} | ||
|
||
// List returns a list of scheduled query runs. | ||
func List(params *stripe.SigmaScheduledQueryRunListParams) *Iter { | ||
return getC().List(params) | ||
} | ||
|
||
// List returns a list of scheduled query runs. | ||
func (c Client) List(listParams *stripe.SigmaScheduledQueryRunListParams) *Iter { | ||
return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListMeta, error) { | ||
list := &stripe.SigmaScheduledQueryRunList{} | ||
err := c.B.CallRaw(http.MethodGet, "/sigma/scheduled_query_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 scheduled query runs. | ||
type Iter struct { | ||
*stripe.Iter | ||
} | ||
|
||
// SigmaScheduledQueryRun returns the scheduled query run which the iterator is currently pointing to. | ||
func (i *Iter) SigmaScheduledQueryRun() *stripe.SigmaScheduledQueryRun { | ||
return i.Current().(*stripe.SigmaScheduledQueryRun) | ||
} | ||
|
||
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,28 @@ | ||
package scheduledqueryrun | ||
|
||
import ( | ||
"testing" | ||
|
||
assert "github.com/stretchr/testify/require" | ||
stripe "github.com/stripe/stripe-go" | ||
_ "github.com/stripe/stripe-go/testing" | ||
) | ||
|
||
func TestSigmaScheduledQueryRunGet(t *testing.T) { | ||
t.Skip("skipping test as stripe-mock does not support this resource") | ||
run, err := Get("sqr_123", nil) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, run) | ||
assert.Equal(t, "scheduled_query_run", run.Object) | ||
} | ||
|
||
func TestSigmaScheduledQueryRunList(t *testing.T) { | ||
t.Skip("skipping test as stripe-mock does not support this resource") | ||
i := List(&stripe.SigmaScheduledQueryRunListParams{}) | ||
|
||
// Verify that we can get at least one scheduled query run | ||
assert.True(t, i.Next()) | ||
assert.Nil(t, i.Err()) | ||
assert.NotNil(t, i.SigmaScheduledQueryRun()) | ||
assert.Equal(t, "scheduled_query_run", i.SigmaScheduledQueryRun().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,63 @@ | ||
package stripe | ||
|
||
import "encoding/json" | ||
|
||
// SigmaScheduledQueryRunStatus is the possible values for status for a scheduled query run. | ||
type SigmaScheduledQueryRunStatus string | ||
|
||
const ( | ||
SigmaScheduledQueryRunStatusCanceled SigmaScheduledQueryRunStatus = "canceled" | ||
SigmaScheduledQueryRunStatusCompleted SigmaScheduledQueryRunStatus = "completed" | ||
SigmaScheduledQueryRunStatusFailed SigmaScheduledQueryRunStatus = "failed" | ||
SigmaScheduledQueryRunStatusTimedOut SigmaScheduledQueryRunStatus = "timed_out" | ||
) | ||
|
||
// SigmaScheduledQueryRunParams is the set of parameters that can be used when updating a scheduled query run. | ||
type SigmaScheduledQueryRunParams struct { | ||
Params `form:"*"` | ||
} | ||
|
||
// SigmaScheduledQueryRunListParams is the set of parameters that can be used when listing scheduled query runs. | ||
type SigmaScheduledQueryRunListParams struct { | ||
ListParams `form:"*"` | ||
} | ||
|
||
// SigmaScheduledQueryRun is the resource representing a scheduled query run. | ||
type SigmaScheduledQueryRun struct { | ||
Created int64 `json:"created"` | ||
DataLoadTime int64 `json:"data_load_time"` | ||
Error string `json:"error"` | ||
File *FileUpload `json:"file"` | ||
ID string `json:"id"` | ||
Livemode bool `json:"livemode"` | ||
Object string `json:"object"` | ||
ResultAvailableUntil int64 `json:"result_available_until"` | ||
SQL string `json:"sql"` | ||
Status SigmaScheduledQueryRunStatus `json:"status"` | ||
Query string `json:"query"` | ||
} | ||
|
||
// SigmaScheduledQueryRunList is a list of scheduled query runs as retrieved from a list endpoint. | ||
type SigmaScheduledQueryRunList struct { | ||
ListMeta | ||
Data []*SigmaScheduledQueryRun `json:"data"` | ||
} | ||
|
||
// UnmarshalJSON handles deserialization of an SigmaScheduledQueryRun. | ||
// This custom unmarshaling is needed because the resulting | ||
// property may be an id or the full struct if it was expanded. | ||
func (i *SigmaScheduledQueryRun) UnmarshalJSON(data []byte) error { | ||
if id, ok := ParseID(data); ok { | ||
i.ID = id | ||
return nil | ||
} | ||
|
||
type sigmaScheduledQueryRun SigmaScheduledQueryRun | ||
var v sigmaScheduledQueryRun | ||
if err := json.Unmarshal(data, &v); err != nil { | ||
return err | ||
} | ||
|
||
*i = SigmaScheduledQueryRun(v) | ||
return nil | ||
} |