connpass

package module
v0.0.0-...-e429fd3 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2019 License: MIT Imports: 8 Imported by: 0

README

go-connpass

GoDoc Circle CI Coverage Status

connpass のサーチ API (https://connpass.com/about/api/) を Go で実装したものです。

インストール

$ go get github.com/hkurokawa/go-connpass

使い方

query := connpass.Query{Start: 1, Order: connpass.CREATE}
query.KeywordOr = []string{"go", "golang"}
query.Time = []connpass.Time{connpass.Time{Year: 2015, Month: 3}, connpass.Time{Year: 2015, Month: 4}}
result, e := query.Search()

if e != nil {
   log.Errorf("Failed to fetch the result: %v\n", e)
} else {
   fmt.Printf("Num returned: %d\n", res.Returned)
   fmt.Printf("Num available: %d\n", res.Available)
   fmt.Printf("Start position: %d\n", res.Start)
   for _, e := range res.Events {
      fmt.Printf("\t%s\t%d\t%s\n", e.Start, e.Id, e.Title)
   }
}

ライセンス

MIT

作者

Hiroshi Kurokawa

Documentation

Overview

Package connpass provides a search method for using the connpass API (See https://connpass.com/about/api/).

Construct a query, then search with that on connpass. For example:

query := connpass.Query{}
// Retrieve the latest 10 events.
res, err := query.Search()

Specify query parameters by setting fields of a Query object.

query := connpass.Query{Start: 1, Order: connpass.CREATE}
query.KeywordOr = []string{"go", "golang"}
query.Time = []connpass.Time{connpass.Time{Year: 2015, Month: 3}, connpass.Time{Year: 2015, Month: 4}}
// Retrieve the recently created 10 events containing "go" or "golang" in its title or description
// and being held in March or April, 2015.
res, err := query.Search()

Pagination

The search API supports pagenation. Pagenation options can be specified with Start, Order and Count. Pages information is available via ResultSet struct.

	var allEvents []connpass.Event
	for {
		res, err := query.Search()
		if err != nil {
			return err
		}
		allEvents = append(allEvents, res.Events...)
		offset := res.Start + res.Returned
		if offset > res.Available {
			break
		}
		query.Start = offset
    }

Index

Constants

View Source
const BaseUrl = "https://connpass.com/api/v1/event/"

BaseUrl is the base URL of the API (See https://connpass.com/about/api/)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Id            int    `json:"event_id"`
	Title         string `json:"title"`
	Catch         string `json:"catch"`
	Description   string `json:"description"`
	Url           string `json:"event_url"`
	Tag           string `json:"hash_tag"`
	Start         string `json:"started_at"`
	End           string `json:"ended_at"`
	Limit         int    `json:"limit"`
	Etype         string `json:"event_type"`
	Address       string `json:"address"`
	Place         string `json:"place"`
	Lat           string `json:"lat"`
	Lon           string `json:"lon"`
	OwnerID       int    `json:"owner_id"`
	OwnerNickname string `json:"owner_nickname"`
	OwnerName     string `json:"owner_display_name"`
	Accepted      int    `json:"accepted"`
	Waiting       int    `json:"waiting"`
	Updated       string `json:"updated_at"`
}

Event specifies an event on connpass.

type Format

type Format string

Format specifies the format of the response. Currently, only JSON format is supported.

const (
	JSON Format = "json"
)

type Order

type Order int

Order specifies how the returned events should be sorted.

const (
	UPDATE Order = 1 + iota // 1: descending in updated time
	START                   // 2: descending in event start time
	CREATE                  // 3: descending in created time
)

type Query

type Query struct {
	EventId     []int    // Event ID
	KeywordAnd  []string // Keywords combined with AND operator
	KeywordOr   []string // Keywords combined with OR operator
	Time        []Time   // Holding date of the event
	Participant []string //  Nickname of participants
	Owner       []string // Nickname of the owner
	SeriesId    []int    // Series ID
	Start       int      // Offset
	Order       Order    // Order of the result
	Count       int      // Max number of results
	Format               // Format of response
}

Query specifies the criteria of search. Note that multiple values can be specified for each parameter type. And each type of the parameter is combined with other types with AND, while the values of a parameter are combined with OR.

func (Query) Search

func (q Query) Search() (*ResultSet, error)

Search searches events on connpass with the specified query.

type ResultSet

type ResultSet struct {
	Returned  int     `json:"results_returned"`
	Available int     `json:"results_available"`
	Start     int     `json:"results_start"`
	Events    []Event `json:"events"`
}

ResultSet specifies information about response and a set of returned events.

type Time

type Time struct {
	Year  int
	Month int
	Date  int
}

Day or month at the event. If 0 is specified for Date, it represents the month, date otherwise. For example, if Year = 2015, Month = 3 and Date = 0 (initial value), all the events held on March 2015 are returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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