status_page_vi 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
+ SHA256:
3
+ metadata.gz: 56434be78783d95fdd426cbf92fac4f3e4fc6fa34244e05c08830535e16af2bc
4
+ data.tar.gz: 896aeddd6c469f79ef82ca72b4fb1afa03f4ee476648296f1292a55c370a1bd8
5
+ SHA512:
6
+ metadata.gz: d9c1894c3db0ee37823d49fa6ccda6b340de5ef35a120bdceeca4706b0837df0e681f49de95d51afda62e6d90b943da75e56e904f86e788209e260f5a4691066
7
+ data.tar.gz: 33dc8f01d5e6e7f10fa3a390ad1eb5a30729f75dc88255ec7b7e3d1918ac8781906b8e21f59558f8ff40355a87473399c4684bfc7f0ce3fc693bbb65e61bac72
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /cache/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.1
7
+ before_install: gem install bundler -v 1.17.1
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in status_page_vi.gemspec
6
+ gemspec
7
+ gem 'pry'
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ status_page_vi (0.1.0)
5
+ nokogiri (= 1.8.5)
6
+ thor (= 0.20.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ coderay (1.1.2)
12
+ diff-lcs (1.3)
13
+ method_source (0.9.2)
14
+ mini_portile2 (2.3.0)
15
+ nokogiri (1.8.5)
16
+ mini_portile2 (~> 2.3.0)
17
+ pry (0.12.2)
18
+ coderay (~> 1.1.0)
19
+ method_source (~> 0.9.0)
20
+ rake (10.5.0)
21
+ rspec (3.3.0)
22
+ rspec-core (~> 3.3.0)
23
+ rspec-expectations (~> 3.3.0)
24
+ rspec-mocks (~> 3.3.0)
25
+ rspec-core (3.3.2)
26
+ rspec-support (~> 3.3.0)
27
+ rspec-expectations (3.3.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.3.0)
30
+ rspec-mocks (3.3.2)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.3.0)
33
+ rspec-support (3.3.0)
34
+ thor (0.20.3)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler (~> 1.17)
41
+ pry
42
+ rake (~> 10.0)
43
+ rspec (= 3.3)
44
+ status_page_vi!
45
+
46
+ BUNDLED WITH
47
+ 1.17.1
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # StatusPageVi
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/status_page_vi`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'status_page_vi'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install status_page_vi
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/status_page_vi.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "status_page_vi"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "status_page_vi"
4
+
5
+ StatusPageVi::CLI.start(ARGV)
@@ -0,0 +1,13 @@
1
+ module StatusPageVi
2
+ class InvalidResource < StandardError
3
+ def initialize(msg = "Resource is invalid, shoud be one of: #{RESOURCES.keys.join(" ,")}.")
4
+ super(msg)
5
+ end
6
+ end
7
+
8
+ class InvalidBackup < StandardError
9
+ def initialize(msg = "Backup file is invalid")
10
+ super(msg)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,56 @@
1
+ module StatusPageVi
2
+ module Recordable
3
+ def self.included(klass)
4
+ klass.extend(RecordableClassMethods)
5
+ end
6
+
7
+ module RecordableClassMethods
8
+ def save(service)
9
+ data = collection.merge(service)
10
+ update_storrage(data)
11
+
12
+ @collection = nil
13
+ end
14
+
15
+ def list
16
+ collection.map do |timestamp, options|
17
+ self.new(timestamp, options)
18
+ end
19
+ end
20
+
21
+ def cache_file_path
22
+ "#{__dir__}/../../../cache/#{self}.json"
23
+ end
24
+
25
+ def update_storrage(data)
26
+ File.delete(cache_file_path) if File.exists?(cache_file_path)
27
+ write_to_service_file(data)
28
+ end
29
+
30
+ private
31
+
32
+ def collection
33
+ @collection ||= begin
34
+ JSON.parse(File.read cache_file_path)
35
+ rescue Errno::ENOENT
36
+ {}
37
+ end
38
+ end
39
+
40
+ def write_to_service_file(data)
41
+ Dir.mkdir("cache") unless Dir.exists?("cache")
42
+ File.open(cache_file_path, "w") { |file| file.write(data.to_json) }
43
+ end
44
+ end
45
+
46
+ def initialize(timestamp = nil, options = {})
47
+ self.timestamp = timestamp
48
+ self.options = options
49
+ end
50
+
51
+ def save
52
+ self.class.save(self.to_h)
53
+ self
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,41 @@
1
+ require "status_page_vi/modules/recordable"
2
+
3
+ module StatusPageVi
4
+ class BaseResource
5
+ include StatusPageVi::Recordable
6
+
7
+ def self.pull
8
+ resource = self.new
9
+ resource.call
10
+ resource.save
11
+
12
+ puts resource
13
+ end
14
+
15
+ def self.print_history
16
+ puts "-------#{self}-------"
17
+ self.list.each { |resource| puts resource }
18
+ puts
19
+ end
20
+
21
+ attr_accessor :timestamp, :options, :scraper
22
+
23
+ def call
24
+ self.scraper = Nokogiri::HTML(open(self.class::URL))
25
+ get_data
26
+ end
27
+
28
+ def get_data
29
+ self.timestamp = Time.now
30
+ self.options["status"] = stats_good? ? "good" : "bad"
31
+ end
32
+
33
+ def to_h
34
+ { self.timestamp => { "status" => self.options["status"] } }
35
+ end
36
+
37
+ def to_s
38
+ "#{self.class::URL}: #{self.timestamp} : #{self.options["status"]}"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,12 @@
1
+ module StatusPageVi
2
+ class BitBucket < BaseResource
3
+ URL = "https://status.bitbucket.org".freeze
4
+
5
+ private
6
+
7
+ def stats_good?
8
+ self.scraper.css("span.status.font-large").first.text ==
9
+ "\n All Systems Operational\n "
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module StatusPageVi
2
+ class CloudFlareStatus < BaseResource
3
+ URL = "https://www.cloudflarestatus.com".freeze
4
+
5
+ private
6
+
7
+ def stats_good?
8
+ self.scraper.css("span.status.font-large").first.text ==
9
+ "\n All Systems Operational\n "
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module StatusPageVi
2
+ class Github < BaseResource
3
+ URL = "https://status.github.com/messages".freeze
4
+
5
+ private
6
+
7
+ def stats_good?
8
+ self.scraper.css(".logo a img").attr("src").value == "/images/logo-good.png"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ module StatusPageVi
2
+ class RubyGems < BaseResource
3
+ URL = "https://status.rubygems.org".freeze
4
+
5
+ private
6
+
7
+ def stats_good?
8
+ self.scraper.css(".page-status.status-none span").first.text ==
9
+ "\n All Systems Operational\n "
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module StatusPageVi
2
+ class BackupService < BaseService
3
+ def self.backup(path, resource)
4
+ resources(resource).each do |resource|
5
+ FileUtils.cp(
6
+ resource.cache_file_path,
7
+ "#{path}/#{resource.name.split("::").last}.json"
8
+ )
9
+ end
10
+ end
11
+
12
+ def self.restore(path_to_file)
13
+ validator = StatusPageVi::BackupFileValidator.new(path_to_file)
14
+
15
+ raise InvalidBackup unless validator.valid_backup?
16
+
17
+ validator.resource.update_storrage(validator.json_data)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ module StatusPageVi
2
+ class BaseService
3
+ def self.resources(resource_name)
4
+ return StatusPageVi::RESOURCES.values if resource_name == "ALL"
5
+ [ resource_name ]
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module StatusPageVi
2
+ class HistoryService < BaseService
3
+ def self.call(option = nil)
4
+ resources(option).each(&:print_history)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module StatusPageVi
2
+ class PullService < BaseService
3
+ def self.call(option = nil)
4
+ resources(option).each(&:pull)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ module StatusPageVi
2
+ class BackupFileValidator
3
+ attr_accessor :file_path, :resource, :json_data
4
+
5
+ def initialize(file_path)
6
+ self.file_path = file_path
7
+ end
8
+
9
+ def valid_backup?
10
+ extention = File.extname(self.file_path)
11
+ return false if extention != ".json"
12
+
13
+ file_name = File.basename(self.file_path, extention)
14
+ self.resource = RESOURCES[file_name]
15
+ return false unless self.resource
16
+
17
+ begin
18
+ self.json_data = JSON.parse(File.read(self.file_path))
19
+ rescue JSON::ParserError
20
+ return false
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module StatusPageVi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,91 @@
1
+ require "status_page_vi/resources/base_resource"
2
+ require "status_page_vi/resources/bit_bucket"
3
+ require "status_page_vi/resources/cloud_flare_status"
4
+ require "status_page_vi/resources/github"
5
+ require "status_page_vi/resources/ruby_gems"
6
+
7
+ require "status_page_vi/services/base_service"
8
+ require "status_page_vi/services/pull_service"
9
+ require "status_page_vi/services/history_service"
10
+ require "status_page_vi/services/backup_service"
11
+
12
+ require "status_page_vi/validators/backup_file_validator"
13
+
14
+ require "status_page_vi/errors"
15
+
16
+ require "thor"
17
+ require 'nokogiri'
18
+ require 'open-uri'
19
+ require 'json'
20
+
21
+ module StatusPageVi
22
+ RESOURCES = {
23
+ 'BitBucket' => BitBucket,
24
+ 'CloudFlareStatus' => CloudFlareStatus,
25
+ 'Github' => Github,
26
+ 'RubyGems' => RubyGems
27
+ }.freeze
28
+
29
+ class CLI < Thor
30
+ desc "resources", "outputs avaliable resources with urls"
31
+ def resources
32
+ RESOURCES.each do |resource_name, resource_class|
33
+ puts "#{resource_name} : #{resource_class::URL}"
34
+ end
35
+ end
36
+
37
+ desc "pull RESOURCE_NAME", "make the application pull data from RESOURCE and save into the data store, ALL resources by default"
38
+ def pull(resource = 'ALL')
39
+ raise InvalidResource unless valid_resource?(resource)
40
+
41
+ StatusPageVi::PullService.call(
42
+ RESOURCES[resource] || resource
43
+ )
44
+ end
45
+
46
+ desc "live RESOURCE_NAME", "constantly queries URL and outputs the status periodically on the console and save it to the data store, ALL resources by default"
47
+ def live(resource = 'ALL')
48
+ raise InvalidResource unless valid_resource?(resource)
49
+
50
+ loop do
51
+ begin
52
+ StatusPageVi::PullService.call(
53
+ RESOURCES[resource] || resource
54
+ )
55
+ rescue Interrupt
56
+ break
57
+ end
58
+ end
59
+ end
60
+
61
+ desc "history RESOURCE_NAME", "display all the data which was gathered by the tool, ALL resources by default"
62
+ def history(resource = 'ALL')
63
+ raise InvalidResource unless valid_resource?(resource)
64
+
65
+ StatusPageVi::HistoryService.call(
66
+ RESOURCES[resource] || resource
67
+ )
68
+ end
69
+
70
+ desc "backup PATH RESOURCE_NAME", "takes a path variable, and creates a backup of historic and currently saved data, ALL resources by default"
71
+ def backup(path, resource = 'ALL')
72
+ raise InvalidResource unless valid_resource?(resource)
73
+
74
+ StatusPageVi::BackupService.backup(
75
+ path,
76
+ RESOURCES[resource] || resource
77
+ )
78
+ end
79
+
80
+ desc "restore PATH_TO_BACKUP", "takes a path variable which is a backup created by the application and restores that data"
81
+ def restore(path_to_file)
82
+ StatusPageVi::BackupService.restore(path_to_file)
83
+ end
84
+
85
+ private
86
+
87
+ def valid_resource?(resource)
88
+ return true if RESOURCES[resource] || resource == 'ALL'
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "status_page_vi/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "status_page_vi"
8
+ spec.version = StatusPageVi::VERSION
9
+ spec.authors = ["Oleg Cherednichenko"]
10
+ spec.email = ["oleg.cherednichenko@wimdu.com"]
11
+
12
+ spec.summary = "A nice command-line tool named ‘status-page-vi’ that pulls status information from different services, displays the results and saves it into a data store."
13
+ spec.homepage = "https://github.com/sorefull/status_page_vi"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/sorefull/status_page_vi"
20
+ spec.metadata["changelog_uri"] = "https://github.com/sorefull/status_page_vi"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "bin"
32
+ spec.executables = ["status_page_vi"]
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.17"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "3.3"
38
+
39
+ spec.add_dependency "thor", "0.20.3"
40
+ spec.add_dependency "nokogiri", "1.8.5"
41
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: status_page_vi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oleg Cherednichenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.20.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.20.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.8.5
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.8.5
83
+ description:
84
+ email:
85
+ - oleg.cherednichenko@wimdu.com
86
+ executables:
87
+ - status_page_vi
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - bin/status_page_vi
101
+ - lib/status_page_vi.rb
102
+ - lib/status_page_vi/errors.rb
103
+ - lib/status_page_vi/modules/recordable.rb
104
+ - lib/status_page_vi/resources/base_resource.rb
105
+ - lib/status_page_vi/resources/bit_bucket.rb
106
+ - lib/status_page_vi/resources/cloud_flare_status.rb
107
+ - lib/status_page_vi/resources/github.rb
108
+ - lib/status_page_vi/resources/ruby_gems.rb
109
+ - lib/status_page_vi/services/backup_service.rb
110
+ - lib/status_page_vi/services/base_service.rb
111
+ - lib/status_page_vi/services/history_service.rb
112
+ - lib/status_page_vi/services/pull_service.rb
113
+ - lib/status_page_vi/validators/backup_file_validator.rb
114
+ - lib/status_page_vi/version.rb
115
+ - status_page_vi.gemspec
116
+ homepage: https://github.com/sorefull/status_page_vi
117
+ licenses: []
118
+ metadata:
119
+ homepage_uri: https://github.com/sorefull/status_page_vi
120
+ source_code_uri: https://github.com/sorefull/status_page_vi
121
+ changelog_uri: https://github.com/sorefull/status_page_vi
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.7.8
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: A nice command-line tool named ‘status-page-vi’ that pulls status information
142
+ from different services, displays the results and saves it into a data store.
143
+ test_files: []