snitcher 0.4.0.pre1 → 0.4.0.pre2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31fd69148d1e700f8fb0530699877e3efc5fad4b
4
- data.tar.gz: cd47d65eb4574061cab9352d6de6818cdbc591dc
3
+ metadata.gz: 52b46733dac8b3d6892d836ce73c27527c705f4c
4
+ data.tar.gz: 8117b728733b857dd8840491a6fa16f0a2db6ba0
5
5
  SHA512:
6
- metadata.gz: 934c98e32c1880697ecd3e13d50c4296b843de6fd85c7625ed150117c07cbbb2391fc7efc3c221efad17abe20a31caabd5bc1c14a7abe40941697ab585da6bfd
7
- data.tar.gz: d6c37d3f7ff629ba62c2a6cf79254998a6a528ce85d63ab8104c3abcd129d509eaeae7a21f5d6182d9edb91746de7dba9ba26c01758d6d050b3e4eb8fdb53975
6
+ metadata.gz: fe9a30bdb596ffc377f951fd853ac66b00b22370cde6989224bd7a9e8ffa05a8b5a8832f14e74b0a779d458a29c4216e8efd8098720311c53fdb15491460dad0
7
+ data.tar.gz: f37a6ee3a9473e27e2a905bb81469c7df72990f3a35c16cc5892ffa5961ac92b5a52e7917af65a223767004666464104e6c2f7cce04ea620186e441f813d5318
@@ -30,7 +30,7 @@ module Snitcher
30
30
  # Raises Snitcher::API::Error based on the type from the server.
31
31
  # Raises Timeout::Error if the request timed out.
32
32
  def get_key(username, password, options={})
33
- api = options.fetch(:uri, "https://deadmanssnitch.com")
33
+ api = options.fetch(:uri, "https://api.deadmanssnitch.com")
34
34
  uri = URI.parse("#{api}/v1/api_key")
35
35
 
36
36
  timeout = options.fetch(:timeout, 5)
@@ -187,16 +187,16 @@ class Snitcher::API::Client
187
187
  # Example
188
188
  #
189
189
  # Add tags to an existing snitch.
190
- # token = "c2354d53d2"
191
- # tags = [ "red", "green" ]
192
- # @client.add_tags(token, tags)
193
- # => [
194
- # "red",
195
- # "green"
196
- # ]
190
+ # @client.add_tags("c2354d53d2", %w("red", "green")
191
+ # => [ "yellow", "red", "green" ]
192
+ #
193
+ # Adding a single tag
194
+ # @client.add_tags("c2354d53d2", "orange")
195
+ # => [ "yellow", "orange" ]
197
196
  #
198
197
  # Raise Timeout::Error if the API request times out
199
198
  def add_tags(token, tags=[])
199
+ tags = [tags].flatten
200
200
  post("/v1/snitches/#{token}/tags", tags)
201
201
  end
202
202
 
@@ -1,3 +1,3 @@
1
1
  module Snitcher
2
- VERSION = "0.4.0.pre1"
2
+ VERSION = "0.4.0.pre2"
3
3
  end
@@ -287,29 +287,26 @@ describe Snitcher::API::Client do
287
287
  end
288
288
 
289
289
  describe "#add_tags" do
290
- let(:token) { "c2354d53d2" }
291
- let(:tags) { ["red", "green"] }
292
- let(:url) { "#{snitch_url}/#{token}/tags" }
293
- let(:body) { '[
294
- "red",
295
- "green"
296
- ]'
297
- }
290
+ it "adds the tags to the Snitch via the API" do
291
+ request = stub_request(:post, "#{snitch_url}/c2354d53d2/tags").
292
+ with(:body => %|["red","green"]|).
293
+ to_return(:body => %|["red", "green"]|, :status => 200)
298
294
 
299
- before do
300
- stub_request(:post, stub_url).to_return(:body => body, :status => 200)
295
+ result = client.add_tags("c2354d53d2", ["red", "green"])
296
+
297
+ expect(request).to have_been_made.once
298
+ expect(result).to eq(["red", "green"])
301
299
  end
302
300
 
