Documentation ¶
Overview ¶
Package xingapi is a wrapper and connector to the XING API (https://dev.xing.com/docs/resources)
Index ¶
- func Print(s string)
- func PrintCommand(command string)
- func PrintError(err error)
- func PrintMessageWithParam(message string, param string)
- func PrintResponse(response *http.Response)
- func PrintUser(user User)
- func PrintUserOneLine(user User)
- type APIError
- type Address
- type AuthenticateHandler
- type AuthenticationHandler
- type Birthdate
- type Client
- type ContactRepository
- type ContactsHandler
- type ContactsList
- type ContactsListUnmarshaler
- type Conversation
- type ConversationsInfo
- type ConversationsList
- type ConversationsMarshaler
- type CredentialStore
- type Credentials
- type CredentialsMarshaler
- type CredentialsUnmarshaler
- type DummyClient
- type DummyUser
- type JSONContactsList
- type JSONContactsUserIDList
- type JSONMarshaler
- func (JSONMarshaler) MarshalCredentials(writer io.Writer, credentials Credentials) error
- func (JSONMarshaler) MarshalUser(user User) ([]byte, error)
- func (JSONMarshaler) MarshalUsers(writer io.Writer, users Users) error
- func (JSONMarshaler) UnmarshalContactsList(reader io.Reader) (ContactsList, error)
- func (JSONMarshaler) UnmarshalCredentials(reader io.Reader) (Credentials, error)
- func (JSONMarshaler) UnmarshalUser(reader io.Reader) (User, error)
- func (JSONMarshaler) UnmarshalUsers(reader io.Reader) (Users, error)
- type JSONMessageMarshaler
- type Message
- type OAuthAuthenticator
- type OAuthConsumer
- type Printer
- type ResponseHandler
- type User
- type UserHandler
- type UserMarshaler
- type UserUnmarshaler
- type Users
- type UsersMarshaler
- type UsersRequest
- type UsersRequestHandler
- type UsersUnmarshaler
- type XINGClient
- func (client *XINGClient) ContactsList(userID string, limit int, offset int, handler ContactsHandler)
- func (client *XINGClient) Me(handler UserHandler)
- func (client *XINGClient) Messages(userID string, handler func(err error))
- func (client *XINGClient) User(id string, handler UserHandler)
- func (client *XINGClient) Users(userIDs []string) []User
- type XINGUser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrintMessageWithParam ¶
PrintMessageWithParam allows to print two arbitrary strings
func PrintResponse ¶
PrintResponse prints a HTTP response
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
type Address ¶
type Address struct { Street string Zipcode string `json:"zip_code"` City string Province string Country string }
Address represents user and companys' addresses.
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 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 ¶
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 ¶
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 ¶
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 ¶
DummyUser is used as a mock in tests that need a user mock
func (DummyUser) DisplayName ¶
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 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 ¶
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 ¶
A UserHandler is used as parameter to methods that fetch a User. Either the User or error might be nil.
type UserMarshaler ¶
UserMarshaler defines marshaler for marshaling user to JSON
type UserUnmarshaler ¶
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 ¶
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 ¶
UsersRequestHandler represents the function to execute once the users request has completed.
type UsersUnmarshaler ¶
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 ¶
ActiveEmail returns the user's email address
func (XINGUser) BusinessAddress ¶
BusinessAddress returns the user's business address
func (XINGUser) DisplayName ¶
DisplayName returns the users display name
Source Files ¶
- address.go
- apierror.go
- birthdate.go
- client.go
- contactrepository.go
- contactslist.go
- conversation.go
- conversationlist.go
- conversationsinfo.go
- credentialstore.go
- dummyclient.go
- dummyuser.go
- jsoncontactslist.go
- jsonconversationsmarshaler.go
- jsonmarshaler.go
- jsonmessagemarshaler.go
- message.go
- oauthauthenticator.go
- oauthconsumer.go
- printer.go
- user.go
- users.go
- usersrequest.go