Sha256: 03b265038ac985fd5453e6ac05cf93da93b71e70e27584e0e9b5540675ec46dd

Contents?: true

Size: 1.06 KB

Versions: 6

Compression:

Stored size: 1.06 KB

Contents

# Wrapper around requests to DEP endpoint
# Will also handle any error conditions

require "json"
require "typhoeus"

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

    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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
apple_dep_client-2.2.3 lib/apple_dep_client/request.rb
apple_dep_client-2.2.2 lib/apple_dep_client/request.rb
apple_dep_client-2.2.0 lib/apple_dep_client/request.rb
apple_dep_client-2.1.1 lib/apple_dep_client/request.rb
apple_dep_client-2.1.0 lib/apple_dep_client/request.rb
apple_dep_client-2.0.1 lib/apple_dep_client/request.rb