goodreads

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2018 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// APIUri holds the Goodreads API uri.
	APIUri = "https://www.goodreads.com"
	// SearchEndpoint is the API endpoint for searching for books.
	SearchEndpoint = "/search/index.xml"
	// ShelfListEndpoint is the API endpoint for listing shelves
	ShelfListEndpoint = "/shelf/list.xml"
	// CurrentUserEndpoint is the API endpoint to get the current user
	CurrentUserEndpoint = "/api/auth_user"
	// ListShelfEndpoint is the API endpoint to list books on a shelf
	ListShelfEndpoint = "/review/list"
	// AddToShelfEndpoint is the API endpoint to add a book to a shelf
	AddToShelfEndpoint = "/shelf/add_to_shelf.xml"
	// RequestTokenURI holds the Goodreads request token uri
	RequestTokenURI = "https://www.goodreads.com/oauth/request_token"
	// AuthorizeTokenURI holds the Goodreads authorize token uri
	AuthorizeTokenURI = "https://www.goodreads.com/oauth/authorize"
	// AccessTokenURI holds the Goodreads access token uri
	AccessTokenURI = "https://www.goodreads.com/oauth/access_token"
)

Variables

View Source
var (
	// ErrorEmptyResult defines the error when the result is empty.
	ErrorEmptyResult = errors.New("Empty result")
)

Functions

func GetAccessToken

func GetAccessToken(developerKey string, developerSecret string) (*oauth.AccessToken, error)

GetAccessToken returns an oauth access token

func WriteConfig

func WriteConfig(config *Config, path string) error

WriteConfig writes a Config object to the config file

Types

type Arguments

type Arguments map[string]string

Arguments are a map of key/value query strings

func (Arguments) ToURLValues

func (args Arguments) ToURLValues() url.Values

ToURLValues converts Arguments into query strings

type Book

type Book struct {
	ID        string `xml:"book>id,omitempty"`
	Title     string `xml:"book>title,omitempty"`
	AvgRating string `xml:"book>average_rating,omitempty"`
	Link      string `xml:"book>link,omitempty"`
	Pages     string `xml:"book>num_pages,omitempty"`
	ReadAt    string `xml:"read_at,omitempty"`
}

Book defines the struct for the book object

type Client

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

Client contains information for authenticating with Goodreads API

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient creates a new Gooodreads API client

func (*Client) AddToShelf

func (c *Client) AddToShelf(shelf string, bookID string) error

AddToShelf adds a book to shelf.

func (*Client) GetCurrentUserID

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

GetCurrentUserID returns id for oauth user

func (*Client) ListShelfBooks

func (c *Client) ListShelfBooks(shelf string, userID string) ([]Book, error)

ListShelfBooks returns books by from a shelf.

func (*Client) ListShelves

func (c *Client) ListShelves(userID string) ([]UserShelf, error)

ListShelves for current user.

func (*Client) SearchBooks

func (c *Client) SearchBooks(query string) ([]Work, error)

SearchBooks returns books by author, title, id.

type Config

type Config struct {
	DeveloperKey    string `yaml:"DeveloperKey"`
	DeveloperSecret string `yaml:"DeveloperSecret"`
	AccessToken     string `yaml:"AccessToken"`
	AccessSecret    string `yaml:"AccessSecret"`
}

Config contains configuration for authenticating with Goodreads API

func ReadConfig

func ReadConfig(path string) (*Config, error)

ReadConfig parses the config file into a Config object

type Response

type Response struct {
	Search  Search  `xml:"search,omitempty"`
	Shelves Shelves `xml:"shelves,omitempty"`
	User    User    `xml:"user,omitempty"`
	Reviews Reviews `xml:"reviews,omitempty"`
}

Response defines the data struct for an API response object.

type Reviews

type Reviews struct {
	AttrEnd   string `xml:"end,attr"`
	AttrStart string `xml:"start,attr"`
	AttrTotal string `xml:"total,attr"`
	Books     []Book `xml:"review,omitempty"`
}

Reviews defines the struct for the reviews object

type Search struct {
	Works []Work `xml:"results>work,omitempty" json:"work,omitempty"`
}

Search defines the struct for the search object

type Shelves

type Shelves struct {
	UserShelves []UserShelf `xml:"user_shelf,omitempty"`
}

Shelves defines the struct for the shelves object

type User

type User struct {
	ID string `xml:"id,attr"`
}

User defines the struct for the user object

type UserShelf

type UserShelf struct {
	ID        string `xml:"id,omitempty"`
	Name      string `xml:"name,omitempty"`
	BookCount string `xml:"book_count,omitempty"`
}

UserShelf defines the struct for the user shelf object

type Work

type Work struct {
	ID           string `xml:"best_book>id,omitempty"`
	Title        string `xml:"best_book>title,omitempty"`
	Author       string `xml:"best_book>author>name,omitempty"`
	RatingsCount string `xml:"ratings_count,omitempty"`
	AvgRating    string `xml:"average_rating,omitempty"`
}

Work defines the struct for the work object

Jump to

Keyboard shortcuts

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