예제 #1
0
        public static Tuple<Channel, ApiCallResponse> create(string access_token, string type, List<Annotation> annotations, ACL readers = null, ACL writers = null)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            Channel channel = new Channel();
            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return new Tuple<Channel, ApiCallResponse>(channel, apiCallResponse);
                }

                string requestUrl = Common.baseUrl += "/stream/0/channels";

                channel.annotations = annotations;
                channel.readers = readers;
                channel.writers = writers;
                channel.type = type;

                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.NullValueHandling = NullValueHandling.Ignore;

                string jsonString = JsonConvert.SerializeObject(channel, Formatting.None, settings);

                Dictionary<string, string> headers = new Dictionary<string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                headers.Add("X-ADN-Migration-Overrides", "response_envelope=1");
                Helper.Response response = Helper.SendPostRequestStringDataOnly(
                        requestUrl,
                        jsonString,
                        headers,
                        true,
                        contentType: "application/json");

                return Helper.getData<Channel>(response);

            }
            catch (Exception exp)
            {
                apiCallResponse.success = false;
                apiCallResponse.errorMessage = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return new Tuple<Channel, ApiCallResponse>(channel, apiCallResponse);
        }
예제 #2
0
        public static Tuple<Channel, ApiCallResponse> get(string access_token, string id)
        {
            ApiCallResponse apiCallResponse = new ApiCallResponse();
            Channel channel = new Channel();
            try
            {
                if (string.IsNullOrEmpty(access_token))
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = "Missing parameter access_token";
                    return new Tuple<Channel, ApiCallResponse>(channel, apiCallResponse);
                }
                if (string.IsNullOrEmpty(id))
                {
                    apiCallResponse.success = false;
                    apiCallResponse.errorMessage = "Missing parameter id";
                    return new Tuple<Channel, ApiCallResponse>(channel, apiCallResponse);
                }

                string requestUrl = Common.baseUrl += "/stream/0/channels/" + id;

                Dictionary<string, string> headers = new Dictionary<string, string>();
                headers.Add("Authorization", "Bearer " + access_token);
                headers.Add("X-ADN-Migration-Overrides", "response_envelope=1");
                Helper.Response response = Helper.SendGetRequest(
                        requestUrl,
                        headers);

                return Helper.getData<Channel>(response);
            }
            catch (Exception exp)
            {
                apiCallResponse.success = false;
                apiCallResponse.errorMessage = exp.Message;
                apiCallResponse.errorDescription = exp.StackTrace;
            }
            return new Tuple<Channel, ApiCallResponse>(channel, apiCallResponse);
        }