apple_vpp 3.0.2 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adcdb9612aaa35734ab5e10326f5002494f64844
4
- data.tar.gz: 1807d39e5144529eec881e42cf8e85b7633cb8ce
3
+ metadata.gz: 66e3f762a1be742576c657a6d8c7a597cf3a2952
4
+ data.tar.gz: 0a811283fbe9b3e3c18b8552f3cf9bad3aa8543d
5
5
  SHA512:
6
- metadata.gz: 0125c4e4fef7f9936e3074724f854807995143737b102e7c5581b500a699e050e357490dfa2a309ebe991e3d31547f3027040367cacbd23d072b78491400d0fb
7
- data.tar.gz: 81256495a17d68f7bf7737589d9277b89e4218e082e4ede1e48e7c00ec3016f9af3c040d0c9c444cd8b21004565242e9bb48a9d461ff6744f83aa33a0bf740d2
6
+ metadata.gz: 54a55e79df45d3b96f1414e262f48aaea2881765ee82091fa226dc06f8796936dac6549f889d1ad73d289e7e5c2fd17e7187bddd3de6ae066a952ed77c838715
7
+ data.tar.gz: 696437d6b02a2dc705a4f1059dd2e8471609af868543355744a0d558a90a65470269bb33eda8b95fe83bdf8019dc9c2b7c8a2b4843408e826233f7e483decc13
data/README.md CHANGED
@@ -29,7 +29,7 @@ c = AppleVPP::Client.new s_token
29
29
  resp = c.get_users
30
30
 
31
31
  c.edit_user user_id: resp[:users].first[:user_id],
32
- email: 'youremail@example.org'
32
+ email: 'youremail@example.org'
33
33
  ```
34
34
 
35
35
  # Methods
@@ -38,7 +38,7 @@ For information beyond what is included here, refer to the "Mobile Device Manage
38
38
 
39
39
  ## associate_license_with_user
40
40
 
41
- One of these is required:
41
+ One of these is required:
42
42
 
43
43
  * user_id
44
44
  * client_user_id_str
@@ -76,6 +76,12 @@ Optional:
76
76
 
77
77
  * email
78
78
 
79
+ ## get_assets
80
+
81
+ Optional:
82
+
83
+ * include_license_counts
84
+
79
85
  ## get_licenses
80
86
 
81
87
  Optional:
@@ -102,6 +108,24 @@ Optional:
102
108
  * since_modified_token
103
109
  * include_retired
104
110
 
111
+ ## manage_licenses_by_adam_id_src
112
+
113
+ Required:
114
+
115
+ * adam_id_str
116
+ * pricing_param
117
+
118
+ One (and only one) of these are required:
119
+
120
+ * associate_client_user_id_strs
121
+ * associate_serial_numbers
122
+ * disassociate_client_user_id_strs
123
+ * disassociate_serial_numbers
124
+
125
+ Optional:
126
+
127
+ * notify_disassociation
128
+
105
129
  ## register_user
106
130
 
107
131
  Required:
@@ -121,6 +145,8 @@ One of these is required:
121
145
 
122
146
  # Error Handling
123
147
 
148
+ ## Apple API Errors
149
+
124
150
  Should an error be reported by the Apple API service, the library will raise a custom error class that will correspond to the Apple error code like so:
125
151
 
126
152
  ```ruby
@@ -129,6 +155,11 @@ AppleVPP::Error::Code#{error_code}
129
155
 
130
156
  A message will also be provided with the error.
131
157
 
158
+ ## 503 Service Unavailable Errors
159
+
160
+ The Apple API service may return a `503 Service Unavailable` error if the service is overwhelmed or if your client is being too aggressive. In this scenario, `apple_vpp` will raise `AppleVPP::Error::ServiceUnavailable`. The raised error will include a method `.retry_in_seconds` which returns an integer value, in seconds, of how long you should wait before retrying your request. The raw `Retry-After` header that Apple returns is also available via `.retry_after`.
161
+
162
+
132
163
  ## Contributing
133
164
 
134
165
  1. Fork it
data/apple_vpp.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'rest-client', '~> 1.6.7'
21
+ spec.add_dependency 'rest-client', '~> 1.8.0'
22
22
  spec.add_development_dependency "bundler", "~> 1.3"
23
23
  spec.add_development_dependency "rake"
24
24
  spec.add_development_dependency "rspec"
@@ -65,6 +65,16 @@ module AppleVPP
65
65
  AppleSerializer.to_ruby resp['user']
66
66
  end
67
67
 
68
+ def get_assets(params = {})
69
+ body = {
70
+ 'includeLicenseCounts' => params[:include_license_counts]
71
+ }
72
+
73
+ resp = request :get_vpp_assets_srv_url, body
74
+
75
+ AppleSerializer.to_ruby resp['assets']
76
+ end
77
+
68
78
  def get_licenses(params = {})
69
79
  licenses = []
70
80
  batch_token = nil
@@ -88,7 +98,7 @@ module AppleVPP
88
98
 
