airwatch-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 775aafdbb0a361df1e1dc3bc638216df732dfd2480df69aeb8ec1c857ab66478
4
+ data.tar.gz: 02fd6ebbfe64d3f5d46af4ba35ac3f00e8130c9ff767a3af39320b2ac0dd94a5
5
+ SHA512:
6
+ metadata.gz: f995fd58984c6075c09d8329b38fb670b37101b623d0ca3b6131f6fcf7f07d924b906559b56ac06f64beb8faeec5a2d5c2be12229d5e2a2ef62dd88f47dada1a
7
+ data.tar.gz: f23677fb66ca59e8da832a07ab4b5225f96b5dc391cebd08800a4091935c671eb1ea8e9183ea035410d7293241f52279e341a1cf523a5ebe8562401575209ea9
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at daveschukin@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in airwatch-ruby.gemspec
6
+ gemspec
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ airwatch-ruby (0.1.0)
5
+ addressable (~> 2.7.0)
6
+ httparty (~> 0.18)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ diff-lcs (1.4.4)
14
+ httparty (0.18.1)
15
+ mime-types (~> 3.0)
16
+ multi_xml (>= 0.5.2)
17
+ io-console (0.5.6)
18
+ irb (1.2.4)
19
+ reline (>= 0.0.1)
20
+ mime-types (3.3.1)
21
+ mime-types-data (~> 3.2015)
22
+ mime-types-data (3.2020.0512)
23
+ multi_xml (0.6.0)
24
+ public_suffix (4.0.5)
25
+ rake (10.5.0)
26
+ reline (0.1.4)
27
+ io-console (~> 0.5)
28
+ rspec (3.9.0)
29
+ rspec-core (~> 3.9.0)
30
+ rspec-expectations (~> 3.9.0)
31
+ rspec-mocks (~> 3.9.0)
32
+ rspec-core (3.9.2)
33
+ rspec-support (~> 3.9.3)
34
+ rspec-expectations (3.9.2)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.9.0)
37
+ rspec-mocks (3.9.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.9.0)
40
+ rspec-support (3.9.3)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ airwatch-ruby!
47
+ bundler (~> 1.17)
48
+ irb
49
+ rake (~> 10.0)
50
+ rspec (~> 3.0)
51
+
52
+ BUNDLED WITH
53
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Observant
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # airwatch-ruby
2
+
3
+ TODO: make a readme
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "airwatch/ruby/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "airwatch-ruby"
8
+ spec.version = Airwatch::Ruby::VERSION
9
+ spec.authors = ["Dave Schukin"]
10
+ spec.email = ["daveschukin@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper around AirWatch REST API}
13
+ spec.description = %q{Ruby wrapper around AirWatch REST API.}
14
+ spec.homepage = "https://www.github.com/observantlabs/airwatch-ruby"
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
+
22
+ # spec.metadata["homepage_uri"] = spec.homepage
23
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
24
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
+ # else
26
+ # raise "RubyGems 2.0 or newer is required to protect against " \
27
+ # "public gem pushes."
28
+ # end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.17"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ spec.add_runtime_dependency 'httparty', '~> 0.18'
43
+ spec.add_runtime_dependency 'addressable', '~> 2.7.0'
44
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "airwatch/ruby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ require 'airwatch/client'
2
+
3
+ module Airwatch
4
+ end
@@ -0,0 +1,178 @@
1
+ module Airwatch
2
+ class Client
3
+ # @param [String] host make sure you get this from Settings > System > Advanced > Site URLs
4
+ def initialize(host_name, api_key, email: nil, password: nil, authorization: nil)
5
+ @host_name = host_name
6
+ @api_key = api_key
7
+
8
+ if email && password
9
+ @authorization = "Basic #{Base64.strict_encode64("#{email}:#{password}")}"
10
+ elsif authorization
11
+ @authorization = authorization
12
+ else
13
+ raise 'must provide (email & password) or authorization'
14
+ end
15
+ end
16
+
17
+ #############################
18
+ # Apps #
19
+ #############################
20
+
21
+ # @param [String] (optional) bundleid the app's bundle identifier, or nil
22
+ # @param [String] (optional) type 'app' or nill
23
+ # @param [String] (optional) applicationtype 'internal' or nil
24
+ def apps_search(**args)
25
+ params = args.to_h
26
+ get('mam/apps/search', params)
27
+ end
28
+
29
+ # returns a list of device IDs that the app is installed on
30
+ def app_devices(app_id)
31
+ get("mam/apps/internal/#{app_id}/devices")
32
+ end
33
+
34
+ def install_internal_app(app_id, device_id)
35
+ post("mam/apps/internal/#{app_id}/install", { deviceid: device_id })
36
+ end
37
+
38
+ #############################
39
+ # Profiles #
40
+ #############################
41
+
42
+ # @see page 722 of AirWatch REST API docs
43
+ def profiles_platforms_apple_create
44
+ end
45
+
46
+ # @see page 1034 of AirWatch REST API docs
47
+ # @param [String] profile_id the AirWatch profile ID
48
+ # @param [Integer] device_id the AirWatch device ID
49
+ #
50
+ # This method is idempotent.
51
+ def profiles_install(profile_id, device_id: nil, serial_number: nil)
52
+ params = {}
53
+
54
+ unless device_id.nil?
55
+ params[:deviceid] = device_id
56
+ end
57
+
58
+ unless serial_number.nil?
59
+ params[:serialnumber] = serial_number
60
+ end
61
+
62
+ post("mdm/profiles/#{profile_id}/install", params)
63
+ end
64
+
65
+ # @see page 1034 of AirWatch REST API docs
66
+ # @param [String] profile_id the AirWatch profile ID
67
+ # @param [Integer] device_id the AirWatch device ID
68
+ #
69
+ # This method is NOT idempotent; after the first successful call, subsequent calls will return HTTP 400.
70
+ def profiles_remove(profile_id, device_id)
71
+ post("mdm/profiles/#{profile_id}/remove", { deviceid: device_id })
72
+ end
73
+
74
+ #############################
75
+ # Smart groups #
76
+ #############################
77
+
78
+ def smart_groups_search
79
+ get('mdm/smartgroups/search')
80
+ end
81
+
82
+ # @see page 1173 of AirWatch REST API docs
83
+ #
84
+ # returns the list of apps assigned to Smart Group.
85
+ def smart_group_apps(smart_group_id)
86
+ get("mdm/smartgroups/#{smart_group_id}/apps")
87
+ end
88
+
89
+ def smart_group_details(smart_group_id)
90
+ get("mdm/smartgroups/#{smart_group_id}")
91
+ end
92
+
93
+ #############################
94
+ # Devices #
95
+ #############################
96
+
97
+ def device_details(device_id)
98
+ get("mdm/devices/#{device_id}")
99
+ end
100
+
101
+ def device_profile_details(device_id: nil, serial_number: nil)
102
+ params = {}
103
+
104
+ unless device_id.nil?
105
+ params[:searchby] = 'deviceid'
106
+ params[:id] = device_id
107
+ end
108
+
109
+ unless serial_number.nil?
110
+ params[:searchby] = 'serialnumber'
111
+ params[:id] = serial_number
112
+ end
113
+
114
+ get('mdm/devices/profiles', params)
115
+ end
116
+
117
+ #############################
118
+ # HTTP request stuff #
119
+ #############################
120
+
121
+ def get(resource, params = {})
122
+ url = build_url(resource, params)
123
+ HTTParty.get(url, { headers: request_headers })
124
+ end
125
+
126
+ def put(resource, params = {})
127
+ url = build_url(resource)
128
+ HTTParty.put(url, { headers: request_headers, body: params })
129
+ end
130
+
131
+ def post(resource, params = {})
132
+ url = build_url(resource)
133
+ HTTParty.post(url, { headers: request_headers, body: params })
134
+ end
135
+
136
+ def pretty_get(resource, params = {})
137
+ response = get(resource, params)
138
+ unless response.code == 200
139
+ puts response
140
+ puts "⚠️ HTTP #{response.code}"
141
+ return
142
+ end
143
+ puts JSON.pretty_generate(response.parsed_response)
144
+ end
145
+
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
+ # private
163
+ def request_headers
164
+ {
165
+ 'aw-tenant-code': @api_key,
166
+ 'Accept': 'application/json',
167
+ 'Authorization': @authorization
168
+ }
169
+ end
170
+
171
+ def build_url(resource, query_params = nil)
172
+ url = "https://#{@host_name}/api/#{resource}"
173
+ return url if query_params.nil?
174
+ template = Addressable::Template.new("#{url}{?query*}")
175
+ template.expand(query: query_params).to_s
176
+ end
177
+ end
178
+ end
@@ -0,0 +1,8 @@
1
+ require "airwatch/ruby/version"
2
+
3
+ module Airwatch
4
+ module Ruby
5
+ class Error < StandardError; end
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Airwatch
2
+ module Ruby
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: airwatch-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Schukin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.18'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.18'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.7.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.7.0
83
+ description: Ruby wrapper around AirWatch REST API.
84
+ email:
85
+ - daveschukin@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - airwatch-ruby.gemspec
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/airwatch.rb
103
+ - lib/airwatch/client.rb
104
+ - lib/airwatch/ruby.rb
105
+ - lib/airwatch/ruby/version.rb
106
+ homepage: https://www.github.com/observantlabs/airwatch-ruby
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubygems_version: 3.0.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Ruby wrapper around AirWatch REST API
129
+ test_files: []