redditreadgo

package module
v0.0.0-...-6c413c0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

README

redditreadgo

The goal of this project is to provide an efficient way of retrieving Reddit submissions of a specified subreddit or of a redditor.

Build Status Go Report Card GoDoc Widget

Installing

Run

go get github.com/MihaiBogdanEugen/redditreadgo

Include in your source:

import "github.com/MihaiBogdanEugen/redditreadgo"

Using dep:

dep ensure -add github.com/MihaiBogdanEugen/redditreadgo

Godoc

See http://godoc.org/github.com/MihaiBogdanEugen/redditreadgo

Configuration

One can configure a ReadOnlyRedditClient by providing the following:

  • the Reddit API Consumer Key,
  • the Reddit API Consumer Secret and
  • an user agent used for preventing banning or API throttling

Documentation

Index

Constants

View Source
const DefaultSliceSize = 100

DefaultSliceSize specifies the size of the slice of submission retrieved when querying

View Source
const QueryURL = "https://oauth.reddit.com"

QueryURL specifies default Reddit query URL

View Source
const TokenURL = "https://www.reddit.com/api/v1/access_token"

TokenURL specifies default Reddit access token URL

Variables

This section is empty.

Functions

This section is empty.

Types

type AgeSort

type AgeSort string

AgeSort represents the possible ways to sort submissions by age.

const (
	// ThisHour value
	ThisHour AgeSort = "hour"
	// ThisDay value
	ThisDay AgeSort = "day"
	// ThisWeek value
	ThisWeek AgeSort = "week"
	//ThisMonth value
	ThisMonth AgeSort = "month"
	// ThisYear value
	ThisYear AgeSort = "year"
	// AllTime value
	AllTime AgeSort = "all"
)

type IReadOnlyRedditClient

type IReadOnlyRedditClient interface {

	// Logger sets the logger. Optional, useful for debugging purposes.
	Logger(logger *logrus.Logger)

	// Throttle sets the interval of each HTTP request. Disable by setting interval to 0. Disabled by default.
	Throttle(interval time.Duration)

	// AllSubmissionsTo returns a total no. of submissions to the given subreddit, considering popularity sort and age sort
	AllSubmissionsTo(subreddit string, sort PopularitySort, age AgeSort, total int) ([]*Submission, error)

	// SubmissionsTo returns the submissions to the given subreddit, considering popularity sort, age sort, and listing options
	SubmissionsTo(subreddit string, sort PopularitySort, age AgeSort, params ListingOptions) ([]*Submission, *SliceInfo, error)

	// AllSubmissionsOf returns a total no. of submissions of the given author, considering popularity sort and age sort
	AllSubmissionsOf(author string, sort PopularitySort, age AgeSort, total int) ([]*Submission, error)

	// SubmissionsOf returns the submissions of the given author, considering popularity sort, age sort, and listing options
	SubmissionsOf(author string, sort PopularitySort, age AgeSort, params ListingOptions) ([]*Submission, *SliceInfo, error)
}

IReadOnlyRedditClient defines behaviour for an OAuth, read-only session with reddit.

type ListingOptions

type ListingOptions struct {
	// Region - filter hot results by specifying the region
	Region Region `url:"q,omitempty"`

	// Limit - the maximum number of items to return in this slice of the listing - default: 25, maximum: 100
	Limit int `url:"limit,omitempty"`

	// After or Before - only one should be specified. These indicate the full name of an item in the listing to use as the anchor point of the slice
	After string `url:"after,omitempty"`

	// Before or After - only one should be specified. These indicate the full name of an item in the listing to use as the anchor point of the slice
	Before string `url:"before,omitempty"`

	// Count - the number of items already seen in this listing - default: 0
	Count int `url:"count,omitempty"`

	// Show - optional parameter; if all is passed, filters such as "hide links that I have voted on" will be disabled
	Show string `url:"show,omitempty"`
}

ListingOptions represents listings query url parameters. More info: https://www.reddit.com/dev/api/

type PopularitySort

type PopularitySort string

PopularitySort represents the possible ways to sort submissions by popularity.

const (
	// DefaultPopularity value
	DefaultPopularity PopularitySort = ""
	// HotSubmissions value
	HotSubmissions PopularitySort = "hot"
	// NewSubmissions value
	NewSubmissions PopularitySort = "new"
	// RisingSubmissions value
	RisingSubmissions PopularitySort = "rising"
	// TopSubmissions value
	TopSubmissions PopularitySort = "top"
	// ControversialSubmissions value
	ControversialSubmissions PopularitySort = "controversial"
)

type ReadOnlyRedditClient

type ReadOnlyRedditClient struct {
	Token  *oauth2.Token
	Cookie *http.Cookie
	// contains filtered or unexported fields
}

