Skip to content

stationFortyTwo/ReddiGo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

README for ReddiGo SDK

ReddiGo SDK

ReddiGo is a Go-based SDK for interacting with the Reddit API. It allows developers to easily integrate Reddit's functionalities into their Go applications, providing a simple interface for accessing various endpoints.

Installation

First, ensure you have Go installed and set up correctly on your machine. You can install the SDK using:

go get github.com/stationFortyTwo/ReddiGo

Import the SDK into your Go project:

import "github.com/stationFortyTwo/ReddiGo"

Usage

Initialization

To initialize the SDK, you need to create a new instance of ReddiGoSDK by providing your Reddit API credentials.

package main

import (
	"fmt"
	"log"
	"github.com/stationFortyTwo/ReddiGo"
)

func main() {
	sdk := ReddiGo.NewReddiGoSDK("your-client-id", "your-client-secret", "your-redirect-uri", "your-refresh-token")

	// Use the SDK to make API calls
	user, err := sdk.GetMe()
	if err != nil {
		log.Fatalf("Error retrieving user info: %v", err)
	}
	fmt.Printf("User info: %+v\n", user)
}

Generating the SDK

ReddiGo is generated by reddigo-generator based on the reddit dev page. To generate the latest version of ReddiGo, use the generator here and follow the instructions.

Setting Up the SDK Directory

The SDK creates a default directory structure for organizing the generated files. Ensure the path you provide using the -o flag exists or has the necessary permissions.

Contributing

If you wish to contribute to ReddiGo, fork the repository, make your changes, and submit a pull request.

Functions

For a full list of available functions see documentation.md

1. GetMe()

Description:
Fetches the authenticated user's information.

Parameters:
None.

Returns:
(GetMeResponse, error) - The response contains user details or an error if the request fails.

Example:

user, err := sdk.GetMe()
if err != nil {
    log.Fatal(err)
}
fmt.Printf("User: %+v\n", user)

2. MakeRequest(method string, endpoint string, body io.Reader)

Description:
Performs a generic API request to the specified Reddit endpoint.

Parameters:

  • method (string): The HTTP method (e.g., "GET", "POST").
  • endpoint (string): The API endpoint path (e.g., "/api/v1/me").
  • body (io.Reader): The request body (if any).

Returns:
(*http.Response, error) - The response from the Reddit API or an error.

Example:

resp, err := sdk.MakeRequest("GET", "/api/v1/me", nil)
if err != nil {
    log.Fatal(err)
}
defer resp.Body.Close()
// Handle response...

3. RefreshTokenIfNeeded()

Description:
Refreshes the access token if it is expired or near expiration.

Parameters:
None.

Returns:
error - Returns an error if the token refresh fails.

Example:

err := sdk.RefreshTokenIfNeeded()
if err != nil {
    log.Fatal("Token refresh failed:", err)
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages