Skip to content

Commit

Permalink
feat: Added schema endpoint to go client
Browse files Browse the repository at this point in the history
  • Loading branch information
rtisma committed Nov 28, 2018
1 parent d033175 commit 73e652d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
67 changes: 67 additions & 0 deletions song-go-client/cmd/schema.go
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2018 Ontario Institute for Cancer Research
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package cmd

import (
"bytes"
"encoding/json"
"fmt"
"github.com/spf13/cobra"
)

var listMode bool

var schemaId string

func init() {
RootCmd.AddCommand(schemaCmd)
schemaCmd.Flags().BoolVarP(&listMode, "list", "l", false, "List all registered schemas")
schemaCmd.Flags().StringVarP(&schemaId, "schemaId", "s", "", "Get a schema")
}

func schema() {
// init song client
client := createClient()

// -a analysis-id, -d donor-id, -f file-id, -sa -sample-id,
// -sp specimen-id
// -t search-terms ([]), -i info(false)
var responseBody string

if listMode {
responseBody = client.ListSchemas()
} else {
responseBody = client.GetSchema(schemaId)
}

var formattedJson bytes.Buffer
if err := json.Indent(&formattedJson, []byte(responseBody), "", " "); err != nil {
panic("Response from server is not a valid json string")
}

fmt.Println(formattedJson.String())
}

var schemaCmd = &cobra.Command{
Use: "schema ( -l | -s <schemaId> )",
Short: "Retrieve schema information",
Long: "Retrieve schema information",
Run: func(cmd *cobra.Command, args []string) {
schema()
},
}
8 changes: 8 additions & 0 deletions song-go-client/song/endpoint.go
Expand Up @@ -100,6 +100,14 @@ func (s *Endpoint) ExportStudy(studyID string) url.URL {
return s.makeURL("export", "studies", studyID)
}

func (s *Endpoint) GetSchema(schemaId string) url.URL {
return s.makeURL("schema", schemaId)
}

func (s *Endpoint) ListSchemas() url.URL {
return s.makeURL("schema", "list")
}

func (s *Endpoint) ExportAnalyses(analysesIds []string) url.URL {
return s.makeURL("export", "analysis", strings.Join(analysesIds, ","))
}
Expand Down
8 changes: 8 additions & 0 deletions song-go-client/song/song.go
Expand Up @@ -88,6 +88,14 @@ func (c *Client) getAnalysis(studyID string, analysisID string) string {
return c.get(c.endpoint.GetAnalysis(studyID, analysisID))
}

func (c *Client) GetSchema(schemaId string) string {
return c.get(c.endpoint.GetSchema(schemaId))
}

func (c *Client) ListSchemas() string {
return c.get(c.endpoint.ListSchemas())
}

func (c *Client) getAnalysisFiles(studyID string, analysisID string) string {
return c.get(c.endpoint.GetAnalysisFiles(studyID, analysisID))
}
Expand Down

0 comments on commit 73e652d

Please sign in to comment.