dev

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2022 License: MIT Imports: 14 Imported by: 0

README

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/karvounis/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.

Documentation

Index

Constants

View Source
const (
	StateFresh  = State("fresh")
	StateRising = State("rising")
	StateAll    = State("all")
)
View Source
const (
	ListingCategoryCfp       = ListingCategory("cfp")
	ListingCategoryForhire   = ListingCategory("forhire")
	ListingCategoryCollabs   = ListingCategory("collabs")
	ListingCategoryEducation = ListingCategory("education")
	ListingCategoryJobs      = ListingCategory("jobs")
	ListingCategoryMentors   = ListingCategory("mentors")
	ListingCategoryProducts  = ListingCategory("products")
	ListingCategoryMentees   = ListingCategory("mentees")
	ListingCategoryForsale   = ListingCategory("forsale")
	ListingCategoryEvents    = ListingCategory("events")
	ListingCategoryMisc      = ListingCategory("misc")
)
View Source
const (
	ActionDraft     = Action("draft")
	ActionBump      = Action("bump")
	ActionPublish   = Action("publish")
	ActionUnpublish = Action("unpublish")
)
View Source
const (
	BASE_URL = "https://dev.to/api"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

type Article

type Article struct {
	TypeOf                 string           `json:"type_of"`
	ID                     int32            `json:"id"`
	Title                  string           `json:"title"`
	Description            string           `json:"description"`
	CoverImage             string           `json:"cover_image,omitempty"`
	Published              bool             `json:"published"`
	ReadablePublishDate    string           `json:"readable_publish_date"`
	SocialImage            string           `json:"social_image"`
	BodyMarkdown           string           `json:"body_markdown"`
	BodyHTML               string           `json:"body_html"`
	TagList                []string         `json:"tag_list"`
	Tags                   string           `json:"tags"`
	Slug                   string           `json:"slug"`
	Path                   string           `json:"path"`
	URL                    string           `json:"url"`
	CanonicalURL           string           `json:"canonical_url"`
	CommentsCount          int32            `json:"comments_count"`
	PageViewsCount         int32            `json:"page_views_count"`
	PositiveReactionsCount int32            `json:"positive_reactions_count"`
	PublicReactionsCount   int32            `json:"public_reactions_count"`
	CreatedAt              string           `json:"created_at"`
	EditedAt               string           `json:"edited_at,omitempty"`
	CrosspostedAt          string           `json:"crossposted_at,omitempty"`
	PublishedAt            string           `json:"published_at"`
	LastCommentAt          string           `json:"last_comment_at"`
	PublishedTimestamp     string           `json:"published_timestamp"`
	User                   *User            `json:"user"`
	ReadingTimeMinutes     int32            `json:"reading_time_minutes"`
	Organization           *Organization    `json:"organization,omitempty"`
	FlareTag               *ArticleFlareTag `json:"flare_tag,omitempty"`
}

type ArticleBodySchema

type ArticleBodySchema struct {
	Article struct {
		Title          string   `json:"title"`
		BodyMarkdown   string   `json:"body_markdown"`
		Published      bool     `json:"published"`
		Series         string   `json:"series"`
		MainImage      string   `json:"main_image"`
		CanonicalURL   string   `json:"canonical_url"`
		Description    string   `json:"description"`
		Tags           []string `json:"tags"`
		OrganizationID int32    `json:"organization_id"`
	} `json:"article"`
}

type ArticleFlareTag

type ArticleFlareTag struct {
	Name         string `json:"name"`
	BGColorHEX   string `json:"bg_color_hex"`
	TextColorHEX string `json:"text_color_hex"`
}

type ArticleQueryParams

type ArticleQueryParams struct {
	Page         int32  `url:"page,omitempty"`
	PerPage      int32  `url:"per_page,omitempty"`
	Tag          string `url:"tag,omitempty"`
	Tags         string `url:"tags,omitempty"`
	TagsExclude  string `url:"tags_exclude,omitempty"`
	Username     string `url:"username,omitempty"`
	State        State  `url:"state,omitempty"`
	Top          int32  `url:"top,omitempty"`
	CollectionID int32  `url:"collection_id,omitempty"`
}

type ArticleVariant

type ArticleVariant struct {
	Article
	Tags    []string `json:"tags"`
	TagList string   `json:"tag_list"`
}

There are some inconsistencies with regards to the article schema returned when fetching articles and the schema returned when creating articles. This structure fixes that

type Client

type Client struct {
	Client  *http.Client
	BaseUrl *url.URL
	Token   string
}

func NewClient

func NewClient(options Options) (*Client, error)

func NewTestClient

func NewTestClient() (*Client, error)

func (*Client) CreateArticle

func (c *Client) CreateArticle(payload ArticleBodySchema, filepath interface{}) (*ArticleVariant, error)

CreateArticle allows the client to create a new article @filepath - article body can be set on the payload as a string

or passed via the path to a markdown file

func (*Client) CreateListing

func (c *Client) CreateListing(payload ListingBodySchema, filepath interface{}) (*Listing, error)

CreateListing allows the client to create a listing. Listings are classified as ads that users create on DEV

func (*Client) CreateWebhook

func (c *Client) CreateWebhook(payload WebhookBodySchema) (*Webhook, error)

CreateWebhook allows the client to create a new webhook

func (*Client) DeleteWebhook

func (c *Client) DeleteWebhook(webhookID string) error

DeleteWebhook allows the client to delete a single webhook given its id

func (*Client) GetArticlesWithVideo

func (c *Client) GetArticlesWithVideo(q ArticleQueryParams) ([]VideoArticle, error)

GetArticlesWithVideo allows the client to retrieve a list of articles that are uploaded with a video

func (*Client) GetAuthenticatedUser

func (c *Client) GetAuthenticatedUser() (*User, error)

GetAuthenticatedUser allows the client to retrieve information about the authenticated user

func (*Client) GetComment

func (c *Client) GetComment(commentID string) (*Comment, error)

GetComment allows the client to retrieve a comment alongside its descendants

func (*Client) GetComments

func (c *Client) GetComments(q CommentQueryParams) ([]Comment, error)

GetComments allows the client to retrieve all comments belonging to an article or podcast as threaded conversations

func (*Client) GetFollowedTags

func (c *Client) GetFollowedTags() ([]Tag, error)

GetFollowedTags allows the client to retrieve a list of the tags they follow

func (*Client) GetListingByID

func (c *Client) GetListingByID(listingID string) (*Listing, error)

GetListingByID allows the client to retrieve a single listing given its Id

func (*Client) GetOrganization

func (c *Client) GetOrganization(orgname string) (*Organization, error)

GetOrganization allows the client retrieve a single organization by their username

func (*Client) GetOrganizationArticles

func (c *Client) GetOrganizationArticles(orgname string, q OrganizationQueryParams) ([]Article, error)

GetOrganizationArticles allows the client to retrieve a list of Articles belonging to the organization

func (*Client) GetOrganizationListings

func (c *Client) GetOrganizationListings(orgname string, q OrganizationQueryParams) ([]Listing, error)

GetOrganizationListings allows the client to retrieve a list of listings belonging to the organization

func (*Client) GetOrganizationUsers

func (c *Client) GetOrganizationUsers(orgname string, q OrganizationQueryParams) ([]User, error)

GetOrganizationUsers allows the client to retrieve a list of users belonging to the organization

func (*Client) GetProfileImage

func (c *Client) GetProfileImage(username string) (*ProfileImage, error)

GetProfileImage allows the client to retrieve a user or organization profile image information by its corresponding username

func (*Client) GetPublishedArticleByID

func (c *Client) GetPublishedArticleByID(articleID string) (*ArticleVariant, error)

GetPublishedArticleByID allows the client to retrieve a single published article by the specified ID

func (*Client) GetPublishedArticleByPath

func (c *Client) GetPublishedArticleByPath(username, slug string) (*ArticleVariant, error)

GetPublishedArticleByPath allows the client to retrieve a single published article given its path (slug)

func (*Client) GetPublishedArticles

func (c *Client) GetPublishedArticles(q ArticleQueryParams) ([]Article, error)

GetPublishedArticles allows client to retrieve a list of articles

func (*Client) GetPublishedArticlesSorted

func (c *Client) GetPublishedArticlesSorted(q ArticleQueryParams) ([]Article, error)

GetPublishedArticlesSorted allows the client to recieve a list of articles ordered by descending publish date

func (*Client) GetPublishedListings

func (c *Client) GetPublishedListings(q ListingQueryParams) ([]Listing, error)

GetPublishedListings allows the client retrieve a list of listings

func (*Client) GetPublishedListingsByCategory

func (c *Client) GetPublishedListingsByCategory(category string, q ListingQueryParams) ([]Listing, error)

GetPublishedListingsByCategory allows the client to retrieve a list of listings belonging to the given category

func (*Client) GetPublishedPodcastEpisodes

func (c *Client) GetPublishedPodcastEpisodes(q PodcastQueryParams) ([]PodcastEpisode, error)

GetPublishedPodcastEpisodes allows the client to retrieve a list of podcast episodes

func (*Client) GetUserArticles

func (c *Client) GetUserArticles(q ArticleQueryParams) ([]Article, error)

GetUserArticles allows the client to retrieve a list of articles on behalf of an authenticated user

func (*Client) GetUserByID

func (c *Client) GetUserByID(userID string) (*User, error)

GetUserByID allows the client to retrieve a single user with the given id

func (*Client) GetUserByUsername

func (c *Client) GetUserByUsername(q UserQueryParams) (*User, error)

GetUserByUsername allows the client to retrieve a single user with the given username

func (*Client) GetUserFollowers

func (c *Client) GetUserFollowers(q UserQueryParams) ([]User, error)

GetUserFollowers allows the client to retrieve a list of the followers they have.

func (*Client) GetUserPublishedArticles

func (c *Client) GetUserPublishedArticles(q ArticleQueryParams) ([]Article, error)

GetUserArticles allows the client to retrieve a list of published articles on behalf of an authenticated user

func (*Client) GetUserReadingList

func (c *Client) GetUserReadingList(q ReadingListQueryParams) ([]ReadingList, error)

GetUserReadingList allows the client to retrieve a list of readinglist reactions along with the related article for the authenticated user.

func (*Client) GetUserUnPublishedArticles

func (c *Client) GetUserUnPublishedArticles(q ArticleQueryParams) ([]Article, error)

GetUserArticles allows the client to retrieve a list of unpublished articles on behalf of an authenticated user

func (*Client) GetWebhookByID

func (c *Client) GetWebhookByID(webhookID string) (*Webhook, error)

GetWebhookByID allows the client to retrieve a single webhook given its id

func (*Client) GetWebhooks

func (c *Client) GetWebhooks() ([]Webhook, error)

GetWebhooks allows the client to retrieve a list of webhooks they have previously registered.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, payload interface{}) (*http.Request, error)

