gopenn

package module
v0.0.0-...-42e6631 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2017 License: MIT Imports: 9 Imported by: 0

README

Penn OpenData Go SDK

Build Status

This is the Penn OpenData API implementation in Go.

Install

To get started, just run

go get github.com/adelq/gopenn

Requesting an API key

To use this library, you must first obtain an API token and password for the API you want to use, which can be done here.

Note: There are separate API tokens for each API.

Contributing

We'd love to accept pull requests! Also, file bugs or ask questions in GitHub issues if you have any problems.

Authors

  • Adel Qalieh

License

MIT Licensed

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL *url.URL

	// Services for communicating with API
	Directory DirectoryService
	Registrar RegistrarService
	News      NewsService
	// contains filtered or unexported fields
}

Client manages communiction with the Penn OpenData API.

func NewClient

func NewClient(username string, password string) *Client

NewClient returns a new Penn OpenData API client.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred, If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included in as the request body.

type Course

type Course struct {
	ActivitiesAndCredits []struct {
		Credit       string `json:"credit"`
		ActivityCode string `json:"activity_code"`
	} `json:"activities_and_credits"`
	Corequisites           string `json:"corequisites"`
	CourseCreditConnector  string `json:"course_credit_connector"`
	CourseCreditType       string `json:"course_credit_type"`
	CourseDescription      string `json:"course_description"`
	CourseID               string `json:"course_id"`
	CourseLevel            string `json:"course_level"`
	CourseLevelDescription string `json:"course_level_description"`
	CourseNotes            string `json:"course_notes"`
	CourseNumber           string `json:"course_number"`
	CourseTitle            string `json:"course_title"`
	Crosslistings          []struct {
		CourseID  string `json:"course_id"`
		SectioNID string `json:"section_id"`
		Subject   string `json:"subject"`
	} `json:"crosslistings"`
	Department              string `json:"department"`
	DepartmentOfRecord      string `json:"department_of_record"`
	DistributionRequirement string `json:"distribution_requirement"`
	EasCreditFactorCode     string `json:"eas_credit_factor_code"`
	// Instructors             []interface{} `json:"instructors"`
	Prerequisites           string        `json:"prerequisites"`
	RegisterSubgroupOne     string        `json:"register_subgroup_one"`
	RegisterSubgroupTwo     string        `json:"register_subgroup_two"`
	RequirementsMet         []interface{} `json:"requirements_met"`
	SchedulingPriority      string        `json:"scheduling_priority"`
	SchoolCode              string        `json:"school_code"`
	TermsOfferedCode        string        `json:"terms_offered_code"`
	TermsOfferedDescription string        `json:"terms_offered_description"`
}

Expected JSON structure for course from course catalog

type CourseSearchOptions

type CourseSearchOptions struct {
	CourseID    string `url:"course_id,omitempty"`
	Description string `url:"description,omitempty"`
	Instructor  string `url:"instructor,omitempty"`
}

Acceptable parameters for use with the course search endpoint. Still missing many values due to lack of enums

type CourseWrap

type CourseWrap struct {
	Courses []Course    `json:"result_data"`
	Meta    ServiceMeta `json:"service_meta"`
}

type DateHours

type DateHours struct {
	Date  string `json:"date"`
	Meals []Meal `json:"meal"`
}

type DiningHallDaily

type DiningHallDaily struct {
}

type DiningHallWeekly

type DiningHallWeekly struct {
}

type DiningService

type DiningService interface {
	GetDaily(int) (*DiningHallDaily, *http.Response, error)
	GetWeekly(int) (*DiningHallWeekly, *http.Response, error)
	List() ([]Venue, *http.Response, error)
}

type DiningServiceOp

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

type DiningWrap

type DiningWrap struct {
	Venues []Venue     `json:"result_data.document.venue"`
	Meta   ServiceMeta `json:"service_meta"`
}

type DirectorySearchOptions

type DirectorySearchOptions struct {
	FirstName    string `url:"first_name,omitempty"`
	LastName     string `url:"last_name,omitempty"`
	Email        string `url:"email,omitempty"`
	Affiliation  string `url:"affiliation,omitempty"`
	Organization string `url:"organization,omitempty"`
}

Acceptable parameters for use with the directory search endpoint.

