stackoverflow

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 21 Imported by: 0

README

Go API client for stackoverflow

Stack Exchange API

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 2.2
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context
go get github.com/antihax/optional

Put the package under your project folder and add the following in import:

import "./stackoverflow"

Documentation for API Endpoints

All URIs are relative to https://api.stackexchange.com/2.2

Class Method HTTP request Description
QuestionsApi GetFeaturedQuestions Get /questions/featured
QuestionsApi GetQuestions Get /questions
QuestionsApi GetQuestionsWithoutAnswers Get /questions/no-answers
QuestionsApi GetUnansweredQuestions Get /questions/unanswered
UsersApi GetMe Get /me
UsersApi GetMyReputation Get /me/reputation
UsersApi GetMyReputationHistory Get /me/reputation-history
UsersApi GetUsers Get /users
UsersApi GetUsersReputation Get /users/{userIds}/reputation
UsersApi GetUsersReputationHistory Get /users/{userIds}/reputation-history

Documentation For Models

Documentation For Authorization

Endpoints do not require authorization.

Author

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ContextOAuth2 takes an oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func CacheExpires

func CacheExpires(r *http.Response) time.Time

CacheExpires helper function to determine remaining time before repeating a request.

Types

type APIClient

type APIClient struct {
	QuestionsApi *QuestionsApiService

	UsersApi *UsersApiService
	// contains filtered or unexported fields
}

APIClient manages communication with the Stack Exchange API API v2.2 In most cases there should be only one, shared, APIClient.

func NewAPIClient

func NewAPIClient(cfg *Configuration) *APIClient

NewAPIClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) ChangeBasePath

func (c *APIClient) ChangeBasePath(path string)

Change base path to allow switching to mocks

func (*APIClient) HTTPClient

func (apiClient *APIClient) HTTPClient() *http.Client

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the OpenAPI operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type Configuration

type Configuration struct {
	BasePath      string            `json:"basePath,omitempty"`
	Host          string            `json:"host,omitempty"`
	Scheme        string            `json:"scheme,omitempty"`
	DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
	UserAgent     string            `json:"userAgent,omitempty"`
	HTTPClient    *http.Client
}

func NewConfiguration

func NewConfiguration() *Configuration

func (*Configuration) AddDefaultHeader

func (c *Configuration) AddDefaultHeader(key string, value string)

type GenericOpenAPIError

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

GenericOpenAPIError Provides access to the body, error and model on returned errors.

func (GenericOpenAPIError) Body

func (e GenericOpenAPIError) Body() []byte

Body returns the raw bytes of the response

func (GenericOpenAPIError) Error

func (e GenericOpenAPIError) Error() string

Error returns non-empty string if there was an error.

func (GenericOpenAPIError) Model

func (e GenericOpenAPIError) Model() interface{}

Model returns the unpacked model of the error

type GetFeaturedQuestionsOpts

type GetFeaturedQuestionsOpts struct {
	Fromdate optional.Int32
	Todate   optional.Int32
	Min      optional.Int32
	Max      optional.Int32
	Tagged   optional.String
	Order    optional.String
	Sort     optional.String
	Page     optional.Int32
	Pagesize optional.Int32
}

type GetMyReputationHistoryOpts

type GetMyReputationHistoryOpts struct {
	Page     optional.Int32
	Pagesize optional.Int32
}

type GetQuestionsOpts

type GetQuestionsOpts struct {
	Fromdate optional.Int32
	Todate   optional.Int32
	Min      optional.Int32
	Max      optional.Int32
	Tagged   optional.String
	Order    optional.String
	Sort     optional.String
	Page     optional.Int32
	Pagesize optional.Int32
}

type GetQuestionsWithoutAnswersOpts

type GetQuestionsWithoutAnswersOpts struct {
	Fromdate optional.Int32
	Todate   optional.Int32
	Min      optional.Int32
	Max      optional.Int32
	Tagged   optional.String
	Order    optional.String
	Sort     optional.String
	Page     optional.Int32
	Pagesize optional.Int32
}

type GetUnansweredQuestionsOpts

type GetUnansweredQuestionsOpts struct {
	Fromdate optional.Int32
	Todate   optional.Int32
	Min      optional.Int32
	Max      optional.Int32
	Tagged   optional.String
	Order    optional.String
	Sort     optional.String
	Page     optional.Int32
	Pagesize optional.Int32
}

