im-alive 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b3fcfe6ed955de5b393d957655893c2662b8697
4
+ data.tar.gz: fbf714c7cc2d2eab0ea47f1b81f02fdec162cee1
5
+ SHA512:
6
+ metadata.gz: 451a7d20d8a00e12e3842b1f1de11b40d64ea6e9818306dbc7c6daa6bb4453629e1514f8777c7e357d7f53a043d56aa42c5fc18d47a4696c261d6d3c2607c758
7
+ data.tar.gz: 270b56a1d34fa1b6d982cb632cd8f65ea6ee75c37b112d1841c3c8f53c52118f52f71ed05f142ea634a2935b35658f248f68a67a1ca6e4770292d5b05f61d2bb
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in im-alive.gemspec
4
+ gemspec
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 David Griffiths
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Im::Alive
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'im-alive'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install im-alive
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/alphasights/im-alive/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push "spec"
6
+ t.test_files = FileList['spec/**/*_spec.rb']
7
+ end
data/bin/im-alive ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/im_alive.rb'
4
+
5
+ unless ARGV[1]
6
+ puts "Provide DB document URL and document key (id)"
7
+ puts "Example: imalive https://user.@pass.heroku.cloudant.com/backups birdie_weekly"
8
+ exit -1
9
+ end
10
+
11
+ logger = ImAlive::Log.new(ARGV[0], ARGV[1])
12
+ logger.send
data/im-alive.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'im_alive/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "im-alive"
8
+ spec.version = ImAlive::VERSION
9
+ spec.authors = ["David Griffiths"]
10
+ spec.email = ["david.griffiths@alphasights.com"]
11
+ spec.summary = %q{Sends a quick heartbeat timestamp to a document store.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "minitest", "~> 5.5"
21
+ spec.add_development_dependency "timecop"
22
+
23
+ spec.add_runtime_dependency "couchrest", ["~> 2.0.0.rc2"]
24
+ end
data/lib/im_alive.rb ADDED
@@ -0,0 +1,5 @@
1
+ require_relative "im_alive/version"
2
+ require_relative "im_alive/log"
3
+
4
+ module ImAlive
5
+ end
@@ -0,0 +1,36 @@
1
+ require 'couchrest'
2
+
3
+ module ImAlive
4
+ class Log
5
+ def initialize(db_uri, document_id)
6
+ @db_uri = db_uri
7
+ @document_id = document_id
8
+ end
9
+
10
+ def send
11
+ doc = begin
12
+ db.get(document_id)
13
+ rescue CouchRest::NotFound
14
+ {'_id' => document_id}
15
+ end
16
+ doc.merge!(timestamps)
17
+ db.save_doc(doc)
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :db_uri, :document_id
23
+
24
+ def db
25
+ @db ||= CouchRest.database!(db_uri)
26
+ end
27
+
28
+ def timestamps
29
+ {
30
+ "timestamp" => Time.now.utc.to_s,
31
+ "js_timestamp" => Time.now.utc.to_i,
32
+ }
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module ImAlive
2
+ VERSION = '0.1.1'
3
+ end
data/spec/log_spec.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module ImAlive
4
+ describe Log do
5
+ it 'sends the correct payload to the specfied url' do
6
+ rest_client = MiniTest::Mock.new
7
+ url = 'http://document.store/backups'
8
+ logger = Log.new(url, 'polly')
9
+
10
+ Timecop.freeze Time.utc(2015, 02, 1, 0, 0, 0) do
11
+ logger.stub :db, rest_client do
12
+ rest_client.expect :get, {}, ['polly']
13
+ rest_client.expect :save_doc, {}, [{"timestamp" => "2015-02-01 00:00:00 UTC", "js_timestamp" => 1422748800}]
14
+
15
+ logger.send
16
+
17
+ rest_client.verify
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ require 'im_alive'
2
+ require 'minitest/autorun'
3
+ require 'minitest/pride'
4
+ require 'timecop'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: im-alive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - David Griffiths
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: timecop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: couchrest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0.rc2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0.rc2
55
+ description:
56
+ email:
57
+ - david.griffiths@alphasights.com
58
+ executables:
59
+ - im-alive
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/im-alive
69
+ - im-alive.gemspec
70
+ - lib/im_alive.rb
71
+ - lib/im_alive/log.rb
72
+ - lib/im_alive/version.rb
73
+ - spec/log_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Sends a quick heartbeat timestamp to a document store.
99
+ test_files:
100
+ - spec/log_spec.rb
101
+ - spec/spec_helper.rb
102
+ has_rdoc: