dashy4r 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA512:
3
+ data.tar.gz: c8a60d2428fb63c99a911c646530a6184b621e185f1a46e7c45bdd2a755ab221e540af693b5c3bdddea576ac30ec48955cc2b6c2f74ffd8828daf8e54a856989
4
+ metadata.gz: 236d89dd633c33fe215e5a8ac661976e85a2a397f143d1edb68168fb5f4cd208a9084a187b17bdc879410f27b0aa4ff026040a8b95a1b03d53cd0e4fcb9bfe85
5
+ SHA1:
6
+ data.tar.gz: 37201da6203a0367793c142503d9d67c2c033b4f
7
+ metadata.gz: 97eb5c41d2bd93bf6126fe83513979839806c318
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem 'system_timer', '~> 1.2.4'
5
+ gem 'mime-types', '~> 1.16'
6
+ gem 'rest-client', '~> 1.6.7'
7
+ gem 'nokogiri', '~> 1.5.10'
8
+ gem "bundler", "~> 1.0"
9
+ gem "jeweler", "~> 2.0.1"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ faraday (0.8.9)
7
+ multipart-post (~> 1.2.0)
8
+ git (1.2.6)
9
+ github_api (0.10.1)
10
+ addressable
11
+ faraday (~> 0.8.1)
12
+ hashie (>= 1.2)
13
+ multi_json (~> 1.4)
14
+ nokogiri (~> 1.5.2)
15
+ oauth2
16
+ hashie (2.1.1)
17
+ highline (1.6.21)
18
+ jeweler (2.0.1)
19
+ builder
20
+ bundler (>= 1.0)
21
+ git (>= 1.2.5)
22
+ github_api
23
+ highline (>= 1.6.15)
24
+ nokogiri (>= 1.5.10)
25
+ rake
26
+ rdoc
27
+ json (1.8.1)
28
+ jwt (1.0.0)
29
+ mime-types (1.25.1)
30
+ multi_json (1.10.1)
31
+ multi_xml (0.5.5)
32
+ multipart-post (1.2.0)
33
+ nokogiri (1.5.11)
34
+ oauth2 (0.9.4)
35
+ faraday (>= 0.8, < 0.10)
36
+ jwt (~> 1.0)
37
+ multi_json (~> 1.3)
38
+ multi_xml (~> 0.5)
39
+ rack (~> 1.2)
40
+ rack (1.5.2)
41
+ rake (10.3.2)
42
+ rdoc (4.1.1)
43
+ json (~> 1.4)
44
+ rest-client (1.6.7)
45
+ mime-types (>= 1.16)
46
+ system_timer (1.2.4)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ bundler (~> 1.0)
53
+ jeweler (~> 2.0.1)
54
+ mime-types (~> 1.16)
55
+ nokogiri (~> 1.5.10)
56
+ rest-client (~> 1.6.7)
57
+ system_timer (~> 1.2.4)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Alabê Duarte
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ dashy4r
2
+ =======
3
+
4
+ dashy4r is a gem that helps you use ruby to integrate with [Dashy](https://github.com/thoughtworks/dashy)
5
+
6
+ ## Documentation
7
+
8
+ ### Configuration file
9
+ Create a file dashy_config.yml
10
+ ```yaml
11
+ app_id: <YOUR_APP_ID>
12
+ url: <YOUR_DASHY_URL>
13
+ timeout: <YOUR_TIMEOUT_IN_SECONDS>
14
+ ```
15
+
16
+ ### Enable configuration
17
+ ```ruby
18
+ Dashy::Base.enable_with_config '<path for your dashy_config.yml>'
19
+ ```
20
+
21
+ ### Usage
22
+
23
+ Simplest way of reporting status. It will fail if any exception is raised
24
+ ```ruby
25
+ Dashy::Runner.run_and_report_status_for do
26
+ # your code goes here
27
+ run_something_that_you_want_to_report_status
28
+ end
29
+ ```
30
+
31
+ A more complete Runner setup where you can set options and also validate the response the response is the return of your block to run
32
+ ```ruby
33
+ Dashy::Runner.config_and_run do |runner|
34
+ runner.with_options :environment => 'My Environment', :endpoint => 'My Web Service'
35
+ runner.block_to_run do
36
+ # your code goes here
37
+ run_something_that_you_want_to_report_status_and_returns_something
38
+ end
39
+ runner.valid_response? do |response|
40
+ # your code goes here
41
+ validates_response_and_returns_a_boolean(response)
42
+ end
43
+ end
44
+ ```
45
+
46
+ ### Very Important
47
+ #### Works only with ruby 1.8.7
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "dashy4r"
18
+ gem.homepage = "http://github.com/fabiopereira/dashy4r"
19
+ gem.license = "MIT"
20
+ gem.summary = "dashy4r is a gem that helps you use ruby to integrate with [Dashy](https://github.com/thoughtworks/dashy)"
21
+ gem.description = "Intercept endpoint calls to notify a Dash server about endpoint status"
22
+ gem.email = "aduarte@thoughtworks.com"
23
+ gem.authors = ["ThoughtWorks"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "dashy4r #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/dashy/base.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Dashy
2
+ class Base
3
+
4
+ def self.enable_with_config config_file_path
5
+ @config = Dashy::ConfigYml.new config_file_path
6
+ @enabled = true
7
+ end
8
+
9
+ def self.enabled?
10
+ @enabled
11
+ end
12
+
13
+ def self.config
14
+ @config
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ require 'yaml'
2
+
3
+ module Dashy
4
+ class ConfigYml
5
+ DEFAULT_TIMEOUT = 5
6
+
7
+ def initialize file_path
8
+ @yaml ||= YAML.load_file(file_path)
9
+ end
10
+
11
+ def app_id
12
+ @yaml['app_id']
13
+ end
14
+
15
+ def url
16
+ @yaml['url']
17
+ end
18
+
19
+ def timeout
20
+ @yaml['timeout'] || DEFAULT_TIMEOUT
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'system_timer'
3
+ require 'rest_client'
4
+
5
+ module Dashy
6
+ class RestInterface
7
+
8
+ def self.report_status options = {}
9
+ return unless Dashy::Base.enabled?
10
+ begin
11
+ config = Dashy::Base.config
12
+ # TODO: change SystemTimer to use Timeout::timeout instead for ruby ~>1.9
13
+ SystemTimer.timeout_after(config.timeout) do
14
+ RestClient.post "#{config.url}/requests/#{config.app_id}", :request => options
15
+ end
16
+ rescue => e
17
+ puts e
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,52 @@
1
+ module Dashy
2
+ class Runner
3
+
4
+ def self.run_and_report_status_for &block
5
+ Dashy::Runner.config_and_run do |runner|
6
+ runner.block_to_run &block
7
+ end
8
+ end
9
+
10
+ def self.config_and_run
11
+ runner = Dashy::Runner.new
12
+ yield runner
13
+ runner.run
14
+ end
15
+
16
+ def block_to_run &block
17
+ @block_to_run = block
18
+ end
19
+
20
+ def with_options options = {}
21
+ @options = options
22
+ end
23
+
24
+ def valid_response? &block
25
+ @valid_response_block = block
26
+ end
27
+
28
+ def run
29
+ raise 'Please before running Dashy you need to set the block_to_run' unless @block_to_run
30
+ begin
31
+ response = @block_to_run.call
32
+ Dashy::RestInterface.report_status(({:success => valid_response_after_calling_block?(response)}).merge(extra_options))
33
+ return response
34
+ rescue StandardError => e
35
+ Dashy::RestInterface.report_status(({:success => false}).merge(extra_options))
36
+ raise
37
+ end
38
+ end
39
+
40
+
41
+ protected
42
+ def valid_response_after_calling_block? response
43
+ return true unless @valid_response_block
44
+ @valid_response_block.call response
45
+ end
46
+
47
+ def extra_options
48
+ @options || {}
49
+ end
50
+
51
+ end
52
+ end
data/lib/dashy4r.rb ADDED
@@ -0,0 +1,10 @@
1
+ # require 'dashy/base'
2
+ # require 'dashy/config_yml'
3
+ # require 'dashy/rest_interface'
4
+ # require 'dashy/runner'
5
+
6
+ require "#{File.dirname(__FILE__)}/dashy/base"
7
+ require "#{File.dirname(__FILE__)}/dashy/config_yml"
8
+ require "#{File.dirname(__FILE__)}/dashy/rest_interface"
9
+ require "#{File.dirname(__FILE__)}/dashy/runner"
10
+
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dashy4r
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ThoughtWorks
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2014-06-03 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.4
20
+ version_requirements: *id001
21
+ prerelease: false
22
+ type: :development
23
+ name: system_timer
24
+ - !ruby/object:Gem::Dependency
25
+ requirement: &id002 !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: "1.16"
30
+ version_requirements: *id002
31
+ prerelease: false
32
+ type: :development
33
+ name: mime-types
34
+ - !ruby/object:Gem::Dependency
35
+ requirement: &id003 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: 1.6.7
40
+ version_requirements: *id003
41
+ prerelease: false
42
+ type: :development
43
+ name: rest-client
44
+ - !ruby/object:Gem::Dependency
45
+ requirement: &id004 !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: 1.5.10
50
+ version_requirements: *id004
51
+ prerelease: false
52
+ type: :development
53
+ name: nokogiri
54
+ - !ruby/object:Gem::Dependency
55
+ requirement: &id005 !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: "1.0"
60
+ version_requirements: *id005
61
+ prerelease: false
62
+ type: :development
63
+ name: bundler
64
+ - !ruby/object:Gem::Dependency
65
+ requirement: &id006 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.0.1
70
+ version_requirements: *id006
71
+ prerelease: false
72
+ type: :development
73
+ name: jeweler
74
+ description: Intercept endpoint calls to notify a Dash server about endpoint status
75
+ email: aduarte@thoughtworks.com
76
+ executables: []
77
+
78
+ extensions: []
79
+
80
+ extra_rdoc_files:
81
+ - LICENSE.txt
82
+ - README.md
83
+ files:
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - LICENSE.txt
87
+ - README.md
88
+ - Rakefile
89
+ - VERSION
90
+ - lib/dashy/base.rb
91
+ - lib/dashy/config_yml.rb
92
+ - lib/dashy/rest_interface.rb
93
+ - lib/dashy/runner.rb
94
+ - lib/dashy4r.rb
95
+ homepage: http://github.com/fabiopereira/dashy4r
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - &id007
108
+ - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - *id007
114
+ requirements: []
115
+
116
+ rubyforge_project:
117
+ rubygems_version: 2.0.14
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: dashy4r is a gem that helps you use ruby to integrate with [Dashy](https://github.com/thoughtworks/dashy)
121
+ test_files: []
122
+