snitcher 0.4.0.rc4 → 0.4.0

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
  SHA1:
3
- metadata.gz: 269d8a39f4f95c7cf5d1d574d7e0db92f3ca3d95
4
- data.tar.gz: 9b6ce02c920e04cb8e544b0d1b2d0b2510626ca5
3
+ metadata.gz: 5ce9137c78af3585cd04a72db5dcfa25890c5c58
4
+ data.tar.gz: 0382afa241770a4ce4eb1757fa3e3dd911ac608a
5
5
  SHA512:
6
- metadata.gz: 394d5c82f089074d385f237da314701ea7cf00a353d2339698f90da97a988a4387c41ce7c422bdfddc42719026b9721c5e737f90ba21379883e4bdb8705571f7
7
- data.tar.gz: b9126ddc040154e125d763a13cfef5b09897d916fcb04c49cce36a00af93b1b838dd96bd8bb05e725a8bc15d0dce5baa7f409ef060266ff912f424bacdaaf754
6
+ metadata.gz: 9f4d73519250309f111a2359162a4748eeccf10161aa3f37dce680372b11c2d611efd32c1da98a4c2246c0e3f653e00c6a832cf99964ca668c87049bb44a7f57
7
+ data.tar.gz: 03a7310d071a11568fcb2f6d05abf74c69138dc8211715c9d8782431fada6d0136ddf5772e443f043aff40e6b5bf16b1483bf97534988dc95789165cc5361172
@@ -14,6 +14,12 @@ rvm:
14
14
  - 2.0.0
15
15
  - 2.1
16
16
  - 2.2
17
- - 2.3
17
+ - 2.3.1
18
18
  - jruby
19
19
  - ruby-head
20
+
21
+ notifications:
22
+ webhooks:
23
+ urls:
24
+ - http://buildlight.collectiveidea.com/
25
+ on_start: always
@@ -1,4 +1,4 @@
1
- ## 0.4.0 / TBD
1
+ ## 0.4.0 / 2016-06-20
2
2
  * [FEATURE] Added Snitcher::API for integrating with the DMS API ([@danabrit](https://github.com/danabrit))
3
3
  * [FEATURE] Added Snitcher.snitch! which raises exceptions on errors ([@gaffneyc](https://github.com/gaffneyc))
4
4
 
data/README.md CHANGED
@@ -31,16 +31,6 @@ Snitcher.snitch("c2354d53d2", timeout: 10)
31
31
 
32
32
  ## API Access
33
33
 
34
- ### Retrieving Your API Key At Command Line
35
-
36
- ```ruby
37
- require "snitcher/api"
38
-
39
- key = Snitcher::API.get_key("jane@example.com", "password")
40
- ```
41
-
42
- Returns an authentication key to access the api.
43
-
44
34
  ### Setup
45
35
 
46
36
  Initialize the API client directly with your api key:
@@ -3,17 +3,17 @@ $:.unshift File.expand_path("../../lib", __FILE__)
3
3
  # Need to require the API separately as it is not required by Snitcher itself.
4
4
  require "snitcher/api"
5
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"
6
+ if !ENV["DMS_API_KEY"]
7
+ puts "Set DMS_API_KEY environment variable to your deadmanssnitch.com API key"
8
+ puts "before running this example."
9
9
  puts
10
- puts "example: DMS_USER=email DMS_PASS=pass ruby examples/api.rb"
10
+ puts "example: DMS_API_KEY=c23452notarealkeyhello! ruby examples/api.rb"
11
11
 
12
12
  exit 1
13
13
  end
14
14
 
15
15
  # Get an API key for a given user with password
16
- key = Snitcher::API.get_key(ENV["DMS_USER"], ENV["DMS_PASS"])
16
+ key = ENV["DMS_API_KEY"]
17
17
 
18
18
  # Create a new API client
19
19
  client = Snitcher::API::Client.new(key)
@@ -7,67 +7,8 @@ require "snitcher/version"
7
7
 
8
8
  module Snitcher
9
9
  module API
10
- extend self
11
-
12
10
  # Snitcher::API::Error and subclasses
13
11
  require "snitcher/api/error"
14
-
15
- # Retrieve an API Key for your account.
16
- #
17
- # @param username [String] username for your Dead Man's Snitch account.
18
- # @param password [String] password for your Dead Man's Snitch account.
19
- #
20
- # @param [Hash] options
21
- # @option options [String] uri location of alternative Dead Man's Snitch API
22
- # @option timeout [Float, Fixnum] timeout number of seconds to wait for
23
- # server response before timing out.
24
- #
25
- # @example
26
- # Snitcher::API.get_key("alice@example.com", "password")
27
- # # => "_caeEiZXnEyEzXXYVh2NhQ"
28
- #
29
- # @raise [Timeout::Error] if the API request took too long to execute.
30
- # @raise [Snitcher::API::AuthenticationError] credentials are invalid.
31
- # @raise [Snitcher::API::Error] if any other API errors occur.
32
- #
33
- # @return [String] the API key to use for further API requests.
34
- def get_key(username, password, options={})
35
- api = options.fetch(:uri, "https://api.deadmanssnitch.com")
36
- uri = URI.parse("#{api}/v1/api_key")
37
-
38
- timeout = options.fetch(:timeout, 5)
39
- http_options = {
40
- open_timeout: timeout,
41
- read_timeout: timeout,
42
- ssl_timeout: timeout,
43
- use_ssl: uri.scheme == "https",
44
- }
45
-
46
- Net::HTTP.start(uri.host, uri.port, http_options) do |http|
47
- request = Net::HTTP::Get.new(uri.path)
48
- request["User-Agent"] = user_agent
49
- request.basic_auth(username, password)
50
-
51
- response = http.request(request)
52
-
53
- if response.is_a?(Net::HTTPSuccess)
54
- JSON.parse(response.body)["api_key"]
55
- else
56
- error = JSON.parse(response.body)
57
-
58
- raise ::Snitcher::API::Error.new(error)
59
- end
60
- end
61
- end
62
-
63
- private
64
-
65
- def user_agent
66
- # RUBY_ENGINE was not added until 1.9.3
67
- engine = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : "Ruby"
68
-
69
- "Snitcher; #{engine}/#{RUBY_VERSION}; #{RUBY_PLATFORM}; v#{::Snitcher::VERSION}"
70
- end
71
12
  end
72
13
  end
73
14
 
@@ -1,3 +1,3 @@
1
1
  module Snitcher
2
- VERSION = "0.4.0.rc4"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,78 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- require "base64"
4
- require "securerandom"
5
-
6
3
  require "snitcher/api"
7
4
 
8
5
  describe Snitcher::API do
9
- describe "#get_key" do
10
- it "returns the api_key" do
11
- user = "alice@example.com"
12
- pass = "password"
13
-
14
- request = stub_request(:get, "https://api.deadmanssnitch.com/v1/api_key").
15
- with(basic_auth: [user, pass]).
16
- to_return({
17
- :body => '{"api_key": "_caeEiZXnEyEzXXYVh2NhQ"}',
18
- :status => 200
19
- })
20
-
21
- actual = Snitcher::API.get_key(user, pass)
22
-
23
- expect(actual).to eq("_caeEiZXnEyEzXXYVh2NhQ")
24
- expect(request).to have_been_made.once
25
- end
26
-
27
- it "raises an error if authentication failed" do
28
- user = "lol@notreally.horse"
29
- pass = "nope"
30
-
31
- request = stub_request(:get, "https://api.deadmanssnitch.com/v1/api_key").
32
- with(basic_auth: [user, pass]).
33
- to_return({
34
- :body => JSON.generate({
35
- :type => "sign_in_incorrect",
36
- :error => "Invalid email or password."
37
- }),
38
- :status => 401
39
- })
40
-
41
- expect {
42
- # Some shenanigans to verify type
43
- begin
44
- Snitcher::API.get_key(user, pass)
45
- rescue Snitcher::API::Error => e
46
- expect(e.type).to eq("sign_in_incorrect")
47
- expect(e.message).to eq("Invalid email or password.")
48
-
49
- raise e
50
- end
51
- }.to raise_error(Snitcher::API::AuthenticationError)
52
-
53
- expect(request).to have_been_made.once
54
- end
55
-
56
- it "raises Timeout::Error on a timeout" do
57
- stub_request(:any, "https://api.deadmanssnitch.com/v1/api_key").to_timeout
58
-
59
- expect {
60
- Snitcher::API.get_key("", "")
61
- }.to raise_error(Timeout::Error)
62
- end
63
-
64
- it "allows the API URI to be provided" do
65
- request = stub_request(:any, "dms.dev:4000/v1/api_key").
66
- with(basic_auth: ["user", "pass"]).
67
- to_return({
68
- :body => '{"api_key": "this_is_an_api_key"}',
69
- :status => 200
70
- })
71
-
72
- actual = Snitcher::API.get_key("user", "pass", uri: "http://dms.dev:4000")
73
-
74
- expect(actual).to eq("this_is_an_api_key")
75
- expect(request).to have_been_made.once
76
- end
77
- end
78
6
  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.rc4
4
+ version: 0.4.0
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-31 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,12 +85,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
85
  version: 1.9.3
86
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ">"
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: 1.3.1
90
+ version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 2.5.1
93
+ rubygems_version: 2.6.4
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Simple API client for deadmanssnitch.com