Exemplo n.º 1
0
        public static WSSettings MakeExample()
        {
            var result = new WSSettings();

            result.root           = "https://sandbox.whitespace.co.uk";
            result.bucket         = "sandboxbucket";
            result.renewableToken = "Login to the platform and copy from the user settings panel, replacing this text";
            return(result);
        }
Exemplo n.º 2
0
        public static WSAPIClient ForToken(WSSettings settings)
        {
            var client = new WSAPIClient();

            client.BaseAddress = new Uri(settings.root);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            return(client);
        }
Exemplo n.º 3
0
        public static WSAPIClient ForMIMEType(WSSettings settings, string mimetype)
        {
            var client = new WSAPIClient();

            client.BaseAddress = new Uri(settings.root);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(mimetype));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", settings.sessionToken);
            return(client);
        }
Exemplo n.º 4
0
        public async Task <String> DoOIDC(WSSettings settings)
        {
            HttpResponseMessage response = await this.GetAsync(settings.MakeOIDC_URL());

            string json = await response.Content.ReadAsStringAsync();

            WSOIDCResult oidc = JsonConvert.DeserializeObject <WSOIDCResult>(json);

            settings.sessionToken = oidc.id_token;

            return(json);
        }
Exemplo n.º 5
0
        public static WSSettings Load(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new Exception(String.Format("No settings file {0}", filename));
            }

            string     settingsjson = File.ReadAllText(filename);
            WSSettings settings     = JsonConvert.DeserializeObject <WSSettings>(settingsjson);

            settings.CheckValid();
            return(settings);
        }
Exemplo n.º 6
0
        public static string WriteExample(string filename)
        {
            WSSettings example = WSSettings.MakeExample();

            try
            {
                using (StreamWriter sw = new StreamWriter(filename))
                {
                    String str = JsonConvert.SerializeObject(example, Formatting.Indented);
                    sw.WriteLine(str);
                    return(String.Format("{0} written", filename));
                }
            }
            catch (Exception ex)
            {
                return(String.Format("ERROR {0}", ex.Message));
            }
        }
Exemplo n.º 7
0
 public static WSAPIClient ForPDF(WSSettings settings)
 {
     return(WSAPIClient.ForMIMEType(settings, "application/pdf"));
 }