xingapi

package module
v0.0.0-...-0b96f7e Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2015 License: MIT Imports: 19 Imported by: 1

README

GoDoc

xingapi

Open source XING API adapter written in Go

Installation

You need to copy ./src/xingapi/consumercredentials.go.example to ./src/xingapi/consumercredentials.go. Within the consumercredentials.go remove all occurrences of 'example' and enter your key and secret as provided by https://developer.xing.com/applications/dashboard.

Documentation

Overview

Package xingapi is a wrapper and connector to the XING API (https://dev.xing.com/docs/resources)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(s string)

Print prints an arbitrary string

func PrintCommand

func PrintCommand(command string)

PrintCommand prints a command formatted

func PrintError

func PrintError(err error)

PrintError prints out an error

func PrintMessageWithParam

func PrintMessageWithParam(message string, param string)

PrintMessageWithParam allows to print two arbitrary strings

func PrintResponse

func PrintResponse(response *http.Response)

PrintResponse prints a HTTP response

func PrintUser

func PrintUser(user User)

PrintUser prints out a User in a verbose style

func PrintUserOneLine

func PrintUserOneLine(user User)

PrintUserOneLine prints a User in one line

Types

type APIError

type APIError struct {
	Message       string `json:"message"`
	ThrottledType string `json:"throttled"`
	BanTime       string `json:"ban_time"`
	ErrorName     string `json:"error_name"`
}

An APIError represents an error that occurred in the XING API error domain

func (APIError) String

func (error APIError) String() string

String makes APIError conform to Stringer interface.

type Address

type Address struct {
	Street   string
	Zipcode  string `json:"zip_code"`
	City     string
	Province string
	Country  string
}

Address represents user and companys' addresses.

func (Address) String

func (address Address) String() string

String makes Address conform to Stringer interface.

type AuthenticateHandler

type AuthenticateHandler func()

AuthenticateHandler will be called upon successful authentication

type AuthenticationHandler

type AuthenticationHandler func(err error)

AuthenticationHandler is the function to be invoked once authentication against the API has completed

type Birthdate

type Birthdate struct {
	Day   uint
	Month uint
	Year  uint
}

A Birthdate represents a user's birthday

func (Birthdate) String

func (birthdate Birthdate) String() string

type Client

type Client interface {
	User(id string, handler UserHandler)
	ContactsList(userID string, limit int, offset int, handler ContactsHandler)
	Me(handler UserHandler)
	Messages(userID string, handler func(err error))
}

The Client interface describes the available methods that wrap around the XING API.

type ContactRepository

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

ContactRepository represents a repository to retrieve and store contacts

func NewContactRepository

func NewContactRepository(client Client) *ContactRepository

NewContactRepository creates a new contact repository given a API client

func (*ContactRepository) Contact

func (repo *ContactRepository) Contact(name string, done func())

Contact gets the user with the given name

func (*ContactRepository) Contacts

func (repo *ContactRepository) Contacts(userID string, contactsHandler func(list []*User, err error))

Contacts fetches all contacts of the user with the given user ID

func (ContactRepository) UserDetails

func (repo ContactRepository) UserDetails(userID string, wg *sync.WaitGroup, userChannel chan User)

type ContactsHandler

type ContactsHandler func(ContactsList, error)

The ContactsHandler can be passed as parameter to methods fetching contact lists. Either ContactsList or error might be nil.

type ContactsList

type ContactsList struct {
	UserIDs []string
	Total   int
}

ContactsList holds a list of UserIDs

type ContactsListUnmarshaler

type ContactsListUnmarshaler interface {
	UnmarshalContactsList(reader io.Reader) (ContactsList, error)
}

ContactsListUnmarshaler defines ContactsList marshaler

type Conversation

type Conversation struct {
	Subject          string `json:"subject"`
	MessageCount     int    `json:"message_count"`
	ChangeTimeString string `json:"updated_at"`
	Readonly         bool   `json:"read_only"`
	Participants     []struct {
		UserID string `json:"id"`
	} `json:"participants"`
}

func (Conversation) ChangeTime

func (c Conversation) ChangeTime() (time.Time, error)

func (Conversation) String

func (c Conversation) String() string

type ConversationsInfo

type ConversationsInfo struct {
	ConversationsList ConversationsList `json:"conversations"`
}

type ConversationsList

type ConversationsList struct {
	Total         string          `json:"total"`
	Conversations []*Conversation `json:"items"`
}

type ConversationsMarshaler

type ConversationsMarshaler struct{}

func (ConversationsMarshaler) UnmarshalConversationList

func (ConversationsMarshaler) UnmarshalConversationList(reader io.Reader) (ConversationsInfo, error)

type CredentialStore

type CredentialStore struct{}

CredentialStore stores credentials

func (*CredentialStore) Credentials

func (store *CredentialStore) Credentials() (Credentials, error)

Credentials returns the stored credentials or an error if no credentials have been stored

func (*CredentialStore) SaveCredentials

func (store *CredentialStore) SaveCredentials(credentials Credentials) error

SaveCredentials saves the given credentials

type Credentials

type Credentials struct {
	Token  string `json:"token"`
	Secret string `json:"secret"`
}

Credentials are used to authenticate against the API via OAuth

type CredentialsMarshaler

type CredentialsMarshaler interface {
	MarshalCredentials(writer io.Writer, credentials Credentials) error
}

CredentialsMarshaler defines Credentials marshaler

type CredentialsUnmarshaler

type CredentialsUnmarshaler interface {
	UnmarshalCredentials(reader io.Reader) (Credentials, error)
}

CredentialsUnmarshaler defines Credentials unmarshaler

type DummyClient

type DummyClient struct {
	Client
	DummyUsers []User
}

DummyClient is used as a mock for tests that need a Client

func (*DummyClient) ContactsList

func (client *DummyClient) ContactsList(userID string, limit int, offset int, handler ContactsHandler)

ContactsList is a fake ContactsList implementation

func (*DummyClient) User

func (client *DummyClient) User(contactUserID string, handler UserHandler)

User is a fake User implementation

type DummyUser

type DummyUser struct {
	XINGUser
	UserID string
}

DummyUser is used as a mock in tests that need a user mock

func (DummyUser) DisplayName

func (user DummyUser) DisplayName() string

func (DummyUser) String

func (user DummyUser) String() string

type JSONContactsList

type JSONContactsList struct {
	JSONContactsUserIDList JSONContactsUserIDList `json:"contacts"`
}

JSONContactsList is a wrapper for parsing contacts JSON.

type JSONContactsUserIDList

type JSONContactsUserIDList struct {
	Total int                 `json:"total"`
	Users []map[string]string `json:"users"`
}

JSONContactsUserIDList is a wrapper for parsing ContactsLists that consist of a Total number of users and a list of UserIDs

func (*JSONContactsUserIDList) UserIDs

func (jsonList *JSONContactsUserIDList) UserIDs() []string

UserIDs returns a list of UserIDs for the list's users

type JSONMarshaler

type JSONMarshaler struct{}

The JSONMarshaler is a concrete implementation of UsersMarshaler/UsersUnmarshaler, CredentialsMarshaler/CredentialsUnmarshaler, ContactsListUnmarshaler and UserUnmarshaler. The JSONMarshaler that allows marshaling and unmarshaling all entities to and from JSON.

func (JSONMarshaler) MarshalCredentials

func (JSONMarshaler) MarshalCredentials(writer io.Writer, credentials Credentials) error

MarshalCredentials concrete implementation

func (JSONMarshaler) MarshalUser

func (JSONMarshaler) MarshalUser(user User) ([]byte, error)

MarshalUser concrete implementation

func (JSONMarshaler) MarshalUsers

func (JSONMarshaler) MarshalUsers(writer io.Writer, users Users) error

MarshalUsers concrete implementation

func (JSONMarshaler) UnmarshalContactsList

func (JSONMarshaler) UnmarshalContactsList(reader io.Reader) (ContactsList, error)

UnmarshalContactsList concrete implementation

func (JSONMarshaler) UnmarshalCredentials

func (JSONMarshaler) UnmarshalCredentials(reader io.Reader) (Credentials, error)

UnmarshalCredentials concrete implementation

func (JSONMarshaler) UnmarshalUser

func (JSONMarshaler) UnmarshalUser(reader io.Reader) (User, error)

UnmarshalUser concrete implementation

func (JSONMarshaler) UnmarshalUsers

func (JSONMarshaler) UnmarshalUsers(reader io.Reader) (Users, error)

UnmarshalUsers concrete implementation

type JSONMessageMarshaler

type JSONMessageMarshaler struct{}

func (JSONMessageMarshaler) UnmarshalMessage

func (JSONMessageMarshaler) UnmarshalMessage(reader io.Reader) (Message, error)

type Message

type Message struct {
}

type OAuthAuthenticator

type OAuthAuthenticator struct {
	Client               oauth.Client
	TemporaryCredentials oauth.Credentials
	OAuthCredentials     oauth.Credentials
	// contains filtered or unexported fields
}

OAuthAuthenticator handles OAuth authentication

func (*OAuthAuthenticator) Authenticate

func (authenticator *OAuthAuthenticator) Authenticate(handler AuthenticationHandler)

Authenticate starts the local server that waits for the OAuth callback once the user signs in in the browser

func (*OAuthAuthenticator) AuthenticateUsingStoredCredentials

func (authenticator *OAuthAuthenticator) AuthenticateUsingStoredCredentials(storedCredentials Credentials, handler AuthenticationHandler)

AuthenticateUsingStoredCredentials sets up the authenticator's client and OAuthCredentials. woot!?

type OAuthConsumer

type OAuthConsumer struct {
	// Authenticated indicates whether or not the consumer is currently authenticated
	Authenticated bool

	// AuthenticateHandlers store handlers to be executed once authentication was successful
	AuthenticateHandlers []AuthenticateHandler
	// contains filtered or unexported fields
}

OAuthConsumer connects to the API in a authenticated manner. It wraps GET calls to the API by attaching OAuth information to them.

func (*OAuthConsumer) Get

func (consumer *OAuthConsumer) Get(path string, parameters url.Values, handler ResponseHandler)

Get performs get requests to the API while using OAuth authentication.

type Printer

type Printer struct{}

Printer can be used to print out various domain specific objects in an individually formatted way.

type ResponseHandler

type ResponseHandler func(io.Reader, error)

ResponseHandler handles HTTP response bodies and a potential error

type User

type User interface {
	Name() string
	DisplayName() string
	ID() string
	ActiveEmail() string
	Birthdate() Birthdate
	BusinessAddress() Address
	fmt.Stringer
}

User interface defines methods to call on a user entity

type UserHandler

type UserHandler func(User, error)

A UserHandler is used as parameter to methods that fetch a User. Either the User or error might be nil.

type UserMarshaler

type UserMarshaler interface {
	MarshalUser(user User) (bytes []byte, err error)
}

UserMarshaler defines marshaler for marshaling user to JSON

type UserUnmarshaler

type UserUnmarshaler interface {
	UnmarshalUser(reader io.Reader) (User, error)
}

UserUnmarshaler defines User marshaler

type Users

type Users struct {
	// Users exposes the list of users
	Users []*XINGUser
}

Users contains a list of XING users

type UsersMarshaler

type UsersMarshaler interface {
	MarshalUsers(writer io.Writer, users Users) error
}

UsersMarshaler interface defines Users marshaler

type UsersRequest

type UsersRequest struct {
	UserID     string
	Limit      int
	Offset     int
	Total      int
	Completion UsersRequestHandler
}

UsersRequest represents the request to fetch users from an offset

func (*UsersRequest) IsFinal

func (request *UsersRequest) IsFinal() bool

IsFinal defines if the given request will fetch the last available user.

type UsersRequestHandler

type UsersRequestHandler func(users []*User, err error)

UsersRequestHandler represents the function to execute once the users request has completed.

type UsersUnmarshaler

type UsersUnmarshaler interface {
	UnmarshalUsers(reader io.Reader) (Users, error)
}

UsersUnmarshaler interface defines Users unmarshaler

type XINGClient

type XINGClient struct {
	OAuthConsumer OAuthConsumer
}

The XINGClient conforms to the Client interface and handles oAuth authentication for the XING API. It manages all communication with the API's endpoints.

func (*XINGClient) ContactsList

func (client *XINGClient) ContactsList(userID string, limit int, offset int, handler ContactsHandler)

ContactsList fetches the contact list of the logged in user from the offset with a batch count of limit

func (*XINGClient) Me

func (client *XINGClient) Me(handler UserHandler)

Me fetches the logged in user

func (*XINGClient) Messages

func (client *XINGClient) Messages(userID string, handler func(err error))

Messages fetches the conversations of the user with the given id and prints out raw json

func (*XINGClient) User

func (client *XINGClient) User(id string, handler UserHandler)

User fetches the User for the given user id

func (*XINGClient) Users

func (client *XINGClient) Users(userIDs []string) []User

Users fetches the users according to the given user IDs

type XINGUser

type XINGUser struct {
	InternalName            string    `json:"first_name"`
	InternalDisplayName     string    `json:"display_name"`
	InternalID              string    `json:"id"`
	InternalActiveEmail     string    `json:"active_email"`
	InternalBirthdate       Birthdate `json:"birth_date"`
	InternalBusinessAddress Address   `json:"business_address"`
}

XINGUser is the concrete implementation of a User

func (XINGUser) ActiveEmail

func (user XINGUser) ActiveEmail() string

ActiveEmail returns the user's email address

func (XINGUser) Birthdate

func (user XINGUser) Birthdate() Birthdate

Birthdate represents the user's birthdate

func (XINGUser) BusinessAddress

func (user XINGUser) BusinessAddress() Address

BusinessAddress returns the user's business address

func (XINGUser) DisplayName

func (user XINGUser) DisplayName() string

DisplayName returns the users display name

func (XINGUser) ID

func (user XINGUser) ID() string

ID returns the user's user ID

func (XINGUser) Name

func (user XINGUser) Name() string

Name return the user's full name

func (XINGUser) String

func (user XINGUser) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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