Class: Ruboty::Actions::Jobcan::JobcanClient
- Inherits:
-
Object
- Object
- Ruboty::Actions::Jobcan::JobcanClient
- Defined in:
- lib/ruboty/actions/jobcan.rb
Instance Method Summary collapse
- #authenticate! ⇒ Object
-
#initialize(code, group_id, in_out) ⇒ JobcanClient
constructor
A new instance of JobcanClient.
- #punch_clock! ⇒ Object
Constructor Details
#initialize(code, group_id, in_out) ⇒ JobcanClient
Returns a new instance of JobcanClient.
58 59 60 61 62 |
# File 'lib/ruboty/actions/jobcan.rb', line 58 def initialize(code, group_id, in_out) @code = code @group_id = group_id @in_out = in_out end |
Instance Method Details
#authenticate! ⇒ Object
64 65 66 67 68 69 |
# File 'lib/ruboty/actions/jobcan.rb', line 64 def authenticate! response = faraday.get(authenticate_url) unless response.status == 200 fail "could not log in to JOBCAN; it returned #{response.status}" end end |
#punch_clock! ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ruboty/actions/jobcan.rb', line 71 def punch_clock! response = faraday.post(punch_clock_url, punch_clock_request_body) unless response.status == 200 fail "could not punch the clock on JOBCAN; it returned #{response.status}" end result = JSON.parse(response.body) or fail "could not parse response" if result["result"] == 0 if result["errors"] && result["errors"]["aditCount"] == "duplicate" fail "you have punched the clock within a minute" end fail result["errors"].to_s end result["current_status"] end |