-
Notifications
You must be signed in to change notification settings - Fork 1
/
medidata_api_example.go
57 lines (49 loc) · 1.55 KB
/
medidata_api_example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// The package medidata_apis is one example of using the Go MAuth Client library to accessing a Medidata API
//
package medidata_apis
// Sample Medidata API usage
import (
"log"
"fmt"
"github.com/mdsol/go-mauth-client"
"github.com/mdsol/go-mauth-client/examples"
"net/http"
)
// Encapsulate creation of a MAuth Client
func createClient() (mauthClient *go_mauth_client.MAuthClient, err error) {
// load the configuration from the environment
mauthApp, err := examples.LoadApp()
if err != nil {
log.Fatal("Unable: to load client configuration; "+
"did you define MAUTH_APP_UUID and "+
"MAUTH_PRIVATE_KEY?: ", err)
}
mauthClient, err = mauthApp.CreateClient("https://api.mdsol.com")
return
}
// Get the results from the Countries API
func GetCountriesService(mauthClient *go_mauth_client.MAuthClient) (result *http.Response, err error) {
// Access the Countries API
targetUrl := "https://api.mdsol.com/countries"
// make sure you specify the correct version
mauthClient.SetHeader("Mcc-Version", "v2019-03-22")
// get the response
result, err = mauthClient.Get(targetUrl)
return result, err
}
func main() {
// Create a new client
mauthClient, err := createClient()
if err != nil {
log.Fatal("Error creating the client")
}
// Make the call and get the response
result, err := GetCountriesService(mauthClient)
// Handle a connection failure
if err != nil {
log.Fatal(fmt.Printf("Error calling the URL %s: %v", result.Request.RequestURI, err))
}
// Report
log.Println("Status Code: ", result.StatusCode)
log.Println("Results: ", result.Body)
}