devgorant

package module
v0.0.0-...-69fb03e Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2016 License: MIT Imports: 4 Imported by: 4

README

devgorant GoDoc Build Status

Unofficial golang wrapper for the devRant API

Installation

go get github.com/jayeshsolanki93/devgorant

Usage

Simple implementation to get the user score(points):

package main

import (
  "fmt"
  "github.com/jayeshsolanki93/devgorant"
  "log"
)

func main() {
  devrant := devgorant.New()
  user, _, err := devrant.Profile("jayeshs")
  if err != nil {
    log.Fatal(err)
  }
  fmt.Println(user.Score)
}

API Reference

Rants : Fetches rants

Parameters:

| Name | Type | Description | Default | | ---- | ---- | -------- | ----------- | ------- | | sort | string | Sort by algo, top, recent | algo | | limit | integer | Number of rants required. Cannot be more than 50. | 50 | | skip | integer | Number of rants to skip. | 0 |

Example:

devrant := devgorant.New()
rants, err := devrant.Rants("algo", 20, 0)

Rant : Fetches a rant and its comments given a valid rant id

Parameters:

| Name | Type | Description | Default | | ---- | ---- | -------- | ----------- | ------- | | rantId | integer | rant_id of a posted rant | |

Example:

devrant := devgorant.New()
rant, comments, err := devrant.Rant(27317)

Profile : Fetches ranter's profile data

Parameters:

| Name | Type | Description | Default | | ---- | ---- | -------- | ----------- | ------- | | username | string | a valid username on devRant | |

Example:

devrant := devgorant.New()
user, content, err := devrant.Profile("jayeshs")

Search : Search for rants matching the search term

Parameters:

| Name | Type | Description | Default | | ---- | ---- | -------- | ----------- | ------- | | term | string | any string to use as the search term | |

Example:

devrant := devgorant.New()
rants, err := devrant.Search("golang")

Surprise : Returns a random rant

Example:

devrant := devgorant.New()
rant, err := devrant.Surprise()

WeeklyRants : Returns the rants tagged for 'weekly'

Example:

devrant := devgorant.New()
rants, err := devrant.WeeklyRants()

Tests

To run the tests locally:

go test -v 

TODO

// TODO

Documentation

Index

Constants

View Source
const (
	API           = "https://www.devrant.io/api"
	APP_VERSION   = 3
	RANTS_PATH    = "%s/devrant/rants?sort=%s&limit=%d&skip=%d&app=%d"
	RANT_PATH     = "%s/devrant/rants/%d?app=%d"
	USER_PATH     = "%s/users/%d?app=%d"
	USER_ID_PATH  = "%s/get-user-id?username=%s&app=%d"
	SEARCH_PATH   = "%s/devrant/search?term=%s&app=%d"
	SURPRISE_PATH = "%s/devrant/rants/surprise?app=%d"
	WEEKLY_PATH   = "%s/devrant/weekly-rants?app=%d"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
}

func New

func New() *Client

func (*Client) Profile

func (c *Client) Profile(username string) (UserModel, ContentModel, error)

Fetches ranter's profile data

func (*Client) Rant

func (c *Client) Rant(rantId int) (RantModel, []CommentModel, error)

Fetches a rant and its comments given a valid rant id

func (*Client) Rants

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

Fetches rants

func (*Client) Search

func (c *Client) Search(term string) ([]RantModel, error)

Search for rants matching the search term

func (*Client) Surprise

func (c *Client) Surprise() (RantModel, error)

Returns a random rant

func (*Client) WeeklyRants

func (c *Client) WeeklyRants() ([]RantModel, error)

Returns the rants tagged for 'weekly'

type CommentModel

type CommentModel struct {
	Id           int    `json:"id"`
	RantId       int    `json:"rant_id"`
	Body         string `json:"body"`
	Upvotes      int    `json:"num_upvotes"`
	Downvotes    int    `json:"num_downvotes"`
	Score        int    `json:"score"`
	CreatedTime  int    `json:"created_time"`
	UserId       int    `json:"user_id"`
	UserUsername string `json:"user_username"`
	UserScore    int    `json:"user_score"`
}

type ContentModel

type ContentModel struct {
	Rants     []RantModel    `json:"rants"`
	Upvoted   []RantModel    `json:"upvoted"`
	Comments  []CommentModel `json:"comments"`
	Favorites []RantModel    `json:"favorites"`
}

type GetUserIdResponse

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

type ImageModel

type ImageModel struct {
	Url    string `json:"url"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
}

type NewsModel

type NewsModel 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"`
}

type RantModel

type RantModel struct {
	Id            int        `json:"id"`
	Text          string     `json:"text"`
	Upvotes       int        `json:"num_upvotes"`
	Downvotes     int        `json:"num_downvotes"`
	Score         int        `json:"score"`
	CreatedTime   int        `json:"created_time"`
	AttachedImage ImageModel `json:"attached_image"`
	NumComments   int        `json:"num_comments"`
	Tags          []string   `json:"tags"`
	UserId        int        `json:"user_id"`
	UserUsername  string     `json:"user_username"`
	UserScore     int        `json:"user_score"`
}

type RantResponse

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

type RantsResponse

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

type SearchResponse

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

type UserModel

type UserModel 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"`
	Content     struct {
		Content ContentModel `json:"content"`
	} `json:"content"`
}

type UserResponse

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

Jump to

Keyboard shortcuts

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