Skip to content

Commit

Permalink
Consistently name checkin -> check_in etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
halfbyte committed Nov 14, 2023
1 parent 8c0b939 commit 7476bbc
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 261 deletions.
40 changes: 20 additions & 20 deletions lib/honeybadger/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require 'honeybadger/logging'

require 'honeybadger/checkin'
require 'honeybadger/check_in'

module Honeybadger
module Backend
Expand Down Expand Up @@ -111,59 +111,59 @@ def track_deployment(payload)
notify(:deploys, payload)
end

# Get checkin by id
# Get check_in by id
# @example
# backend.get_checkin('1234', 'ajdja")
# backend.get_check_in('1234', 'ajdja")
#
# @param [String] project_id The unique project id
# @param [String] id The unique check_in id
# @raise NotImplementedError
def get_checkin(project_id, id)
def get_check_in(project_id, id)
raise NotImplementedError, 'must define #get_checkin on subclass'
end

# Get checkins by project
# @example
# backend.get_checkins('1234')
# backend.get_check_ins('1234')
#
# @param [String] project_id The unique project id
# @raise NotImplementedError
def get_checkins(project_id)
def get_check_ins(project_id)
raise NotImplementedError, 'must define #get_checkins on subclass'
end

# Create checkin on project
# Create check_in on project
# @example
# backend.create_checkin('1234', checkin)
# backend.create_check_in('1234', check_in)
#
# @param [String] project_id The unique project id
# @param [Checkin] data A Checkin object encapsulating the config
# @param [CheckIn] data A CheckIn object encapsulating the config
# @raise NotImplementedError
def create_checkin(project_id, data)
raise NotImplementedError, 'must define #create_checkin on subclass'
def create_check_in(project_id, data)
raise NotImplementedError, 'must define #create_check_in on subclass'
end

# Update checkin on project
# Update check_in on project
# @example
# backend.update_checkin('1234', 'eajaj', checkin)
# backend.update_check_in('1234', 'eajaj', check_in)
#
# @param [String] project_id The unique project id
# @param [String] id The unique check_in id
# @param [Checkin] data A Checkin object encapsulating the config
# @param [CheckIn] data A CheckIn object encapsulating the config
# @raise NotImplementedError
def update_checkin(project_id, id, data)
raise NotImplementedError, 'must define #update_checkin on subclass'
def update_check_in(project_id, id, data)
raise NotImplementedError, 'must define #update_check_in on subclass'
end

# Delete checkin
# Delete check_in
# @example
# backend.delete_checkin('1234', 'eajaj')
# backend.delete_check_in('1234', 'eajaj')
#
# @param [String] project_id The unique project id
# @param [String] id The unique check_in id
# @raise NotImplementedError
def delete_checkin(project_id, id)
raise NotImplementedError, 'must define #delete_checkin on subclass'
def delete_check_in(project_id, id)
raise NotImplementedError, 'must define #delete_check_in on subclass'
end

private
Expand Down
81 changes: 40 additions & 41 deletions lib/honeybadger/backend/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ class Server < Base

CHECK_IN_ENDPOINT = '/v1/check_in'.freeze


HTTP_ERRORS = Util::HTTP::ERRORS

def initialize(config)
@http = Util::HTTP.new(config)
# for checkin config sync
# for check_in config sync
@personal_auth_token = config.get(:personal_auth_token)
super
end
Expand Down Expand Up @@ -52,93 +51,93 @@ def check_in(id)


#
##### Checkin Crud methods
##### CheckIn Crud methods
#

# Get checkin by id
# Get check_in by id
# @example
# backend.get_checkin('1234', 'ajdja")
# backend.get_check_in('1234', 'ajdja")
#
# @param [String] project_id The unique project id
# @param [String] id The unique check_in id
# @returns [Checkin] or nil if checkin is not found
# @raises CheckinSyncError on error
# @returns [CheckIn] or nil if check_in is not found
# @raises CheckInSyncError on error

def get_checkin(project_id, id)
def get_check_in(project_id, id)
response = Response.new(@http.get("/v2/projects/#{project_id}/check_ins/#{id}", personal_auth_headers))
if response.success?
return Checkin.from_remote(project_id, JSON.parse(response.body))
return CheckIn.from_remote(project_id, JSON.parse(response.body))
else
if response.code == 404
return nil
end
end
raise CheckinSyncError.new "Fetching Checkin failed (Code: #{response.code}) #{response.body}"
raise CheckInSyncError.new "Fetching CheckIn failed (Code: #{response.code}) #{response.body}"
end

