class AppleVPP::Request

Public Class Methods

submit( url, s_token = nil, body = {} ) click to toggle source
# File lib/apple_vpp/request.rb, line 7
def self.submit( url, s_token = nil, body = {} )
  body['sToken'] = s_token
  body.delete_if { |_k, v| v.nil? }
  begin

    resp = RestClient.post url, body, content_type: :json

  rescue RestClient::ExceptionWithResponse => e

    unless e.response.code == 503
      raise e
    end

    raise AppleVPP::Error::ServiceUnavailable.new(e.response.raw_headers['Retry-After'])

  end

  json = JSON.parse(resp)

  if json['status'] == -1
    raise (eval "AppleVPP::Error::Code#{json['errorNumber']}"), json['errorMessage']
  end

  json
end