ajaxapi

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package ajaxapi handles the AJAX functionality which is not usable from neither the public or the mobile API such as the fanboxes or possibly the like functionality

Index

Constants

View Source
const CookieSession = "PHPSESSID"

CookieSession is the session cookie which is set after a successful login

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	ErrorOccurred bool   `json:"error"`
	ErrorMessage  string `json:"message"`
}

APIError contains error messages of the API

func (APIError) Error

func (e APIError) Error() string

Error returns the occurred API error message

type APIRequestError

type APIRequestError struct {
	ErrorMessage string `json:"error"`
}

APIRequestError is the error struct of invalid requests

func (APIRequestError) Error

func (e APIRequestError) Error() string

Error returns the occurred API error message

type AjaxAPI

type AjaxAPI struct {
	StorageURL    *url.URL
	Session       watcherHttp.SessionInterface
	Key           string
	SessionCookie *models.Cookie
}

AjaxAPI is the implementation of the not reachable but required endpoints not in the public or mobile API

func NewAjaxAPI

func NewAjaxAPI(moduleKey string) *AjaxAPI

NewAjaxAPI initializes the AJAX API and handles the whole auth and round tripper procedures

func (*AjaxAPI) AddRoundTrippers

func (a *AjaxAPI) AddRoundTrippers()

AddRoundTrippers sets the required pixiv session sessionCookie required for the AJAX API and adds the round trippers to the session client

func (*AjaxAPI) GetCreator

func (a *AjaxAPI) GetCreator(userID int) (*CreatorInfo, error)

GetCreator requests the creator information from the unofficial ajax/fanbox/creator endpoint

func (*AjaxAPI) GetPostInfo

func (a *AjaxAPI) GetPostInfo(postID int) (*FanboxPostInfo, error)

GetPostInfo requests the fanbox post info from the API for the passed post ID

func (*AjaxAPI) GetPostList

func (a *AjaxAPI) GetPostList(userID int, limit int) (*PostInfo, error)

GetPostList returns the initial post list of the passed user

func (*AjaxAPI) GetPostListByURL

func (a *AjaxAPI) GetPostListByURL(url string) (*PostInfo, error)

GetPostListByURL returns the post info solely by the URL since the PostInfo objects contain a NextURL string

type CreatorInfo

type CreatorInfo struct {
	Body struct {
		Creator struct {
			User        FanboxUser `json:"user"`
			Description string     `json:"description"`
		} `json:"creator"`
		Post struct {
			Items   []FanboxPost `json:"items"`
			NextURL string       `json:"nextUrl"`
		} `json:"post"`
	} `json:"body"`
	Error   bool   `json:"error"`
	Message string `json:"message"`
}

CreatorInfo contains all relevant information on the creator

type FanboxPost

type FanboxPost struct {
	ID    json.Number `json:"id"`
	Title string      `json:"title"`
	Type  string      `json:"type"`
	User  FanboxUser  `json:"user"`
}

FanboxPost contains the relevant information on posts in the fanbox

type FanboxPostInfo

type FanboxPostInfo struct {
	Body struct {
		PostBody struct {
			Text  string `json:"text"`
			Files []*struct {
				ID        string `json:"id"`
				Name      string `json:"name"`
				Extension string `json:"extension"`
				URL       string `json:"url"`
			}
			Images []*struct {
				ID           string `json:"id"`
				Extension    string `json:"extension"`
				OriginalURL  string `json:"originalUrl"`
				ThumbnailURL string `json:"thumbnailUrl"`
			} `json:"images"`
			Blocks []struct {
				Type    string `json:"type"`
				Text    string `json:"text"`
				ImageID string `json:"imageId"`
			} `json:"blocks"`
			ImageMap map[string]struct {
				ID          string `json:"id"`
				OriginalURL string `json:"originalUrl"`
			} `json:"imageMap"`
		} `json:"body"`
		ID            json.Number `json:"id"`
		Title         string      `json:"title"`
		ImageForShare string      `json:"imageForShare"`
	} `json:"body"`
}

FanboxPostInfo contains the relevant fanbox post information

func (*FanboxPostInfo) ImagesFromBlocks

func (i *FanboxPostInfo) ImagesFromBlocks() []string

ImagesFromBlocks returns all image URLs from the Blocks section of the fanbox post

type FanboxUser

type FanboxUser struct {
	UserID json.Number `json:"userId"`
	Name   string      `json:"name"`
}

FanboxUser contains the relevant information of the user passed from the API

func (*FanboxUser) GetUserTag

func (u *FanboxUser) GetUserTag() string

GetUserTag returns the default download tag for illustrations of the user context

type PostInfo

type PostInfo struct {
	Body struct {
		Items   []FanboxPost `json:"items"`
		NextURL string       `json:"nextUrl"`
	} `json:"body"`
}

PostInfo contains all relevant pixiv fanbox post info

Jump to

Keyboard shortcuts

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