ReadOnlyRedditClient represents an OAuth, read-only session with reddit.

func NewReadOnlyRedditClient

func NewReadOnlyRedditClient(clientID string, clientSecret string, userAgent string) (*ReadOnlyRedditClient, error)

NewReadOnlyRedditClient creates a new session for those who want to log into a reddit account via OAuth.

func (*ReadOnlyRedditClient) AllSubmissionsOf

func (c *ReadOnlyRedditClient) AllSubmissionsOf(author string, sort PopularitySort, age AgeSort, total int) ([]*Submission, error)

AllSubmissionsOf returns a total no. of submissions of the given author, considering popularity sort and age sort

func (*ReadOnlyRedditClient) AllSubmissionsTo

func (c *ReadOnlyRedditClient) AllSubmissionsTo(subreddit string, sort PopularitySort, age AgeSort, total int) ([]*Submission, error)

AllSubmissionsTo returns a total no. of submissions to the given subreddit, considering popularity sort and age sort

func (*ReadOnlyRedditClient) Logger

func (c *ReadOnlyRedditClient) Logger(logger *logrus.Logger)

Logger sets the logger. Optional, useful for debugging purposes.

func (*ReadOnlyRedditClient) SubmissionsOf

func (c *ReadOnlyRedditClient) SubmissionsOf(author string, sort PopularitySort, age AgeSort, params ListingOptions) ([]*Submission, *SliceInfo, error)

SubmissionsOf returns the submissions on the given author, considering popularity sort, age sort, and listing options

func (*ReadOnlyRedditClient) SubmissionsTo

func (c *ReadOnlyRedditClient) SubmissionsTo(subreddit string, sort PopularitySort, age AgeSort, params ListingOptions) ([]*Submission, *SliceInfo, error)

SubmissionsTo returns the submissions on the given subreddit, considering popularity sort, age sort, and listing options

func (*ReadOnlyRedditClient) Throttle

func (c *ReadOnlyRedditClient) Throttle(interval time.Duration)

Throttle sets the interval of each HTTP request. Disable by setting interval to 0. Disabled by default.

type Region

type Region string

Region represents the possible values for querying by region

const (
	Global           Region = "GLOBAL"
	USA              Region = "US"
	Argentina        Region = "AR"
	Australia        Region = "AU"
	Bulgaria         Region = "BG"
	Canada           Region = "CA"
	Chile            Region = "CL"
	Colombia         Region = "CO"
	Croatia          Region = "HR"
	CzechRepublic    Region = "CZ"
	Finald           Region = "FI"
	Greece           Region = "GR"
	Hungary          Region = "HU"
	Iceland          Region = "IS"
	India            Region = "IN"
	Ireland          Region = "IE"
	Japan            Region = "JP"
	Malaysia         Region = "MY"
	Mexico           Region = "MX"
	NewZealand       Region = "NZ"
	Philippines      Region = "PH"
	Poland           Region = "PL"
	Portugal         Region = "PT"
	PuertoRico       Region = "PR"
	Romania          Region = "RO"
	Russia           Region = "RS"
	Singapore        Region = "SG"
	Sweden           Region = "SE"
	Taiwan           Region = "TW"
	Thailand         Region = "TH"
	Turkey           Region = "TR"
	UnitedKingdom    Region = "GB"
	USAAlaska        Region = "US_AK"
	USAAlabama       Region = "US_AL"
	USAArkansas      Region = "US_AR"
	USAArizona       Region = "US_AZ"
	USACalifornia    Region = "US_CA"
	USAColorado      Region = "US_CO"
	USAConnecticut   Region = "US_CT"
	USADC            Region = "US_DC"
	USADelaware      Region = "US_DE"
	USAFlorida       Region = "US_FL"
	USAGeorgia       Region = "US_GA"
	USAHawaii        Region = "US_HI"
	USAIowa          Region = "US_IA"
	USAIdaho         Region = "US_ID"
	USAIllinois      Region = "US_IL"
	USAIndiana       Region = "US_IN"
	USAKansas        Region = "US_KS"
	USAKentucky      Region = "US_KY"
	USALouisiana     Region = "US_LA"
	USAMassachusetts Region = "US_MA"
	USAMaryland      Region = "US_MD"
	USAMaine         Region = "US_ME"
	USAMichigan      Region = "US_MI"
	USAMinnesota     Region = "US_MN"
	USAMissouri      Region = "US_MO"
	USAMississippi   Region = "US_MS"
	USAMontana       Region = "US_MT"
	USANorthCarolina Region = "US_NC"
	USANorthDakota   Region = "US_ND"
	USANebraska      Region = "US_NE"
	USANewHampshire  Region = "US_NH"
	USANewJersey     Region = "US_NJ"
	USANewMexico     Region = "US_NM"
	USANevada        Region = "US_NV"
	USANewYork       Region = "US_NY"
	USAOhio          Region = "US_OH"
	USAOklahoma      Region = "US_OK"
	USAOregon        Region = "US_OR"
	USAPennsylvania  Region = "US_PA"
	USARhodeIsland   Region = "US_RI"
	USASouthCarolina Region = "US_SC"
	USASouthDakota   Region = "US_SD"
	USATennessee     Region = "US_TN"
	USATexas         Region = "US_TX"
	USAUtah          Region = "US_UT"
	USAVirginia      Region = "US_VA"
	USAVermont       Region = "US_VT"
	USAWashington    Region = "US_WA"
	USAWisconsin     Region = "US_WI"
	USAWestVirginia  Region = "US_WV"
	USAWyoming       Region = "US_WY"
)

