class WoerkClient::Commands::StopShift
Public Instance Methods
call()
click to toggle source
# File lib/woerk_client/commands/stop_shift.rb, line 6 def call if current_shift.nil? return errors.add(:stop, 'No running shift found.') end shift = WoerkClient::Models::Shift.new('id' => current_shift['id']) shift.params['stopped_at'] = Time.now if shift.save return 'Shift stopped' end rescue RestClient::ExceptionWithResponse => e errors.add(:stop, e.message) end
Private Instance Methods
current_shift()
click to toggle source
Gets the current shift from all shifts
@return [Hash] The current shift as Hash representation
# File lib/woerk_client/commands/stop_shift.rb, line 28 def current_shift JSON.parse(shifts).find { |s| s['stopped_at'] == 0 } end
shifts()
click to toggle source
Gets all the shifts from current user
@return [String] The response from the server
# File lib/woerk_client/commands/stop_shift.rb, line 36 def shifts WoerkClient::Client.get(WoerkClient::Models::Shift::RESOURCE_PATH) end