moki_ruby 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -3
- data/lib/moki_ruby/device.rb +27 -1
- data/lib/moki_ruby/moki_api.rb +4 -0
- data/lib/moki_ruby/version.rb +1 -1
- data/spec/lib/device_spec.rb +59 -0
- data/spec/lib/moki_api_spec.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d18fa9f0208d979d58737d1e2b635d8cbb32114f
|
4
|
+
data.tar.gz: 666eb49b7a30e14fc61a307afa51830b3c5a9279
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac00d27b093c5339c995ff8284314de1f73f8c25e5d95186d9f666775dad020e78c68c7dea48ec7f86c459cfed0ff2f106191e4ead220960508537448db9fe0e
|
7
|
+
data.tar.gz: aaa2653f1443864249871a5bb2a1ef3caa49809a3335230fbe2db0d23adb5423a755d0e4c076d027b33dc5f062fe3e24df225e91fd882ac26c9e6ebe33982f4a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -68,14 +68,18 @@ Using this device, there are several methods available:
|
|
68
68
|
object, for tracking in the future.
|
69
69
|
- `device.get_action(action_id)` will take in an `id` from an `Action`
|
70
70
|
object, and return an updated `Action` object.
|
71
|
+
- `device.pre_enroll` will send the serial number, `client_id`, and `token`
|
72
|
+
from the device for pre-enrollment, and will return `true` if
|
73
|
+
successful. If `client_id` or `token` are missing, both will be sent
|
74
|
+
as `nil`.
|
75
|
+
|
76
|
+
Note that if the device is not found, each method will return `nil`
|
77
|
+
instead of an object.
|
71
78
|
|
72
79
|
## To do
|
73
80
|
|
74
|
-
- Handle cases where device is not found
|
75
|
-
- Handle error cases
|
76
81
|
- Confirm if profile is on device before adding/removing
|
77
82
|
- Confirm if app is on device before installing
|
78
|
-
- Add new Moki endpoints
|
79
83
|
|
80
84
|
## Special Thanks
|
81
85
|
|
data/lib/moki_ruby/device.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module MokiRuby
|
2
2
|
class Device
|
3
|
+
attr_accessor :client_id, :token
|
3
4
|
attr :id, :identifier_type
|
4
5
|
|
5
6
|
def initialize(identifier)
|
@@ -61,6 +62,16 @@ module MokiRuby
|
|
61
62
|
Action.from_hash(data.body)
|
62
63
|
end
|
63
64
|
|
65
|
+
def pre_enroll
|
66
|
+
data = MokiAPI.pre_enroll(enroll_hash).value
|
67
|
+
|
68
|
+
if data.status == 200
|
69
|
+
return true
|
70
|
+
else
|
71
|
+
return nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
64
75
|
def device_id_param
|
65
76
|
if identifier_type == :serial
|
66
77
|
"sn-!-#{ id }"
|
@@ -69,7 +80,7 @@ module MokiRuby
|
|
69
80
|
end
|
70
81
|
end
|
71
82
|
|
72
|
-
|
83
|
+
private
|
73
84
|
|
74
85
|
def is_serial?(id)
|
75
86
|
(!id.nil? && id.length == 12)
|
@@ -78,5 +89,20 @@ module MokiRuby
|
|
78
89
|
def is_udid?(id)
|
79
90
|
!(/\A[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\Z/.match(id)).nil?
|
80
91
|
end
|
92
|
+
|
93
|
+
def enroll_hash
|
94
|
+
raise "Need Serial Number on Device for Enrollment" unless ((identifier_type == :serial) && !id.nil?)
|
95
|
+
|
96
|
+
hash = { "serialNumber" => id,
|
97
|
+
"clientCode" => nil,
|
98
|
+
"token" => nil }
|
99
|
+
|
100
|
+
unless token.nil? || token == "" || client_id.nil? || client_id == ""
|
101
|
+
hash = hash.merge({ "clientCode" => client_id.to_s,
|
102
|
+
"token" => token })
|
103
|
+
end
|
104
|
+
|
105
|
+
return hash
|
106
|
+
end
|
81
107
|
end
|
82
108
|
end
|
data/lib/moki_ruby/moki_api.rb
CHANGED
@@ -33,6 +33,10 @@ module MokiRuby
|
|
33
33
|
issue_request(:get, full_url("/devices/#{ device_id }/actions/#{ action_id }"), {})
|
34
34
|
end
|
35
35
|
|
36
|
+
def self.pre_enroll(enroll_hash)
|
37
|
+
issue_request(:post, full_url("/preenroll"), enroll_hash)
|
38
|
+
end
|
39
|
+
|
36
40
|
def self.full_url(path)
|
37
41
|
raise "No Moki URL Provided. Set ENV['MOKI_API_URL']." if ENV['MOKI_API_URL'].nil? || ENV['MOKI_API_URL'].empty?
|
38
42
|
raise "No Tenant ID Provided. Set ENV['MOKI_TENANT_ID']." if ENV['MOKI_TENANT_ID'].nil? || ENV['MOKI_TENANT_ID'].empty?
|
data/lib/moki_ruby/version.rb
CHANGED
data/spec/lib/device_spec.rb
CHANGED
@@ -172,4 +172,63 @@ describe MokiRuby::Device do
|
|
172
172
|
expect(device.get_action(action_id)).to be_nil
|
173
173
|
end
|
174
174
|
end
|
175
|
+
|
176
|
+
describe "#pre_enroll" do
|
177
|
+
it "sends the serial number number along with the specific client id and token" do
|
178
|
+
device = MokiRuby::Device.new(sn)
|
179
|
+
device.client_id = 12944
|
180
|
+
device.token = "c12944-token"
|
181
|
+
|
182
|
+
expected_hash = { "clientCode" => "12944",
|
183
|
+
"serialNumber" => sn,
|
184
|
+
"token" => "c12944-token" }
|
185
|
+
|
186
|
+
expect(MokiAPI).to receive(:pre_enroll).with(expected_hash)
|
187
|
+
.and_return(Hashie::Mash.new(value: { body: @action_stub_response }))
|
188
|
+
device.pre_enroll
|
189
|
+
end
|
190
|
+
|
191
|
+
it "will error if does not have a serial number" do
|
192
|
+
expect {device.pre_enroll}.to raise_error
|
193
|
+
end
|
194
|
+
|
195
|
+
it "will send blank values for client ID and token if both are missing" do
|
196
|
+
device = MokiRuby::Device.new(sn)
|
197
|
+
expect(MokiAPI).to receive(:pre_enroll).with({ "clientCode" => nil, "serialNumber" => sn, "token" => nil })
|
198
|
+
.and_return(Hashie::Mash.new(value: { body: nil }))
|
199
|
+
device.pre_enroll
|
200
|
+
end
|
201
|
+
|
202
|
+
it "will send blank values for both client ID and token if client id is missing" do
|
203
|
+
device = MokiRuby::Device.new(sn)
|
204
|
+
device.token = "who cares"
|
205
|
+
expect(MokiAPI).to receive(:pre_enroll).with({ "clientCode" => nil, "serialNumber" => sn, "token" => nil })
|
206
|
+
.and_return(Hashie::Mash.new(value: { body: nil }))
|
207
|
+
device.pre_enroll
|
208
|
+
end
|
209
|
+
|
210
|
+
it "will send blank values for both client ID and token if token is missing" do
|
211
|
+
device = MokiRuby::Device.new(sn)
|
212
|
+
device.client_id = "who cares"
|
213
|
+
expect(MokiAPI).to receive(:pre_enroll).with({ "clientCode" => nil, "serialNumber" => sn, "token" => nil })
|
214
|
+
.and_return(Hashie::Mash.new(value: { body: nil }))
|
215
|
+
device.pre_enroll
|
216
|
+
end
|
217
|
+
|
218
|
+
it "will return true if enrollment is successful" do
|
219
|
+
device = MokiRuby::Device.new(sn)
|
220
|
+
allow(MokiAPI).to receive_message_chain(:pre_enroll, :value).
|
221
|
+
and_return(Hashie::Mash.new({ body: {}, status: 200, headers: {} }))
|
222
|
+
|
223
|
+
expect(device.pre_enroll).to be true
|
224
|
+
end
|
225
|
+
|
226
|
+
it "will return nil if enrollment is not successful" do
|
227
|
+
device = MokiRuby::Device.new(sn)
|
228
|
+
allow(MokiAPI).to receive_message_chain(:pre_enroll, :value).
|
229
|
+
and_return(Hashie::Mash.new({ body: {}, status: 500, headers: {} }))
|
230
|
+
|
231
|
+
expect(device.pre_enroll).to be_nil
|
232
|
+
end
|
233
|
+
end
|
175
234
|
end
|
data/spec/lib/moki_api_spec.rb
CHANGED
@@ -93,5 +93,18 @@ describe MokiAPI do
|
|
93
93
|
MokiAPI.perform_action('abcd1234-1234-1234-1234-abcdef123456', body_hash)
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
describe "pre enroll" do
|
98
|
+
it 'performs the post to preenroll with the provided parameters' do
|
99
|
+
enroll_hash = { "serialNumber" => "ABCDEFGHIJKL", "clientCode" => "12944", "token" => "c12944-token" }
|
100
|
+
expect(MokiAPI).to receive(:issue_request) { |method, url, options|
|
101
|
+
expect(method).to eq(:post)
|
102
|
+
expect(url).to eq("http://localhost:9292/rest/v1/api/tenants/#{ ENV['MOKI_TENANT_ID'] }/preenroll")
|
103
|
+
expect(options).to eq enroll_hash
|
104
|
+
}.and_return('{}')
|
105
|
+
|
106
|
+
MokiAPI.pre_enroll(enroll_hash)
|
107
|
+
end
|
108
|
+
end
|
96
109
|
end
|
97
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moki_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trey Springer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|