func (*Client) SendHttpRequest

func (c *Client) SendHttpRequest(r *http.Request, v interface{}) error

func (*Client) UpdateArticle

func (c *Client) UpdateArticle(articleID string, payload ArticleBodySchema, filepath interface{}) (*ArticleVariant, error)

UpdateArticle allows the client to update an existing article This method is rate-limited (30req/30sec)

func (*Client) UpdateListing

func (c *Client) UpdateListing(listingID string, payload ListingBodySchema, filepath interface{}) (*Listing, error)

type Comment

type Comment struct {
	TypeOf    string    `json:"type_of"`
	IDCode    string    `json:"id_code"`
	CreatedAt string    `json:"created_at"`
	BodyHTML  string    `json:"body_html"`
	User      *User     `json:"user"`
	Children  []Comment `json:"children"`
}

type CommentQueryParams

type CommentQueryParams struct {
	ArticleID int32 `url:"a_id"`
	PodcastID int32 `url:"p_id"`
}

type DevAPIError

type DevAPIError struct {
	// contains filtered or unexported fields
}

func (*DevAPIError) Error

func (d *DevAPIError) Error() string

type Listing

type Listing struct {
	TypeOf        string          `json:"type_of"`
	ID            int64           `json:"id"`
	Title         string          `json:"title"`
	Slug          string          `json:"slug"`
	BodyMarkdown  string          `json:"body_markdown"`
	TagList       string          `json:"tag_list"`
	Tags          []string        `json:"tags"`
	Category      ListingCategory `json:"category"`
	ProcessedHTML string          `json:"processed_html"`
	Published     bool            `json:"published"`
	CreatedAt     string          `json:"created_at"`
	User          *User           `json:"user"`
	Organization  *Organization   `json:"organization"`
}

