Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F13779252
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
diff --git a/collection.go b/collection.go
index 42e2202..2f28dbc 100644
--- a/collection.go
+++ b/collection.go
@@ -1,16 +1,47 @@
package writeas
+import (
+ "fmt"
+ "net/http"
+)
+
// Collection represents a collection of posts. Blogs are a type of collection
// on Write.as.
type Collection struct {
Alias string `json:"alias"`
Title string `json:"title"`
Description string `json:"description"`
StyleSheet string `json:"style_sheet"`
Private bool `json:"private"`
Views int64 `json:"views"`
Domain string `json:"domain,omitempty"`
Email string `json:"email,omitempty"`
TotalPosts int `json:"total_posts"`
}
+
+// GetCollection retrieves a collection, returning the Collection and any error
+// (in user-friendly form) that occurs. See
+// https://writeas.github.io/docs/#retrieve-a-collection
+func (c *Client) GetCollection(alias string) (*Collection, error) {
+ coll := &Collection{}
+ env, err := c.get(fmt.Sprintf("/collections/%s", alias), coll)
+ if err != nil {
+ return nil, err
+ }
+
+ var ok bool
+ if coll, ok = env.Data.(*Collection); !ok {
+ return nil, fmt.Errorf("Wrong data returned from API.")
+ }
+ status := env.Code
+
+ if status == http.StatusOK {
+ return coll, nil
+ } else if status == http.StatusNotFound {
+ return nil, fmt.Errorf("Collection not found.")
+ } else {
+ return nil, fmt.Errorf("Problem getting collection: %s. %v\n", status, err)
+ }
+ return coll, nil
+}
diff --git a/collection_test.go b/collection_test.go
new file mode 100644
index 0000000..87b447a
--- /dev/null
+++ b/collection_test.go
@@ -0,0 +1,19 @@
+package writeas
+
+import (
+ "testing"
+)
+
+func TestGetCollection(t *testing.T) {
+ wac := NewClient()
+
+ res, err := wac.GetCollection("blog")
+ if err != nil {
+ t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
+ } else {
+ t.Logf("Post: %+v", res)
+ if res.Title != "write.as" {
+ t.Errorf("Unexpected fetch results: %+v\n", res)
+ }
+ }
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Jan 30, 12:21 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3608935
Attached To
rWGO writeas-go
Event Timeline
Log In to Comment