snitcher 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28c075e51d743b5bd9cfea27193db58b8eadd72774ac4d1478800ffe6b73fb12
4
- data.tar.gz: e08200f4bc411eed2c909c91cac08bb993497063a8955f0155f499c27f35fc43
3
+ metadata.gz: 2613d8b9e2918478b19e16717aa65726a8a0b6aae250846bd0b966b5b34bffa5
4
+ data.tar.gz: ab08596c2a1fe6e7fba7db7e4c7ecb9b092eb6dd1ac16dae8b75fd68e2f7efd1
5
5
  SHA512:
6
- metadata.gz: f53823e4e0ba5ea1d435104de453427dcafa2f32a51bc092ad7f679c1b79a24a8ba0e9a06dcc7850b30e29c776d78e2b8652ec1099012de89b1093bfa8aa9232
7
- data.tar.gz: a793e491ed792109ec1702287a575d893f215385863add7844242e6524cde7078b4479c1f1fef5fc762f906b0ba4bb3cd7df8dd6f40cfeeaaca3a16208b88d5a
6
+ metadata.gz: 8ca6c380e026b3c086683eba26b836429ac32a6b61dad10f48a0a906012d2d0783c6e15097100b5ffeb4b6a4edfb47736d33e026533afd85e9c86e168fe1f6ba
7
+ data.tar.gz: a04bdb064748796ba5297a28268fed83c0c4c2867f10cecd22be56a595e8914feb7fb5fe5b56ea43d1842cbb775800ed519e1fa47859755df69972b5e1b86b1c
data/.travis.yml CHANGED
@@ -1,22 +1,15 @@
1
+ dist: bionic
2
+
1
3
  language: ruby
2
4
  matrix:
3
5
  allow_failures:
4
6
  - rvm: ruby-head
5
7
 
6
- before_install:
7
- - gem install bundler
8
-
9
- # Disable support for sudo to get faster builds with Docker
10
- sudo: false
11
-
12
8
  rvm:
13
- - 1.9.3
14
- - 2.0.0
15
- - 2.1
16
- - 2.2
17
- - 2.3
18
- - 2.4
19
9
  - 2.5
10
+ - 2.6
11
+ - 2.7
12
+ - 3.0
20
13
  - jruby
21
14
  - ruby-head
