Class: GithubStatus::API

Inherits:
Object
  • Object
show all
Defined in:
lib/github_status/api.rb

Constant Summary collapse

API_URL =
"https://status.github.com/api.json"
STATUS_URL =
"https://status.github.com/api/status.json"
LAST_MESSAGE_URL =
"https://status.github.com/api/last-message.json"
MESSAGES_URL =
"https://status.github.com/api/messages.json"

Class Method Summary collapse

Class Method Details

.apiObject



11
12
13
# File 'lib/github_status/api.rb', line 11

def self.api
  get(API_URL)
end

.current_statusObject



15
16
17
# File 'lib/github_status/api.rb', line 15

def self.current_status
  get(STATUS_URL)
end

.get(uri) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/github_status/api.rb', line 29

def self.get(uri)
  uri = prepare_uri(uri)
  
  response = Net::HTTP.start(uri.host, use_ssl: true) do |http|
    request = Net::HTTP::Get.new(uri.request_uri)
    http.request(request)
  end

  prepare_response(response)
end

.last_messageObject



19
20
21
# File 'lib/github_status/api.rb', line 19

def self.last_message
  get(LAST_MESSAGE_URL)
end

.messagesObject



23
24
25
# File 'lib/github_status/api.rb', line 23

def self.messages
  get(MESSAGES_URL)
end

.prepare_response(response) ⇒ Object



44
45
46
# File 'lib/github_status/api.rb', line 44

def self.prepare_response(response)
  JSON.parse(response.body, symbolize_names: true)
end

.prepare_uri(uri) ⇒ Object



40
41
42
# File 'lib/github_status/api.rb', line 40

def self.prepare_uri(uri)
  URI.parse(uri)
end