github_status 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in github-status.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Murray Summers
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,58 @@
1
+ # GitHub Status API
2
+
3
+ GitHub continuously monitors the status of github.com and all its related services. If there are any interruptions, the system status can be check on https://status.github.com/
4
+ or querying the GitHub Status API.
5
+
6
+ This library allows you to easily integrate and query the GitHub Status API.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'github_status'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install github_status
21
+
22
+ ## Usage
23
+ Firstly, the library can be used to wrap the whole of the Github Status API into objects.
24
+
25
+ ```
26
+ require 'github_status'
27
+
28
+ Github::Status.last_message
29
+ => #<GithubStatus::Status @created_on="2013-01-08T23:13:55Z", @message="Error Message ...",@status="minor">
30
+
31
+ GithubStatus::Status.messages
32
+ => [#<Github::Status @created_on="2013-01-08T23:33:47Z", @message="Error Message ...", @status="minor">,
33
+ #<Github::Status @created_on="2013-01-08T23:33:47Z", @message="Error Message ...", @status="major">,
34
+ #<Github::Status @created_on="2013-01-08T23:33:47Z", @message="Error Message ...", @status="minor">]
35
+
36
+ ```
37
+
38
+ Alternatively, the GitHub Status API can be queried directly:
39
+
40
+ ```
41
+ GithubStatus::API.last_message
42
+ => { :status=>"minor", :body=>"Error message ...", :created_on=>"2013-01-08T23:33:47Z" }
43
+
44
+ GithubStatus::API.messages
45
+ => [
46
+ { :status=>"minor", :body=>"Error message ...", :created_on=>"2013-01-08T23:33:47Z" },
47
+ { :status=>"minor", :body=>"Error message ...", :created_on=>"2013-01-08T23:33:47Z" }
48
+ ]
49
+ ```
50
+
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'github_status/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "github_status"
8
+ gem.version = GithubStatus::VERSION
9
+ gem.authors = GithubStatus::AUTHORS
10
+ gem.email = GithubStatus::EMAIL
11
+ gem.summary = GithubStatus::SUMMARY
12
+ gem.description = GithubStatus::DESCRIPTION
13
+ gem.homepage = GithubStatus::HOMEPAGE
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency("json")
21
+
22
+ gem.add_development_dependency('rspec')
23
+ gem.add_development_dependency 'webmock'
24
+ end
@@ -0,0 +1,48 @@
1
+ module GithubStatus
2
+ class API
3
+ API_URL = "https://status.github.com/api.json"
4
+
5
+ STATUS_URL = "https://status.github.com/api/status.json"
6
+
7
+ LAST_MESSAGE_URL = "https://status.github.com/api/last-message.json"
8
+
9
+ MESSAGES_URL = "https://status.github.com/api/messages.json"
10
+
11
+ def self.api
12
+ get(API_URL)
13
+ end
14
+
15
+ def self.current_status
16
+ get(STATUS_URL)
17
+ end
18
+
19
+ def self.last_message
20
+ get(LAST_MESSAGE_URL)
21
+ end
22
+
23
+ def self.messages
24
+ get(MESSAGES_URL)
25
+ end
26
+
27
+ private
28
+
29
+ def self.get(uri)
30
+ uri = prepare_uri(uri)
31
+
32
+ response = Net::HTTP.start(uri.host, use_ssl: true) do |http|
33
+ request = Net::HTTP::Get.new(uri.request_uri)
34
+ http.request(request)
35
+ end
36
+
37
+ prepare_response(response)
38
+ end
39
+
40
+ def self.prepare_uri(uri)
41
+ URI.parse(uri)
42
+ end
43
+
44
+ def self.prepare_response(response)
45
+ JSON.parse(response.body, symbolize_names: true)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,36 @@
1
+ module GithubStatus
2
+ class Status
3
+
4
+ GOOD = "good"
5
+ MAJOR = "major"
6
+ MINOR = "minor"
7
+
8
+ attr_reader :status, :message, :created_on
9
+
10
+ def initialize(options)
11
+ @status = options[:status]
12
+ @message = options[:body]
13
+ @created_on = options[:created_on]
14
+ end
15
+
16
+ def self.last_message
17
+ new(GithubStatus::API.last_message)
18
+ end
19
+
20
+ def self.messages
21
+ GithubStatus::API.messages.collect { |response| new(response) }
22
+ end
23
+
24
+ def good?
25
+ status == GOOD
26
+ end
27
+
28
+ def major?
29
+ status == MAJOR
30
+ end
31
+
32
+ def minor?
33
+ status == MINOR
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ module GithubStatus
2
+ VERSION = "0.0.1"
3
+
4
+ AUTHORS = [
5
+ "Murray Summers"
6
+ ]
7
+
8
+ EMAIL = [
9
+ "murray.sum@gmail.com"
10
+ ]
11
+
12
+ SUMMARY = "Github Status API"
13
+
14
+ HOMEPAGE = "https://github.com/murraysum/github_status"
15
+
16
+ DESCRIPTION = "Provides a Ruby Library that allows the Github Status API to be queried."
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module GithubStatus
6
+ require "github_status/version"
7
+ require 'github_status/status'
8
+ require 'github_status/api'
9
+ end
data/spec/api_spec.rb ADDED
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe GithubStatus::API do
4
+ describe "#api" do
5
+ before do
6
+ @expected_response = {
7
+ status_url: "https://status.github.com/api/status.json",
8
+ messages_url: "https://status.github.com/api/messages.json",
9
+ last_message_url: "https://status.github.com/api/last-message.json"
10
+ }
11
+
12
+ @stub_request = stub_request(:get, "https://status.github.com/api.json")
13
+ @stub_request.to_return(body: JSON.generate(@expected_response))
14
+
15
+ @actual_response = GithubStatus::API.api
16
+ end
17
+
18
+ describe "request" do
19
+ it "should have been requested" do
20
+ @stub_request.should have_been_requested
21
+ end
22
+
23
+ it "should have requested api.json" do
24
+ @stub_request.should have_requested(:get, "https://status.github.com/api.json")
25
+ end
26
+ end
27
+
28
+ describe "response" do
29
+ it "should have responded with a status url" do
30
+ @actual_response[:status_url].should == @expected_response[:status_url]
31
+ end
32
+
33
+ it "should have responded with a messages url" do
34
+ @actual_response[:messages_url].should == @expected_response[:messages_url]
35
+ end
36
+
37
+ it "should have responded with a last message url" do
38
+ @actual_response[:last_message_url].should == @expected_response[:last_message_url]
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "#last_message" do
44
+ before do
45
+ @expected_response = {
46
+ status: "good",
47
+ body: "good status message",
48
+ created_on: Time.now.to_s
49
+ }
50
+
51
+ @stub_request = stub_request(:get, "https://status.github.com/api/last-message.json")
52
+ @stub_request.to_return(body: JSON.generate(@expected_response))
53
+
54
+ @actual_response = GithubStatus::API.last_message
55
+ end
56
+
57
+ describe "request" do
58
+ it "should have been requested" do
59
+ @stub_request.should have_been_requested
60
+ end
61
+
62
+ it "should have requested last-message.json" do
63
+ @stub_request.should have_requested(:get, "https://status.github.com/api/last-message.json")
64
+ end
65
+ end
66
+
67
+ describe "response" do
68
+ it "should have responded with a status" do
69
+ @actual_response[:status].should == @expected_response[:status]
70
+ end
71
+
72
+ it "should have responded with a body" do
73
+ @actual_response[:body].should == @expected_response[:body]
74
+ end
75
+
76
+ it "should have responded with a created_on" do
77
+ @actual_response[:created_on].should == @expected_response[:created_on]
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#messages" do
83
+ before do
84
+ @status_options_1 = {
85
+ status: "major",
86
+ body: "some major status message",
87
+ created_on: Time.now.to_s
88
+ }
89
+ @status_options_2 = {
90
+ status: "minor",
91
+ body: "some minor status message",
92
+ created_on: Time.now.to_s
93
+ }
94
+ @expected_response = [@status_options_1, @status_options_2]
95
+
96
+ @stub_request = stub_request(:get, "https://status.github.com/api/messages.json")
97
+ @stub_request.to_return(body: JSON.generate(@expected_response))
98
+
99
+ @actual_response = GithubStatus::API.messages
100
+ end
101
+
102
+ describe "request" do
103
+ it "should have been requested" do
104
+ @stub_request.should have_been_requested
105
+ end
106
+
107
+ it "should have requested messages.json" do
108
+ @stub_request.should have_requested(:get, "https://status.github.com/api/messages.json")
109
+ end
110
+ end
111
+
112
+ describe "response" do
113
+ it "should respond with a list of messages" do
114
+ @actual_response.should == @expected_response
115
+ end
116
+ end
117
+ end
118
+ end
119
+
@@ -0,0 +1,9 @@
1
+ require 'rspec'
2
+ require 'webmock/rspec'
3
+
4
+ require 'github_status'
5
+
6
+ RSpec.configure do |config|
7
+ config.color_enabled = true
8
+ config.formatter = 'documentation'
9
+ end
@@ -0,0 +1,183 @@
1
+ require 'spec_helper'
2
+
3
+ describe GithubStatus::Status do
4
+ describe 'status constants' do
5
+ it 'should have good status' do
6
+ GithubStatus::Status::GOOD.should == "good"
7
+ end
8
+
9
+ it 'should have major status' do
10
+ GithubStatus::Status::MAJOR.should == "major"
11
+ end
12
+
13
+ it 'should have minor status' do
14
+ GithubStatus::Status::MINOR.should == "minor"
15
+ end
16
+ end
17
+
18
+ describe "initialize" do
19
+ before do
20
+ @options = {
21
+ status: "good",
22
+ body: "some status message",
23
+ created_on: Time.now
24
+ }
25
+ @status_item = GithubStatus::Status.new(@options)
26
+ end
27
+
28
+ it 'should initialise the status' do
29
+ @status_item.status.should == @options[:status]
30
+ end
31
+
32
+ it 'should initialise the message' do
33
+ @status_item.message.should == @options[:body]
34
+ end
35
+
36
+ it 'should initialise the created on' do
37
+ @status_item.created_on.should == @options[:created_on]
38
+ end
39
+ end
40
+
41
+ describe ".good?" do
42
+ before do
43
+ @options = {
44
+ status: "good",
45
+ body: "some status message",
46
+ created_on: Time.now
47
+ }
48
+ @status_item = GithubStatus::Status.new(@options)
49
+ end
50
+
51
+ it 'should identify as good' do
52
+ @status_item.good?.should be_true
53
+ end
54
+
55
+ it 'should not identify as major' do
56
+ @status_item.major?.should be_false
57
+ end
58
+
59
+ it 'should not identify as minor' do
60
+ @status_item.minor?.should be_false
61
+ end
62
+ end
63
+
64
+ describe ".major?" do
65
+ before do
66
+ @options = {
67
+ status: "major",
68
+ body: "some status message",
69
+ created_on: Time.now
70
+ }
71
+ @status_item = GithubStatus::Status.new(@options)
72
+ end
73
+
74
+ it 'should not identify as good' do
75
+ @status_item.good?.should be_false
76
+ end
77
+
78
+ it 'should identify as major' do
79
+ @status_item.major?.should be_true
80
+ end
81
+
82
+ it 'should not identify as minor' do
83
+ @status_item.minor?.should be_false
84
+ end
85
+ end
86
+
87
+ describe ".minor?" do
88
+ before do
89
+ @options = {
90
+ status: "minor",
91
+ body: "some status message",
92
+ created_on: Time.now
93
+ }
94
+ @status_item = GithubStatus::Status.new(@options)
95
+ end
96
+
97
+ it 'should not identify as good' do
98
+ @status_item.good?.should be_false
99
+ end
100
+
101
+ it 'should not identify as major' do
102
+ @status_item.major?.should be_false
103
+ end
104
+
105
+ it 'should identify as minor' do
106
+ @status_item.minor?.should be_true
107
+ end
108
+ end
109
+
110
+ describe "#last_message" do
111
+ before do
112
+ @options = {
113
+ status: "major",
114
+ body: "some status message",
115
+ created_on: Time.now
116
+ }
117
+ GithubStatus::API.stub(:last_message) { @options }
118
+ @status_item = GithubStatus::Status.last_message
119
+ end
120
+
121
+ it 'should initialise the status' do
122
+ @status_item.status.should == @options[:status]
123
+ end
124
+
125
+ it 'should initialise the message' do
126
+ @status_item.message.should == @options[:body]
127
+ end
128
+
129
+ it 'should initialise the created on' do
130
+ @status_item.created_on.should == @options[:created_on]
131
+ end
132
+ end
133
+
134
+ describe "#messages" do
135
+ before do
136
+ @status_options_1 = {
137
+ status: "major",
138
+ body: "some major status message",
139
+ created_on: Time.now
140
+ }
141
+ @status_options_2 = {
142
+ status: "minor",
143
+ body: "some minor status message",
144
+ created_on: Time.now
145
+ }
146
+ @options = [@status_options_1, @status_options_2]
147
+ GithubStatus::API.stub(:messages) { @options }
148
+ @status_items = GithubStatus::Status.messages
149
+ end
150
+
151
+ it "should contain both status messages" do
152
+ @status_items.should have(2).items
153
+ end
154
+
155
+ describe "initialize the first status" do
156
+ it 'should initialise the status' do
157
+ @status_items[0].status.should == @status_options_1[:status]
158
+ end
159
+
160
+ it 'should initialise the message' do
161
+ @status_items[0].message.should == @status_options_1[:body]
162
+ end
163
+
164
+ it 'should initialise the created on' do
165
+ @status_items[0].created_on.should == @status_options_1[:created_on]
166
+ end
167
+ end
168
+
169
+ describe "initialize the second status" do
170
+ it 'should initialise the status' do
171
+ @status_items[1].status.should == @status_options_2[:status]
172
+ end
173
+
174
+ it 'should initialise the message' do
175
+ @status_items[1].message.should == @status_options_2[:body]
176
+ end
177
+
178
+ it 'should initialise the created on' do
179
+ @status_items[1].created_on.should == @status_options_2[:created_on]
180
+ end
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe "#{GithubStatus::Status} version information" do
4
+ it "should be version 0.0.1" do
5
+ GithubStatus::VERSION.should == "0.0.1"
6
+ end
7
+
8
+ it "should have authors" do
9
+ GithubStatus::AUTHORS.should_not be_empty
10
+ end
11
+
12
+ it "should have email addresses" do
13
+ GithubStatus::EMAIL.should_not be_empty
14
+ end
15
+
16
+ it "should have a summary" do
17
+ GithubStatus::SUMMARY.should == "Github Status API"
18
+ end
19
+
20
+ it "should have a homepage" do
21
+ GithubStatus::HOMEPAGE.should == "https://github.com/murraysum/github_status"
22
+ end
23
+
24
+ it "should have a description" do
25
+ GithubStatus::DESCRIPTION.should_not be_empty
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Murray Summers
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: webmock
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Provides a Ruby Library that allows the Github Status API to be queried.
63
+ email:
64
+ - murray.sum@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - github_status.gemspec
75
+ - lib/github_status.rb
76
+ - lib/github_status/api.rb
77
+ - lib/github_status/status.rb
78
+ - lib/github_status/version.rb
79
+ - spec/api_spec.rb
80
+ - spec/spec_helper.rb
81
+ - spec/status_spec.rb
82
+ - spec/version_spec.rb
83
+ homepage: https://github.com/murraysum/github_status
84
+ licenses: []
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.23
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Github Status API
107
+ test_files:
108
+ - spec/api_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/status_spec.rb
111
+ - spec/version_spec.rb