Module: Jamf::Connection::JamfProAPI
- Included in:
- Jamf::Connection
- Defined in:
- lib/jamf/api/connection/jamf_pro_api.rb
Overview
This Module defines methods used for interacting with the Jamf Pro API. This includes creating the Faraday connection, sending HTTP requests and handling responses
Instance Method Summary collapse
-
#create_jp_connection(parse_json: true) ⇒ Object
create the faraday JPAPI connection object.
-
#jp_delete(rsrc) ⇒ String
(also: #delete)
Delete an existing Jamf Pro API resource.
-
#jp_download(rsrc) ⇒ Object
GET a rsrc without doing any JSON parsing, using a temporary Faraday connection object.
-
#jp_get(rsrc) ⇒ Hash
(also: #get)
The result of the get.
-
#jp_patch(rsrc, data) ⇒ String
(also: #patch)
Update an existing Jamf Pro API resource.
-
#jp_post(rsrc, data) ⇒ String
(also: #post)
Create a JPAPI resource via POST.
-
#jp_put(rsrc, data) ⇒ String
(also: #put)
Replace an existing Jamf Pro API resource.
Instance Method Details
#create_jp_connection(parse_json: true) ⇒ Object
create the faraday JPAPI connection object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jamf/api/connection/jamf_pro_api.rb', line 38 def create_jp_connection(parse_json: true) Faraday.new(@jp_base_url, ssl: ) do |cnx| cnx. :Bearer, @token.token cnx.[:timeout] = @timeout cnx.[:open_timeout] = @open_timeout if parse_json cnx.request :json cnx.response :json, parser_options: { symbolize_names: true } end cnx.adapter Faraday::Adapter::NetHttp end end |
#jp_delete(rsrc) ⇒ String Also known as: delete
Delete an existing Jamf Pro API resource
143 144 145 146 147 148 149 150 |
# File 'lib/jamf/api/connection/jamf_pro_api.rb', line 143 def jp_delete(rsrc) validate_connected @jp_cnx resp = @jp_cnx.delete rsrc @last_http_response = resp return resp.body if resp.success? raise Jamf::Connection::JamfProAPIError, resp end |
#jp_download(rsrc) ⇒ Object
GET a rsrc without doing any JSON parsing, using a temporary Faraday connection object
157 158 159 160 161 162 163 164 |
# File 'lib/jamf/api/connection/jamf_pro_api.rb', line 157 def jp_download(rsrc) temp_cnx = create_jp_connection(parse_json: false) resp = temp_cnx.get rsrc @last_http_response = resp return resp.body if resp.success? raise Jamf::Connection::JamfProAPIError, resp end |
#jp_get(rsrc) ⇒ Hash Also known as: get
Returns the result of the get.
59 60 61 62 63 64 65 66 |
# File 'lib/jamf/api/connection/jamf_pro_api.rb', line 59 def jp_get(rsrc) validate_connected @jp_cnx resp = @jp_cnx.get rsrc @last_http_response = resp return resp.body if resp.success? raise Jamf::Connection::JamfProAPIError, resp end |
#jp_patch(rsrc, data) ⇒ String Also known as: patch
Update an existing Jamf Pro API resource
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/jamf/api/connection/jamf_pro_api.rb', line 123 def jp_patch(rsrc, data) validate_connected @jp_cnx resp = @jp_cnx.patch(rsrc) do |req| req.body = data end @last_http_response = resp return resp.body if resp.success? raise Jamf::Connection::JamfProAPIError, resp end |
#jp_post(rsrc, data) ⇒ String Also known as: post
Create a JPAPI resource via POST
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/jamf/api/connection/jamf_pro_api.rb', line 79 def jp_post(rsrc, data) validate_connected @jp_cnx resp = @jp_cnx.post(rsrc) do |req| req.body = data end @last_http_response = resp return resp.body if resp.success? raise Jamf::Connection::JamfProAPIError, resp end |
#jp_put(rsrc, data) ⇒ String Also known as: put
Replace an existing Jamf Pro API resource
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/jamf/api/connection/jamf_pro_api.rb', line 101 def jp_put(rsrc, data) validate_connected @jp_cnx resp = @jp_cnx.put(rsrc) do |req| req.body = data end @last_http_response = resp return resp.body if resp.success? raise Jamf::Connection::JamfProAPIError, resp end |