goRant

package module
Version: v0.0.0-...-4b8cbee Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2017 License: MIT Imports: 5 Imported by: 0

README

goRant

An unofficial Go client for public devRant API

https://www.devrant.io/

Go Report Card

Table of Content

  1. Installation
  2. Documentation
  3. Getting Started
  4. Todo

Installation:

go get github.com/jay9596/goRant

Documentation

go doc github.com/jay9596/goRant
Or visit: GoDoc

Getting Started

  • goRant Functions
    Assign a New client
    devRant := goRant.New()
    
    Rants : Fetch rants
    rants,err := devRant.Rants()
    Rant : Fetch a single rant

    rant,comments,err := devRant.GetRant(rantID)

    Profile : Fetch a user profile

    user,err := devRant.Profile("byte")

    Search : Search on devrant

    rants,err := devRant.Search("vscode")

    Surprise : Fetch a random rant

    rant,comments,err := devRant.Surprise()

    WeeklyRant : Fetch weekly rants

    rants,err := devRant.WeeklyRant()

    Collabs : Fetch collabs

    rants,err := devRant.Collabs()

    Stories : Fetch stories

    rants,err := devRant.Stories()

  • goRant Types
    All rant specified above represent a Rant struct
    The rants represent an array of Rant [ ]Rant
    The user represent User struct
    The comments represent an array of Comment [ ]Comment

Todo

  • Add supporter ++ support
  • Add Tests

Documentation

Overview

Package goRant implements a API-wrapper for the public API of http://www.devrant.io

Index

Constants

View Source
const (
	API      = "https://www.devrant.io/api"
	VERSION  = 3
	RANTS    = "%s/devrant/rants?sort=%s&limit=%d&skip=%d&app=%d"
	RANT     = "%s/devrant/rants/%d?app=%d"
	USERID   = "%s/get-user-id?username=%s&app=%d"
	USER     = "%s/users/%d?app=%d"
	SEARCH   = "%s/devrant/search?term=%s&app=%d"
	SURPRISE = "%s/devrant/rants/surprise?app=%d"
	WEEKLY   = "%s/devrant/weekly-rants?app=%d"
	COLLABS  = "%s/devrant/collabs?app=%d"
	STORIES  = "%s/devrant/story-rants?app=%d"
)

All Constants are written in uppercase, and have no need to be exported

Variables

This section is empty.

Functions

This section is empty.

Types

type Avatar

type Avatar struct {
	B string `json:"b"`
	I string `json:"i"`
}

Avatar is a struct to save avatar information of a user profile B stands for background color I is the actual image of the profile

type Client

type Client struct {
}

Client in an empty interface It is has all functionalitios of goRant Wrapper

func New

func New() *Client

New returns a new Client

func (*Client) Collabs

func (c *Client) Collabs() ([]Rant, error)

Collabs return an array of Rants from the collabs tob of devRant

func (*Client) GetRant

func (c *Client) GetRant(id int) (Rant, []Comment, error)

GetRant returns a singel Rant Just pass a rant-id as parameter

func (*Client) Profile

func (c *Client) Profile(username string) (User, error)

Profile returns a User profile info It takes a username of type string as input

func (*Client) Rants

func (c *Client) Rants(sort string, limit int, skip int) ([]Rant, error)

Rants return an array of Rants from devRant.io

It has 3 parameters: Sort, Limit, Skip Sort can take 3 values, "algo", "recent", "top" Limit is an int value, used to specify number of rants to get Skip is an int value, used to specify number of rants to skip Example: If you eant the recent 20 rants: Rants("recent",20,0) If you want the next 20 rants: Rants("recent",20,20)

func (*Client) Search

func (c *Client) Search(query string) ([]Rant, error)

Search returns array of Rants as the search result

func (*Client) Stories

func (c *Client) Stories() ([]Rant, error)

Stories return an array of Rants from stories tab of devRant

func (*Client) Surprise

func (c *Client) Surprise() (Rant, []Comment, error)