type ListingBodySchema

type ListingBodySchema struct {
	Listing struct {
		Title             string          `json:"title"`
		BodyMarkdown      string          `json:"body_markdown"`
		Category          ListingCategory `json:"category"`
		Tags              []string        `json:"tags"`
		TagList           string          `json:"tag_list"`
		ExpiresAt         string          `json:"expires_at"`
		ContactViaConnect bool            `json:"contact_via_connect"`
		Location          string          `json:"location"`
		OrganizationID    int64           `json:"organization_id,omitempty"`
		Action            Action          `json:"action"`
	} `json:"listing"`
}

type ListingCategory

type ListingCategory string

type ListingQueryParams

type ListingQueryParams struct {
	Page     int32  `url:"page"`
	PerPage  int32  `url:"per_page"`
	Category string `url:"category"`
}

type Options

type Options struct {
	Host  string
	Token string
}

type Organization

type Organization struct {
	TypeOf          string `json:"type_of"`
	Name            string `json:"name"`
	Username        string `json:"username"`
	Summary         string `json:"summary"`
	TwitterUsername string `json:"twitter_username,omitempty"`
	GithubUsername  string `json:"github_username,omitempty"`
	URL             string `json:"url"`
	Location        string `json:"location,omitempty"`
	TechStack       string `json:"tech_stack,omitempty"`
	TagLine         string `json:"tag_line,omitempty"`
	Story           string `json:"story,omitempty"`
	Slug            string `json:"slug"`
	JoinedAt        string `json:"joined_at"`
	ProfileImage    string `json:"profile_image"`
	ProfileImage90  string `json:"profile_image_90"`
}

