/dev-client-go

Client library for the Forem (dev.to) developer API written in Go

Primary LanguageGoMIT LicenseMIT

Dev-Client-Go

dev-client-go is a client library for the Forem (dev.to) developer api written in Go. It provides fully typed methods for every operation you can carry out with the current api (beta)(0.9.7)

Installation

Go version >= 1.13

$ go get github.com/Mayowa-Ojo/dev-client-go

Usage

Import the package and initialize a new client with your auth token(api-key). To get a token, see the authentication docs

package main

import (
   dev "github.com/Mayowa-Ojo/dev-client-go"
)

func main() {
   token := <your-api-key>
   client, err := dev.NewClient(token)
   if err != nil {
      // handle err
   }
}

Documentation

Examples on basic usage for some of the operations you can carry out.

Articles [API doc]

Articles are all the posts that users create on DEV that typically show up in the feed.

Example:

Get published articles

query parameters gives you options to filter the results

// ...
// fetch 10 published articles
articles, err := client.GetPublishedArticles(
   dev.ArticleQueryParams{
      PerPage: 10
   }
)

if err != nil {
   fmt.Println(err.Error())
}

fmt.Printf("Articles: \n%+v", articles)
// ...

Create an article

you can pass the article content as string by setting the Article.Body field, or as a markdown file by passing the filepath as a second parameter

// ...
payload := dev.ArticleBodySchema{}
payload.Article.Title = "The crust of structs in Go"
payload.Article.Published = false
payload.Article.Tags = []string{"golang"}

article, err := client.CreateArticle(payload, "article_sample.md")
if err != nil {
   fmt.Println(err.Error())
}

fmt.Printf("Article: \n%+v", article)
// ...

Organizations [API doc]

Example:

Get an organization

// ...
organization, err := client.GetOrganization(orgname)
if err != nil {
   fmt.Println(err.Error())
}

fmt.Printf("Organization: \n%+v", organization)
// ...

Get users in an organization

// ...
users, err := client.GetOrganizationUsers(
   orgname,
   dev.OrganizationQueryParams{
      Page:    1,
      PerPage: 5,
   },
)

if err != nil {
   fmt.Println(err.Error())
}

fmt.Printf("Users: \n%+v", users)
// ...

Comments [API doc]

Example:

Get comments for article/podcast

// ...
comments, err := client.GetComments(
   dev.CommentQueryParams{
      ArticleID: articleID,
   },
)

if err != nil {
   fmt.Println(err.Error())
}

fmt.Printf("Comments: \n%+v", comments)
// ...

Get a single comment

// ...
comment, err := client.GetComment(commentID)
if err != nil {
   fmt.Println(err.Error())
}

fmt.Printf("Comment: \n%+v", comment)
// ...

Listings [API doc]

Example:

Get published listings

// ...
listings, err := client.GetPublishedListings(
   dev.ListingQueryParams{
      PerPage:  5,
      Category: "cfp",
   },
)

if err != nil {
   fmt.Println(err.Error())
}

fmt.Printf("Listings: \n%+v", listings)
// ...

Get a single listing

// ...
listing, err := client.GetListingByID(listingID)
if err != nil {
   fmt.Println(err.Error())
}

fmt.Printf("Listings: \n%+v", listings)
// ...

API methods

Here's a list of all methods matching every operation currently supported. Clicking them will also take you to the location in the test file to see usage examples.

[Articles]

[Comments]

[Listings]

[Organizations]

[Podcasts]

[ProfileImage]

[Tags]

[Users]

[Webhooks]