Documentation ¶
Overview ¶
A simple CloudSight API client library. For full API documentation go to https://cloudsight.readme.io/v1.0/docs.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) ImageRequest(image io.Reader, filename string, params Params) (*Job, error)
- func (c *Client) RemoteImageRequest(url string, params Params) (*Job, error)
- func (c *Client) RepostJob(job *Job) error
- func (c *Client) UpdateJob(job *Job) error
- func (c *Client) WaitJob(job *Job, timeout time.Duration) error
- type Job
- type JobStatus
- type Params
- func (p Params) SetAltitude(alt float64)
- func (p Params) SetDeviceID(id string)
- func (p Params) SetFocusAbsolute(x, y int) error
- func (p Params) SetFocusRelative(x, y float64) error
- func (p Params) SetLanguage(lang string)
- func (p Params) SetLatitude(lat float64) error
- func (p Params) SetLocale(locale string)
- func (p Params) SetLongitude(lon float64) error
- func (p Params) SetMaxTTL()
- func (p Params) SetPosition(lat, lon, alt float64) error
- func (p Params) SetTTL(ttl int) error
- type SkipReason
Examples ¶
Constants ¶
const BaseURL = "https://api.cloudsightapi.com"
Base API URL.
const DefaultLocale = "en-US"
Default locale that will be used when none is specified in Params.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClientOAuth ¶
Create a new Client instance that will authenticate using OAuth1 protocol.
Error (ErrMissingKey or ErrMissingSecret) will be returned if either key or secret is empty.
func NewClientSimple ¶
Create a new Client instance that will authenticate using simple key-based method.
ErrMissingKey will be returned if key is empty.
func (*Client) ImageRequest ¶
Send an image for classification. The image may be a os.File instance any other object implementing io.Reader interface. The params parameter is optional and may be nil.
On success this method will immediately return a Job instance. Its status will initially be "not completed" as it usually takes 6-12 seconds for the server to process an image. In order to retrieve the annotation data, you need to keep updating the job status using the UpdateJob() method until the status changes. You may also use the WaitJob() method which does this automatically.
Example ¶
c, _ := NewClientSimple("api-key") f, _ := os.Open("some-file.jpg") defer f.Close() params := Params{} // Set the position to 50.0°N 19.0°E params.SetLatitude(50.0) params.SetLongitude(19.0) job, err := c.ImageRequest(f, "some-file.jpg", params) if err != nil { panic(err) } fmt.Println("Token:", job.Token)
Output:
func (*Client) RemoteImageRequest ¶
Send an image for classification. The image will be retrieved from the URL specified. The params parameter is optional and may be nil.
On success this method will immediately return a Job instance. Its status will initially be "not completed" as it usually takes 6-12 seconds for the server to process an image. In order to retrieve the annotation data, you need to keep updating the job status using the UpdateJob() method until the status changes. You may also use the WaitJob() method which does this automatically.
Example ¶
c, _ := NewClientSimple("api-key") params := Params{} // Set the position to 50.0°N 19.0°E params.SetLatitude(50.0) params.SetLongitude(19.0) job, err := c.RemoteImageRequest("http://www.example.com/some-image.jpg", params) if err != nil { panic(err) } fmt.Println("Token:", job.Token)
Output:
func (*Client) RepostJob ¶
Repost the job if it has timed out (StatusTimeout).
ErrInvalidRepostStatus will be returned if current job status is different than StatusTimeout.
func (*Client) UpdateJob ¶
Contact the server and update the job status. This method does nothing if the status has already changed from "not completed".
After a request has been submitted, it usually takes 6-12 seconds to receive a completed response. We recommend polling for a response every 1 second after a 4 second delay from the initial request, while the status is "not completed". WaitJob() method does this automatically.
Example ¶
c, _ := NewClientSimple("api-key") job, _ := c.RemoteImageRequest("http://www.example.com/some-image.jpg", nil) time.Sleep(3 * time.Second) for job.Status == StatusNotCompleted { time.Sleep(1 * time.Second) c.UpdateJob(job) } fmt.Println("Status:", job.Status, job.Status.Description())
Output:
func (*Client) WaitJob ¶
Wait for the job until it has been processed. This method will block for up to timeout seconds. After that ErrTimeout will be returned. If the timeout parameter is set to 0, WaitJob() will wait infinitely.
This method will wait for 4 seconds after the initial request and then will call UpdateJob() method every second until the status changes.
type Job ¶
type Job struct { // Image description as annotated by the API. Name string // Current job status. Status JobStatus // Time To Live. TTL float64 // Token uniquely identifying the job. Token string // URL to the image as stored on CloudSight API servers. URL string // The reason for the job being skipped, if any. SkipReason SkipReason // contains filtered or unexported fields }
Job is a result of sending an image to CloudSight API.
type JobStatus ¶
type JobStatus string
Possible values for current job status.
const ( // Recognition has not yet been completed for this image. Continue polling // until response has been marked completed. StatusNotCompleted JobStatus = "not completed" // Recognition has been completed. Annotation can be found in Name and // Categories field of Job structure. StatusCompleted JobStatus = "completed" // Token supplied on URL does not match an image. StatusNotFound JobStatus = "not found" // Image couldn't be recognized because of a specific reason. Check the // SkipReason field. StatusSkipped JobStatus = "skipped" // Recognition process exceeded the allowed TTL setting. StatusTimeout JobStatus = "timeout" )
func (JobStatus) Description ¶
Return a detailed description of the job status.
type Params ¶
Additional API parameters.
func (Params) SetAltitude ¶
Set the altitude for additional geolocation context.
func (Params) SetDeviceID ¶
Set a unique ID generated for the device sending the request. We recommend generating a UUID.
func (Params) SetFocusAbsolute ¶
Set an absolute focal point on image for specificity.
The point uses North-West gravity (0, 0 corresponds to upper-left corner), for which to place a hightlight of attention on the image. In the event there are many identifiable objects in the image, this attempts to place importance on the ones closest to the focal point. This method accepts absolute coordinates (ie. a 400x400 image would have 0 through 400 for each axis).
func (Params) SetFocusRelative ¶
Set a relative focal point on image for specificity.
The point uses North-West gravity (0.0, 0.0 corresponds to upper-left corner), for which to place a hightlight of attention on the image. In the event there are many identifiable objects in the image, this attempts to place importance on the ones closest to the focal point. This method accepts relative coordinates (0.0 through 1.0).
func (Params) SetLanguage ¶
Set the language of the request. The response will be returned in this language. The default is "en".
func (Params) SetLatitude ¶
Set the latitude for additional geolocation context.
func (Params) SetLongitude ¶
Set the longitute for additional geolocation context.
func (Params) SetMaxTTL ¶
func (p Params) SetMaxTTL()
Set the maximum deadline before expired state is set.
func (Params) SetPosition ¶
Set the position for additional geolocation context.
type SkipReason ¶
type SkipReason string
The API may choose not to return any response for given image. SkipReason type includes possible reasons for such behavior.
const ( // Offensive image content. ReasonOffensive SkipReason = "offensive" // Too blurry to identify. ReasonBlurry SkipReason = "blurry" // Too close to identify. ReasonClose SkipReason = "close" // Too dark to identify. ReasonDark SkipReason = "dark" // Too bright to identify. ReasonBright SkipReason = "bright" // Content could not be identified. ReasonUnsure SkipReason = "unsure" )
func (SkipReason) Description ¶
func (r SkipReason) Description() string
Return a detailed description of the skip reason.