type DirectoryService

type DirectoryService interface {
	Get(string) (*Person, *http.Response, error)
	Search(*DirectorySearchOptions) ([]Person, *http.Response, error)
}

type DirectoryServiceOp

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

func (*DirectoryServiceOp) Get

func (s *DirectoryServiceOp) Get(personId string) (*Person, *http.Response, error)

func (*DirectoryServiceOp) Search

type Meal

type Meal struct {
	OpenTime  string `json:"open"`
	CloseTime string `json:"close"`
	Type      string `json:"type"`
}

type News

type News struct {
	Author            string `json:"author"`
	CommentsURL       string `json:"comments_url"`
	ContentCategories []struct {
		Description      string `json:"description"`
		ID               int    `json:"id"`
		Label            string `json:"label"`
		ParentCategoryID int    `json:"parent_category_id"`
	} `json:"content_categories"`
	ContentType string `json:"content_type"`
	Description string `json:"description"`
	GUID        string `json:"guid"`
	ID          int    `json:"id"`
	Images      []struct {
		Caption string `json:"caption"`
		ID      int    `json:"id"`
		Link    string `json:"link"`
		Name    string `json:"name"`
	} `json:"images"`
	Link      string    `json:"link"`
	Pubdate   time.Time `json:"pubdate"`
	SourceURL string    `json:"source_url"`
	Teaser    string    `json:"teaser"`
	Title     string    `json:"title"`
}

Expected JSON structure for news articles

type NewsSearchOptions

type NewsSearchOptions struct {
	Source      string `url:"source,omitempty"`
	Description string `url:"description,omitempty"`
}

Acceptable parameters for use with the news search endpoint.

type NewsService

type NewsService interface {
	Get(string) ([]News, *http.Response, error)
}

type NewsServiceOp

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

func (*NewsServiceOp) Get

func (s *NewsServiceOp) Get(description string) ([]News, *http.Response, error)

type NewsWrap

type NewsWrap struct {
	News []News      `json:"result_data"`
	Meta ServiceMeta `json:"service_meta"`
}

type Person

type Person struct {
	AdditionalData string `json:"additional_data_available"`
	Affiliation    string `json:"list_affiliation"`
	Email          string `json:"list_email"`
	Name           string `json:"list_name"`
	Organization   string `json:"list_organization"`
	Phone          string `json:"list_phone"`
	PhoneType      string `json:"list_phone_type"`
	Prefix         string `json:"list_prefix"`
	TitleOrMajor   string `json:"list_title_or_major"`
	Id             string `json:"person_id"`
}

Expected JSON structure from results from directory

type PersonWrap

type PersonWrap struct {
	Persons []Person    `json:"result_data"`
	Meta    ServiceMeta `json:"service_meta"`
}

type RegistrarService

type RegistrarService interface {
	GetDepartment(string) ([]Course, *http.Response, error)
	GetCourse(string, int) (*Course, *http.Response, error)
	Search(*CourseSearchOptions) ([]Course, *http.Response, error)
}

type RegistrarServiceOp

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

func (*RegistrarServiceOp) GetCourse

func (s *RegistrarServiceOp) GetCourse(department string, courseID int) (*Course, *http.Response, error)

func (*RegistrarServiceOp) GetDepartment

func (s *RegistrarServiceOp) GetDepartment(department string) ([]Course, *http.Response, error)

func (*RegistrarServiceOp) Search

type ServiceMeta

type ServiceMeta struct {
	CurrentPage        int    `json:"current_page_number"`
	ErrorText          string `json:"error_text"`
	NextPage           int    `json:"next_page_number"`
	NumberPages        int    `json:"number_of_pages"`
	PreviousPageNumber int    `json:"previous_page_number"`
	ResultsPerPage     int    `json:"results_per_page"`
}

type Venue

type Venue struct {
	Id            int         `json:"id"`
	Name          string      `json:"name"`
	VenueType     string      `json:"venueType"`
	FacilityURL   string      `json:"facilityURL"`
	WeeklyMenuURL string      `json:"weeklyMenuURL"`
	DailyMenuURL  string      `json:"dailyMenuURL"`
	DateHours     []DateHours `json:"dateHours"`
}

Expected JSON structure from results from venues

Jump to

Keyboard shortcuts

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