This repository has been archived by the owner on Feb 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jackspirou
committed
Jun 22, 2016
1 parent
90e16ab
commit 9ea5f5d
Showing
6 changed files
with
149 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,83 @@ | ||
package checkr | ||
|
||
import "time" | ||
import ( | ||
"encoding/json" | ||
"errors" | ||
"io/ioutil" | ||
"net/http" | ||
"net/url" | ||
"path" | ||
"time" | ||
) | ||
|
||
// Report represents a background check report. Depending on the selected | ||
// package, a report can include the following screenings: SSN trace, sex | ||
// offender search, national criminal search, county criminal searches and | ||
// motor vehicle report. | ||
type Report struct { | ||
ID string `json:"id,omitempty"` | ||
Object string `json:"object,omitempty"` | ||
URI string `json:"uri,omitempty"` | ||
Status string `json:"status,omitempty"` | ||
CreatedAt time.Time `json:"created_at,omitempty"` | ||
CompletedAt time.Time `json:"completed_at,omitempty"` | ||
TurnaroundTime int `json:"turnaround_time,omitempty"` | ||
DueTime time.Time `json:"due_time,omitempty"` | ||
Adjudication string `json:"adjudication,omitempty"` | ||
Package string `json:"package,omitempty"` | ||
CandidateID string `json:"candidate_id,omitempty"` | ||
SsnTraceID string `json:"ssn_trace_id,omitempty"` | ||
SexOffenderSearchID string `json:"sex_offender_search_id,omitempty"` | ||
NationalCriminalSearchID string `json:"national_criminal_search_id,omitempty"` | ||
CountyCriminalSearchIDs []string `json:"county_criminal_search_ids,omitempty"` | ||
MotorVehicleReportID string `json:"motor_vehicle_report_id,omitempty"` | ||
StateCriminalSearchIDs []string `json:"state_criminal_search_ids,omitempty"` | ||
ID string `json:"id,omitempty"` | ||
Object string `json:"object,omitempty"` | ||
URI string `json:"uri,omitempty"` | ||
Status string `json:"status,omitempty"` | ||
CreatedAt *time.Time `json:"created_at,omitempty"` | ||
CompletedAt *time.Time `json:"completed_at,omitempty"` | ||
TurnaroundTime int `json:"turnaround_time,omitempty"` | ||
DueTime *time.Time `json:"due_time,omitempty"` | ||
Adjudication string `json:"adjudication,omitempty"` | ||
Package string `json:"package,omitempty"` | ||
CandidateID string `json:"candidate_id,omitempty"` | ||
SsnTraceID string `json:"ssn_trace_id,omitempty"` | ||
SexOffenderSearchID string `json:"sex_offender_search_id,omitempty"` | ||
NationalCriminalSearchID string `json:"national_criminal_search_id,omitempty"` | ||
CountyCriminalSearchIDs []string `json:"county_criminal_search_ids,omitempty"` | ||
MotorVehicleReportID string `json:"motor_vehicle_report_id,omitempty"` | ||
StateCriminalSearchIDs []string `json:"state_criminal_search_ids,omitempty"` | ||
} | ||
|
||
// Show shows one report. | ||
func (r *Report) Show() error { | ||
|
||
if r.ID == "" { | ||
return errors.New("an id is needed to show a report") | ||
} | ||
|
||
// create a new request | ||
u, _ := url.Parse(URL.String()) | ||
u.Path = path.Join(URL.Path, reports, r.ID) | ||
|
||
// create a new request | ||
req, err := http.NewRequest(http.MethodGet, u.String(), nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// set API key for authentication and authorization | ||
req.SetBasicAuth(apiKey, "") | ||
|
||
// send the HTTP request with the default Go client | ||
resp, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// read the HTTP response body | ||
defer resp.Body.Close() | ||
b, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// unmarshal the candidate | ||
if err = json.Unmarshal(b, &r); err != nil { | ||
return err | ||
} | ||
|
||
// check the HTTP response status code is 200 | ||
if resp.StatusCode != http.StatusOK { | ||
|
||
// return the HTTP response body as an error | ||
return errors.New(string(b)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package checkr | ||
|
||
import "testing" | ||
|
||
func TestReportShow(t *testing.T) { | ||
SetAPIKey(testKey) | ||
r := Report{ID: "4722c07dd9a10c3985ae432a"} | ||
if err := r.Show(); err != nil { | ||
t.Error(err) | ||
} | ||
} |