Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Commit

Permalink
add report show
Browse files Browse the repository at this point in the history
  • Loading branch information
jackspirou committed Jun 22, 2016
1 parent 90e16ab commit 9ea5f5d
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 26 deletions.
11 changes: 3 additions & 8 deletions candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "testing"

func TestCandidateCreate(t *testing.T) {
SetAPIKey(testKey)
c := Candidate{
c := &Candidate{
FirstName: "John",
MiddleName: "Alfred",
LastName: "Smith",
Expand Down Expand Up @@ -47,13 +47,8 @@ func TestCandidatesIndex(t *testing.T) {

func TestCandidateShow(t *testing.T) {
SetAPIKey(testKey)
c := Candidates{}
if err := c.Index(); err != nil {
c := &Candidate{ID: "e44aa283528e6fde7d542194"}
if err := c.Show(); err != nil {
t.Error(err)
}
if len(c.Data) > 0 {
if err := c.Data[0].Show(); err != nil {
t.Error(err)
}
}
}
1 change: 1 addition & 0 deletions checkr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
// endpoints used by different checkr API versions
candidates = "/candidates"
invitations = "/invitations"
reports = "/reports"
)

var (
Expand Down
48 changes: 48 additions & 0 deletions invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,54 @@ func (i Invitation) Create() error {
return nil
}

// Show shows one invitation.
func (i *Invitation) Show() error {

if i.ID == "" {
return errors.New("an id is needed to show an invitation")
}

// create a new request
u, _ := url.Parse(URL.String())
u.Path = path.Join(URL.Path, invitations, i.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, &i); 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
}

// Invitations represents a listing of invitations.
type Invitations struct {
Paginator
Expand Down
12 changes: 12 additions & 0 deletions invitation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ func TestCreateInvitation(t *testing.T) {
}
}

func TestInvitationShow(t *testing.T) {
SetAPIKey(testKey)
list := Invitations{}
if err := list.Index(); err != nil {
t.Error(err)
}
i := &Invitation{ID: list.Data[0].ID}
if err := i.Show(); err != nil {
t.Error(err)
}
}

func TestInvitationsIndex(t *testing.T) {

SetAPIKey(testKey)
Expand Down
92 changes: 74 additions & 18 deletions report.go
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
}
11 changes: 11 additions & 0 deletions report_test.go
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)
}
}

0 comments on commit 9ea5f5d

Please sign in to comment.