Class: AppleVPP::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/apple_vpp/request.rb

Class Method Summary collapse

Class Method Details

.submit(url, s_token = nil, body = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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