snitcher 0.4.0.rc1 → 0.4.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +3 -27
- data/Rakefile +0 -3
- data/examples/api.rb +51 -0
- data/lib/snitcher/api/client.rb +37 -36
- data/lib/snitcher/version.rb +1 -1
- data/spec/api/client_spec.rb +24 -71
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d59a08f5f3886dc3f7b0aef1943627c22795c2f
|
4
|
+
data.tar.gz: 108054b71ff9b607b91ac3808d01e8c9173b5b0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fb6accdbc955dd55cf0f1e1a994660557a2425882fe125fa09caa1051510585bc4fea89d4f56bc7588985bf01c487b35b78db8b0b454b5b6c7fe5813786e930
|
7
|
+
data.tar.gz: 3dfdbc8579aac588a50626ed6993bbbf380ca0579c355554a9711fd1d9d0aaa57d84ef03a04f984f1e0e21beccef787e0b7ab2a272f9685461e9a9fac11bd7e2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -82,8 +82,7 @@ Returns a Snitch.
|
|
82
82
|
### Retrieve Snitches That Match a Set of Tags
|
83
83
|
|
84
84
|
```ruby
|
85
|
-
tags
|
86
|
-
client.tagged_snitches(tags)
|
85
|
+
client.snitches(tags: ["critical", "sales"])
|
87
86
|
```
|
88
87
|
|
89
88
|
Returns an array of Snitches.
|
@@ -141,29 +140,6 @@ client.remove_tag(token, tag)
|
|
141
140
|
|
142
141
|
Returns an array of all of the Snitch's remaining tags.
|
143
142
|
|
144
|
-
### Replace Tags on a Snitch
|
145
|
-
|
146
|
-
Replaces all of a Snitch's tags with an array of new tags.
|
147
|
-
|
148
|
-
```ruby
|
149
|
-
token = "c2354d53d2"
|
150
|
-
tags = ["csv", "server_a"]
|
151
|
-
client.replace_tags(token, tags)
|
152
|
-
```
|
153
|
-
|
154
|
-
Returns the updated Snitch.
|
155
|
-
|
156
|
-
### Remove Tags From a Snitch
|
157
|
-
|
158
|
-
Removes all of a Snitch's tags.
|
159
|
-
|
160
|
-
```ruby
|
161
|
-
token = "c2354d53d2"
|
162
|
-
client.clear_tags(token)
|
163
|
-
```
|
164
|
-
|
165
|
-
Returns the updated Snitch.
|
166
|
-
|
167
143
|
### Pause a Snitch
|
168
144
|
|
169
145
|
```ruby
|
@@ -171,7 +147,7 @@ token = "c2354d53d2"
|
|
171
147
|
client.pause_snitch(token)
|
172
148
|
```
|
173
149
|
|
174
|
-
Returns a
|
150
|
+
Returns a nil object.
|
175
151
|
|
176
152
|
### Delete a Snitch
|
177
153
|
|
@@ -180,7 +156,7 @@ token = "c2354d53d2"
|
|
180
156
|
client.delete_snitch(token)
|
181
157
|
```
|
182
158
|
|
183
|
-
Returns a
|
159
|
+
Returns a nil object.
|
184
160
|
|
185
161
|
## Contributing
|
186
162
|
|
data/Rakefile
CHANGED
data/examples/api.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
# Need to require the API separately as it is not required by Snitcher itself.
|
4
|
+
require "snitcher/api"
|
5
|
+
|
6
|
+
if !(ENV["DMS_USER"] && ENV["DMS_PASS"])
|
7
|
+
puts "Set DMS_USER and DMS_PASS environment variables to your"
|
8
|
+
puts "deadmanssnitch.com credentials before running this example"
|
9
|
+
puts
|
10
|
+
puts "example: DMS_USER=email DMS_PASS=pass ruby examples/api.rb"
|
11
|
+
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get an API key for a given user with password
|
16
|
+
key = Snitcher::API.get_key(ENV["DMS_USER"], ENV["DMS_PASS"])
|
17
|
+
|
18
|
+
# Create a new API client
|
19
|
+
client = Snitcher::API::Client.new(key)
|
20
|
+
|
21
|
+
# Create an hourly Snitch called "Monitor All The Things"
|
22
|
+
snitch = client.create_snitch({
|
23
|
+
name: "Monitor All The Things",
|
24
|
+
tags: ["things"],
|
25
|
+
interval: "hourly",
|
26
|
+
})
|
27
|
+
puts "Created: #{snitch.inspect}"
|
28
|
+
|
29
|
+
# Change the name and notes of an existing Snitch
|
30
|
+
snitch = client.update_snitch(snitch.token, {
|
31
|
+
name: "Monitor Fewer Things",
|
32
|
+
notes: "Only monitoring a couple things",
|
33
|
+
})
|
34
|
+
|
35
|
+
# Add new tags to a Snitch
|
36
|
+
snitch.tags = client.add_tags(snitch.token, ["production", "critical issues"])
|
37
|
+
|
38
|
+
# Remove the "critical issues" tag from the Snitch
|
39
|
+
snitch.tags = client.remove_tag(snitch.token, "critical issues")
|
40
|
+
|
41
|
+
# Get a list of Snitches tagged with "production"
|
42
|
+
production = client.snitches(tags: ["production"])
|
43
|
+
puts "Production Snitches:"
|
44
|
+
production.each { |s| puts " - #{s.inspect}"}
|
45
|
+
|
46
|
+
# Pause a Snitch if it's currently missing or errored
|
47
|
+
client.pause_snitch(snitch.token)
|
48
|
+
|
49
|
+
# Delete a Snitch
|
50
|
+
client.delete_snitch(snitch.token)
|
51
|
+
puts "Deleted: #{snitch.token}"
|
data/lib/snitcher/api/client.rb
CHANGED
@@ -35,16 +35,46 @@ class Snitcher::API::Client
|
|
35
35
|
|
36
36
|
# Get the list snitches on the account
|
37
37
|
#
|
38
|
+
# @param [Hash] filters
|
39
|
+
# @option filters [String, Array<String>] tags only return Snitches that are
|
40
|
+
# tagged with _all_ of the given tags. For example, if a Snitch is tagged
|
41
|
+
# with "production" and "critical" it will be returned when filtering by
|
42
|
+
# "production", "critical", or ["production", "critical"] but not
|
43
|
+
# ["production", "backups"].
|
44
|
+
#
|
38
45
|
# @example List the Snitches on an account
|
39
|
-
#
|
40
|
-
#
|
46
|
+
# client.snitches
|
47
|
+
# # => [ #<Snitcher::API::Snitch:...>, #<Snitcher::API::Snitch:...> ]
|
48
|
+
#
|
49
|
+
# @example List Snitches with a specific tag
|
50
|
+
# client.snitches(tags: "production")
|
51
|
+
# # => [ #<Snitcher::API::Snitch:...>, #<Snitcher::API::Snitch:...> ]
|
52
|
+
#
|
53
|
+
# @example List Snitches with multiple tags
|
54
|
+
# client.snitches(tags: ["production", "critical"])
|
55
|
+
# # => [ #<Snitcher::API::Snitch:...>, #<Snitcher::API::Snitch:...> ]
|
41
56
|
#
|
42
57
|
# @raise [Timeout::Error] if the API request took too long to execute.
|
43
58
|
# @raise [Snitcher::API::Error] if any API errors occur.
|
44
59
|
#
|
45
60
|
# @return [Array<Snitcher::API::Snitch>] the snitches on the account.
|
46
|
-
def snitches
|
47
|
-
|
61
|
+
def snitches(filters = {})
|
62
|
+
path = "/v1/snitches"
|
63
|
+
query = {}
|
64
|
+
|
65
|
+
# Tags allow for labeling Snitches for better categorization. This allows
|
66
|
+
# filtering by a set of tags.
|
67
|
+
if filters[:tags]
|
68
|
+
tags = Array(filters[:tags]).flatten
|
69
|
+
query[:tags] = tags.map(&:strip).compact.uniq.join(",")
|
70
|
+
end
|
71
|
+
|
72
|
+
# Only add the query param if any valid filters were given.
|
73
|
+
if query.any?
|
74
|
+
path = "#{path}?#{URI.encode_www_form(query)}"
|
75
|
+
end
|
76
|
+
|
77
|
+
snitch_array(get(path))
|
48
78
|
end
|
49
79
|
|
50
80
|
# Get a single Snitch by it's unique token.
|
@@ -67,36 +97,6 @@ class Snitcher::API::Client
|
|
67
97
|
Snitcher::API::Snitch.new(payload)
|
68
98
|
end
|
69
99
|
|
70
|
-
# Retrieve Snitches filtered by a list of tags. Only Snitches that are tagged
|
71
|
-
# with all of the given tags will be returned.
|
72
|
-
#
|
73
|
-
# @param tags [String, Array<String>] the tag(s) to filter by.
|
74
|
-
#
|
75
|
-
# @example Get the snitches that match a list of tags
|
76
|
-
# client.tagged_snitches(["production","critical"])
|
77
|
-
#
|
78
|
-
# # => [
|
79
|
-
# #<Snitcher::API::Snitch tags=["production", "critical"]>,
|
80
|
-
# #<Snitcher::API::Snitch tags=["production", "critical"]>,
|
81
|
-
# ]
|
82
|
-
#
|
83
|
-
# @raise [Timeout::Error] if the API request took too long to execute.
|
84
|
-
# with that token
|
85
|
-
# @raise [Snitcher::API::Error] if any API errors occur.
|
86
|
-
#
|
87
|
-
# @return [Array<Snitcher::API::Snitch>] list of Snitches matching all tags.
|
88
|
-
def tagged_snitches(*tags)
|
89
|
-
(tags ||= []).flatten!
|
90
|
-
|
91
|
-
query = URI.encode_www_form({
|
92
|
-
# Strip extra spaces, dedupe, and clean up the list of tags to be filtered
|
93
|
-
# by.
|
94
|
-
tags: tags.map(&:strip).compact.uniq.join(","),
|
95
|
-
})
|
96
|
-
|
97
|
-
snitch_array(get("/v1/snitches?#{query}"))
|
98
|
-
end
|
99
|
-
|
100
100
|
# Create a new Snitch.
|
101
101
|
#
|
102
102
|
# @param [Hash] attributes The properties for the new Snitch
|
@@ -113,7 +113,7 @@ class Snitcher::API::Client
|
|
113
113
|
# @example Create a new Snitch
|
114
114
|
# client.create_snitch({
|
115
115
|
# name: "Daily Backups",
|
116
|
-
#
|
116
|
+
# interval: "hourly",
|
117
117
|
# notes: "On error check the print tray for paper jams",
|
118
118
|
# tags: [ "backups", "maintenance" ],
|
119
119
|
# })
|
@@ -227,7 +227,8 @@ class Snitcher::API::Client
|
|
227
227
|
#
|
228
228
|
# @return [Array<String>] list of the remaining tags on the Snitch.
|
229
229
|
def remove_tag(token, tag)
|
230
|
-
|
230
|
+
path = "/v1/snitches/#{token}/tags/#{tag}"
|
231
|
+
delete(URI.encode(path))
|
231
232
|
end
|
232
233
|
|
233
234
|
# Pauses a Snitch if it can be paused. Snitches can only be paused if their
|
data/lib/snitcher/version.rb
CHANGED
data/spec/api/client_spec.rb
CHANGED
@@ -60,6 +60,22 @@ describe Snitcher::API::Client do
|
|
60
60
|
expect(client.snitches).to be_a(Array)
|
61
61
|
expect(client.snitches.first).to be_a(Snitcher::API::Snitch)
|
62
62
|
end
|
63
|
+
|
64
|
+
it "allows filtering by a tag" do
|
65
|
+
request = stub_request(:get, "#{snitch_url}?tags=production")
|
66
|
+
.to_return(body: body, status: 200)
|
67
|
+
|
68
|
+
client.snitches(tags: "production")
|
69
|
+
expect(request).to have_been_made.once
|
70
|
+
end
|
71
|
+
|
72
|
+
it "allows filtering by multiple tags" do
|
73
|
+
request = stub_request(:get, "#{snitch_url}?tags=phoenix%20foundary,murggle")
|
74
|
+
.to_return(body: body, status: 200)
|
75
|
+
|
76
|
+
client.snitches(tags: ["phoenix foundary", "murggle"])
|
77
|
+
expect(request).to have_been_made.once
|
78
|
+
end
|
63
79
|
end
|
64
80
|
|
65
81
|
describe "#snitch" do
|
@@ -99,77 +115,6 @@ describe Snitcher::API::Client do
|
|
99
115
|
end
|
100
116
|
end
|
101
117
|
|
102
|
-
describe "#tagged_snitches" do
|
103
|
-
let(:tags) { ["sneetch", "belly"] }
|
104
|
-
let(:url) { "#{snitch_url}?tags=sneetch,belly" }
|
105
|
-
let(:body) { '[
|
106
|
-
{
|
107
|
-
"token": "c2354d53d2",
|
108
|
-
"href": "/v1/snitches/c2354d53d2",
|
109
|
-
"name": "Best Kind of Sneetch on the Beach",
|
110
|
-
"tags": [
|
111
|
-
"sneetch",
|
112
|
-
"belly",
|
113
|
-
"star-belly"
|
114
|
-
],
|
115
|
-
"status": "pending",
|
116
|
-
"checked_in_at": "",
|
117
|
-
"type": {
|
118
|
-
"interval": "hourly"
|
119
|
-
}
|
120
|
-
},
|
121
|
-
{
|
122
|
-
"token": "c2354d53d3",
|
123
|
-
"href": "/v1/snitches/c2354d53d3",
|
124
|
-
"name": "Have None Upon Thars",
|
125
|
-
"tags": [
|
126
|
-
"sneetch",
|
127
|
-
"belly",
|
128
|
-
"plain-belly"
|
129
|
-
],
|
130
|
-
"status": "pending",
|
131
|
-
"checked_in_at": "",
|
132
|
-
"type": {
|
133
|
-
"interval": "hourly"
|
134
|
-
}
|
135
|
-
}
|
136
|
-
]'
|
137
|
-
}
|
138
|
-
|
139
|
-
before do
|
140
|
-
stub_request(:get, stub_url).to_return(:body => body, :status => 200)
|
141
|
-
end
|
142
|
-
|
143
|
-
it "pings API with the api_key" do
|
144
|
-
client.tagged_snitches(tags)
|
145
|
-
|
146
|
-
expect(a_request(:get, url)).to have_been_made.once
|
147
|
-
end
|
148
|
-
|
149
|
-
it "returns the snitches" do
|
150
|
-
expect(client.tagged_snitches(tags)).to be_a(Array)
|
151
|
-
expect(client.tagged_snitches(tags).first).to be_a(Snitcher::API::Snitch)
|
152
|
-
end
|
153
|
-
|
154
|
-
it "supports spaces in tags" do
|
155
|
-
request = stub_request(:get, "#{snitch_url}?tags=phoenix%20foundary,murggle").
|
156
|
-
to_return(body: body, status: 200)
|
157
|
-
|
158
|
-
client.tagged_snitches("phoenix foundary", "murggle")
|
159
|
-
|
160
|
-
expect(request).to have_been_made.once
|
161
|
-
end
|
162
|
-
|
163
|
-
it "allows an array to be passed for tags" do
|
164
|
-
request = stub_request(:get, "#{snitch_url}?tags=murggle,gurgggle").
|
165
|
-
to_return(body: body, status: 200)
|
166
|
-
|
167
|
-
client.tagged_snitches(["murggle", "gurgggle"])
|
168
|
-
|
169
|
-
expect(request).to have_been_made.once
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
118
|
describe "#create_snitch" do
|
174
119
|
let(:data) {
|
175
120
|
{
|
@@ -442,6 +387,14 @@ describe Snitcher::API::Client do
|
|
442
387
|
|
443
388
|
expect(a_request(:delete, url)).to have_been_made.once
|
444
389
|
end
|
390
|
+
|
391
|
+
it "properly escapes tags with spaces" do
|
392
|
+
request = stub_request(:delete, "#{snitch_url}/c2354d53d2/tags/tag%20with%20spaces").
|
393
|
+
to_return(:body => body, :status => 200)
|
394
|
+
|
395
|
+
client.remove_tag(token, "tag with spaces")
|
396
|
+
expect(request).to have_been_made.once
|
397
|
+
end
|
445
398
|
|
446
399
|
context "when successful" do
|
447
400
|
it "returns an array of the snitch's remaining tags" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snitcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.
|
4
|
+
version: 0.4.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Collective Idea
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- Rakefile
|
55
55
|
- bin/snitch
|
56
56
|
- doc/get_them_stitches.jpg
|
57
|
+
- examples/api.rb
|
57
58
|
- lib/snitcher.rb
|
58
59
|
- lib/snitcher/api.rb
|
59
60
|
- lib/snitcher/api/client.rb
|
@@ -102,4 +103,3 @@ test_files:
|
|
102
103
|
- spec/spec_helper.rb
|
103
104
|
- spec/support/random.rb
|
104
105
|
- spec/support/webmock.rb
|
105
|
-
has_rdoc:
|