# Get checkins by project
# Get check_ins by project
# @example
# backend.get_checkins('1234')
# backend.get_check_ins('1234')
#
# @param [String] project_id The unique project id
# @returns [Array<Checkin>] All checkins for this project
# @raises CheckinSyncError on error
def get_checkins(project_id)
# @returns [Array<CheckIn>] All checkins for this project
# @raises CheckInSyncError on error
def get_check_ins(project_id)
response = Response.new(@http.get("/v2/projects/#{project_id}/check_ins", personal_auth_headers))
if response.success?
all_checkins = JSON.parse(response.body)["results"]
return all_checkins.map{|cfg| Checkin.from_remote(project_id, cfg) }
all_check_ins = JSON.parse(response.body)["results"]
return all_check_ins.map{|cfg| CheckIn.from_remote(project_id, cfg) }
end
raise CheckinSyncError.new "Fetching Checkins failed (Code: #{response.code}) #{response.body}"
raise CheckInSyncError.new "Fetching CheckIns failed (Code: #{response.code}) #{response.body}"
end

# Create checkin on project
# Create check_in on project
# @example
# backend.create_checkin('1234', checkin)
# backend.create_check_in('1234', check_in)
#
# @param [String] project_id The unique project id
# @param [Checkin] data A Checkin object encapsulating the config
# @returns [Checkin] A checkin object containing the id
# @raises CheckinSyncError on error
def create_checkin(project_id, data)
response = Response.new(@http.post("/v2/projects/#{project_id}/check_ins", data.to_json, personal_auth_headers))
# @param [CheckIn] check_in_config A CheckIn object encapsulating the config
# @returns [CheckIn] A CheckIn object additionally containing the id
# @raises CheckInSyncError on error
def create_check_in(project_id, check_in_config)
response = Response.new(@http.post("/v2/projects/#{project_id}/check_ins", check_in_config.to_json, personal_auth_headers))
if response.success?
return Checkin.from_remote(project_id, JSON.parse(response.body))
return CheckIn.from_remote(project_id, JSON.parse(response.body))
end
raise CheckinSyncError.new "Creating Checkin failed (Code: #{response.code}) #{response.body}"
raise CheckInSyncError.new "Creating CheckIn failed (Code: #{response.code}) #{response.body}"
end

# Update checkin on project
# Update check_in on project
# @example
# backend.update_checkin('1234', 'eajaj', checkin)
# backend.update_check_in('1234', 'eajaj', check_in)
#
# @param [String] project_id The unique project id
# @param [String] id The unique check_in id
# @param [Checkin] data A Checkin object encapsulating the config
# @returns [Checkin] updated Checkin object
# @raises CheckinSyncError on error
def update_checkin(project_id, id, data)
response = Response.new(@http.put("/v2/projects/#{project_id}/check_ins/#{id}", data.to_json, personal_auth_headers))
# @param [CheckIn] check_in_config A CheckIn object encapsulating the config
# @returns [CheckIn] updated CheckIn object
# @raises CheckInSyncError on error
def update_check_in(project_id, id, check_in_config)
response = Response.new(@http.put("/v2/projects/#{project_id}/check_ins/#{id}", check_in_config.to_json, personal_auth_headers))
if response.success?
return Checkin.from_remote(project_id, JSON.parse(response.body))
return CheckIn.from_remote(project_id, JSON.parse(response.body))
end
raise CheckinSyncError.new "Updating Checkin failed (Code: #{response.code}) #{response.body}"
raise CheckInSyncError.new "Updating CheckIn failed (Code: #{response.code}) #{response.body}"
end

# Delete checkin
# Delete check_in
# @example
# backend.delete_checkin('1234', 'eajaj')
# backend.delete_check_in('1234', 'eajaj')
#
# @param [String] project_id The unique project id
# @param [String] id The unique check_in id
# @returns [Boolean] true if deletion was successful
# @raises CheckinSyncError on error
def delete_checkin(project_id, id)
# @raises CheckInSyncError on error
def delete_check_in(project_id, id)
response = Response.new(@http.delete("/v2/projects/#{project_id}/check_ins/#{id}", personal_auth_headers))
if response.success?
return true
end
raise CheckinSyncError.new "Deleting Checkin failed (Code: #{response.code}) #{response.body}"
raise CheckInSyncError.new "Deleting CheckIn failed (Code: #{response.code}) #{response.body}"
end

private
Expand Down
94 changes: 47 additions & 47 deletions lib/honeybadger/backend/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,102 +42,102 @@ def check_in(id)
super
end

def self.checkin_configs
@checkin_configs ||= {}
def self.check_in_configs
@check_in_configs ||= {}
end

def checkin_configs
self.class.checkin_configs
def check_in_configs
self.class.check_in_configs
end