type GetUsersOpts

type GetUsersOpts struct {
	Inname   optional.String
	Fromdate optional.Int32
	Todate   optional.Int32
	Min      optional.Int32
	Max      optional.Int32
	Sort     optional.String
	Order    optional.String
	Page     optional.Int32
	Pagesize optional.Int32
	Key      optional.String
	Filter   optional.String
}

type GetUsersReputationHistoryOpts

type GetUsersReputationHistoryOpts struct {
	Page     optional.Int32
	Pagesize optional.Int32
}

type GetUsersReputationOpts

type GetUsersReputationOpts struct {
	Fromdate optional.Int32
	Todate   optional.Int32
	Page     optional.Int32
	Pagesize optional.Int32
}

type Question

type Question struct {
	Tags             []string      `json:"tags,omitempty"`
	Owner            QuestionOwner `json:"owner,omitempty"`
	IsAnswered       bool          `json:"is_answered,omitempty"`
	ViewCount        int32         `json:"view_count,omitempty"`
	AnswerCount      int32         `json:"answer_count,omitempty"`
	Score            int32         `json:"score,omitempty"`
	LastActivityDate int32         `json:"last_activity_date,omitempty"`
	CreationDate     int32         `json:"creation_date,omitempty"`
	QuestionId       int32         `json:"question_id,omitempty"`
	Link             string        `json:"link,omitempty"`
	Title            string        `json:"title,omitempty"`
}

type QuestionOwner

type QuestionOwner struct {
	Reputation   int32  `json:"reputation,omitempty"`
	UserId       int32  `json:"user_id,omitempty"`
	UserType     string `json:"user_type,omitempty"`
	ProfileImage string `json:"profile_image,omitempty"`
	DisplayName  string `json:"display_name,omitempty"`
	Link         string `json:"link,omitempty"`
}

type QuestionsApiService

type QuestionsApiService service

func (*QuestionsApiService) GetFeaturedQuestions

func (a *QuestionsApiService) GetFeaturedQuestions(ctx context.Context, site string, localVarOptionals *GetFeaturedQuestionsOpts) (QuestionsResponse, *http.Response, error)

func (*QuestionsApiService) GetQuestions

func (a *QuestionsApiService) GetQuestions(ctx context.Context, site string, localVarOptionals *GetQuestionsOpts) (QuestionsResponse, *http.Response, error)

func (*QuestionsApiService) GetQuestionsWithoutAnswers

func (a *QuestionsApiService) GetQuestionsWithoutAnswers(ctx context.Context, site string, localVarOptionals *GetQuestionsWithoutAnswersOpts) (QuestionsResponse, *http.Response, error)

func (*QuestionsApiService) GetUnansweredQuestions

func (a *QuestionsApiService) GetUnansweredQuestions(ctx context.Context, site string, localVarOptionals *GetUnansweredQuestionsOpts) (QuestionsResponse, *http.Response, error)

type QuestionsResponse

type QuestionsResponse struct {
	// A list of questions.
	Items          []Question `json:"items,omitempty"`
	HasMore        bool       `json:"has_more,omitempty"`
	QuotaMax       int32      `json:"quota_max,omitempty"`
	QuotaRemaining int32      `json:"quota_remaining,omitempty"`
}

type ReputationChange

type ReputationChange struct {
	OnDate           int32  `json:"on_date,omitempty"`
	ReputationChange int32  `json:"reputation_change,omitempty"`
	VoteType         string `json:"vote_type,omitempty"`
	PostType         string `json:"post_type,omitempty"`
	PostId           int32  `json:"post_id,omitempty"`
	UserId           int32  `json:"user_id,omitempty"`
}

type ReputationHistory

type ReputationHistory struct {
	ReputationHistoryType string `json:"reputation_history_type,omitempty"`
	ReputationChange      int32  `json:"reputation_change,omitempty"`
	PostId                int32  `json:"post_id,omitempty"`
	CreationDate          int32  `json:"creation_date,omitempty"`
	UserId                int32  `json:"user_id,omitempty"`
}

type ReputationHistoryResponse

