Skip to content
Permalink
Browse files

Move function and improve documentation.

  • Loading branch information...
plusvic committed Jul 12, 2019
1 parent 1daa0c8 commit a76668832254fed9dfff2403112a4a1088bd2271
Showing with 37 additions and 24 deletions.
  1. +26 −0 client.go
  2. +0 −23 iterator.go
  3. +11 −1 object.go
@@ -279,7 +279,33 @@ func (cli *Client) DownloadFile(hash string, w io.Writer) (int64, error) {
return io.Copy(w, resp.Body)
}

// Iterator returns an iterator for a collection. If the endpoint passed to the
// iterator returns a single object instead of a collection, it behaves as if
// iterating over a collection with a single object. Iterators are usually
// used like this:
//
// cli := vt.Client(<api key>)
// it, err := cli.Iterator(vt.URL(<collection path>))
// if err != nil {
// ...handle error
// }
// defer it.Close()
// for it.Next() {
// obj := it.Get()
// ...do something with obj
// }
// if err := it.Error(); err != nil {
// ...handle error
// }
//
func (cli *Client) Iterator(url *url.URL, options ...IteratorOption) (*Iterator, error) {
return newIterator(cli, url, options...)
}

// Search for files using VirusTotal Intelligence query language.
// Example:
// it, err := client.Search("p:10+ size:30MB+")
//
func (cli *Client) Search(query string, options ...IteratorOption) (*Iterator, error) {
u := URL("intelligence/search")
q := u.Query()
@@ -175,29 +175,6 @@ func newIterator(cli *Client, u *url.URL, options ...IteratorOption) (*Iterator,
return it, nil
}

// Iterator returns an iterator for a collection. If the endpoint passed to the
// iterator returns a single object instead of a collection it behaves as if
// iterating over a collection with a single object. Iterators are usually
// used like this:
//
// cli := vt.Client(<api key>)
// it, err := cli.Iterator(vt.URL(<collection path>))
// if err != nil {
// ...handle error
// }
// defer it.Close()
// for it.Next() {
// obj := it.Get()
// ...do something with obj
// }
// if err := it.Error(); err != nil {
// ...handle error
// }
//
func (cli *Client) Iterator(url *url.URL, options ...IteratorOption) (*Iterator, error) {
return newIterator(cli, url, options...)
}

// Next advances the iterator to the next object and returns true if there are
// more objects or false if the end of the collection has been reached.
func (it *Iterator) Next() bool {
@@ -350,7 +350,17 @@ func (obj *Object) SetTime(attr string, value time.Time) error {
return obj.Set(attr, value.Unix())
}

// GetRelationship returns a relationship by name.
// GetRelationship returns a relationship by name. Object's will have
// relationships were explicitly asked for during a call to GetObject by
// including the "relationships" paramether in the URL.
//
// Example:
// f, _ := client.GetObject(vt.URL("files/%s?relationships=contacted_ips"))
// // OK as "contacted_ip" was requested.
// r, _ := f.GetRelationship("contacted_ips")
// // Not OK, "contacted_urls" won't be present
// r, _ := f.GetRelationship("contacted_urls")
//
func (obj *Object) GetRelationship(name string) (*Relationship, error) {
if r, exists := obj.data.Relationships[name]; exists {
return &Relationship{data: *r}, nil

0 comments on commit a766688

Please sign in to comment.
You can’t perform that action at this time.