snitcher 0.3.2 → 0.4.0.pre1

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.
@@ -0,0 +1,62 @@
1
+ describe Snitcher::API::Error do
2
+ it "returns a AuthenticationError for 'sign_in_incorrect'" do
3
+ error = Snitcher::API::Error.new({
4
+ "type" => "sign_in_incorrect",
5
+ "error" => "Oh noes!",
6
+ })
7
+
8
+ expect(error).to be_a(Snitcher::API::AuthenticationError)
9
+ expect(error.message).to eq("Oh noes!")
10
+ end
11
+
12
+ it "returns a base Error for unknown type" do
13
+ error = Snitcher::API::Error.new({
14
+ "type" => "not_documented",
15
+ "error" => "Oh noes!",
16
+ })
17
+
18
+ expect(error).to be_a(Snitcher::API::Error)
19
+ expect(error.message).to eq("Oh noes!")
20
+ end
21
+
22
+ it "returns AuthenticationError for an 'api_key_invalid'" do
23
+ error = Snitcher::API::Error.new({
24
+ "type" => "api_key_invalid",
25
+ "error" => "Not a valid key!!",
26
+ })
27
+
28
+ expect(error).to be_a(Snitcher::API::AuthenticationError)
29
+ expect(error.message).to eq("Not a valid key!!")
30
+ end
31
+
32
+ it "returns PlanLimitReachedError for an 'plan_limit_reached'" do
33
+ error = Snitcher::API::Error.new({
34
+ "type" => "plan_limit_reached",
35
+ "error" => "Plan limit reached error!!",
36
+ })
37
+
38
+ expect(error).to be_a(Snitcher::API::PlanLimitReachedError)
39
+ expect(error.message).to eq("Plan limit reached error!!")
40
+ end
41
+
42
+ it "returns AccountOnHoldError for an 'account_on_hold'" do
43
+ error = Snitcher::API::Error.new({
44
+ "type" => "account_on_hold",
45
+ "error" => "Pay us!!",
46
+ })
47
+
48
+ expect(error).to be_a(Snitcher::API::AccountOnHoldError)
49
+ expect(error.message).to eq("Pay us!!")
50
+ end
51
+
52
+ it "returns ResourceNotFoundError for an 'resource_not_found'" do
53
+ error = Snitcher::API::Error.new({
54
+ "type" => "resource_not_found",
55
+ "error" => "I can't find that!!",
56
+ })
57
+
58
+ expect(error).to be_a(Snitcher::API::ResourceNotFoundError)
59
+ expect(error.message).to eq("I can't find that!!")
60
+ end
61
+
62
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+ require "snitcher/api"
3
+ require "snitcher/api/snitch"
4
+
5
+ describe Snitcher::API::Snitch do
6
+ describe "#new" do
7
+ before do
8
+ payload = {
9
+ "token" => "c2354d53d3",
10
+ "name" => "Daily Backups",
11
+ "type" => {
12
+ "interval" => "daily"
13
+ },
14
+ "notes" => "Important user data."
15
+ }
16
+
17
+ @snitch = Snitcher::API::Snitch.new(payload)
18
+ end
19
+
20
+ it "returns a Snitch object" do
21
+ expect(@snitch).to be_a(Snitcher::API::Snitch)
22
+ end
23
+
24
+ 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")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+ require "base64"
3
+ require "securerandom"
4
+
5
+ describe Snitcher::API do
6
+ describe "#get_key" do
7
+ it "returns the api_key" do
8
+ user = "alice@example.com"
9
+ pass = "password"
10
+
11
+ request = stub_request(:get, "http://#{user}:#{pass}@dms.dev/v1/api_key").
12
+ to_return({
13
+ :body => '{"api_key": "_caeEiZXnEyEzXXYVh2NhQ"}',
14
+ :status => 200
15
+ })
16
+
17
+ actual = Snitcher::API.get_key(user, pass, uri: "http://dms.dev")
18
+
19
+ expect(actual).to eq("_caeEiZXnEyEzXXYVh2NhQ")
20
+ expect(request).to have_been_made.once
21
+ end
22
+
23
+ it "raises an error if authentication failed" do
24
+ user = "lol@notreally.horse"
25
+ pass = "nope"
26
+
27
+ request = stub_request(:get, "http://#{user}:#{pass}@dms.dev/v1/api_key").
28
+ to_return({
29
+ :body => JSON.generate({
30
+ :type => "sign_in_incorrect",
31
+ :error => "Invalid email or password."
32
+ }),
33
+ :status => 401
34
+ })
35
+
36
+ expect {
37
+ # Some shenanigans to verify type
38
+ begin
39
+ Snitcher::API.get_key(user, pass, uri: "http://dms.dev")
40
+ rescue Snitcher::API::Error => e
41
+ expect(e.type).to eq("sign_in_incorrect")
42
+ expect(e.message).to eq("Invalid email or password.")
43
+
44
+ raise e
45
+ end
46
+ }.to raise_error(Snitcher::API::AuthenticationError)
47
+
48
+ expect(request).to have_been_made.once
49
+ end
50
+
51
+ it "raises Timeout::Error on a timeout" do
52
+ stub_request(:any, "dms.dev/v1/api_key").to_timeout
53
+
54
+ expect {
55
+ Snitcher::API.get_key("", "", uri: "http://dms.dev")
56
+ }.to raise_error(Timeout::Error)
57
+ end
58
+ end
59
+ end
@@ -48,7 +48,7 @@ describe Snitcher do
48
48
 
