Example #1
0
        public void AddUrl(Endpoint endpoint)
        {
            Table table = (Table)AddTable(1, 1);

            table.Rows[0].Cells[0].Paragraphs[0].Append(endpoint.Url);
            Styler.SetTableStyle(table);
            Document.InsertParagraph("").InsertTableAfterSelf(table);
        }
Example #2
0
 public void ParseResponse(List <Response> responses)
 {
     foreach (Response response in responses)
     {
         Styler.SetResponseNameStyle(Document.InsertParagraph(response.Name + " [" + response.Status + "]"));
         Document.InsertParagraph("");
         Document.InsertParagraph("Response Status Code: " + response.StatusCode);
         Table table = (Table)AddTable(1, 1);
         table.Rows[0].Cells[0].Paragraphs[0].Append(response.Body);
         Styler.SetTableStyle(table, Styler.Table1Row);
         Document.InsertParagraph("").InsertTableAfterSelf(table);
     }
 }
Example #3
0
        public void GenerateCurlExampleRequest(Endpoint endpoint)
        {
            String curl       = "curl -X " + endpoint.Method.ToUpper() + " \\\n";
            String bodyParams = "";

            if (endpoint.BodyMode.Equals("urlencoded"))
            {
                List <String> urlencodedParams = new List <String>();
                foreach (Body body in endpoint.Body)
                {
                    urlencodedParams.Add(String.Format("{0}={1}", body.Key, body.Value));
                }

                bodyParams = String.Format(" -d \"{0}\"", String.Join("&", urlencodedParams));
            }
            else if (endpoint.BodyMode.Equals("formdata"))
            {
                foreach (Body body in endpoint.Body)
                {
                    bodyParams = bodyParams + String.Format(" -F \"{0}={1}\" \\\n", body.Key, body.Value);
                }
            }
            else if (endpoint.BodyMode.Equals("raw"))
            {
                bodyParams = bodyParams + String.Format(" -d '{0}' \\\n", endpoint.Body[0].Value);
            }

            foreach (KeyValuePair <String, String> kvp in endpoint.Headers)
            {
                curl = curl + String.Format(" -H \"{0}:{1}\" \\\n", kvp.Key, kvp.Value);
            }

            curl = curl + bodyParams;

            curl = curl + String.Format(" \"{0}\"", endpoint.Url);

            //Console.WriteLine("Generated CURL: " + curl + "\n\n\n");

            Styler.SetBodyTitleStyle(Document.InsertParagraph("Curl Example Request"));
            Table table = (Table)AddTable(1, 1);

            table.Rows[0].Cells[0].Paragraphs[0].Append(curl);
            Styler.SetTableStyle(table, Styler.Table1Row);
            Document.InsertParagraph("").InsertTableAfterSelf(table);
        }
Example #4
0
        public void ParseHeaders(Dictionary <String, String> headers)
        {
            Table table = (Table)AddTable(headers.Count + 1, 2);

            Styler.SetHeaderTitleStyle(Document.InsertParagraph("Headers"));
            table.Rows[0].Cells[0].Paragraphs[0].Append("Name").Bold();
            table.Rows[0].Cells[1].Paragraphs[0].Append("Value").Bold();

            int i = 1;

            foreach (KeyValuePair <String, String> header in headers)
            {
                table.Rows[i].Cells[0].Paragraphs[0].Append(header.Key);
                table.Rows[i].Cells[1].Paragraphs[0].Append(header.Value);
                i++;
            }
            Styler.SetTableStyle(table);
            Document.InsertParagraph("").InsertTableAfterSelf(table);
        }
Example #5
0
        public void ParseQueryParams(Dictionary <String, String> queryParams)
        {
            Table table = (Table)AddTable(queryParams.Count + 1, 2);

            table.Rows[0].Cells[0].Paragraphs[0].Append("Name").Bold();
            table.Rows[0].Cells[1].Paragraphs[0].Append("Value").Bold();

            Styler.SetQueryParametersStyle(Document.InsertParagraph("Query Parameters"));

            int i = 1;

            foreach (KeyValuePair <String, String> query in queryParams)
            {
                table.Rows[i].Cells[0].Paragraphs[0].Append(query.Key);
                table.Rows[i].Cells[1].Paragraphs[0].Append(query.Value);
                i++;
            }
            Styler.SetTableStyle(table);
            Document.InsertParagraph("").InsertTableAfterSelf(table);
        }
Example #6
0
        public void ParseBody(String type, List <Body> bodies)
        {
            Table table;

            if (type.Equals("raw"))
            {
                table = (Table)AddTable(bodies.Count, 1);
                table.Rows[0].Cells[0].Paragraphs[0].Append(bodies[0].Value);
                Styler.SetTableStyle(table, Styler.Table1Row);
            }
            else
            {
                table = (Table)AddTable(bodies.Count + 1, type.Equals("urlencoded") ? 4 : 3);

                table.Rows[0].Cells[0].Paragraphs[0].Append("Name").Bold();
                table.Rows[0].Cells[1].Paragraphs[0].Append("Value").Bold();
                table.Rows[0].Cells[2].Paragraphs[0].Append("Type").Bold();

                if (type.Equals("urlencoded"))
                {
                    table.Rows[0].Cells[3].Paragraphs[0].Append("Description").Bold();
                }

                int i = 1;
                foreach (var body in bodies)
                {
                    table.Rows[i].Cells[0].Paragraphs[0].Append(body.Key);
                    table.Rows[i].Cells[1].Paragraphs[0].Append(body.Value);
                    table.Rows[i].Cells[2].Paragraphs[0].Append(body.Type);

                    if (type.Equals("urlencoded"))
                    {
                        table.Rows[i].Cells[3].Paragraphs[0].Append(body.Description);
                    }
                    i++;
                }
                Styler.SetTableStyle(table);
            }

            Document.InsertParagraph("").InsertTableAfterSelf(table);
        }