updown 0.1.0 → 0.2.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 +4 -4
- data/.gitignore +5 -0
- data/README.md +30 -25
- data/Rakefile +6 -1
- data/lib/updown/call.rb +18 -7
- data/lib/updown/check.rb +17 -12
- data/lib/updown/cli.rb +23 -2
- data/lib/updown/downtime.rb +4 -4
- data/lib/updown/version.rb +1 -1
- data/lib/updown.rb +1 -1
- data/updown.gemspec +6 -6
- metadata +23 -6
- data/Gemfile.lock +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd938c29ae89b14996a0c327baa66cf3bdfdade3
|
4
|
+
data.tar.gz: ebdefb7d0cefab8592785555cafce000d956d1ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c07ae3f8c77b886a00b0a29d7a8eb0403d7a8f229de9af85b5ad5edbd52128796bf355016ac8a8418dfe90540405250c75237f532c57aa77e496135abf049933
|
7
|
+
data.tar.gz: eafc6788479953c7043341daccd8b368f220f5705c706d2bdc4010c200a226d2749a6c42042c2286ef7d7829a82a3f6baf5cc4f6fc3a3eaea99ebcfec056912a
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Updown
|
2
2
|
|
3
|
-
A wrapper for the
|
3
|
+
A Ruby wrapper and CLI for the [updown.io](https://updown.io) API
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -10,15 +10,10 @@ Add this line to your application's Gemfile:
|
|
10
10
|
gem 'updown'
|
11
11
|
```
|
12
12
|
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
13
|
Or install it yourself as:
|
18
14
|
|
19
15
|
$ gem install updown
|
20
16
|
|
21
|
-
|
22
17
|
## Configuration
|
23
18
|
|
24
19
|
Set your API key
|
@@ -34,75 +29,85 @@ Updown.configuration.api_key = 'your_api_key'
|
|
34
29
|
|
35
30
|
Or set the `UPDOWN_API_KEY` environment variable
|
36
31
|
|
32
|
+
Find your API key in your [settings page](https://updown.io/settings/edit).
|
33
|
+
|
37
34
|
## Usage
|
38
35
|
|
39
36
|
List all your checks:
|
40
37
|
|
41
38
|
```ruby
|
42
39
|
Updown::Check.all
|
40
|
+
# => [<Updown::Check>, <Updown::Check>, … ]
|
43
41
|
```
|
44
42
|
|
45
|
-
|
43
|
+
List downtimes for a specific check (paginated, 100 per call):
|
46
44
|
|
47
45
|
```ruby
|
48
46
|
check.downtimes
|
47
|
+
# => [<Updown::Downtime>, <Updown::Downtime>, … ]
|
48
|
+
|
49
|
+
check.downtimes page: 2
|
50
|
+
# => [<Updown::Downtime>]
|
49
51
|
```
|
50
52
|
|
51
53
|
Create a new check:
|
52
54
|
|
53
55
|
```ruby
|
54
56
|
Updown::Check.create 'https://google.com'
|
57
|
+
# => <Updown::Check>
|
55
58
|
```
|
56
59
|
|
57
|
-
You can also set `period`
|
60
|
+
You can also set any parameters allowed by the API, like `enabled`, `published`, `period` or `apdex_t`:
|
58
61
|
|
59
62
|
```ruby
|
60
63
|
Updown::Check.create 'https://google.com', period: 30, published: true
|
64
|
+
# => <Updown::Check>
|
65
|
+
```
|
66
|
+
|
67
|
+
In case of validation errors, an `Updown::Error` will be raised:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
Updown::Check.create 'https://google.com', period: 45
|
71
|
+
# => Updown::Error: URL is already registered (given: "https://google.com"), Period is not included in the list (given: 45)
|
61
72
|
```
|
62
73
|
|
63
74
|
Update a specific check:
|
64
75
|
|
65
76
|
```ruby
|
66
77
|
check.update period: 30
|
78
|
+
# => <Updown::Check>
|
67
79
|
```
|
68
80
|
|
69
|
-
See more details about the options here: https://updown.io/api
|
70
|
-
|
71
81
|
Delete a specific check:
|
72
82
|
|
73
83
|
```ruby
|
74
84
|
check.destroy
|
85
|
+
# => true
|
75
86
|
```
|
76
87
|
|
77
|
-
|
88
|
+
Learn more about the API here: https://updown.io/api
|
78
89
|
|
79
|
-
|
90
|
+
## Command Line
|
80
91
|
|
92
|
+
This gem also comes with an `updown` shell command.
|
81
93
|
First, configure your API key:
|
82
94
|
|
83
|
-
|
84
|
-
$ updown configure YOUR_API_KEY
|
85
|
-
```
|
95
|
+
$ updown configure YOUR_API_KEY
|
86
96
|
|
87
97
|
See the status of your checks:
|
88
98
|
|
89
|
-
|
90
|
-
|
91
|
-
[
|
92
|
-
[up]
|
93
|
-
```
|
99
|
+
$ updown status
|
100
|
+
[up] rjis — https://google.com
|
101
|
+
[DOWN] bn94 — https://bing.com
|
102
|
+
[up] qwer — http://stackoverflow.com
|
94
103
|
|
95
104
|
Add a new check:
|
96
105
|
|
97
|
-
|
98
|
-
$ updown add https://google.com
|
99
|
-
```
|
100
|
-
|
106
|
+
$ updown add https://google.com
|
101
107
|
|
102
108
|
## Todo
|
103
109
|
|
104
110
|
- Write tests!
|
105
|
-
- Error handling
|
106
111
|
|
107
112
|
## Contributing
|
108
113
|
|
data/Rakefile
CHANGED
data/lib/updown/call.rb
CHANGED
@@ -1,28 +1,39 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Updown
|
2
|
-
|
4
|
+
Error = Class.new StandardError
|
5
|
+
|
6
|
+
module Call
|
3
7
|
|
4
8
|
def self.resource
|
5
9
|
RestClient::Resource.new 'https://updown.io/api/', headers: { 'X-API-KEY' => Updown.configuration.api_key }
|
6
10
|
end
|
7
11
|
|
8
12
|
def self.checks
|
9
|
-
|
13
|
+
process { Call.resource['checks'].get }
|
10
14
|
end
|
11
15
|
|
12
|
-
def self.downtimes(token)
|
13
|
-
|
16
|
+
def self.downtimes(token, filters={})
|
17
|
+
process { Call.resource["checks/#{token}/downtimes"].get(params: filters) }
|
14
18
|
end
|
15
19
|
|
16
20
|
def self.create_check(attributes={})
|
17
|
-
|
21
|
+
process { Call.resource['checks'].post(attributes) }
|
18
22
|
end
|
19
23
|
|
20
24
|
def self.update_check(token, attributes={})
|
21
|
-
|
25
|
+
process { Call.resource["checks/#{token}"].put(attributes) }
|
22
26
|
end
|
23
27
|
|
24
28
|
def self.destroy_check(token)
|
25
|
-
|
29
|
+
process { Call.resource["checks/#{token}"].delete }
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.process
|
33
|
+
JSON.parse yield
|
34
|
+
rescue RestClient::BadRequest, RestClient::Unauthorized, RestClient::ResourceNotFound => e
|
35
|
+
result = (JSON.parse(e.response) rescue {})
|
36
|
+
raise Updown::Error.new(result['error'] || e.reponse)
|
26
37
|
end
|
27
38
|
|
28
39
|
end
|
data/lib/updown/check.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Updown
|
2
2
|
class Check
|
3
|
-
attr_accessor :token, :
|
3
|
+
attr_accessor :token, :url, :last_status, :uptime, :down, :down_since, :error, :period, :apdex_t, :enabled, :published, :last_check_at, :next_check_at, :ssl_tested_at, :ssl_valid, :ssl_error
|
4
4
|
|
5
5
|
def self.all
|
6
6
|
Updown::Call.checks.map do |check|
|
@@ -8,36 +8,41 @@ module Updown
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.create(url,
|
12
|
-
Check.new Updown::Call.create_check(url: url
|
11
|
+
def self.create(url, attributes = {})
|
12
|
+
Check.new Updown::Call.create_check(attributes.merge(url: url))
|
13
13
|
end
|
14
14
|
|
15
15
|
def initialize(json)
|
16
16
|
@token = json['token']
|
17
|
-
@enabled = json['enabled']
|
18
17
|
@url = json['url']
|
18
|
+
@last_status = json['last_status']
|
19
|
+
@enabled = json['enabled']
|
19
20
|
@period = json['period']
|
20
21
|
@apdex_t = json['apdex_t']
|
21
22
|
@published = json['published']
|
22
23
|
@uptime = json['uptime']
|
23
24
|
@down = json['down']
|
24
25
|
@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']
|
26
|
+
@down_since = Time.parse(json['down_since']) if json['down_since']
|
27
|
+
@last_check_at = Time.parse(json['last_check_at']) if json['last_check_at']
|
28
|
+
@next_check_at = Time.parse(json['next_check_at']) if json['next_check_at']
|
29
|
+
if ssl = json['ssl']
|
30
|
+
@ssl_tested_at = Time.parse(ssl['tested_at']) if ssl['tested_at']
|
31
|
+
@ssl_valid = ssl['valid']
|
32
|
+
@ssl_error = ssl['error']
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
|
-
def downtimes
|
31
|
-
Downtime.find(@token)
|
36
|
+
def downtimes page: 1
|
37
|
+
Downtime.find(@token, page: page)
|
32
38
|
end
|
33
39
|
|
34
40
|
def update(attributes={})
|
35
|
-
Check.new Updown::Call.update_check(@token,
|
41
|
+
Check.new Updown::Call.update_check(@token, attributes)
|
36
42
|
end
|
37
43
|
|
38
44
|
def destroy
|
39
|
-
Updown::Call.destroy_check(@token)
|
40
|
-
nil
|
45
|
+
Updown::Call.destroy_check(@token)['deleted']
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
data/lib/updown/cli.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
String.disable_colorization(true) if not STDOUT.isatty
|
4
|
+
|
1
5
|
module Updown
|
2
6
|
class CLI < Thor
|
3
7
|
|
@@ -6,9 +10,24 @@ module Updown
|
|
6
10
|
configure_api_key
|
7
11
|
|
8
12
|
Updown::Check.all.each do |check|
|
9
|
-
status = check.
|
10
|
-
|
13
|
+
status = if !check.enabled
|
14
|
+
' ---- '.colorize(:light_black)
|
15
|
+
elsif check.down
|
16
|
+
'[DOWN]'.colorize(:light_red)
|
17
|
+
else
|
18
|
+
' [up] '.colorize(:light_green)
|
19
|
+
end
|
20
|
+
url = if check.ssl_valid == true
|
21
|
+
check.url.sub('https', 'https'.colorize(:light_green))
|
22
|
+
elsif check.ssl_valid == false
|
23
|
+
check.url.sub('https', 'https'.colorize(:light_red))
|
24
|
+
else
|
25
|
+
check.url
|
26
|
+
end
|
27
|
+
puts "#{status} #{check.token.colorize(:light_magenta)} #{"—".colorize(:light_black)} #{url}"
|
11
28
|
end
|
29
|
+
rescue Updown::Error => e
|
30
|
+
puts "Error: #{e}"
|
12
31
|
end
|
13
32
|
|
14
33
|
desc 'add URL [PERIOD]', 'add a new check'
|
@@ -17,6 +36,8 @@ module Updown
|
|
17
36
|
|
18
37
|
check = Updown::Check.create url, period: period
|
19
38
|
system "open https://updown.io/#{check.token}"
|
39
|
+
rescue Updown::Error => e
|
40
|
+
puts "Error: #{e}"
|
20
41
|
end
|
21
42
|
|
22
43
|
desc 'configure API_KEY', 'set your updown.io api key'
|
data/lib/updown/downtime.rb
CHANGED
@@ -2,16 +2,16 @@ module Updown
|
|
2
2
|
class Downtime
|
3
3
|
attr_accessor :error, :started_at, :ended_at, :duration
|
4
4
|
|
5
|
-
def self.find(token)
|
6
|
-
Updown::Call.downtimes(token).map do |downtime|
|
5
|
+
def self.find(token, page: 1)
|
6
|
+
Updown::Call.downtimes(token, page: page).map do |downtime|
|
7
7
|
Downtime.new downtime
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(json)
|
12
12
|
@error = json['error']
|
13
|
-
@started_at = json['started_at']
|
14
|
-
@ended_at = json['ended_at']
|
13
|
+
@started_at = Time.parse(json['started_at']) if json['started_at']
|
14
|
+
@ended_at = Time.parse(json['ended_at']) if json['ended_at']
|
15
15
|
@duration = json['duration']
|
16
16
|
end
|
17
17
|
|
data/lib/updown/version.rb
CHANGED
data/lib/updown.rb
CHANGED
data/updown.gemspec
CHANGED
@@ -6,10 +6,10 @@ require 'updown/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "updown"
|
8
8
|
spec.version = Updown::VERSION
|
9
|
-
spec.authors = ["Aske Hansen"]
|
10
|
-
spec.email = ["aske@deeco.dk"]
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{A wrapper for the
|
9
|
+
spec.authors = ["Aske Hansen", "Adrien Jarthon"]
|
10
|
+
spec.email = ["aske@deeco.dk", "me@adrienjarthon.com"]
|
11
|
+
spec.summary = %q{updown.io API wrapper}
|
12
|
+
spec.description = %q{A wrapper for the updown.io API}
|
13
13
|
spec.homepage = "https://github.com/askehansen/updown-ruby"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_dependency 'rest-client'
|
25
25
|
spec.add_dependency 'thor'
|
26
|
-
|
27
|
-
spec.
|
26
|
+
spec.add_dependency 'gem_config'
|
27
|
+
spec.add_dependency 'colorize'
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: updown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aske Hansen
|
8
|
+
- Adrien Jarthon
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-
|
12
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -80,16 +81,31 @@ dependencies:
|
|
80
81
|
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
83
|
-
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: colorize
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :runtime
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
description: A wrapper for the updown.io API
|
84
99
|
email:
|
85
100
|
- aske@deeco.dk
|
101
|
+
- me@adrienjarthon.com
|
86
102
|
executables:
|
87
103
|
- updown
|
88
104
|
extensions: []
|
89
105
|
extra_rdoc_files: []
|
90
106
|
files:
|
107
|
+
- ".gitignore"
|
91
108
|
- Gemfile
|
92
|
-
- Gemfile.lock
|
93
109
|
- LICENSE.txt
|
94
110
|
- README.md
|
95
111
|
- Rakefile
|
@@ -121,8 +137,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
137
|
version: '0'
|
122
138
|
requirements: []
|
123
139
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.2.2
|
125
141
|
signing_key:
|
126
142
|
specification_version: 4
|
127
|
-
summary:
|
143
|
+
summary: updown.io API wrapper
|
128
144
|
test_files: []
|
145
|
+
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
updown (0.1.0)
|
5
|
-
gem_config
|
6
|
-
rest-client
|
7
|
-
thor
|
8
|
-
|
9
|
-
GEM
|
10
|
-
remote: https://rubygems.org/
|
11
|
-
specs:
|
12
|
-
gem_config (0.3.1)
|
13
|
-
mime-types (2.4.3)
|
14
|
-
netrc (0.10.3)
|
15
|
-
rake (10.4.2)
|
16
|
-
rest-client (1.7.3)
|
17
|
-
mime-types (>= 1.16, < 3.0)
|
18
|
-
netrc (~> 0.7)
|
19
|
-
thor (0.19.1)
|
20
|
-
|
21
|
-
PLATFORMS
|
22
|
-
ruby
|
23
|
-
|
24
|
-
DEPENDENCIES
|
25
|
-
bundler (~> 1.7)
|
26
|
-
rake (~> 10.0)
|
27
|
-
updown!
|