snipeit

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

README

go-snipeit

GoDoc

go-snipeit is a Go client library for accessing the SNIPE-IT API.

Notice

The library is under development and currently supports only API endpoints and methods used internally by Eurac Research. Contributions are very welcome!

License

The library is distributed under the BSD-style licence found in LICENSE file.

Documentation

Overview

Copyright 2020 Eurac Research. All rights reserved.

Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Package snipeit provides a client for communicating with the Snipe-IT API and defines Snipe-IT specific data types.

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
	// contains filtered or unexported fields
}

A Client manages communication with the Snipe-IT API.

func NewClient

func NewClient(baseURL, token string) (*Client, error)

NewClient returns a new Snipe-IT API client with provided base URL. If base URL does not have a trailing slash, one is added automatically.

func (*Client) AddOptions

func (c *Client) AddOptions(s string, opt interface{}) (string, error)

AddOptions adds the parameters in opt as URL query parameters to s. opt must be a struct whose fields may contain "url" tags.

func (*Client) Do

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

func (*Client) Hardware

func (c *Client) Hardware(opt *HardwareOptions) ([]*Hardware, *http.Response, error)

Hardware lists all Hardware.

https://snipe-it.readme.io/reference#hardware-list

func (*Client) Location

func (c *Client) Location(id int64) (*Location, *http.Response, error)

Location by ID.

Snipe-IT API doc: https://snipe-it.readme.io/reference#locations-1

func (*Client) Locations

func (c *Client) Locations(opt *LocationOptions) ([]*Location, *http.Response, error)

Locations lists all locations.

Snipe-IT API doc: https://snipe-it.readme.io/reference#locations

func (*Client) NewRequest

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

type Hardware

type Hardware struct {
	ID       int64  `json:"id,omitempty"`
	Name     string `json:"name,omitempty"`
	AssetTag string `json:"asset_tag,omitempty"`
	Serial   string `json:"serial,omitempty"`
	Model    struct {
		ID   int64  `json:"id,omitempty"`
		Name string `json:"name,omitempty"`
	} `json:"model,omitempty"`
	ModelNumber string `json:"model_number,omitempty"`
	StatusLabel struct {
		ID         int64  `json:"id,omitempty"`
		Name       string `json:"name,omitempty"`
		StatusMeta string `json:"status_meta,omitempty"`
	} `json:"status_label,omitempty"`
	Category struct {
		ID   int64  `json:"id,omitempty"`
		Name string `json:"name,omitempty"`
	} `json:"category,omitempty"`
	Manufacturer struct {
		ID   int64  `json:"id,omitempty"`
		Name string `json:"name,omitempty"`
	} `json:"manufacturer,omitempty"`
	Supplier struct {
		ID   int64  `json:"id,omitempty"`
		Name string `json:"name,omitempty"`
	} `json:"supplier,omitempty"`
	Notes       string `json:"notes,omitempty"`
	OrderNumber string `json:"order_number,omitempty"`
	Company     string `json:"company,omitempty"`
	Location    int64  `json:"location,omitempty"`
	RtdLocation struct {
		ID   int64  `json:"id,omitempty"`
		Name string `json:"name,omitempty"`
	} `json:"rtd_location,omitempty"`
	Image      string `json:"image,omitempty"`
	AssignedTo struct {
		ID        int64  `json:"id,omitempty"`
		Username  string `json:"username,omitempty"`
		Name      string `json:"name,omitempty"`
		Firstname string `json:"first_name,omitempty"`
		Lastname  string `json:"last_name,omitempty"`
		Emplyee   string `json:"employee_number,omitempty"`
		Type      string `json:"type,omitempty"`
	} `json:"assigned_to,omitempty"`
	WarrantyMonths   interface{}   `json:"warranty_months,omitempty"`
	WarrantyExpires  interface{}   `json:"warranty_expires,omitempty"`
	CreatedAt        Timestamp     `json:"created_at,omitempty"`
	UpdatedAt        Timestamp     `json:"updated_at,omitempty"`
	DeletedAt        Timestamp     `json:"deleted_at,omitempty"`
	PurchaseDate     Timestamp     `json:"purchase_date,omitempty"`
	LastCheckout     Timestamp     `json:"last_checkout,omitempty"`
	ExpectedCheckin  Timestamp     `json:"expected_checkin,omitempty"`
	PurchaseCost     int64         `json:"purchase_cost,omitempty"`
	UserCanCheckout  bool          `json:"user_can_checkout,omitempty"`
	CustomFields     []interface{} `json:"custom_fields,omitempty"`
	AvailableActions struct {
		Checkout bool `json:"checkout,omitempty"`
		Checkin  bool `json:"checkin,omitempty"`
		Clone    bool `json:"clone,omitempty"`
		Restore  bool `json:"restore,omitempty"`
		Update   bool `json:"update,omitempty"`
		Delete   bool `json:"delete,omitempty"`
	} `json:"available_actions,omitempty"`
}

Hardware represents a Snipe-IT hardware object.

type HardwareOptions

type HardwareOptions struct {
	LocationID int `url:"location_id,omitempty"`
	CompanyID  int `url:"company_id,omitempty"`
}

HardwareOptions specifies a subset of optional query parameters for listing assets.

type Location

type Location struct {
	ID             int64     `json:"id,omitempty"`
	Name           string    `json:"name,omitempty"`
	Image          string    `json:"image,omitempty"`
	Address        string    `json:"address,omitempty"`
	Address2       string    `json:"address2,omitempty"`
	City           string    `json:"city,omitempty"`
	State          string    `json:"state,omitempty"`
	Country        string    `json:"country,omitempty"`
	Zip            string    `json:"zip,omitempty"`
	AssetsAssigned int64     `json:"assigned_assets_count,omitempty"`
	Assets         int64     `json:"assets_count,omitempty"`
	Users          int64     `json:"users_count,omitempty"`
	Currency       string    `json:"currency,omitempty"`
	CreatedAt      Timestamp `json:"created_at,omitempty"`
	UpdatedAt      Timestamp `json:"updated_at,omitempty"`
	Parent         struct {
		ID   int64  `json:"id,omitempty"`
		Name string `json:"name,omitempty"`
	} `json:"parent,omitempty"`
	Manager  string     `json:"manager,omitempty"`
	Children []Location `json:"children,omitempty"`
	Actions  struct {
		Update bool
		Delete bool
	} `json:"available_actions,omitempty"`
}

Location represents a Snipe-IT location.

type LocationOptions

type LocationOptions struct {
	// Search string
	Search string `url:"search,omitempty"`
}

LocationOptions specifies a subset of optional query parameters for listing locations.

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp is a custom time type for parsing Snipe-ITs API updated_at and created_at JSON values.

func (*Timestamp) UnmarshalJSON

func (ts *Timestamp) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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