airwatch-ruby 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 775aafdbb0a361df1e1dc3bc638216df732dfd2480df69aeb8ec1c857ab66478
4
- data.tar.gz: 02fd6ebbfe64d3f5d46af4ba35ac3f00e8130c9ff767a3af39320b2ac0dd94a5
3
+ metadata.gz: 6c1f9622b014e91eb5c3108e92c5d9df7aa0471ec1fdbb3f894e4d6f0ca8402b
4
+ data.tar.gz: 8be3335943ad9e7cf0c8590b24dd45435a8ccd0609923b56c589967d92143694
5
5
  SHA512:
6
- metadata.gz: f995fd58984c6075c09d8329b38fb670b37101b623d0ca3b6131f6fcf7f07d924b906559b56ac06f64beb8faeec5a2d5c2be12229d5e2a2ef62dd88f47dada1a
7
- data.tar.gz: f23677fb66ca59e8da832a07ab4b5225f96b5dc391cebd08800a4091935c671eb1ea8e9183ea035410d7293241f52279e341a1cf523a5ebe8562401575209ea9
6
+ metadata.gz: 1120ac8803c2bd1ae956aa83b8bdc9182a644ac3b1e3dd31776a16e179b6f5688ee2515e68891d45acd7990cbb3bfa36cc9e5aeb0017c1b11ed7fcad60ef0816
7
+ data.tar.gz: 474564403a76874911f7b1e91ffb83b0675276934c9325a4e946f9ff74a29d079d36515eee40dff7e7f8a64abde1a93c4ae49c3e78d79b3389d5b6625524b335
data/README.md CHANGED
@@ -1,3 +1,16 @@
1
1
  # airwatch-ruby
2
2
 
3
- TODO: make a readme
3
+ Add the gem to your Gemfile:
4
+
5
+ ```ruby
6
+ gem 'airwatch-ruby'
7
+ ```
8
+
9
+ Example usage:
10
+
11
+ ```
12
+ require 'airwatch'
13
+
14
+ client = Airwatch::Client.new('as1111.awmdm.com', 'MY_API_KEY', email: 'admin@example.com', password: 'password')
15
+ client.apps_search # returns a list of apps
16
+ ```
@@ -41,4 +41,5 @@ Gem::Specification.new do |spec|
41
41
  spec.add_development_dependency "rspec", "~> 3.0"
42
42
  spec.add_runtime_dependency 'httparty', '~> 0.18'
43
43
  spec.add_runtime_dependency 'addressable', '~> 2.7.0'
44
+ spec.add_runtime_dependency 'rest-client', '~> 2.1.0'
44
45
  end
@@ -1,3 +1,7 @@
1
+ require 'httparty'
2
+ require 'addressable'
3
+ require 'rest-client'
4
+
1
5
  module Airwatch
2
6
  class Client
3
7
  # @param [String] host make sure you get this from Settings > System > Advanced > Site URLs
@@ -35,6 +39,50 @@ module Airwatch
35
39
  post("mam/apps/internal/#{app_id}/install", { deviceid: device_id })
36
40
  end
37
41
 
42
+ def upload_blob(file_path, org_group_id)
43
+ raise "No IPA found at path: #{file_path}" unless File.file?(file_path)
44
+ filename = File.basename(file_path)
45
+ url = build_url('mam/blobs/uploadblob', { filename: filename, organizationgroupid: org_group_id.to_s })
46
+ payload = File.open(file_path, 'rb')
47
+ headers = request_headers
48
+ headers[:'Content-Type'] = 'application/octet-stream'
49
+ headers[:'Expect'] = '100-continue'
50
+ response = nil
51
+ begin
52
+ response = RestClient::Request.execute(
53
+ :url => url,
54
+ :method => :post,
55
+ :headers => headers,
56
+ :payload => File.open(file_path, 'rb')
57
+ )
58
+ rescue RestClient::BadRequest => e
59
+ puts "Error uploading blob"
60
+ puts "Exception message: ---------"
61
+ puts e.message
62
+ puts "HTTP status code: ---------"
63
+ puts e.http_code
64
+ puts "HTTP body: ---------"
65
+ puts e.http_body
66
+ return nil
67
+ end
68
+ JSON.parse(response)
69
+ end
70
+
71
+ def begin_install(blob_id, app_name, org_group_id)
72
+ supportedmodels = {'Model' => [{'ModelId' => 1,'ModelName' => 'iPhone'},{'ModelId' => 2,'ModelName' => 'iPad'},{'ModelId' => 3,'ModelName' => 'iPod Touch'}]}
73
+ params = {
74
+ 'BlobId' => blob_id,
75
+ 'DeviceType' => 'Apple', # 'Apple',
76
+ 'ApplicationName' => app_name,
77
+ 'AppVersion' => nil,
78
+ 'SupportedModels' => supportedmodels,
79
+ 'PushMode' => 'On Demand',
80
+ 'LocationGroupId' => org_group_id
81
+ }
82
+ url = build_url('mam/apps/internal/begininstall')
83
+ post('mam/apps/internal/begininstall', params.to_json)
84
+ end
85
+
38
86
  #############################