type SliceInfo

type SliceInfo struct {
	After  string
	Before string
}

SliceInfo represents after and before pointers for retrieving the next slice of submissions

type Submission

type Submission struct {
	ApprovedAtUTC         float64 `json:"approved_at_utc"`
	ApprovedBy            string  `json:"approved_by"`
	Archived              bool    `json:"archived"`
	Author                string  `json:"author"`
	BannedAtUTC           float64 `json:"banned_at_utc"`
	BannedBy              string  `json:"banned_by"`
	CanGlid               bool    `json:"can_gild"`
	Category              string  `json:"category"`
	Clicked               bool    `json:"clicked"`
	ContentCategories     string  `json:"content_categories"`
	ContestMode           bool    `json:"contest_mode"`
	Created               float64 `json:"created"`
	CreatedUTC            float64 `json:"created_utc"`
	Distinguished         string  `json:"distinguished"`
	Domain                string  `json:"domain"`
	Downs                 int     `json:"downs"`
	Edited                bool    `json:"edited"`
	Glided                uint64  `json:"gilded"`
	Hidden                bool    `json:"hidden"`
	HideScore             bool    `json:"hide_score"`
	ID                    string  `json:"id"`
	IsCrosspostable       bool    `json:"is_crosspostable"`
	IsOriginalContent     bool    `json:"is_original_content"`
	IsRedditMediaDomain   bool    `json:"is_reddit_media_domain"`
	IsSelf                bool    `json:"is_self"`
	IsVideo               bool    `json:"is_video"`
	Likes                 string  `json:"likes"`
	Locked                bool    `json:"locked"`
	MediaOnly             bool    `json:"media_only"`
	Name                  string  `json:"name"`
	NoFollow              bool    `json:"no_follow"`
	NumComments           uint64  `json:"num_comments"`
	NumCrossposts         uint64  `json:"num_crossposts"`
	NumReports            uint64  `json:"num_reports"`
	Over18                bool    `json:"over_18"`
	ParentWhitelistStatus string  `json:"parent_whitelist_status"`
	Permalink             string  `json:"permalink"`
	Pinned                bool    `json:"pinned"`
	PostCategories        string  `json:"post_categories"`
	PostHint              string  `json:"post_hint"`
	Quarantine            bool    `json:"quarantine"`
	RemovalReason         string  `json:"removal_reason"`
	ReportReasons         string  `json:"report_reasons"`
	Saved                 bool    `json:"saved"`
	Score                 uint64  `json:"score"`
	Selftext              string  `json:"selftext"`
	SelftextHTML          string  `json:"selftext_html"`
	SendReplies           bool    `json:"send_replies"`
	Spoiler               bool    `json:"spoiler"`
	Stickied              bool    `json:"stickied"`
	Subreddit             string  `json:"subreddit"`
	SubredditID           string  `json:"subreddit_id"`
	SubredditNamePrefixed string  `json:"subreddit_name_prefixed"`
	SubredditSubscribers  uint64  `json:"subreddit_subscribers"`
	SubredditType         string  `json:"subreddit_type"`
	SuggestedSort         string  `json:"suggested_sort"`
	Thumbnail             string  `json:"thumbnail"`
	Title                 string  `json:"title"`
	Ups                   int     `json:"ups"`
	URL                   string  `json:"url"`
	ViewCount             uint64  `json:"view_count"`
	Visited               bool    `json:"visited"`
	WhitelistStatus       string  `json:"whitelist_status"`
}

Submission represents an individual post from the perspective of a subreddit

type TokenAsJSON

type TokenAsJSON struct {
	// AccessToken value
	AccessToken string `json:"access_token"`
	// TokenType value
	TokenType string `json:"token_type"`
	// RefreshToken value
	RefreshToken string `json:"refresh_token"`
	// ExpiresIn value
	ExpiresIn int32 `json:"expires_in"`
}

TokenAsJSON represents the access token serialized as a json object

Jump to

Keyboard shortcuts

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