type ReputationHistoryResponse struct {
	// A list of reputation_history.
	Items          []ReputationHistory `json:"items,omitempty"`
	HasMore        bool                `json:"has_more,omitempty"`
	QuotaMax       int32               `json:"quota_max,omitempty"`
	QuotaRemaining int32               `json:"quota_remaining,omitempty"`
}

type ReputationResponse

type ReputationResponse struct {
	// A list of reputation_history.
	Items          []ReputationChange `json:"items,omitempty"`
	HasMore        bool               `json:"has_more,omitempty"`
	QuotaMax       int32              `json:"quota_max,omitempty"`
	QuotaRemaining int32              `json:"quota_remaining,omitempty"`
}

type User

type User struct {
	BadgeCounts             UserBadgeCounts `json:"badge_counts,omitempty"`
	AboutMe                 string          `json:"about_me,omitempty"`
	AccountId               int64           `json:"account_id,omitempty"`
	IsEmployee              bool            `json:"is_employee,omitempty"`
	LastModifiedDate        int64           `json:"last_modified_date,omitempty"`
	LastAccessDate          int64           `json:"last_access_date,omitempty"`
	ReputationChangeYear    int32           `json:"reputation_change_year,omitempty"`
	ReputationChangeQuarter int32           `json:"reputation_change_quarter,omitempty"`
	ReputationChangeMonth   int32           `json:"reputation_change_month,omitempty"`
	ReputationChangeWeek    int32           `json:"reputation_change_week,omitempty"`
	ReputationChangeDay     int32           `json:"reputation_change_day,omitempty"`
	Reputation              int64           `json:"reputation,omitempty"`
	CreationDate            int64           `json:"creation_date,omitempty"`
	UserType                string          `json:"user_type,omitempty"`
	UserId                  int64           `json:"user_id,omitempty"`
	AcceptRate              int32           `json:"accept_rate,omitempty"`
	Location                string          `json:"location,omitempty"`
	WebsiteUrl              string          `json:"website_url,omitempty"`
	Link                    string          `json:"link,omitempty"`
	ProfileImage            string          `json:"profile_image,omitempty"`
	DisplayName             string          `json:"display_name,omitempty"`
}

type UserBadgeCounts

type UserBadgeCounts struct {
	Bronze int32 `json:"bronze,omitempty"`
	Silver int32 `json:"silver,omitempty"`
	Gold   int32 `json:"gold,omitempty"`
}

type UsersApiService

type UsersApiService service

func (*UsersApiService) GetMe

UsersApiService Returns the user associated with the passed access_token. This method returns a [user](https://api.stackexchange.com/docs/types/user).

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param site

@return UsersResponse

func (*UsersApiService) GetMyReputation

func (a *UsersApiService) GetMyReputation(ctx context.Context) (ReputationResponse, *http.Response, error)

UsersApiService Returns the reputation changed for the user associated with the given access_token. This method returns a list of [reputation changes](https://api.stackexchange.com/docs/types/reputation).

  • @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().

@return ReputationResponse

func (*UsersApiService) GetMyReputationHistory

func (a *UsersApiService) GetMyReputationHistory(ctx context.Context, localVarOptionals *GetMyReputationHistoryOpts) (ReputationHistoryResponse, *http.Response, error)

func (*UsersApiService) GetUsers

func (a *UsersApiService) GetUsers(ctx context.Context, site string, localVarOptionals *GetUsersOpts) (UsersResponse, *http.Response, error)

func (*UsersApiService) GetUsersReputation

func (a *UsersApiService) GetUsersReputation(ctx context.Context, userIds string, site string, localVarOptionals *GetUsersReputationOpts) (ReputationResponse, *http.Response, error)

func (*UsersApiService) GetUsersReputationHistory

func (a *UsersApiService) GetUsersReputationHistory(ctx context.Context, userIds string, site string, localVarOptionals *GetUsersReputationHistoryOpts) (ReputationHistoryResponse, *http.Response, error)

type UsersResponse

type UsersResponse struct {
	Items          []User `json:"items,omitempty"`
	HasMore        bool   `json:"has_more,omitempty"`
	QuoteMax       int32  `json:"quote_max,omitempty"`
	QuotaRemaining int32  `json:"quota_remaining,omitempty"`
}

Jump to

Keyboard shortcuts

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