89
99
  end while batch_token
90
100
 
91
- {
101
+ {
92
102
  licenses: AppleSerializer.to_ruby(licenses),
93
103
  since_modified_token: since_modified_token
94
104
  }
@@ -96,10 +106,10 @@ module AppleVPP
96
106
 
97
107
  def get_user(params = {})
98
108
  require_params [[:user_id, :client_user_id_str]], params
99
-
109
+
100
110
  body = {
101
- 'userId' => params[:user_id],
102
- 'clientUserIdStr' => params[:client_user_id_str],
111
+ 'userId' => params[:user_id],
112
+ 'clientUserIdStr' => params[:client_user_id_str],
103
113
  'itsIdHash' => params[:its_id_hash]
104
114
  }
105
115
 
@@ -108,6 +118,34 @@ module AppleVPP
108
118
  AppleSerializer.to_ruby resp['user']
109
119
  end
110
120
 
121
+ def manage_licenses_by_adam_id(params = {})
122
+ require_params [:adam_id_str, :pricing_param], params
123
+
124
+ unless params.has_key?(:associate_client_user_id_strs) ^
125
+ params.has_key?(:associate_serial_numbers) ^
126
+ params.has_key?(:disassociate_client_user_id_strs) ^
127
+ params.has_key?(:disassociate_license_id_strs)
128
+ raise ArgumentError, 'One and only one of these parameters may be provided: associate_client_user_id_strs, associate_serial_numbers, disassociate_client_user_id_strs, disassociate_license_id_strs.'
129
+ end
130
+
131
+ body = {
132
+ 'adamIdStr' => params[:adam_id_str],
133
+ 'associateClientUserIdStrs' => params[:associate_client_user_id_strs],
134
+ 'associateSerialNumbers' => params[:associate_serial_numbers],
135
+ 'disassociateClientUserIdStrs' => params[:disassociate_client_user_id_strs],
136
+ 'disassociateLicenseIdStrs' => params[:disassociate_license_id_strs],
137
+ 'pricingParam' => params[:pricing_param],
138
+ 'notifyDisassociation' => params[:notify_disassociation]
139
+ }
140
+
141
+ resp = request :manage_vpp_licenses_by_adam_id_srv_url, body
142
+
143
+ ret = AppleSerializer.to_ruby resp
144
+ ret.delete(:status)
145
+
146
+ ret
147
+ end
148
+
111
149
  def register_user(params = {})
112
150
  require_params :client_user_id_str, params
113
151
 
@@ -117,7 +155,7 @@ module AppleVPP
117
155
  }
118
156
 
119
157
  resp = request :register_user_srv_url, body
120
-
158
+
121
159
  AppleSerializer.to_ruby resp['user']
122
160
  end
123
161
 
@@ -153,21 +191,21 @@ module AppleVPP
153
191
 
154
192
  batch_token = resp['batchToken']
155
193
  since_modified_token = resp['sinceModifiedToken']
156
-
194
+
157
195
  end while batch_token
158
196
 
