@@ -68,7 +68,7 @@ func (c *Client) Fetch(args []string) ([]*Problem, error) {
6868 }
6969
7070 if res .StatusCode != http .StatusOK {
71- return nil , fmt .Errorf (` unable to fetch problems (HTTP: %d) - %s` , res .StatusCode , payload .Error )
71+ return nil , fmt .Errorf (" unable to fetch problems (HTTP: %d) - %s" , res .StatusCode , payload .Error )
7272 }
7373
7474 return payload .Problems , nil
@@ -89,27 +89,22 @@ func (c *Client) Restore() ([]*Problem, error) {
8989 }
9090
9191 if res .StatusCode != http .StatusOK {
92- return nil , fmt .Errorf (` unable to fetch problems (HTTP: %d) - %s` , res .StatusCode , payload .Error )
92+ return nil , fmt .Errorf (" unable to fetch problems (HTTP: %d) - %s" , res .StatusCode , payload .Error )
9393 }
9494
9595 return payload .Problems , nil
9696}
9797
9898// Submissions gets a list of submitted exercises and their current acceptance state.
99- func Submissions (url string ) (map [string ][]SubmissionInfo , error ) {
100- req , err := http .NewRequest ("GET" , url , nil )
101- if err != nil {
102- return nil , err
103- }
104-
105- res , err := http .DefaultClient .Do (req )
99+ func (c * Client ) Submissions () (map [string ][]SubmissionInfo , error ) {
100+ url := fmt .Sprintf ("%s/api/v1/exercises?key=%s" , c .APIHost , c .APIKey )
101+ req , err := c .NewRequest ("GET" , url , nil )
106102 if err != nil {
107103 return nil , err
108104 }
109- defer res .Body .Close ()
110105
111- payload := map [string ][]SubmissionInfo {}
112- if err := json . NewDecoder ( res . Body ). Decode ( & payload ); err != nil {
106+ var payload map [string ][]SubmissionInfo
107+ if _ , err := c . Do ( req , & payload ); err != nil {
113108 return nil , err
114109 }
115110
@@ -153,7 +148,7 @@ func (c *Client) Demo() ([]*Problem, error) {
153148 }
154149
155150 if res .StatusCode != http .StatusOK {
156- return nil , fmt .Errorf (` unable to fetch problems (HTTP: %d) - %s` , res .StatusCode , payload .Error )
151+ return nil , fmt .Errorf (" unable to fetch problems (HTTP: %d) - %s" , res .StatusCode , payload .Error )
157152 }
158153
159154 return payload .Problems , nil
@@ -179,7 +174,7 @@ func (c *Client) Submit(iter *Iteration) (*Submission, error) {
179174 }
180175
181176 if res .StatusCode != http .StatusCreated {
182- return nil , fmt .Errorf (` unable to submit (HTTP: %d) - %s` , res .StatusCode , ps .Error )
177+ return nil , fmt .Errorf (" unable to submit (HTTP: %d) - %s" , res .StatusCode , ps .Error )
183178 }
184179
185180 return ps .Submission , nil
0 commit comments