Class: PyBossa::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/pybossa-api.rb,
lib/pybossa-api/version.rb

Overview

A Ruby wrapper for the PyBossa API.

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



21
22
23
# File 'lib/pybossa-api.rb', line 21

def api_key
  @api_key
end

Class Method Details

.create(klass, opts = {}) ⇒ Hash

Creates an object.

Parameters:

  • klass (String)

    one of “app”, “task” or “taskrun”

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :api_key (String)

    an API key

Returns:

  • (Hash)

    an object

Raises:

See Also:



56
57
58
# File 'lib/pybossa-api.rb', line 56

def create(klass, opts = {})
  request :post, "/#{klass}", opts
end

.destroy(klass, id, opts = {}) ⇒ Object

Deletes an object.

Parameters:

  • klass (String)

    one of “app”, “task” or “taskrun”

  • id (Integer)

    an object ID

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :api_key (String)

    an API key

Raises:

See Also:



82
83
84
# File 'lib/pybossa-api.rb', line 82

def destroy(klass, id, opts = {})
  request :delete, "/#{klass}/#{id}", opts
end

.many(klass, opts = {}) ⇒ Array

Lists objects. To filter objects, add key-value pairs to the :opts argument in which each key is the name of a field on which you want to filter. For example, you may want to filter tasks by app_id.

Parameters:

  • klass (String)

    one of “app”, “task” or “taskrun”

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :limit (Integer)

    number of results to return [default 20]

  • :api_key (String)

    an API key

Returns:

  • (Array)

    a list of objects



32
33
34
# File 'lib/pybossa-api.rb', line 32

def many(klass, opts = {})
  request :get, "/#{klass}", opts
end

.retrieve(klass, id, opts = {}) ⇒ Hash

Gets an object by ID.

Parameters:

  • klass (String)

    one of “app”, “task” or “taskrun”

  • id (Integer)

    an object ID

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :api_key (String)

    an API key

Returns:

  • (Hash)

    an object



43
44
45
# File 'lib/pybossa-api.rb', line 43

def retrieve(klass, id, opts = {})
  request :get, "/#{klass}/#{id}", opts
end

.update(klass, id, opts = {}) ⇒ Object

Updates an object.

Parameters:

  • klass (String)

    one of “app”, “task” or “taskrun”

  • id (Integer)

    an object ID

  • opts (Hash) (defaults to: {})

    optional arguments

Options Hash (opts):

  • :api_key (String)

    an API key

Raises:

See Also:



69
70
71
# File 'lib/pybossa-api.rb', line 69

def update(klass, id, opts = {})
  request :put, "/#{klass}/#{id}", opts
end