togglehq 1.1.0 → 1.2.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/README.md +27 -0
- data/lib/togglehq/device.rb +75 -0
- data/lib/togglehq/version.rb +1 -1
- data/lib/togglehq.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cad499d2b55fe1f98f70828478da19bec368ede3
|
|
4
|
+
data.tar.gz: a91488b597f4dceea5325c562d5261da09bc4233
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10b4188c6d029a88736b978d8d5338d4ac9bf3248e1dc76a8ae5267934fb54e7e3e0d041760062616ea156d7aba15a940aff395ba90c7564dc112e61a57247f0
|
|
7
|
+
data.tar.gz: 9ef900273e811106f7c0cb32a11520c40353daa5a3ea828b0425bf5a902b7506ea18581cb76c78b4992a0850ab7a62b289119399b52add6088835e39f5cb39e0
|
data/README.md
CHANGED
|
@@ -56,6 +56,33 @@ If a user with the given identifier cannot be found, `nil` will be returned.
|
|
|
56
56
|
|
|
57
57
|
Alternatively, you can call `Togglehq::User.find_by_identifier!`, which will raise a RuntimeError if the given user cannot be found.
|
|
58
58
|
|
|
59
|
+
### Devices
|
|
60
|
+
|
|
61
|
+
Create a device (usually done via the ToggleHQ SDK)
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
device = Togglehq::Device.new(:os => "ios", :os_version => 10.0, :manufacturer => "Apple", :model => "iPhone")
|
|
65
|
+
device.save
|
|
66
|
+
```
|
|
67
|
+
If created successfully, `device.uuid` will return the unique device identifier.
|
|
68
|
+
|
|
69
|
+
Enable a device to receive notifications
|
|
70
|
+
```ruby
|
|
71
|
+
device = Togglehq::Device.new(:uuid => "123456789")
|
|
72
|
+
device.enable!("2b6f0cc4...831186")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Assign a device to a specific user
|
|
76
|
+
```ruby
|
|
77
|
+
device = Togglehq::Device.new(:uuid => "123456789")
|
|
78
|
+
device.assign!("abcdef0123456789")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Unassign a device from all users
|
|
82
|
+
```ruby
|
|
83
|
+
device = Togglehq::Device.new(:uuid => "123456789")
|
|
84
|
+
device.unassign!
|
|
85
|
+
```
|
|
59
86
|
|
|
60
87
|
### ToggleHQ Notify Usage
|
|
61
88
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
module Togglehq
|
|
2
|
+
class Device
|
|
3
|
+
attr_accessor :os, :uuid, :os_version, :manufacturer, :model
|
|
4
|
+
|
|
5
|
+
def initialize(params = {})
|
|
6
|
+
@os = params[:os]
|
|
7
|
+
@uuid = params[:uuid]
|
|
8
|
+
@os_version = params[:os_version]
|
|
9
|
+
@manufacturer = params[:manufacturer]
|
|
10
|
+
@model = params[:model]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Enables a device to receive notifications
|
|
14
|
+
# @param token [String] the token of the device
|
|
15
|
+
# @raise [RuntimeError] raised if the device is invalid or not found
|
|
16
|
+
def enable!(token)
|
|
17
|
+
response = Togglehq::Request.new("/devices/enable",{"device" => {"uuid" => self.uuid, "token" => token}}).patch!
|
|
18
|
+
if response.status == 200
|
|
19
|
+
return true
|
|
20
|
+
elsif response.status == 404
|
|
21
|
+
json = JSON.parse(response.body)
|
|
22
|
+
raise json["message"]
|
|
23
|
+
else
|
|
24
|
+
raise "unexpected error enabling the device"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Assigns a device to a specific user
|
|
29
|
+
# @param user_identifier [String] the identifier of the user
|
|
30
|
+
# @raise [RuntimeError] raised if either the device or user is invalid or not found
|
|
31
|
+
def assign!(user_identifier)
|
|
32
|
+
response = Togglehq::Request.new("/devices/assign",{"device" => {"uuid" => self.uuid}, "user" => {"identifier" => user_identifier}}).patch!
|
|
33
|
+
if response.status == 200
|
|
34
|
+
return true
|
|
35
|
+
elsif response.status == 404
|
|
36
|
+
json = JSON.parse(response.body)
|
|
37
|
+
raise json["message"]
|
|
38
|
+
else
|
|
39
|
+
raise "unexpected error assigning the device"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Unassigns a device from all users
|
|
44
|
+
# @raise [RuntimeError] raised if either the device or user is invalid or not found
|
|
45
|
+
def unassign!
|
|
46
|
+
response = Togglehq::Request.new("/devices/unassign",{"device" => {"uuid" => self.uuid}}).patch!
|
|
47
|
+
if response.status == 200
|
|
48
|
+
return true
|
|
49
|
+
elsif response.status == 404
|
|
50
|
+
json = JSON.parse(response.body)
|
|
51
|
+
raise json["message"]
|
|
52
|
+
else
|
|
53
|
+
raise "unexpected error unassigning the device"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Saves a new device
|
|
58
|
+
def save
|
|
59
|
+
response = Togglehq::Request.new("/devices", {"device" => {"os" => self.os, "os_version" => self.os_version, "manufacturer" => self.manufacturer, "model" => self.model}}).post!
|
|
60
|
+
if response.status == 200
|
|
61
|
+
self.persisted!
|
|
62
|
+
json = JSON.parse(response.body)
|
|
63
|
+
self.uuid = json["device"]["uuid"]
|
|
64
|
+
return true
|
|
65
|
+
else
|
|
66
|
+
raise "unexpected error saving the device"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# @private
|
|
71
|
+
def persisted!
|
|
72
|
+
@persisted = true
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
data/lib/togglehq/version.rb
CHANGED
data/lib/togglehq.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: togglehq
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Toggle
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-10-
|
|
11
|
+
date: 2016-10-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -154,6 +154,7 @@ files:
|
|
|
154
154
|
- bin/setup
|
|
155
155
|
- lib/togglehq.rb
|
|
156
156
|
- lib/togglehq/config.rb
|
|
157
|
+
- lib/togglehq/device.rb
|
|
157
158
|
- lib/togglehq/notify.rb
|
|
158
159
|
- lib/togglehq/notify/notification.rb
|
|
159
160
|
- lib/togglehq/notify/preferences.rb
|