49
49
  describe "with message" do
50
50
  it "includes the message as a query param" do
51
- Snitcher.snitch(token, :message => "A thing just happened")
51
+ Snitcher.snitch(token, message: "A thing just happened")
52
52
 
53
53
  expect(a_request(:get, "https://nosnch.in/#{token}?m=A%20thing%20just%20happened")).to have_been_made
54
54
  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.3.2
4
+ version: 0.4.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collective Idea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-13 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,8 +55,16 @@ files:
55
55
  - bin/snitch
56
56
  - doc/get_them_stitches.jpg
57
57
  - lib/snitcher.rb
58
+ - lib/snitcher/api.rb
59
+ - lib/snitcher/api/client.rb
60
+ - lib/snitcher/api/error.rb
61
+ - lib/snitcher/api/snitch.rb
58
62
  - lib/snitcher/version.rb
59
63
  - snitcher.gemspec
64
+ - spec/api/client_spec.rb
65
+ - spec/api/error_spec.rb
66
+ - spec/api/snitch_spec.rb
67
+ - spec/api_spec.rb
60
68
  - spec/snitcher_spec.rb
61
69
  - spec/spec_helper.rb
62
70
  - spec/support/random.rb
@@ -73,19 +81,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
81
  requirements:
74
82
  - - ">="
75
83
  - !ruby/object:Gem::Version
76
- version: '0'
84
+ version: 1.9.3
77
85
  required_rubygems_version: !ruby/object:Gem::Requirement
78
86
  requirements:
79
- - - ">="
87
+ - - ">"
80
88
  - !ruby/object:Gem::Version
81
- version: '0'
89
+ version: 1.3.1
82
90
  requirements: []
83
91
  rubyforge_project:
84
- rubygems_version: 2.4.6
92
+ rubygems_version: 2.5.1
85
93
  signing_key:
86
94
  specification_version: 4
87
95
  summary: Simple API client for deadmanssnitch.com
88
96
  test_files:
97
+ - spec/api/client_spec.rb
98
+ - spec/api/error_spec.rb
99
+ - spec/api/snitch_spec.rb
100
+ - spec/api_spec.rb
89
101
  - spec/snitcher_spec.rb
90
102
  - spec/spec_helper.rb
91
103
  - spec/support/random.rb