Module: Windoo::Connection::Actions

Included in:
Windoo::Connection
Defined in:
lib/windoo/connection/actions.rb

Overview

This module defines methods used for interacting with the TitleEditor API. This includes sending HTTP requests and handling responses

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(includer) ⇒ Object



18
19
20
# File 'lib/windoo/connection/actions.rb', line 18

def self.included(includer)
  Windoo.verbose_include(includer, self)
end

Instance Method Details

#delete(rsrc) ⇒ Object

Delete a resource from the API

Parameters:

  • rsrc (String)

    the resource to delete

Returns:

  • (Object)

    The parsed JSON from the result of the request



80
81
82
83
84
85
86
87
88
89
# File 'lib/windoo/connection/actions.rb', line 80

def delete(rsrc)
  validate_connected

  # send the data
  resp = cnx.delete(rsrc)
  @last_http_response = resp
  return resp.body if resp.success?

  handle_http_error resp
end

#get(rsrc) ⇒ Object

Returns The parsed JSON from the result of the request.

Parameters:

  • rsrc (String)

    the resource path to get

Returns:

  • (Object)

    The parsed JSON from the result of the request



26
27
28
29
30
31
32
33
34
# File 'lib/windoo/connection/actions.rb', line 26

def get(rsrc)
  validate_connected

  resp = cnx.get(rsrc)
  @last_http_response = resp
  return resp.body if resp.success?

  handle_http_error resp
end

#post(rsrc, content) ⇒ Object

Create a new API resource via POST

Parameters:

  • rsrc (String)

    the API resource being created, the URL part after ‘JSSResource/’

  • content (String)

    the content specifying the new object.

Returns:

  • (Object)

    The parsed JSON from the result of the request



44
45
46
47
48
49
50
51
52
53
# File 'lib/windoo/connection/actions.rb', line 44

def post(rsrc, content)
  validate_connected

  # send the data
  resp = cnx.post(rsrc) { |req| req.body = content }
  @last_http_response = resp
  return resp.body if resp.success?

  handle_http_error resp
end

#put(rsrc, content) ⇒ Object

Update an existing API resource via PUT

Parameters:

  • rsrc (String)

    the API resource being changed, the URL part after ‘JSSResource/’

  • content (String)

    the content specifying the changes.

Returns:

  • (Object)

    The parsed JSON from the result of the request



63
64
65
66
67
68
69
70
71
72
# File 'lib/windoo/connection/actions.rb', line 63

def put(rsrc, content)
  validate_connected

  # send the data
  resp = cnx.put(rsrc) { |req| req.body = content }
  @last_http_response = resp
  return resp.body if resp.success?

  handle_http_error resp
end