303
- it "pings API with the api_key" do
304
- client.add_tags(token, tags)
301
+ it "allows passing a single tag to add" do
302
+ request = stub_request(:post, "#{snitch_url}/TOKEN/tags").
303
+ with(:body => %|["extremely important"]|).
304
+ to_return(:body => %|["extremely important"]|, :status => 200)
305
305
 
306
- expect(a_request(:post, url)).to have_been_made.once
307
- end
306
+ result = client.add_tags("TOKEN", "extremely important")
308
307
 
309
- context "when successful" do
310
- it "returns an array of the snitch's tags" do
311
- expect(client.add_tags(token, tags)).to eq(JSON.parse(body))
312
- end
308
+ expect(request).to have_been_made.once
309
+ expect(result).to eq(["extremely important"])
313
310
  end
314
311
  end
315
312
 
@@ -1,20 +1,23 @@
1
1
  require "spec_helper"
2
+
2
3
  require "base64"
3
4
  require "securerandom"
4
5
 
6
+ require "snitcher/api"
7
+
5
8
  describe Snitcher::API do
6
9
  describe "#get_key" do
7
10
  it "returns the api_key" do
8
11
  user = "alice@example.com"
9
12
  pass = "password"
10
13
 
11
- request = stub_request(:get, "http://#{user}:#{pass}@dms.dev/v1/api_key").
14
+ request = stub_request(:get, "https://#{user}:#{pass}@api.deadmanssnitch.com/v1/api_key").
12
15
  to_return({
13
16
  :body => '{"api_key": "_caeEiZXnEyEzXXYVh2NhQ"}',
14
17
  :status => 200
15
18
  })
16
19
 
17
- actual = Snitcher::API.get_key(user, pass, uri: "http://dms.dev")
20
+ actual = Snitcher::API.get_key(user, pass)
18
21
 
19
22
  expect(actual).to eq("_caeEiZXnEyEzXXYVh2NhQ")
20
23
  expect(request).to have_been_made.once
@@ -24,7 +27,7 @@ describe Snitcher::API do
24
27
  user = "lol@notreally.horse"
25
28
  pass = "nope"
26
29
 
27
- request = stub_request(:get, "http://#{user}:#{pass}@dms.dev/v1/api_key").
30
+ request = stub_request(:get, "https://#{user}:#{pass}@api.deadmanssnitch.com/v1/api_key").
28
31
  to_return({
29
32
  :body => JSON.generate({
30
33
  :type => "sign_in_incorrect",
@@ -36,7 +39,7 @@ describe Snitcher::API do
36
39
  expect {
37
40
  # Some shenanigans to verify type
38
41
  begin
39
- Snitcher::API.get_key(user, pass, uri: "http://dms.dev")
42
+ Snitcher::API.get_key(user, pass)
40
43
  rescue Snitcher::API::Error => e
41
44
  expect(e.type).to eq("sign_in_incorrect")
42
45
  expect(e.message).to eq("Invalid email or password.")
@@ -49,11 +52,24 @@ describe Snitcher::API do
49
52
  end
50
53
 
51
54
  it "raises Timeout::Error on a timeout" do
52
- stub_request(:any, "dms.dev/v1/api_key").to_timeout
55
+ stub_request(:any, "https://api.deadmanssnitch.com/v1/api_key").to_timeout
53
56
 
54
57
  expect {
55
- Snitcher::API.get_key("", "", uri: "http://dms.dev")
58
+ Snitcher::API.get_key("", "")
56
59
  }.to raise_error(Timeout::Error)
57
60
  end
61
+
62
+ it "allows the API URI to be provided" do
63
+ request = stub_request(:any, "user:pass@dms.dev:4000/v1/api_key").
64
+ to_return({
65
+ :body => '{"api_key": "this_is_an_api_key"}',
66
+ :status => 200
67
+ })
68
+
69
+ actual = Snitcher::API.get_key("user", "pass", uri: "http://dms.dev:4000")
70
+
71
+ expect(actual).to eq("this_is_an_api_key")
72
+ expect(request).to have_been_made.once
73
+ end
58
74
  end
59
75
  end
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.pre1
4
+ version: 0.4.0.pre2
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-04-20 00:00:00.000000000 Z
11
+ date: 2016-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler