moki_ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +2 -0
- data/lib/future_wrapper.rb +20 -0
- data/lib/moki_api.rb +117 -0
- data/lib/moki_ruby.rb +18 -0
- data/lib/moki_ruby/device_identifier.rb +9 -0
- data/lib/moki_ruby/device_managed_app.rb +20 -0
- data/lib/moki_ruby/iosprofile.rb +20 -0
- data/lib/moki_ruby/version.rb +3 -0
- data/moki_ruby.gemspec +31 -0
- data/spec/lib/device_identifier_spec.rb +19 -0
- data/spec/lib/device_managed_app_spec.rb +27 -0
- data/spec/lib/iosprofile_spec.rb +28 -0
- data/spec/lib/moki_api_spec.rb +87 -0
- data/spec/moki_ruby_spec.rb +100 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/common_stubs.rb +24 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 56759e3cd228fdbed3145ceca240cc9e1f56ff76
|
4
|
+
data.tar.gz: ba4779f759632df8cdb2152a718e9b14c7f39ef7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 465c74e207e8e012121c3c2c984cf6b61bb58c370657334abfa6e04811dfe1876d208c5fe889b38ac578fe3bb54d96882c8e12084ed2d987ffd5803faaa10fa1
|
7
|
+
data.tar.gz: a85a20ee50bfa5e2bcd0be308afd21c75b9402f0be01523b8e85ce6a611b369d52e1ab3a99c60249b361194e9cd7c8c8393e23f7e198395d8e9962ae275efcd8
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
moki_ruby (0.0.1)
|
5
|
+
celluloid
|
6
|
+
celluloid-io
|
7
|
+
faraday
|
8
|
+
faraday_middleware
|
9
|
+
hashie
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
celluloid (0.16.0)
|
15
|
+
timers (~> 4.0.0)
|
16
|
+
celluloid-io (0.16.1)
|
17
|
+
celluloid (>= 0.16.0)
|
18
|
+
nio4r (>= 1.0.0)
|
19
|
+
coderay (1.1.0)
|
20
|
+
diff-lcs (1.2.5)
|
21
|
+
faraday (0.9.1)
|
22
|
+
multipart-post (>= 1.2, < 3)
|
23
|
+
faraday_middleware (0.9.1)
|
24
|
+
faraday (>= 0.7.4, < 0.10)
|
25
|
+
hashie (3.3.2)
|
26
|
+
hitimes (1.2.2)
|
27
|
+
method_source (0.8.2)
|
28
|
+
multipart-post (2.0.0)
|
29
|
+
nio4r (1.1.0)
|
30
|
+
pry (0.10.1)
|
31
|
+
coderay (~> 1.1.0)
|
32
|
+
method_source (~> 0.8.1)
|
33
|
+
slop (~> 3.4)
|
34
|
+
rake (10.4.2)
|
35
|
+
rspec (3.2.0)
|
36
|
+
rspec-core (~> 3.2.0)
|
37
|
+
rspec-expectations (~> 3.2.0)
|
38
|
+
rspec-mocks (~> 3.2.0)
|
39
|
+
rspec-core (3.2.0)
|
40
|
+
rspec-support (~> 3.2.0)
|
41
|
+
rspec-expectations (3.2.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.2.0)
|
44
|
+
rspec-mocks (3.2.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.2.0)
|
47
|
+
rspec-support (3.2.1)
|
48
|
+
slop (3.6.0)
|
49
|
+
timers (4.0.1)
|
50
|
+
hitimes
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
bundler (~> 1.6)
|
57
|
+
moki_ruby!
|
58
|
+
pry
|
59
|
+
rake
|
60
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Trey Springer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# MokiRuby
|
2
|
+
|
3
|
+
[![travis-status](https://travis-ci.org/bellycard/moki_ruby.svg)](https://travis-ci.org/bellycard/moki_ruby)
|
4
|
+
|
5
|
+
A ruby gem for interacting with the Moki API, as a part of Moki Total
|
6
|
+
Control and Moki Management.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'moki_ruby'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install moki_ruby
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Make sure to set the following environment variables:
|
25
|
+
|
26
|
+
```
|
27
|
+
ENV['MOKI_API_URL']
|
28
|
+
ENV['MOKI_TENANT_ID']
|
29
|
+
ENV['MOKI_API_KEY']
|
30
|
+
```
|
31
|
+
|
32
|
+
The following methods have been built out:
|
33
|
+
|
34
|
+
- `MokiRuby.ios_profiles` asks for all current profiles associated with this tenant.
|
35
|
+
- `MokiRuby.device_profiles(device_id)` asks for all profiles installed
|
36
|
+
on the provided device. `device_id` must be a UDID or a serial number.
|
37
|
+
- `MokiRuby.device_managed_apps(device_id)` asks for all managed apps on
|
38
|
+
a specific device, provided in a simplified list.
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it ( https://github.com/bellycard/moki_ruby/fork )
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module FutureWrapper
|
2
|
+
def[](key)
|
3
|
+
response = value
|
4
|
+
if response[key].present?
|
5
|
+
response[key]
|
6
|
+
else
|
7
|
+
response.body[key]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def method_missing(sym, *args, &block)
|
12
|
+
response = value
|
13
|
+
if response.respond_to? sym
|
14
|
+
response.send sym, *args, &block
|
15
|
+
else
|
16
|
+
response.body.send sym, *args, &block
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/lib/moki_api.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'celluloid/io'
|
4
|
+
require 'future_wrapper'
|
5
|
+
require 'hashie'
|
6
|
+
require 'moki_ruby/device_identifier'
|
7
|
+
|
8
|
+
class MokiAPI
|
9
|
+
include Celluloid::IO
|
10
|
+
BASE_URL = '/rest/v1/api/tenants/'
|
11
|
+
|
12
|
+
def self.ios_profiles
|
13
|
+
issue_request(:get, full_url('/iosprofiles'), {})
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.device_profile_list(device_id)
|
17
|
+
if DeviceIdentifier.is_udid?(device_id)
|
18
|
+
issue_request(:get, full_url("/devices/#{ device_id }/profiles"), {})
|
19
|
+
elsif DeviceIdentifier.is_serial?(device_id)
|
20
|
+
issue_request(:get, full_url("/devices/sn-!-#{ device_id }/profiles"), {})
|
21
|
+
else
|
22
|
+
raise "Must pass a serial number or UDID to get device profile list"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.device_managed_app_list(device_id)
|
27
|
+
if DeviceIdentifier.is_udid?(device_id)
|
28
|
+
issue_request(:get, full_url("/devices/#{ device_id }/managedapps"), {})
|
29
|
+
elsif DeviceIdentifier.is_serial?(device_id)
|
30
|
+
issue_request(:get, full_url("/devices/sn-!-#{ device_id }/managedapps"), {})
|
31
|
+
else
|
32
|
+
raise "Must pass a serial number or UDID to get device profile list"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.full_url(path)
|
37
|
+
raise "No Moki URL Provided. Set ENV['MOKI_API_URL']." if ENV['MOKI_API_URL'].nil? || ENV['MOKI_API_URL'].empty?
|
38
|
+
raise "No Tenant ID Provided. Set ENV['MOKI_TENANT_ID']." if ENV['MOKI_TENANT_ID'].nil? || ENV['MOKI_TENANT_ID'].empty?
|
39
|
+
|
40
|
+
ENV['MOKI_API_URL'] + BASE_URL + ENV['MOKI_TENANT_ID'] + path
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.issue_request(method, url, options)
|
44
|
+
raise "No API Key Provided. Set ENV['MOKI_API_KEY']." if ENV['MOKI_API_KEY'].nil? || ENV['MOKI_API_KEY'].empty?
|
45
|
+
|
46
|
+
future = Celluloid::Future.new do
|
47
|
+
begin
|
48
|
+
log_request(method, url)
|
49
|
+
response = conn.send(method, url, options) do |request|
|
50
|
+
request.headers = request.headers.merge(headers)
|
51
|
+
end
|
52
|
+
to_return_type response
|
53
|
+
rescue => e
|
54
|
+
Honeybadger.notify(e, context: { method: method,
|
55
|
+
url: url,
|
56
|
+
options: options,
|
57
|
+
response_status: response.try(:status),
|
58
|
+
response_body: response.try(:body) }) if defined?(Honeybadger)
|
59
|
+
raise e
|
60
|
+
end
|
61
|
+
end
|
62
|
+
future.extend(FutureWrapper)
|
63
|
+
end
|
64
|
+
|
65
|
+
def issue_request(method, url, options)
|
66
|
+
self.class.issue_request(method, url, options)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def self.to_return_type response
|
71
|
+
begin
|
72
|
+
Hashie::Mash.new({
|
73
|
+
body: JSON.parse(response.body),
|
74
|
+
status: response.status,
|
75
|
+
headers: response.headers
|
76
|
+
})
|
77
|
+
rescue => e
|
78
|
+
response
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.conn
|
83
|
+
connection = Faraday.new do |conn|
|
84
|
+
conn.request :json
|
85
|
+
conn.adapter Faraday.default_adapter
|
86
|
+
end
|
87
|
+
connection
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.headers
|
91
|
+
{
|
92
|
+
"X-Moki-TenantAPIToken" => ENV['MOKI_API_KEY']
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.log_request(method, url)
|
97
|
+
logger = if defined?(Rails)
|
98
|
+
Rails.logger
|
99
|
+
elsif defined?(Napa::Logger)
|
100
|
+
Napa::Logger.logger
|
101
|
+
else
|
102
|
+
nil
|
103
|
+
end
|
104
|
+
|
105
|
+
return unless logger
|
106
|
+
|
107
|
+
data = { moki_api_request:
|
108
|
+
{
|
109
|
+
message: "Calling Moki API URL #{ url }",
|
110
|
+
request_method: method,
|
111
|
+
request_url: url,
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
logger.info(data.as_json)
|
116
|
+
end
|
117
|
+
end
|
data/lib/moki_ruby.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "moki_ruby/version"
|
2
|
+
|
3
|
+
module MokiRuby
|
4
|
+
def self.ios_profiles
|
5
|
+
data = MokiAPI.ios_profiles.value
|
6
|
+
data.body.map { |profile| IOSProfile.from_hash(profile) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.device_profiles(device_id)
|
10
|
+
data = MokiAPI.device_profile_list(device_id).value
|
11
|
+
data.body.map { |profile| IOSProfile.from_hash(profile) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.device_managed_apps(device_id)
|
15
|
+
data = MokiAPI.device_managed_app_list(device_id).value
|
16
|
+
data.body.map { |app| DeviceManagedApp.from_hash(app) }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class DeviceManagedApp
|
2
|
+
attr_accessor :status, :app_identifier, :management_flags
|
3
|
+
|
4
|
+
def self.from_hash(input_hash)
|
5
|
+
new_profile = self.new
|
6
|
+
new_profile.status = input_hash['Status']
|
7
|
+
new_profile.app_identifier = input_hash['appIdentifier']
|
8
|
+
new_profile.management_flags = input_hash['ManagementFlags']
|
9
|
+
|
10
|
+
new_profile
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_hash
|
14
|
+
{
|
15
|
+
"Status" => self.status,
|
16
|
+
"appIdentifier" => self.app_identifier,
|
17
|
+
"ManagementFlags" => self.management_flags
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class IOSProfile
|
2
|
+
attr_accessor :id, :lastSeen, :name, :displayName, :description, :identifier
|
3
|
+
|
4
|
+
def self.from_hash(input_hash)
|
5
|
+
new_profile = self.new
|
6
|
+
%w(id lastSeen name displayName description identifier).each do |attr|
|
7
|
+
new_profile.send("#{ attr }=", input_hash[attr])
|
8
|
+
end
|
9
|
+
|
10
|
+
new_profile
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_hash
|
14
|
+
{}.tap do |hash|
|
15
|
+
self.instance_variables.each do |var|
|
16
|
+
hash[var.to_s.delete("@")] = instance_variable_get(var)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/moki_ruby.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'moki_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "moki_ruby"
|
8
|
+
spec.version = MokiRuby::VERSION
|
9
|
+
spec.authors = ["Trey Springer"]
|
10
|
+
spec.email = ["tspringer@bellycard.com"]
|
11
|
+
spec.summary = %q{A gem for interacting with the Moki Total Control API.}
|
12
|
+
spec.description = %q{Manage your MDM-controlled devices with Moki and the moki_ruby gem.}
|
13
|
+
spec.homepage = "https://www.github.com/bellycard/moki_ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'faraday'
|
22
|
+
spec.add_dependency 'faraday_middleware'
|
23
|
+
spec.add_dependency 'celluloid'
|
24
|
+
spec.add_dependency 'celluloid-io'
|
25
|
+
spec.add_dependency 'hashie'
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "pry"
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'moki_ruby/device_identifier'
|
3
|
+
|
4
|
+
describe DeviceIdentifier do
|
5
|
+
it "picks out a serial number as a 12-character string" do
|
6
|
+
expect(DeviceIdentifier.is_serial?("ABC123DEF456")).to eq(true)
|
7
|
+
expect(DeviceIdentifier.is_serial?("123456789012")).to eq(true)
|
8
|
+
expect(DeviceIdentifier.is_serial?("F55VM3KK9G5F")).to eq(true)
|
9
|
+
expect(DeviceIdentifier.is_serial?("ABC123DE56")).to eq(false)
|
10
|
+
expect(DeviceIdentifier.is_serial?("123456789012123")).to eq(false)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "identifies a UDID" do
|
14
|
+
expect(DeviceIdentifier.is_udid?("ABC123DEF456")).to eq(false)
|
15
|
+
expect(DeviceIdentifier.is_udid?("abc12345-de12-abd5-7777-abcdefghijkl")).to eq(false)
|
16
|
+
expect(DeviceIdentifier.is_udid?("abc12345-de12-abd5-1234-abcdef123456")).to eq(true)
|
17
|
+
expect(DeviceIdentifier.is_udid?("abc1235-def125-hjm-erm")).to eq(false)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'moki_ruby/device_managed_app'
|
3
|
+
|
4
|
+
describe DeviceManagedApp do
|
5
|
+
let(:response_hash) { { "Status" => "Managed",
|
6
|
+
"appIdentifier" => "com.belly.gem.moki.enterprise",
|
7
|
+
"ManagementFlags" => 0 } }
|
8
|
+
|
9
|
+
let(:attrs) { %w(Status appIdentifier ManagementFlags) }
|
10
|
+
|
11
|
+
it "will load from a hash with string keys" do
|
12
|
+
profile = DeviceManagedApp.from_hash(response_hash)
|
13
|
+
expect(profile.status).to eq(response_hash["Status"])
|
14
|
+
expect(profile.app_identifier).to eq(response_hash["appIdentifier"])
|
15
|
+
expect(profile.management_flags).to eq(response_hash["ManagementFlags"])
|
16
|
+
end
|
17
|
+
|
18
|
+
it "will convert the response to a hash" do
|
19
|
+
profile = DeviceManagedApp.new
|
20
|
+
attrs.each do |attribute|
|
21
|
+
profile.status = "Managed"
|
22
|
+
profile.app_identifier = "com.belly.gem.moki.enterprise"
|
23
|
+
profile.management_flags = 0
|
24
|
+
end
|
25
|
+
expect(profile.to_hash).to eq(response_hash)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'moki_ruby/iosprofile'
|
3
|
+
|
4
|
+
describe IOSProfile do
|
5
|
+
let(:response_hash) { { "id" => "01234699-5767-8abc-d123-ffffffffffff",
|
6
|
+
"lastSeen" => 1413913980475,
|
7
|
+
"name" => "Profile Name",
|
8
|
+
"displayName" => "Profile Display Name",
|
9
|
+
"description" => "Profile Description",
|
10
|
+
"identifier" => "abcdef12345-abc-123-ffeea.test" } }
|
11
|
+
|
12
|
+
let(:attrs) { %w(id lastSeen name displayName description identifier) }
|
13
|
+
|
14
|
+
it "will load from a hash with string keys" do
|
15
|
+
profile = IOSProfile.from_hash(response_hash)
|
16
|
+
attrs.each do |attribute|
|
17
|
+
expect(profile.send(attribute)).to eq(response_hash[attribute])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it "will convert the response to a hash" do
|
22
|
+
profile = IOSProfile.new
|
23
|
+
attrs.each do |attribute|
|
24
|
+
profile.send("#{ attribute }=", response_hash[attribute])
|
25
|
+
end
|
26
|
+
expect(profile.to_hash).to eq(response_hash)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'moki_api'
|
3
|
+
|
4
|
+
describe MokiAPI do
|
5
|
+
describe "missing env variable" do
|
6
|
+
it "MOKI_API_URL raises an error" do
|
7
|
+
ENV['MOKI_API_URL'] = ''
|
8
|
+
ENV['MOKI_TENANT_ID'] = 'abcd123-test'
|
9
|
+
ENV['MOKI_API_KEY'] = 'secret-key'
|
10
|
+
expect { MokiAPI.full_url("/test") }.to raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "MOKI_TENANT_ID raises an error" do
|
14
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
15
|
+
ENV['MOKI_TENANT_ID'] = ''
|
16
|
+
ENV['MOKI_API_KEY'] = 'secret-key'
|
17
|
+
expect { MokiAPI.full_url("/test") }.to raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
it "MOKI_API_KEY raises an error" do
|
21
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
22
|
+
ENV['MOKI_TENANT_ID'] = 'abcd123-test'
|
23
|
+
ENV['MOKI_API_KEY'] = ''
|
24
|
+
expect { MokiAPI.issue_request(:get, "/test", {}) }.to raise_error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "with all environment variables set" do
|
29
|
+
before do
|
30
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
31
|
+
ENV['MOKI_TENANT_ID'] = 'abcd123-test'
|
32
|
+
ENV['MOKI_API_KEY'] = 'secret-key'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'hits the iosprofiles endpoint correctly' do
|
36
|
+
expect(MokiAPI).to receive(:issue_request) { |method, url, options|
|
37
|
+
expect(method).to eq(:get)
|
38
|
+
expect(url).to eq("http://localhost:9292/rest/v1/api/tenants/#{ ENV['MOKI_TENANT_ID'] }/iosprofiles")
|
39
|
+
}.and_return('{}')
|
40
|
+
MokiAPI.ios_profiles
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "device profile list" do
|
44
|
+
it 'hits the endpoint correctly with a UDID' do
|
45
|
+
expect(MokiAPI).to receive(:issue_request) { |method, url, options|
|
46
|
+
expect(method).to eq(:get)
|
47
|
+
expect(url).to eq("http://localhost:9292/rest/v1/api/tenants/#{ ENV['MOKI_TENANT_ID'] }/devices/abcd1234-1234-1234-1234-abcdef123456/profiles")
|
48
|
+
}.and_return('{}')
|
49
|
+
MokiAPI.device_profile_list("abcd1234-1234-1234-1234-abcdef123456")
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'hits the endpoint correctly with a serial number' do
|
53
|
+
expect(MokiAPI).to receive(:issue_request) { |method, url, options|
|
54
|
+
expect(method).to eq(:get)
|
55
|
+
expect(url).to eq("http://localhost:9292/rest/v1/api/tenants/#{ ENV['MOKI_TENANT_ID'] }/devices/sn-!-ABCDEFGHIJ12/profiles")
|
56
|
+
}.and_return('{}')
|
57
|
+
MokiAPI.device_profile_list("ABCDEFGHIJ12")
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'raises an error if not given a serial or udid' do
|
61
|
+
expect { MokiAPI.device_profile_list("ermishness-nope") }.to raise_error
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "device managed app list" do
|
66
|
+
it 'hits the endpoint correctly with a UDID' do
|
67
|
+
expect(MokiAPI).to receive(:issue_request) { |method, url, options|
|
68
|
+
expect(method).to eq(:get)
|
69
|
+
expect(url).to eq("http://localhost:9292/rest/v1/api/tenants/#{ ENV['MOKI_TENANT_ID'] }/devices/abcd1234-1234-1234-1234-abcdef123456/managedapps")
|
70
|
+
}.and_return('{}')
|
71
|
+
MokiAPI.device_managed_app_list("abcd1234-1234-1234-1234-abcdef123456")
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'hits the endpoint correctly with a serial number' do
|
75
|
+
expect(MokiAPI).to receive(:issue_request) { |method, url, options|
|
76
|
+
expect(method).to eq(:get)
|
77
|
+
expect(url).to eq("http://localhost:9292/rest/v1/api/tenants/#{ ENV['MOKI_TENANT_ID'] }/devices/sn-!-ABCDEFGHIJ12/managedapps")
|
78
|
+
}.and_return('{}')
|
79
|
+
MokiAPI.device_managed_app_list("ABCDEFGHIJ12")
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'raises an error if not given a serial or udid' do
|
83
|
+
expect { MokiAPI.device_managed_app_list("ermishness-nope") }.to raise_error
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'support/common_stubs'
|
3
|
+
|
4
|
+
describe MokiRuby do
|
5
|
+
describe ".iosprofiles" do
|
6
|
+
it "raises an error if no tenant ID is provided" do
|
7
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
8
|
+
ENV['MOKI_TENANT_ID'] = ''
|
9
|
+
ENV['MOKI_API_KEY'] = 'secret-key'
|
10
|
+
|
11
|
+
expect { MokiRuby.iosprofiles }.to raise_error
|
12
|
+
end
|
13
|
+
|
14
|
+
it "raises an error if no API key is provided" do
|
15
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
16
|
+
ENV['MOKI_TENANT_ID'] = 'abcd123-test'
|
17
|
+
ENV['MOKI_API_KEY'] = ''
|
18
|
+
|
19
|
+
expect { MokiRuby.iosprofiles }.to raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it "retuns an array of IOSProfile objects" do
|
23
|
+
load_good_stubs
|
24
|
+
data = MokiRuby.ios_profiles
|
25
|
+
expect(data.count).to eq(4)
|
26
|
+
expect(data.first).to be_kind_of(IOSProfile)
|
27
|
+
expect(data.first.name).to eq("Test Profile 1")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".device_profiles" do
|
32
|
+
it "raises an error if no tenant ID is provided" do
|
33
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
34
|
+
ENV['MOKI_TENANT_ID'] = ''
|
35
|
+
ENV['MOKI_API_KEY'] = 'secret-key'
|
36
|
+
|
37
|
+
expect { MokiRuby.device_profiles('ABC123DEF456') }.to raise_error
|
38
|
+
end
|
39
|
+
|
40
|
+
it "raises an error if no API key is provided" do
|
41
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
42
|
+
ENV['MOKI_TENANT_ID'] = 'abcd123-test'
|
43
|
+
ENV['MOKI_API_KEY'] = ''
|
44
|
+
|
45
|
+
expect { MokiRuby.device_profiles('ABC123DEF456') }.to raise_error
|
46
|
+
end
|
47
|
+
|
48
|
+
it "raises an error if the device id is bad" do
|
49
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
50
|
+
ENV['MOKI_TENANT_ID'] = 'abcd123-test'
|
51
|
+
ENV['MOKI_API_KEY'] = 'secret-key'
|
52
|
+
|
53
|
+
expect(MokiAPI).to_not receive(:issue_request)
|
54
|
+
expect { MokiRuby.device_profiles('BADSERIAL') }.to raise_error
|
55
|
+
end
|
56
|
+
|
57
|
+
it "retuns an array of IOSProfile objects" do
|
58
|
+
load_good_stubs
|
59
|
+
data = MokiRuby.device_profiles('ABC123DEF456')
|
60
|
+
expect(data.count).to eq(4)
|
61
|
+
expect(data.first).to be_kind_of(IOSProfile)
|
62
|
+
expect(data.first.name).to eq("Test Profile 1")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe ".device_managed_apps" do
|
67
|
+
it "raises an error if no tenant ID is provided" do
|
68
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
69
|
+
ENV['MOKI_TENANT_ID'] = ''
|
70
|
+
ENV['MOKI_API_KEY'] = 'secret-key'
|
71
|
+
|
72
|
+
expect { MokiRuby.device_managed_apps('ABC123DEF456') }.to raise_error
|
73
|
+
end
|
74
|
+
|
75
|
+
it "raises an error if no API key is provided" do
|
76
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
77
|
+
ENV['MOKI_TENANT_ID'] = 'abcd123-test'
|
78
|
+
ENV['MOKI_API_KEY'] = ''
|
79
|
+
|
80
|
+
expect { MokiRuby.device_managed_apps('ABC123DEF456') }.to raise_error
|
81
|
+
end
|
82
|
+
|
83
|
+
it "raises an error if the device id is bad" do
|
84
|
+
ENV['MOKI_API_URL'] = 'http://localhost:9292'
|
85
|
+
ENV['MOKI_TENANT_ID'] = 'abcd123-test'
|
86
|
+
ENV['MOKI_API_KEY'] = 'secret-key'
|
87
|
+
|
88
|
+
expect(MokiAPI).to_not receive(:issue_request)
|
89
|
+
expect { MokiRuby.device_managed_apps('BADSERIAL') }.to raise_error
|
90
|
+
end
|
91
|
+
|
92
|
+
it "retuns an array of IOSProfile objects" do
|
93
|
+
load_good_stubs
|
94
|
+
data = MokiRuby.device_managed_apps('ABC123456DEF')
|
95
|
+
expect(data.count).to eq(2)
|
96
|
+
expect(data.first).to be_kind_of(DeviceManagedApp)
|
97
|
+
expect(data.first.status).to eq("Managed")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'moki_ruby'
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.expect_with :rspec do |expectations|
|
6
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
7
|
+
end
|
8
|
+
|
9
|
+
config.mock_with :rspec do |mocks|
|
10
|
+
mocks.verify_partial_doubles = true
|
11
|
+
end
|
12
|
+
|
13
|
+
config.warnings = true
|
14
|
+
|
15
|
+
if config.files_to_run.one?
|
16
|
+
config.default_formatter = 'doc'
|
17
|
+
end
|
18
|
+
|
19
|
+
config.order = :random
|
20
|
+
Kernel.srand config.seed
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
def load_good_stubs
|
2
|
+
@iosprofiles_stub_response = [{"id"=>"093b57ba-face-0100-4321-abcdef123456", "lastSeen"=>1413913980475, "name"=>"Test Profile 1", "displayName"=>"Test Profile 1", "description"=>"Test Profile 1", "identifier"=>"com.belly.a9a4129f-other01.TestProfile1"},
|
3
|
+
{"id"=>"4023fb77-face-0200-4321-abcdef123456", "lastSeen"=>1423528420218, "name"=>"Custom Profile", "displayName"=>"Custom Profile", "description"=>"Custom Profile", "identifier"=>nil},
|
4
|
+
{"id"=>"462d3468-face-0300-4321-abcdef123456", "lastSeen"=>1415637997309, "name"=>"Test Profile 3", "displayName"=>"Test Profile 3", "description"=>"Test Profile 3", "identifier"=>"com.belly.1e968fa0-other03.TestProfile3"},
|
5
|
+
{"id"=>"fcd2bfb0-face-0400-4321-abcdef123456", "lastSeen"=>1423524426266, "name"=>"Test Profile 4", "displayName"=>"Test Profile 4", "description"=>"Test Profile 4", "identifier"=>"com.belly.1e968fa0-other04.TestProfile4"}]
|
6
|
+
|
7
|
+
@device_managed_app_stub_response = [{ "Status" => "Managed", "appIdentifier" => "com.belly.moki.gem.enterprise", "ManagementFlags" => 1 },
|
8
|
+
{ "Status" => "Managed", "appIdentifier" => "com.belly.flop.html.enterprise", "ManagementFlags" => 0 }]
|
9
|
+
|
10
|
+
allow(MokiAPI).to receive_message_chain(:ios_profiles, :value).
|
11
|
+
and_return(Hashie::Mash.new({ body: @iosprofiles_stub_response,
|
12
|
+
status: 200,
|
13
|
+
headers: {}}))
|
14
|
+
|
15
|
+
allow(MokiAPI).to receive_message_chain(:device_profile_list, :value).
|
16
|
+
and_return(Hashie::Mash.new({ body: @iosprofiles_stub_response,
|
17
|
+
status: 200,
|
18
|
+
headers: {}}))
|
19
|
+
|
20
|
+
allow(MokiAPI).to receive_message_chain(:device_managed_app_list, :value).
|
21
|
+
and_return(Hashie::Mash.new({ body: @device_managed_app_stub_response,
|
22
|
+
status: 200,
|
23
|
+
headers: {}}))
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: moki_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Trey Springer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: celluloid
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: celluloid-io
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hashie
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Manage your MDM-controlled devices with Moki and the moki_ruby gem.
|
140
|
+
email:
|
141
|
+
- tspringer@bellycard.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- .gitignore
|
147
|
+
- .rspec
|
148
|
+
- .travis.yml
|
149
|
+
- Gemfile
|
150
|
+
- Gemfile.lock
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- lib/future_wrapper.rb
|
155
|
+
- lib/moki_api.rb
|
156
|
+
- lib/moki_ruby.rb
|
157
|
+
- lib/moki_ruby/device_identifier.rb
|
158
|
+
- lib/moki_ruby/device_managed_app.rb
|
159
|
+
- lib/moki_ruby/iosprofile.rb
|
160
|
+
- lib/moki_ruby/version.rb
|
161
|
+
- moki_ruby.gemspec
|
162
|
+
- spec/lib/device_identifier_spec.rb
|
163
|
+
- spec/lib/device_managed_app_spec.rb
|
164
|
+
- spec/lib/iosprofile_spec.rb
|
165
|
+
- spec/lib/moki_api_spec.rb
|
166
|
+
- spec/moki_ruby_spec.rb
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
- spec/support/common_stubs.rb
|
169
|
+
homepage: https://www.github.com/bellycard/moki_ruby
|
170
|
+
licenses:
|
171
|
+
- MIT
|
172
|
+
metadata: {}
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options: []
|
175
|
+
require_paths:
|
176
|
+
- lib
|
177
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - '>='
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
requirements: []
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 2.2.2
|
190
|
+
signing_key:
|
191
|
+
specification_version: 4
|
192
|
+
summary: A gem for interacting with the Moki Total Control API.
|
193
|
+
test_files:
|
194
|
+
- spec/lib/device_identifier_spec.rb
|
195
|
+
- spec/lib/device_managed_app_spec.rb
|
196
|
+
- spec/lib/iosprofile_spec.rb
|
197
|
+
- spec/lib/moki_api_spec.rb
|
198
|
+
- spec/moki_ruby_spec.rb
|
199
|
+
- spec/spec_helper.rb
|
200
|
+
- spec/support/common_stubs.rb
|