39
87
  # Profiles #
40
88
  #############################
@@ -90,6 +138,20 @@ module Airwatch
90
138
  get("mdm/smartgroups/#{smart_group_id}")
91
139
  end
92
140
 
141
+ def smart_group_update(smart_group_id, device_addition_ids:)
142
+ raise 'need to assign to at least 1 device' if device_addition_ids.empty?
143
+ device_additions = device_addition_ids.map { |id| { id: id } }
144
+ put("mdm/smartgroups/#{smart_group_id}", { criteriatype: 'UserDevice', deviceadditions: device_additions }.to_json)
145
+ end
146
+
147
+ def add_smart_group_assignment_to_app(smart_group_id, app_id)
148
+ post("mam/apps/internal/#{app_id}/smartgroups/#{smart_group_id}")
149
+ end
150
+
151
+ def remove_smart_group_asignment_from_app(smart_group_id, app_id)
152
+ delete("mam/apps/internal/#{app_id}/smartgroups/#{smart_group_id}")
153
+ end
154
+
93
155
  #############################
94
156
  # Devices #
95
157
  #############################
@@ -114,6 +176,16 @@ module Airwatch
114
176
  get('mdm/devices/profiles', params)
115
177
  end
116
178
 
179
+ def search_devices(serial_number: nil)
180
+ params = {}
181
+
182
+ unless serial_number.nil?
183
+ params[:serialnumber] = serial_number
184
+ end
185
+
186
+ get('mdm/devices', params)
187
+ end
188
+
117
189
  #############################
118
190
  # HTTP request stuff #
119
191
  #############################
@@ -143,27 +215,12 @@ module Airwatch
143
215
  puts JSON.pretty_generate(response.parsed_response)
144
216
  end
145
217
 
146
- def upload_blob(file_path, org_group_id)
147
- raise "No IPA found at path: #{file_path}" unless File.file?(file_path)
148
- filename = File.basename(file_path)
149
- url = build_url('mam/blobs/uploadblob', { filename: filename, organizationgroupid: org_group_id })
150
- payload = File.open(file_path, 'rb')
151
- headers = request_headers
152
- headers[:'Content-Type'] = 'application/octet-stream'
153
- headers[:'Expect'] = '100-continue'
154
- response = RestClient::Request.execute(
155
- :url => url,
156
- :method => :post,
157
- :headers => headers,
158
- :payload => File.open(file_path, 'rb')
159
- )
160
- end
161
-
162
218
  # private
163
219
  def request_headers
164
220
  {
165
221
  'aw-tenant-code': @api_key,
166
222
  'Accept': 'application/json',
223
+ 'Content-Type': 'application/json',
167
224
  'Authorization': @authorization
168
225
  }
169
226
  end
@@ -1,5 +1,5 @@
1
1
  module Airwatch
2
2
  module Ruby
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airwatch-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Schukin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-14 00:00:00.000000000 Z
11
+ date: 2020-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 2.7.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.1.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.1.0
83
97
  description: Ruby wrapper around AirWatch REST API.
84
98
  email:
85
99
  - daveschukin@gmail.com
@@ -107,7 +121,7 @@ homepage: https://www.github.com/observantlabs/airwatch-ruby
107
121
  licenses:
108
122
  - MIT
109
123
  metadata: {}
110
- post_install_message:
124
+ post_install_message:
111
125
  rdoc_options: []
112
126
  require_paths:
113
127
  - lib
@@ -123,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
137
  version: '0'
124
138
  requirements: []
125
139
  rubygems_version: 3.0.6
126
- signing_key:
140
+ signing_key:
127
141
  specification_version: 4
128
142
  summary: Ruby wrapper around AirWatch REST API
129
143
  test_files: []