Module: AppleDEPClient::Request

Defined in:
lib/apple_dep_client/request.rb

Constant Summary collapse

DEFAULT_HEADERS =
{
  "User-Agent" => "#{AppleDEPClient.user_agent}/#{AppleDEPClient::VERSION}",
  "X-Server-Protocol-Version" => "2",
  "Content-Type" => "application/json;charset=UTF8",
}

Class Method Summary collapse

Class Method Details

.make_headersObject



32
33
34
35
# File 'lib/apple_dep_client/request.rb', line 32

def self.make_headers
  session_auth_token = AppleDEPClient::Auth.get_session_token
  DEFAULT_HEADERS.merge("X-ADM-Auth-Session" => session_auth_token)
end

.make_request(url, query_type, body, params: nil, headers: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/apple_dep_client/request.rb', line 16

def self.make_request(url, query_type, body, params:nil, headers:nil)
  if headers == nil
    headers = make_headers
  end
  request = Typhoeus::Request.new(
    url,
    method: query_type,
    body: body,
    params: params,
    headers: headers,
  )
  request.run
  AppleDEPClient::Error.check_request_error request.response
  JSON.parse request.response.body
end

.make_url(path) ⇒ Object



37
38
39
# File 'lib/apple_dep_client/request.rb', line 37

def self.make_url(path)
  AppleDEPClient.apple_dep_server + path
end