forked from ohookins/contentful-go
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from fauzi-as/update-schedule-get-method
Update schedule get method
- Loading branch information
Showing
4 changed files
with
96 additions
and
7 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,53 @@ | ||
package contentful | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
) | ||
|
||
// SpacesService model | ||
type ScheduledActionsService service | ||
|
||
type ScheduledFor struct { | ||
Datetime string `json:"datetime,omitempty"` | ||
Timezone string `json:"timezone,omitempty"` | ||
} | ||
|
||
// ScheduledActions model | ||
type ScheduledActions struct { | ||
Sys *Sys `json:"sys,omitempty"` | ||
Action string `json:"action,omitempty"` | ||
ScheduledFor *ScheduledFor `json:"scheduledFor,omitempty"` | ||
} | ||
|
||
// Get returns a single scheduledActions entity | ||
func (service *ScheduledActionsService) Get(spaceID string, entryID string, environmentID string) (*ScheduledActions, error) { | ||
path := fmt.Sprintf("/spaces/%s/scheduled_actions", spaceID) | ||
|
||
query := url.Values{} | ||
|
||
query.Add("entity.sys.id", entryID) | ||
query.Add("environment.sys.id", environmentID) | ||
query.Add("sys.status[in]", "scheduled") | ||
|
||
method := "GET" | ||
|
||
req, err := service.c.newRequest(method, path, query, nil) | ||
if err != nil { | ||
return &ScheduledActions{}, err | ||
} | ||
|
||
col := NewCollection(&CollectionOptions{}) | ||
col.c = service.c | ||
col.req = req | ||
|
||
if ok := service.c.do(req, &col); ok != nil { | ||
return &ScheduledActions{}, ok | ||
} | ||
|
||
for _, ct := range col.ToScheduledAction() { | ||
fmt.Println(ct) | ||
} | ||
|
||
return &ScheduledActions{}, nil | ||
} |
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,24 @@ | ||
package contentful | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_ExampleScheduledActionsService_Get(t *testing.T) { | ||
|
||
cma := NewCMA("cma-token") | ||
assert.NotNil(t, cma) | ||
assert.NotNil(t, cma.ScheduledActions) | ||
|
||
scheduledActions, err := cma.ScheduledActions.Get("space-id", "entry-id", "env") | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Printf("%v", scheduledActions) | ||
} |