Rework client.Interface

This commit is contained in:
derekwaynecarr
2014-10-21 17:14:35 -04:00
parent 2bbd11eda6
commit 580cb5ea4f
20 changed files with 640 additions and 368 deletions

85
pkg/client/events.go Normal file
View File

@@ -0,0 +1,85 @@
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package client
import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)
// Events has methods to work with Event resources
type EventsInterface interface {
Events() EventInterface
}
// EventInterface has methods to work with Event resources
type EventInterface interface {
Create(event *api.Event) (*api.Event, error)
List(label, field labels.Selector) (*api.EventList, error)
Get(id string) (*api.Event, error)
Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error)
}
// EventsClient implements Events interface
type EventsClient struct {
r *Client
}
// NewEventsClient returns a EventsClient
func NewEventsClient(c *Client) *EventsClient {
return &EventsClient{
r: c,
}
}
// Create makes a new event. Returns the copy of the event the server returns, or an error.
func (c *EventsClient) Create(event *api.Event) (*api.Event, error) {
result := &api.Event{}
err := c.r.Post().Path("events").Body(event).Do().Into(result)
return result, err
}
// List returns a list of events matching the selectors.
func (c *EventsClient) List(label, field labels.Selector) (*api.EventList, error) {
result := &api.EventList{}
err := c.r.Get().
Path("events").
SelectorParam("labels", label).
SelectorParam("fields", field).
Do().
Into(result)
return result, err
}
// Get returns the given event, or an error.
func (c *EventsClient) Get(id string) (*api.Event, error) {
result := &api.Event{}
err := c.r.Get().Path("events").Path(id).Do().Into(result)
return result, err
}
// Watch starts watching for events matching the given selectors.
func (c *EventsClient) Watch(label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
return c.r.Get().
Path("watch").
Path("events").
Param("resourceVersion", resourceVersion).
SelectorParam("labels", label).
SelectorParam("fields", field).
Watch()
}