# Set checkin by id, only for use in tests
# Set check_in by id, only for use in tests
# @example
# backend.set_checkin('1234', 'ajdja', checkin)
# backend.set_checkin('1234', 'ajdja', check_in)
#
# @param [String] project_id The unique project id
# @param [String] id The unique check_in id
# @param [Checkin] data Checkin object with config
# @param [CheckIn] data CheckIn object with config
def set_checkin(project_id, id, data)
self.checkin_configs[project_id] = self.checkin_configs[project_id] || {}
self.checkin_configs[project_id][id] = data
self.check_in_configs[project_id] = self.check_in_configs[project_id] || {}
self.check_in_configs[project_id][id] = data
end

# Get checkin by id
# Get check_in by id
# @example
# backend.get_checkin('1234', 'ajdja")
# backend.get_check_in('1234', 'ajdja")
#
# @param [String] project_id The unique project id
# @param [String] id The unique check_in id
# @returns [Checkin] or nil if checkin is not found
def get_checkin(project_id, id)
self.checkin_configs ||= {}
self.checkin_configs[project_id]&.[](id)
# @returns [CheckIn] or nil if check_in is not found
def get_check_in(project_id, id)
self.check_in_configs ||= {}
self.check_in_configs[project_id]&.[](id)
end

# Get checkins by project
# @example
# backend.get_checkins('1234')
# backend.get_check_ins('1234')
#
# @param [String] project_id The unique project id
# @returns [Array<Checkin>] All checkins for this project
def get_checkins(project_id)
self.checkin_configs ||= {}
self.checkin_configs[project_id] = self.checkin_configs[project_id] || {}
return [] if self.checkin_configs[project_id].empty?
self.checkin_configs[project_id].values
# @returns [Array<CheckIn>] All checkins for this project
def get_check_ins(project_id)
self.check_in_configs ||= {}
self.check_in_configs[project_id] = self.check_in_configs[project_id] || {}
return [] if self.check_in_configs[project_id].empty?
self.check_in_configs[project_id].values
end

# Create checkin on project
# Create check_in on project
# @example
# backend.create_checkin('1234', checkin)
# backend.create_check_in('1234', check_in)
#
# @param [String] project_id The unique project id
# @param [Checkin] data A Checkin object encapsulating the config
# @returns [Checkin] A checkin object containing the id
def create_checkin(project_id, data)
self.checkin_configs ||= {}
self.checkin_configs[project_id] = self.checkin_configs[project_id] || {}
id = self.checkin_configs[project_id].length + 1
# @param [CheckIn] data A CheckIn object encapsulating the config
# @returns [CheckIn] A check_in object containing the id
def create_check_in(project_id, data)
self.check_in_configs ||= {}
self.check_in_configs[project_id] = self.check_in_configs[project_id] || {}
id = self.check_in_configs[project_id].length + 1
loop do
break unless self.checkin_configs[project_id].has_key?(id)
break unless self.check_in_configs[project_id].has_key?(id)
id += 1
end
id = id.to_s
data.id = id
self.checkin_configs[project_id][id] = data
self.check_in_configs[project_id][id] = data
data
end

# Update checkin on project
# Update check_in on project
# @example
# backend.update_checkin('1234', 'eajaj', checkin)
# backend.update_check_in('1234', 'eajaj', check_in)
#
# @param [String] project_id The unique project id
# @param [String] id The unique check_in id
# @param [Checkin] data A Checkin object encapsulating the config
# @returns [Checkin] updated Checkin object
def update_checkin(project_id, id, data)
self.checkin_configs ||= {}
if self.checkin_configs[project_id]&.[](id)
self.checkin_configs[project_id][id] = data
# @param [CheckIn] data A CheckIn object encapsulating the config
# @returns [CheckIn] updated CheckIn object
def update_check_in(project_id, id, data)
self.check_in_configs ||= {}
if self.check_in_configs[project_id]&.[](id)
self.check_in_configs[project_id][id] = data
return data
else
raise "Update failed"
end
end

# Delete checkin
# Delete check_in
# @example
# backend.delete_checkin('1234', 'eajaj')
# backend.delete_check_in('1234', 'eajaj')
#
# @param [String] project_id The unique project id
# @param [String] id The unique check_in id
# @returns [Boolean] true if deletion was successful
# @raises CheckinSyncError on error
def delete_checkin(project_id, id)
self.checkin_configs ||= {}
if self.checkin_configs[project_id]&.[](id)
self.checkin_configs[project_id].delete(id)
# @raises CheckInSyncError on error
def delete_check_in(project_id, id)
self.check_in_configs ||= {}
if self.check_in_configs[project_id]&.[](id)
self.check_in_configs[project_id].delete(id)
else
raise "Delete failed"
end
Expand Down
Loading

0 comments on commit 7476bbc

Please sign in to comment.