updown 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aba4862ff0038ce2d2371c6bf3bc0366d05f1c23
4
+ data.tar.gz: c8b42e77da15cbe65567c89d7a7b2ddde4c7ff1e
5
+ SHA512:
6
+ metadata.gz: 68cce5ca5b657a1a34a1d8376884f56fad59f81aa1e33a649c806ba589279361e004ddb196970240a7b8cb68a9707b7426e10e265a1f3ed2302006e45b58ff40
7
+ data.tar.gz: e2bc74df3f6b5ef0eb398c1b0540f320f063a98b324c02d8c7a89af90eb88a27937d99afd3059f226d21b81479d788ce6442f56ec3d35653748ce0cf3d0079c7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in updown.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ updown (0.0.1)
5
+ gem_config
6
+ rest-client
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ gem_config (0.3.1)
12
+ mime-types (2.4.3)
13
+ netrc (0.10.3)
14
+ rake (10.4.2)
15
+ rest-client (1.7.3)
16
+ mime-types (>= 1.16, < 3.0)
17
+ netrc (~> 0.7)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.7)
24
+ rake (~> 10.0)
25
+ updown!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Aske Hansen
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,83 @@
1
+ # Updown
2
+
3
+ A wrapper for the Updown.io API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'updown'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install updown
20
+
21
+
22
+ ## Configuration
23
+
24
+ Set your API key
25
+
26
+ ```ruby
27
+ # config/initializers/updown.rb
28
+ Updown.configure do |config|
29
+ config.api_key = 'your_api_key'
30
+ end
31
+ # or
32
+ Updown.configuration.api_key = 'your_api_key'
33
+ ```
34
+
35
+ Or set the `UPDOWN_API_KEY` environment variable
36
+
37
+ ## Usage
38
+
39
+ List all your checks:
40
+
41
+ ```ruby
42
+ Updown::Check.all
43
+ ```
44
+
45
+ See downtimes for a specific check:
46
+
47
+ ```ruby
48
+ check.downtimes
49
+ ```
50
+
51
+ Create a new check:
52
+
53
+ ```ruby
54
+ Updown::Check.create 'https://google.com'
55
+ ```
56
+
57
+ You can also set `period` and `published`:
58
+
59
+ ```ruby
60
+ Updown::Check.create 'https://google.com', period: 30, published: true
61
+ ```
62
+
63
+ Update a specific check:
64
+
65
+ ```ruby
66
+ check.update period: 30
67
+ ```
68
+
69
+ See more details about the options here: https://updown.io/api
70
+
71
+ Delete a specific check:
72
+
73
+ ```ruby
74
+ check.destroy
75
+ ```
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it ( https://github.com/[my-github-username]/updown/fork )
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,29 @@
1
+ module Updown
2
+ class Call
3
+
4
+ def self.resource
5
+ RestClient::Resource.new 'https://updown.io/api/', headers: { 'X-API-KEY' => Updown.configuration.api_key }
6
+ end
7
+
8
+ def self.checks
9
+ JSON.parse Call.resource['checks'].get
10
+ end
11
+
12
+ def self.downtimes(token)
13
+ JSON.parse Call.resource["checks/#{token}/downtimes"].get
14
+ end
15
+
16
+ def self.create_check(attributes={})
17
+ JSON.parse Call.resource['checks'].post(attributes)
18
+ end
19
+
20
+ def self.update_check(token, attributes={})
21
+ JSON.parse Call.resource["checks/#{token}"].put(attributes)
22
+ end
23
+
24
+ def self.destroy_check(token)
25
+ JSON.parse Call.resource["checks/#{token}"].delete
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,43 @@
1
+ module Updown
2
+ class Check
3
+ attr_accessor :token, :enabled, :url, :period, :apdex_t, :published, :uptime, :down, :error, :down_since, :last_check_at, :next_check_at
4
+
5
+ def self.all
6
+ Updown::Call.checks.map do |check|
7
+ Check.new check
8
+ end
9
+ end
10
+
11
+ def self.create(url, period: 60, published: false)
12
+ Check.new Updown::Call.create_check(url: url, period: period, published: published)
13
+ end
14
+
15
+ def initialize(json)
16
+ @token = json['token']
17
+ @enabled = json['enabled']
18
+ @url = json['url']
19
+ @period = json['period']
20
+ @apdex_t = json['apdex_t']
21
+ @published = json['published']
22
+ @uptime = json['uptime']
23
+ @down = json['down']
24
+ @error = json['error']
25
+ @down_since = json['down_since']
26
+ @last_check_at = json['last_check_at']
27
+ @next_check_at = json['next_check_at']
28
+ end
29
+
30
+ def downtimes
31
+ Downtime.find(@token)
32
+ end
33
+
34
+ def update(attributes={})
35
+ Check.new Updown::Call.update_check(@token, url: url, period: period, published: published)
36
+ end
37
+
38
+ def destroy
39
+ Updown::Call.destroy_check(@token)
40
+ nil
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ module Updown
2
+ class Downtime
3
+ attr_accessor :error, :started_at, :ended_at, :duration
4
+
5
+ def self.find(token)
6
+ Updown::Call.downtimes(token).map do |downtime|
7
+ Downtime.new downtime
8
+ end
9
+ end
10
+
11
+ def initialize(json)
12
+ @error = json['error']
13
+ @started_at = json['started_at']
14
+ @ended_at = json['ended_at']
15
+ @duration = json['duration']
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Updown
2
+ VERSION = "0.0.1"
3
+ end
data/lib/updown.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'rest-client'
2
+ require 'gem_config'
3
+ require 'updown/version'
4
+ require 'updown/check'
5
+ require 'updown/downtime'
6
+ require 'updown/call'
7
+
8
+ module Updown
9
+ include GemConfig::Base
10
+
11
+ with_configuration do
12
+ has :api_key, classes: String, default: ENV['UPDOWN_API_KEY'].to_s
13
+ end
14
+
15
+ end
data/updown.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'updown/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "updown"
8
+ spec.version = Updown::VERSION
9
+ spec.authors = ["Aske Hansen"]
10
+ spec.email = ["aske@deeco.dk"]
11
+ spec.summary = %q{Updown.io wrapper}
12
+ spec.description = %q{A wrapper for the Updown.io API}
13
+ spec.homepage = "https://github.com/askehansen/updown-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_dependency 'rest-client'
25
+
26
+ spec.add_runtime_dependency 'gem_config'
27
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: updown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aske Hansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gem_config
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A wrapper for the Updown.io API
70
+ email:
71
+ - aske@deeco.dk
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/updown.rb
82
+ - lib/updown/call.rb
83
+ - lib/updown/check.rb
84
+ - lib/updown/downtime.rb
85
+ - lib/updown/version.rb
86
+ - updown.gemspec
87
+ homepage: https://github.com/askehansen/updown-ruby
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.5
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Updown.io wrapper
111
+ test_files: []