type OrganizationQueryParams

type OrganizationQueryParams struct {
	Page     int32           `url:"page,omitempty"`
	PerPage  int32           `url:"per_page,omitempty"`
	Category ListingCategory `json:"category,omitempty"`
}

type PodcastEpisode

type PodcastEpisode struct {
	TypeOf   string `json:"type_of"`
	ID       int32  `json:"id"`
	Path     string `json:"path"`
	ImageURL string `json:"image_url"`
	Title    string `json:"title"`
	Podcast  struct {
		Title    string `json:"title"`
		Slug     string `json:"slug"`
		ImageURL string `json:"image_url"`
	}
}

type PodcastQueryParams

type PodcastQueryParams struct {
	Page     int32  `url:"page"`
	PerPage  int32  `url:"per_page"`
	Username string `url:"username"`
}

type ProfileImage

type ProfileImage struct {
	TypeOf         string `json:"type_of"`
	ImageOf        string `json:"image_of"`
	ProfileImage   string `json:"profile_image"`
	ProfileImage90 string `json:"profile_image_90"`
}

type ReadingList

type ReadingList struct {
	TypeOf  string            `json:"type_of"`
	ID      int32             `json:"id"`
	Status  ReadingListStatus `json:"status"`
	Article *Article          `json:"article"`
}

type ReadingListQueryParams

type ReadingListQueryParams struct {
	Page    int32 `url:"page,omitempty"`
	PerPage int32 `url:"per_page,omitempty"`
}

type ReadingListStatus

type ReadingListStatus string
const (
	ReadingListStatusValid        ReadingListStatus = "valid"
	ReadingListStatusInvalidValid ReadingListStatus = "invalid"
	ReadingListStatusConfirmed    ReadingListStatus = "confirmed"
	ReadingListStatusArchived     ReadingListStatus = "archived"
)

type State

type State string

type Tag

type Tag struct {
	ID     int64   `json:"id"`
	Name   string  `json:"name"`
	Points float64 `json:"points"`
}

type User

type User struct {
	TypeOf          string `json:"type_of"`
	ID              int32  `json:"id"`
	Username        string `json:"username"`
	Name            string `json:"name"`
	Summary         string `json:"summary,omitempty"`
	TwitterUsername string `json:"twitter_username,omitempty"`
	GithubUsername  string `json:"github_username,omitempty"`
	WebsiteURL      string `json:"website_url,omitempty"`
	Location        string `json:"location,omitempty"`
	JoinedAt        string `json:"joined_at"`
	ProfileImage    string `json:"profile_image"`
}

type UserQueryParams

type UserQueryParams struct {
	Page    int32  `url:"page,omitempty"`
	PerPage int32  `url:"per_page,omitempty"`
	URL     string `url:"url"`
	Sort    string `url:"sort"`
}

type VideoArticle

type VideoArticle struct {
	TypeOf                 string `json:"type_of"`
	ID                     int32  `json:"id"`
	Path                   string `json:"path"`
	CloudinaryVideoURL     string `json:"cloudinary_video_url"`
	Title                  string `json:"title"`
	UserID                 int32  `json:"user_id"`
	VideoDurationInMinutes string `json:"video_duration_in_minutes"`
	VideoSourceURL         string `json:"video_source_url"`
	User                   *User  `json:"user"`
}

type Webhook

type Webhook struct {
	TypeOf    string   `json:"type_of"`
	ID        int64    `json:"id"`
	Source    string   `json:"source"`
	TargetURL string   `json:"target_url"`
	Events    []string `json:"events"`
	CreatedAt string   `json:"created_at"`
}

type WebhookBodySchema

type WebhookBodySchema struct {
	WebhookEndpoint struct {
		Source    string   `json:"source"`
		TargetURL string   `json:"target_url"`
		Events    []string `json:"events"`
	} `json:"webhook_endpoint"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL