Page MenuHomeMusing Studio

No OneTemporary

diff --git a/README.md b/README.md
index d1ee8d3..47a633f 100644
--- a/README.md
+++ b/README.md
@@ -1,76 +1,67 @@
# go-writeas
-[![godoc](https://godoc.org/go.code.as/writeas.v1?status.svg)](https://godoc.org/go.code.as/writeas.v1)
+[![godoc](https://godoc.org/go.code.as/writeas.v2?status.svg)](https://godoc.org/go.code.as/writeas.v2)
Official Write.as Go client library.
## Installation
```bash
-go get go.code.as/writeas.v1
+go get go.code.as/writeas.v2
```
## Documentation
See all functionality and usages in the [API documentation](https://developer.write.as/docs/api/).
### Example usage
```go
-import "go.code.as/writeas.v1"
+import "go.code.as/writeas.v2"
func main() {
// Create the client
c := writeas.NewClient()
// Publish a post
p, err := c.CreatePost(&writeas.PostParams{
Title: "Title!",
Content: "This is a post.",
Font: "sans",
})
if err != nil {
// Perhaps show err.Error()
}
// Save token for later, since it won't ever be returned again
token := p.Token
// Update a published post
- p, err = c.UpdatePost(&writeas.PostParams{
- OwnedPostParams: writeas.OwnedPostParams{
- ID: p.ID,
- Token: token,
- },
+ p, err = c.UpdatePost(p.ID, token, &writeas.PostParams{
Content: "Now it's been updated!",
})
if err != nil {
// handle
}
// Get a published post
p, err = c.GetPost(p.ID)
if err != nil {
// handle
}
// Delete a post
- err = c.DeletePost(&writeas.PostParams{
- OwnedPostParams: writeas.OwnedPostParams{
- ID: p.ID,
- Token: token,
- },
- })
+ err = c.DeletePost(p.ID, token)
}
```
## Contributing
The library covers our usage, but might not be comprehensive of the API. So we always welcome contributions and improvements from the community. Before sending pull requests, make sure you've done the following:
* Run `go fmt` on all updated .go files.
* Document all exported structs and funcs.
## License
MIT
diff --git a/post_test.go b/post_test.go
index abdfa3a..f995f2b 100644
--- a/post_test.go
+++ b/post_test.go
@@ -1,116 +1,111 @@
package writeas
import (
"testing"
"fmt"
"strings"
)
func TestCreatePost(t *testing.T) {
wac := NewClient()
p, err := wac.CreatePost(&PostParams{
Title: "Title!",
Content: "This is a post.",
Font: "sans",
})
if err != nil {
t.Errorf("Post create failed: %v", err)
return
}
t.Logf("Post created: %+v", p)
token := p.Token
// Update post
- p, err = wac.UpdatePost(&PostParams{
- ID: p.ID,
- Token: token,
+ p, err = wac.UpdatePost(p.ID, token, &PostParams{
Content: "Now it's been updated!",
})
if err != nil {
t.Errorf("Post update failed: %v", err)
return
}
t.Logf("Post updated: %+v", p)
// Delete post
- err = wac.DeletePost(&PostParams{
- ID: p.ID,
- Token: token,
- })
+ err = wac.DeletePost(p.ID, token)
if err != nil {
t.Errorf("Post delete failed: %v", err)
return
}
t.Logf("Post deleted!")
}
func TestGetPost(t *testing.T) {
dwac := NewDevClient()
res, err := dwac.GetPost("zekk5r9apum6p")
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
t.Logf("Post: %+v", res)
if res.Content != "This is a post." {
t.Errorf("Unexpected fetch results: %+v\n", res)
}
}
wac := NewClient()
res, err = wac.GetPost("3psnxyhqxy3hq")
if err != nil {
t.Errorf("Unexpected fetch results: %+v, err: %v\n", res, err)
} else {
if !strings.HasPrefix(res.Content, " Write.as Blog") {
t.Errorf("Unexpected fetch results: %+v\n", res)
}
}
}
func TestPinPost(t *testing.T) {
dwac := NewDevClient()
_, err := dwac.LogIn("demo", "demo")
if err != nil {
t.Fatalf("Unable to log in: %v", err)
}
defer dwac.LogOut()
err = dwac.PinPost("tester", &PinnedPostParams{ID: "olx6uk7064heqltf"})
if err != nil {
t.Fatalf("Pin failed: %v", err)
}
}
func TestUnpinPost(t *testing.T) {
dwac := NewDevClient()
_, err := dwac.LogIn("demo", "demo")
if err != nil {
t.Fatalf("Unable to log in: %v", err)
}
defer dwac.LogOut()
err = dwac.UnpinPost("tester", &PinnedPostParams{ID: "olx6uk7064heqltf"})
if err != nil {
t.Fatalf("Unpin failed: %v", err)
}
}
func ExampleClient_CreatePost() {
c := NewClient()
// Publish a post
p, err := c.CreatePost(&PostParams{
Title: "Title!",
Content: "This is a post.",
Font: "sans",
})
if err != nil {
fmt.Printf("Unable to create: %v", err)
return
}
fmt.Printf("%s", p.Content)
// Output: This is a post.
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Apr 26, 9:38 PM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3216710

Event Timeline