159
- {
197
+ {
160
198
  users: AppleSerializer.to_ruby(users),
161
199
  since_modified_token: since_modified_token
162
200
  }
163
201
  end
164
202
 
165
203
  private
166
-
204
+
167
205
  # param_name_array is an array of required parameters. Include a sub-array of parameters for || requirement.
168
206
 
169
207
  def require_params param_name_array, params
170
- param_name_array = [param_name_array] unless param_name_array.kind_of? Array
208
+ param_name_array = [param_name_array] unless param_name_array.kind_of? Array
171
209
 
172
210
  param_name_array.each do |param_names|
173
211
  param_names = [param_names] unless param_names.kind_of?(Array)
@@ -179,7 +217,7 @@ module AppleVPP
179
217
  break
180
218
  end
181
219
  end
182
-
220
+
183
221
  unless param_found
184
222
  raise ArgumentError, "#{param_names.join(' or ')} must be provided"
185
223
  end
@@ -1,3 +1,5 @@
1
+ require 'time'
2
+
1
3
  module AppleVPP
2
4
  class Error < ::StandardError
3
5
 
@@ -9,5 +11,22 @@ module AppleVPP
9
11
  self.const_set "Code#{code}", ( Class.new AppleVPP::Error )
10
12
  end
11
13
 
14
+ class ServiceUnavailable
15
+ attr_accessor :retry_after
16
+
17
+ def initialize retry_after
18
+ @retry_after = retry_after
19
+ end
20
+
21
+ def retry_in_seconds
22
+ if @retry_after == @retry_after.to_i.to_s
23
+ @retry_after
24
+ else
25
+ Time.parse(@retry_after) - Time.now
26
+ end
27
+ end
28
+
29
+ end
30
+
12
31
  end
13
32
  end
@@ -7,12 +7,26 @@ module AppleVPP
7
7
  def self.submit( url, s_token = nil, body = {} )
8
8
  body['sToken'] = s_token
9
9
  body.delete_if { |_k, v| v.nil? }
10
-
11
- resp = RestClient.post url, body, content_type: :json
10
+ require 'awesome_print'
11
+ ap body
12
+ begin
13
+
14
+ resp = RestClient.post url, body, content_type: :json
15
+
16
+ rescue RestClient::ExceptionWithResponse => e
17
+
18
+ unless e.response.code == 503
19
+ raise e
20
+ end
21
+
22
+ raise AppleVPP::Error::ServiceUnavailable.new(e.response.raw_headers['Retry-After'])
23
+
24
+ end
25
+
12
26
  json = JSON.parse(resp)
13
27
 
14
28
  if json['status'] == -1
15
- raise (eval "AppleVPP::Error::Code#{json['errorNumber']}"), json['errorMessage']
29
+ raise (eval "AppleVPP::Error::Code#{json['errorNumber']}"), json['errorMessage']
16
30
  end
17
31
 
18
32
  json
@@ -7,10 +7,12 @@ module AppleVPP
7
7
  :client_config_srv_url,
8
8
  :disassociate_license_srv_url,
9
9
  :edit_user_srv_url,
10
+ :get_vpp_assets_srv_url,
10
11
  :get_licenses_srv_url,
11
12
  :get_user_srv_url,
12
13
  :get_users_srv_url,
13
14
  :invitation_email_url,
15
+ :manage_vpp_licenses_by_adam_id_srv_url,
14
16
  :register_user_srv_url,
15
17
  :retire_user_srv_url,
16
18
  :vpp_website_url,
@@ -25,17 +27,19 @@ module AppleVPP
25
27
  url = "#{SERVICE_URL}VPPServiceConfigSrv"
26
28
  resp = Request.submit url
27
29
 
28
- @associate_license_srv_url = resp['associateLicenseSrvUrl']
29
- @client_config_srv_url = resp['clientConfigSrvUrl']
30
- @disassociate_license_srv_url = resp['disassociateLicenseSrvUrl']
31
- @edit_user_srv_url = resp['editUserSrvUrl']
32
- @get_licenses_srv_url = resp['getLicensesSrvUrl']
33
- @get_user_srv_url = resp['getUserSrvUrl']
34
- @get_users_srv_url = resp['getUsersSrvUrl']
35
- @invitation_email_url = resp['invitationEmailUrl']
36
- @register_user_srv_url = resp['registerUserSrvUrl']
37
- @retire_user_srv_url = resp['retireUserSrvUrl']
38
- @vpp_website_url = resp['vppWebsiteUrl']
30
+ @associate_license_srv_url = resp['associateLicenseSrvUrl']
31
+ @client_config_srv_url = resp['clientConfigSrvUrl']
32
+ @disassociate_license_srv_url = resp['disassociateLicenseSrvUrl']
33
+ @edit_user_srv_url = resp['editUserSrvUrl']
34
+ @get_vpp_assets_srv_url = resp['getVPPAssetsSrvUrl']
35
+ @get_licenses_srv_url = resp['getLicensesSrvUrl']
36
+ @get_user_srv_url = resp['getUserSrvUrl']
37
+ @get_users_srv_url = resp['getUsersSrvUrl']
38
+ @invitation_email_url = resp['invitationEmailUrl']
39
+ @manage_vpp_licenses_by_adam_id_srv_url = resp['manageVPPLicensesByAdamIdSrvUrl']
40
+ @register_user_srv_url = resp['registerUserSrvUrl']
41
+ @retire_user_srv_url = resp['retireUserSrvUrl']
42
+ @vpp_website_url = resp['vppWebsiteUrl']
39
43
 
40
44
  resp['errorCodes'].each do |i|
41
45
  @errors[ i['errorNumber'] ] = i['errorMessage']
@@ -50,3 +54,4 @@ module AppleVPP
50
54
 
51
55
  end
52
56
  end
57
+
@@ -1,3 +1,3 @@
1
1
  module AppleVPP
2
- VERSION = "3.0.2"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AppleVPP::API do
3
+ describe AppleVPP::Client do
4
4
 
5
- end
5
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,7 +10,6 @@ require 'apple_vpp'
10
10
  #
11
11
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
12
12
  RSpec.configure do |config|
13
- config.treat_symbols_as_metadata_keys_with_true_values = true
14
13
  config.run_all_when_everything_filtered = true
15
14
  config.filter_run :focus
16
15
 
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_vpp
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Boyko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-29 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.6.7
19
+ version: 1.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.6.7
26
+ version: 1.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: Ruby bindings for the Apple VPP App Assignment API
@@ -73,8 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
77
- - .rspec
76
+ - ".gitignore"
77
+ - ".rspec"
78
78
  - CHANGELOG.md
79
79
  - Gemfile
80
80
  - LICENSE
@@ -102,17 +102,17 @@ require_paths:
102
102
  - lib
103
103
  required_ruby_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
- - - '>='
105
+ - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - '>='
110
+ - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.0.14
115
+ rubygems_version: 2.4.6
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: Ruby bindings for the Apple VPP App Assignment API