22
15
 
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
+ ## 0.4.2 / 2021-06-07
2
+ * [BUG] Fixed Ruby 3.0 support ([@gaffneyc](https://github.com/gaffneyc))
3
+
1
4
  ## 0.4.1 / 2018-07-09
2
5
  * [FEATURE] Added :status option to Snitcher.snitch! ([@gaffneyc](https://github.com/gaffneyc))
3
6
  *
7
+
4
8
  ## 0.4.0 / 2016-06-20
5
9
  * [FEATURE] Added Snitcher::API for integrating with the DMS API ([@danabrit](https://github.com/danabrit))
6
10
  * [FEATURE] Added Snitcher.snitch! which raises exceptions on errors ([@gaffneyc](https://github.com/gaffneyc))
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Simple API client for [Dead Man's Snitch](https://deadmanssnitch.com)
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/snitcher.png)](http://badge.fury.io/rb/snitcher)
6
- [![Build Status](https://travis-ci.org/deadmanssnitch/snitcher.png?branch=master)](https://travis-ci.org/deadmanssnitch/snitcher)
6
+ [![Build Status](https://travis-ci.com/deadmanssnitch/snitcher.png?branch=master)](https://travis-ci.com/deadmanssnitch/snitcher)
7
7
  [![Code Climate](https://codeclimate.com/github/deadmanssnitch/snitcher.png)](https://codeclimate.com/github/deadmanssnitch/snitcher)
8
8
  [![Coverage Status](https://coveralls.io/repos/deadmanssnitch/snitcher/badge.png)](https://coveralls.io/r/deadmanssnitch/snitcher)
9
9
 
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "net/https"
2
4
  require "timeout"
3
5
  require "json"
6
+ require "cgi"
4
7
 
5
8
  require "snitcher/api"
6
9
  require "snitcher/version"
@@ -93,6 +96,8 @@ class Snitcher::API::Client
93
96
  #
94
97
  # @return [Snitcher::API::Snitch] the Snitch
95
98
  def snitch(token)
99
+ token = CGI.escape(token)
100
+
96
101
  payload = get("/v1/snitches/#{token}")
97
102
  Snitcher::API::Snitch.new(payload)
98
103
  end
@@ -175,7 +180,7 @@ class Snitcher::API::Client
175
180
  #
176
181
  # Raise Timeout::Error if the API request times out
177
182
  def update_snitch(token, attributes = {})
178
- if attributes.has_key?(:tags)
183
+ if attributes.key?(:tags)
179
184
  attributes[:tags] = [attributes[:tags]].flatten.compact
180
185
  end
181
186
 
@@ -185,7 +190,9 @@ class Snitcher::API::Client
185
190
  type[:interval] ||= interval
186
191
  end
187
192
 
193
+ token = CGI.escape(token)
188
194
  payload = patch("/v1/snitches/#{token}", attributes)
195
+
189
196
  Snitcher::API::Snitch.new(payload)
190
197
  end
191
198
 
@@ -209,6 +216,8 @@ class Snitcher::API::Client
209
216
  #
210
217
  # @return [Array<String>] full list of tags on the Snitch.
211
218
  def add_tags(token, tags = [])
219
+ token = CGI.escape(token)
220
+
212
221
  post("/v1/snitches/#{token}/tags", Array(tags).flatten)
213
222
  end
214
223
 
@@ -227,6 +236,9 @@ class Snitcher::API::Client
227
236
  #
228
237
  # @return [Array<String>] list of the remaining tags on the Snitch.
229
238
  def remove_tag(token, tag)
239
+ token = CGI.escape(token)
240
+ tag = CGI.escape(tag)
241
+
230
242
  delete("/v1/snitches/#{token}/tags/#{tag}")
231
243
  end
232
244
 
@@ -245,6 +257,8 @@ class Snitcher::API::Client
245
257
  #
246
258
  # @return [nil]
247
259
  def pause_snitch(token)
260
+ token = CGI.escape(token)
261
+
248
262
  post("/v1/snitches/#{token}/pause")
249
263
 
250
264
  nil
@@ -264,6 +278,8 @@ class Snitcher::API::Client
264
278
  #
265
279
  # @return [nil]
266
280
  def delete_snitch(token)
281
+ token = CGI.escape(token)
282
+
267
283
  delete("/v1/snitches/#{token}")
268
284
 
269
285
  nil
@@ -282,8 +298,8 @@ class Snitcher::API::Client
282
298
  http_options = {
283
299
  open_timeout: @timeout,
284
300
  read_timeout: @timeout,
285
- ssl_timeout: @timeout,
286
- use_ssl: @endpoint.scheme == "https",
301
+ ssl_timeout: @timeout,
302
+ use_ssl: @endpoint.scheme == "https",
287
303
  }
288
304
 
289
305
  Net::HTTP.start(@endpoint.host, @endpoint.port, http_options) do |http|
@@ -315,9 +331,10 @@ class Snitcher::API::Client
315
331
  when Net::HTTPInternalServerError
316
332
  # InternalServerError does not have a parseable body as the error may not
317
333
  # be generated by the application itself.
318
- raise ::Snitcher::API::InternalServerError.new(
319
- "http_#{response.code}", response.body
320
- )
334
+ raise ::Snitcher::API::InternalServerError.new({
335
+ "type" => "internal_server_error",
336
+ "error" => response.body,
337
+ })
321
338
  else
322
339
  error = JSON.parse(response.body)
323
340
 
@@ -326,8 +343,6 @@ class Snitcher::API::Client
326
343
  end
327
344
 
328
345
  def get(path, query = {})
329
- path = URI.encode(path)
330
-
331
346
  # Only add the query param if any valid filters were given.
332
347
  if query.any?
333
348
  path = "#{path}?#{URI.encode_www_form(query)}"
@@ -338,8 +353,6 @@ class Snitcher::API::Client
338
353
  end
339
354
 
340
355
  def post(path, data = nil)
341
- path = URI.encode(path)
342
-
343
356
  request = Net::HTTP::Post.new(path)
344
357
  request.body = data
345
358
 
@@ -347,8 +360,6 @@ class Snitcher::API::Client
347
360
  end
348
361
 
349
362
  def patch(path, data)
350
- path = URI.encode(path)
351
-
352
363
  request = Net::HTTP::Patch.new(path)
353
364
  request.body = data
354
365
 
@@ -356,7 +367,6 @@ class Snitcher::API::Client
356
367
  end
357
368
 
358
369
  def delete(path)
359
- path = URI.encode(path)
360
370
  request = Net::HTTP::Delete.new(path)
361
371
  execute_request(request)
362
372
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Snitcher::API
2
4
  # Error is the base class for all API specific errors. For a full list of
3
5
  # errors and how they can happen please refer to the API documentation.
@@ -13,14 +15,15 @@ module Snitcher::API
13
15
  klass =
14
16
  case type.to_s
15
17
  # sign_in_incorrect is only returned when using username + password.
16
- when "sign_in_incorrect"; AuthenticationError
18
+ when "sign_in_incorrect"; AuthenticationError
17
19
  # api_key_invalid is only returned when using the API key.
18
- when "api_key_invalid"; AuthenticationError
19
- when "plan_limit_reached"; PlanLimitReachedError
20
- when "account_on_hold"; AccountOnHoldError
21
- when "resource_not_found"; ResourceNotFoundError
22
- when "resource_invalid"; ResourceInvalidError
23
- else Error
20
+ when "api_key_invalid"; AuthenticationError
21
+ when "plan_limit_reached"; PlanLimitReachedError
22
+ when "account_on_hold"; AccountOnHoldError
23
+ when "resource_not_found"; ResourceNotFoundError
24
+ when "resource_invalid"; ResourceInvalidError
25
+ when "internal_server_error"; InternalServerError
26
+ else Error
24
27
  end
25
28
 
26
29
  error = klass.allocate
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Snitcher::API::Snitch
2
4
  # @return [String] unique token used to identify a Snitch.
3
5
  attr_accessor :token
@@ -12,6 +14,14 @@ class Snitcher::API::Snitch
12
14
  # "pending", "healthy", "paused", "failed", or "errored".
13
15
  attr_accessor :status
14
16
 
17
+ # alert_email is a list of email addresses that will be notified when this
18
+ # Snitch goes missing, errors, or becomes healthy again. When this is set,
19
+ # only the email addresses in the list will be notified. When the list is
20
+ # empty then all team members will be alerted by default.
21
+ #
22
+ # @return [Array<String>] override list of email addresses
23
+ attr_accessor :alert_email
24
+
15
25
  # @return [String] when the Snitch last checked_in
16
26
  attr_accessor :checked_in_at
17
27
 
@@ -37,6 +47,7 @@ class Snitcher::API::Snitch
37
47
  # "token" => "c2354d53d3",
38
48
  # "href" => "/v1/snitches/c2354d53d3",
39
49
  # "name" => "Daily Backups",
50
+ # "alert_email" => [],
40
51
  # "tags" => [
41
52
  # "production",
42
53
  # "critical"
@@ -64,6 +75,7 @@ class Snitcher::API::Snitch
64
75
  @notes = payload["notes"]
65
76
 
66
77
  @created_at = payload["created_at"]
78
+ @alert_email = payload["alert_email"] || []
67
79
  @check_in_url = payload["check_in_url"]
68
80
  @checked_in_at = payload["checked_in_at"]
69
81
  end
@@ -1,3 +1,3 @@
1
1
  module Snitcher
2
- VERSION = "0.4.1".freeze
2
+ VERSION = "0.4.2".freeze
3
3
  end
data/snitcher.gemspec CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.required_ruby_version = ">= 1.9.3"
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.5"
23
- spec.add_development_dependency "rake", "~> 10.1"
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake"
24
24
  end
@@ -3,7 +3,7 @@ require "snitcher/api/client"
3
3
  require "base64"
4
4
  require "securerandom"
5
5
 
6
- describe Snitcher::API::Client do
6
+ RSpec.describe Snitcher::API::Client do
7
7
  subject(:client) do
8
8
  Snitcher::API::Client.new("key", endpoint: "http://api.dms.dev")
9
9
  end
@@ -76,6 +76,18 @@ describe Snitcher::API::Client do
76
76
  client.snitches(tags: ["phoenix foundary", "murggle"])
77
77
  expect(request).to have_been_made.once
78
78
  end
79
+
80
+ context "when Net::HTTPInternalServerError" do
81
+ it "raise ::Snitcher::API::InternalServerError" do
82
+ stub_request(:any, "#{snitch_url}?tags=phoenix")
83
+ .to_return(body: "Server Error", status: 500)
84
+
85
+ expect { client.snitches(tags: ["phoenix"]) }.to raise_error do |error|
86
+ expect(error).to be_a(::Snitcher::API::InternalServerError)
87
+ expect(error.message).to eq("Server Error")
88
+ end
89
+ end
90
+ end
79
91
  end
80
92
 
81
93
  describe "#snitch" do
@@ -387,9 +399,9 @@ describe Snitcher::API::Client do
387
399
 
388
400
  expect(a_request(:delete, url)).to have_been_made.once
389
401
  end
390
-
402
+
391
403
  it "properly escapes tags with spaces" do
392
- request = stub_request(:delete, "#{snitch_url}/c2354d53d2/tags/tag%20with%20spaces").
404
+ request = stub_request(:delete, "#{snitch_url}/c2354d53d2/tags/tag+with+spaces").
393
405
  to_return(:body => body, :status => 200)
394
406
 
395
407
  client.remove_tag(token, "tag with spaces")
@@ -1,4 +1,7 @@
1
- describe Snitcher::API::Error do
1
+ require "spec_helper"
2
+ require "snitcher/api"
3
+
4
+ RSpec.describe Snitcher::API::Error do
2
5
  it "returns a AuthenticationError for 'sign_in_incorrect'" do
3
6
  error = Snitcher::API::Error.new({
4
7
  "type" => "sign_in_incorrect",
@@ -58,5 +61,4 @@ describe Snitcher::API::Error do
58
61
  expect(error).to be_a(Snitcher::API::ResourceNotFoundError)
59
62
  expect(error.message).to eq("I can't find that!!")
60
63
  end
61
-
62
64
  end
@@ -2,30 +2,32 @@ require "spec_helper"
2
2
  require "snitcher/api"
3
3
  require "snitcher/api/snitch"
4
4
 
5
- describe Snitcher::API::Snitch do
5
+ RSpec.describe Snitcher::API::Snitch do
6
6
  describe "#new" do
7
- before do
7
+ let(:snitch) do
8
8
  payload = {
9
- "token" => "c2354d53d3",
10
- "name" => "Daily Backups",
11
- "type" => {
12
- "interval" => "daily"
9
+ "token" => "c2354d53d3",
10
+ "name" => "Daily Backups",
11
+ "alert_email" => ["user@example.com"],
12
+ "notes" => "Important user data.",
13
+ "type" => {
14
+ "interval" => "daily",
13
15
  },
14
- "notes" => "Important user data."
15
16
  }
16
17
 
17
- @snitch = Snitcher::API::Snitch.new(payload)
18
+ Snitcher::API::Snitch.new(payload)
18
19
  end
19
20
 
20
21
  it "returns a Snitch object" do
21
- expect(@snitch).to be_a(Snitcher::API::Snitch)
22
+ expect(snitch).to be_a(Snitcher::API::Snitch)
22
23
  end
23
24
 
24
25
  it "sets appropriate values" do
25
- expect(@snitch.name).to eq("Daily Backups")
26
- expect(@snitch.token).to eq("c2354d53d3")
27
- expect(@snitch.notes).to eq("Important user data.")
28
- expect(@snitch.interval).to eq("daily")
26
+ expect(snitch.name).to eq("Daily Backups")
27
+ expect(snitch.token).to eq("c2354d53d3")
28
+ expect(snitch.notes).to eq("Important user data.")
29
+ expect(snitch.interval).to eq("daily")
30
+ expect(snitch.alert_email).to eq(["user@example.com"])
29
31
  end
30
32
  end
31
33
  end
metadata CHANGED
@@ -1,44 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snitcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collective Idea
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-09 00:00:00.000000000 Z
11
+ date: 2021-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.1'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.1'
41
- description:
40
+ version: '0'
41
+ description:
42
42
  email: hi@deadmanssnitch.com
43
43
  executables:
44
44
  - snitch
@@ -74,7 +74,7 @@ homepage: https://github.com/deadmanssnitch/snitcher
74
74
  licenses:
75
75
  - MIT
76
76
  metadata: {}
77
- post_install_message:
77
+ post_install_message:
78
78
  rdoc_options: []
79
79
  require_paths:
80
80
  - lib
@@ -89,9 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubyforge_project:
93
- rubygems_version: 2.7.6
94
- signing_key:
92
+ rubygems_version: 3.2.15
93
+ signing_key:
95
94
  specification_version: 4
96
95
  summary: Simple API client for deadmanssnitch.com
97
96
  test_files: