snitcher 0.2.0 → 0.3.0

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: a8c248e10b01d23be566aa4d4f0f63c6536b672d
4
- data.tar.gz: f3f2054fce497f55b4abcb15be75ebba1b8d1532
3
+ metadata.gz: dfa2c9e77f2a460c686bc38cb48b271c32276baf
4
+ data.tar.gz: cb0fe423892d35aec921787bb619e899231148d5
5
5
  SHA512:
6
- metadata.gz: 86e2b8428cf2f239d1e6dd3eb9bc005e11729f1156c208ec5d3906d379f121748a2fe0179d9ed8da68bbfbc9e7a082d580af0abbdd4ec66ebcf502c9f24c2948
7
- data.tar.gz: b0701107c63002a730162abb24d197d9aa3740d85e09956eb86111cd5d2fdfa1ca01c3ea4790226f899b570839fcbba74c9711db0688c56102d30a7afc09e6a9
6
+ metadata.gz: da4d0919667bc3e3ee37316368c5980fb06e34d9c388f9145fdf58a0cfc4e1229e425842150f32b09bfe7b54e7e00b4f7a6f8989483fbae7338bd8a247dddb58
7
+ data.tar.gz: 0ee626c061780cfb8d65ff0b68ab7fd9e0226878b11c0ca777393255a4672485c3b3d35581e7214a36e2606cfdda3132de228eeb3536f81740e67020aa558610
@@ -1,3 +1,9 @@
1
+ ## 0.3.0 / 2014-10-14
2
+
3
+ * [FEATURE] Add support for the message parameter during check-in
4
+ * [FEATUER] Add support for timeouts during check-in
5
+ * [ENHANCEMENT] Improve documentation
6
+
1
7
  ## 0.2.0 / 2014-01-20
2
8
 
3
9
  * [FEATURE] Add "snitch" executable ([@laserlemon](https://github.com/laserlemon))
data/bin/snitch CHANGED
@@ -3,6 +3,8 @@
3
3
  require "optparse"
4
4
  require "snitcher"
5
5
 
6
+ params = {}
7
+
6
8
  option_parser = OptionParser.new do |parser|
7
9
  parser.banner = "Usage: snitch TOKEN"
8
10
 
@@ -10,6 +12,10 @@ option_parser = OptionParser.new do |parser|
10
12
  puts parser.help
11
13
  exit 0
12
14
  end
15
+
16
+ parser.on("-m", "--message", "Include a message with the check-in") do |msg|
17
+ params[:message] = msg
18
+ end
13
19
  end
14
20
 
15
21
  token = ARGV[0]
@@ -17,7 +23,11 @@ token = ARGV[0]
17
23
  if token
18
24
  print "Snitching #{token} ... "
19
25
 
20
- if Snitcher.snitch(token)
26
+ opts = {
27
+ :message => params[:message]
28
+ }
29
+
30
+ if Snitcher.snitch(token, opts)
21
31
  puts "succeeded."
22
32
  exit 0
23
33
  else
@@ -1,13 +1,43 @@
1
+ require "uri"
2
+ require "timeout"
1
3
  require "net/http"
2
4
 
3
5
  module Snitcher
4
6
  extend self
5
7
 
6
- def snitch(token)
7
- http = Net::HTTP.new("nosnch.in", 443)
8
- http.use_ssl = true
8
+ # Public: Check-in to Deadman's Snitch
9
+ #
10
+ # token - The Snitch token given by Deadman's Snitch (see the install page).
11
+ # opts - The hash of optional parameters that can be given during check-in:
12
+ # :message - Text message limited to ~250 characters.
13
+ # :timeout - Number of seconds to set as connect and read timeout.
14
+ #
15
+ # Examples
16
+ #
17
+ # Snitch.snitch("c2354d53d2")
18
+ # # => true
19
+ #
20
+ # Returns true if the check-in succeeded or false if it failed
21
+ def snitch(token, opts = {})
22
+ uri = URI.parse("https://nosnch.in/#{token}")
23
+ timeout = opts.fetch(:timeout, 2)
9
24
 
10
- response = http.request(Net::HTTP::Get.new("/#{token}"))
11
- response.is_a?(Net::HTTPSuccess)
25
+ opts = {
26
+ :open_timeout => timeout,
27
+ :read_timeout => timeout,
28
+ :ssl_timeout => timeout,
29
+ :use_ssl => uri.port == 443
30
+ }
31
+
32
+ Net::HTTP.start(uri.host, uri.port, opts) do |http|
33
+ if message = opts[:message]
34
+ uri.query = URI.encode_www_form(:m => message)
35
+ end
36
+
37
+ response = http.request(Net::HTTP::Get.new(uri.request_uri))
38
+ response.is_a?(Net::HTTPSuccess)
39
+ end
40
+ rescue ::Timeout::Error
41
+ false
12
42
  end
13
43
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "snitcher"
5
- spec.version = "0.2.0"
5
+ spec.version = "0.3.0"
6
6
 
7
7
  spec.author = "Collective Idea"
8
8
  spec.email = "info@collectiveidea.com"
@@ -35,6 +35,24 @@ describe Snitcher do
35
35
  expect(Snitcher.snitch(token)).to eq(false)
36
36
  end
37
37
  end
38
+
39
+ describe "with message" do
40
+ it "includes the message as a query param" do
41
+ Snitcher.snitch(token, :message => "A thing just happened")
42
+
43
+ expect(a_request(:get, "https://nosnch.in/#{token}?m=A%20thing%20just%20happened"))
44
+ end
45
+ end
46
+
47
+ describe "timeout" do
48
+ before do
49
+ stub_request(:get, "https://nosnch.in/#{token}").to_raise(::Timeout::Error)
50
+ end
51
+
52
+ it "returns false when timed out" do
53
+ expect(Snitcher.snitch(token)).to eq(false)
54
+ end
55
+ end
38
56
  end
39
57
 
40
58
  describe "inclusion" 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.2.0
4
+ version: 0.3.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: 2014-01-20 00:00:00.000000000 Z
11
+ date: 2014-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  requirements: []
82
82
  rubyforge_project:
83
- rubygems_version: 2.2.0
83
+ rubygems_version: 2.2.2
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: Simple API client for deadmanssnitch.com