Surprise returns a random Rant

func (*Client) WeeklyRant

func (c *Client) WeeklyRant() ([]Rant, error)

WeeklyRant return an array of Rants from weekly rants tab of devRant

type Comment

type Comment struct {
	ID          int    `json:"id"`
	RantID      int    `json:"rant_id"`
	Body        string `json:"body"`
	Score       int    `json:"score"`
	CreatedTime int    `json:"created_time"`
	UserID      int    `json:"user_id"`
	Username    string `json:"user_username"`
	UserScore   int    `json:"user_score"`
}

Comment is a struct to store comment data

type Content

type Content struct {
	Rants     []Rant    `json:"rants"`
	Upvoted   []Rant    `json:"upvoted"`
	Comments  []Comment `json:"comments"`
	Favorites []Rant    `json:"favorites"`
}

Content is a struct to save Content of a User It has rants,upvotes,comments,favoutites of a user

type Counts

type Counts struct {
	Rants      int `json:"rants"`
	Upvotes    int `json:"upvoted"`
	Comments   int `json:"comments"`
	Favourites int `json:"favourites"`
	Collabs    int `json:"collabs"`
}

Counts is a struct to save Counts of a User It has count(int values) of Rants, Upvotes, Comments, Favourites, and Colabs of a user

type Image

type Image struct {
	URL    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

Image struct is used to store info about Images Any attached images in rants, and/or comments It has Height, Width, and URl of the image

type News

type News struct {
	ID       int    `json:"id"`
	Type     string `json:"type"`
	Headline string `json:"headline"`
	Body     string `json:"body"`
	Footer   string `json:"footer"`
	Height   int    `json:"height"`
	Action   string `json:"action"`
}

News struct is used to store info about any News from devRant

type Rant

type Rant struct {
	ID            int      `json:"id"`
	Text          string   `json:"text"`
	Score         int      `json:"score"`
	CreatedTime   int      `json:"created_time"`
	AttachedImage Image    `json:"attached_image"`
	NumComments   int      `json:"num_comments"`
	Tags          []string `json:"tags"`
	VoteState     int      `json:"vote_state"`
	Edited        bool     `json:"edited"`
	UserID        int      `json:"user_id"`
	Username      string   `json:"user_username"`
	UserScore     int      `json:"user_score"`
}

Rant is a struct to save Rant data

type RantRes

type RantRes struct {
	Success  bool      `json:"success"`
	Error    string    `json:"error"`
	Rant     Rant      `json:"rant"`
	Comments []Comment `json:"comments"`
}

RantRes is a struct to receive Rant response

type Rants

type Rants struct {
	Success  bool   `json:"success"`
	Error    string `json:"error"`
	Rants    []Rant `json:"rants"`
	Settings string `json:"settings"`
	Set      string `json:"set"`
	Wrw      int    `json:"wrw"`
	News     News   `json:"news"`
}

Rants is struct for receiving Rants response

type SearchRes

type SearchRes struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
	Rants   []Rant `json:"results"`
}

SearchRes is a struct to receive Search response

type User

type User struct {
	Username    string `json:"username"`
	Score       int    `json:"score"`
	About       string `json:"about"`
	Location    string `json:"location"`
	CreatedTime int    `json:"created_time"`
	Skills      string `json:"skills"`
	Github      string `json:"github"`
	Website     string `json:"website"`
	Content     struct {
		Content Content `json:"content"`
		Counts  Counts  `json:"counts"`
	} `json:"content"`
	Avatar Avatar `json:"avatar"`
	DPP    int    `json:"dpp"`
}

User is a struct to store User data

type UserIDRes

type UserIDRes struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
	UserID  int    `json:"user_id"`
}

UserIDRes is a struct to receive UserId response that is used to fetch a User

type UserRes

type UserRes struct {
	Success bool   `json:"success"`
	Error   string `json:"error"`
	Profile User   `json:"profile"`
}

UserRes is a struct to receive User response

Jump to

Keyboard shortcuts

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