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.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



16
17
18
# File 'lib/pybossa-api.rb', line 16

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:



51
52
53
# File 'lib/pybossa-api.rb', line 51

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:



77
78
79
# File 'lib/pybossa-api.rb', line 77

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



27
28
29
# File 'lib/pybossa-api.rb', line 27

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



38
39
40
# File 'lib/pybossa-api.rb', line 38

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:



64
65
66
# File 'lib/pybossa-api.rb', line 64

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