Esempio n. 1
0
        public async Task <StatementsResultLRSResponse> QueryStatements(StatementsQuery query)
        {
            var r = new StatementsResultLRSResponse();

            var req = new MyHTTPRequest();

            req.method      = HttpMethod.Get;
            req.resource    = "statements";
            req.queryParams = query.ToParameterMap(version);

            var res = await MakeRequest(req);

            if (res.status != HttpStatusCode.OK)
            {
                r.success       = false;
                r.httpException = res.ex;
                r.SetErrMsgFromBytes(res.content, (int)res.status);
                return(r);
            }

            r.success = true;
            r.content = new StatementsResult(new Json.StringOfJSON(Encoding.UTF8.GetString(res.content, 0, res.content.Length)));

            return(r);
        }
Esempio n. 2
0
        public async Task <StatementsResultLRSResponse> MoreStatements(StatementsResult result)
        {
            var r = new StatementsResultLRSResponse();

            var req = new MyHTTPRequest();

            req.method   = HttpMethod.Get;
            req.resource = endpoint.Authority;
            if (!req.resource.EndsWith("/", StringComparison.Ordinal))
            {
                req.resource += "/";
            }
            req.resource += result.more;

            var res = await MakeRequest(req);

            if (res.status != HttpStatusCode.OK)
            {
                r.success       = false;
                r.httpException = res.ex;
                r.SetErrMsgFromBytes(res.content, (int)res.status);
                return(r);
            }

            r.success = true;
            r.content = new StatementsResult(new Json.StringOfJSON(Encoding.UTF8.GetString(res.content, 0, res.content.Length)));

            return(r);
        }
        public async Task TestSaveStatements()
        {
            var statement1 = new Statement();

            statement1.actor  = Support.agent;
            statement1.verb   = Support.verb;
            statement1.target = Support.parent;

            var statement2 = new Statement();

            statement2.actor   = Support.agent;
            statement2.verb    = Support.verb;
            statement2.target  = Support.activity;
            statement2.context = Support.context;

            var statements = new List <Statement>();

            statements.Add(statement1);
            statements.Add(statement2);

            StatementsResultLRSResponse lrsRes = await lrs.SaveStatements(statements);

            Assert.True(lrsRes.success);
            // TODO: check statements match and ids not null
        }
Esempio n. 4
0
        public StatementsResultLRSResponse MoreStatements(StatementsResult result)
        {
            var r = new StatementsResultLRSResponse();

            var req = new MyHTTPRequest();

            req.method   = "GET";
            req.resource = endpoint.GetLeftPart(UriPartial.Authority);
            if (!req.resource.EndsWith("/"))
            {
                req.resource += "/";
            }
            req.resource += result.more;

            var res = MakeSyncRequest(req);

            if (res.status != HttpStatusCode.OK)
            {
                r.success       = false;
                r.httpException = res.ex;
                r.SetErrMsgFromBytes(res.content);
                return(r);
            }

            r.success = true;
            r.content = new StatementsResult(new Json.StringOfJSON(Encoding.UTF8.GetString(res.content)));

            return(r);
        }
        public async Task TestQueryStatements()
        {
            var query = new TinCan.StatementsQuery();

            query.agent             = Support.agent;
            query.verbId            = Support.verb.id;
            query.activityId        = Support.parent.id;
            query.relatedActivities = true;
            query.relatedAgents     = true;
            query.format            = StatementsQueryResultFormat.IDS;
            query.limit             = 10;

            StatementsResultLRSResponse lrsRes = await lrs.QueryStatements(query);

            Assert.True(lrsRes.success);
            Console.WriteLine("TestQueryStatements - statement count: " + lrsRes.content.statements.Count);
        }
Esempio n. 6
0
        public void TestMoreStatements()
        {
            var query = new TinCan.StatementsQuery();

            query.format = StatementsQueryResultFormat.IDS;
            query.limit  = 2;

            StatementsResultLRSResponse queryRes = lrs.QueryStatements(query);

            if (queryRes.success && queryRes.content.more != null)
            {
                StatementsResultLRSResponse moreRes = lrs.MoreStatements(queryRes.content);
                Assert.IsTrue(moreRes.success);
                Console.WriteLine("TestMoreStatements - statement count: " + moreRes.content.statements.Count);
            }
            else
            {
                // TODO: skipped?
            }
        }
Esempio n. 7
0
        public async Task <StatementsResultLRSResponse> SaveStatements(List <Statement> statements)
        {
            var r = new StatementsResultLRSResponse();

            var req = new MyHTTPRequest();

            req.resource    = "statements";
            req.method      = HttpMethod.Post;
            req.contentType = "application/json";

            var jarray = new JArray();

            foreach (Statement st in statements)
            {
                jarray.Add(st.ToJObject(version));
            }
            req.content = Encoding.UTF8.GetBytes(jarray.ToString());

            var res = await MakeRequest(req);

            if (res.status != HttpStatusCode.OK)
            {
                r.success       = false;
                r.httpException = res.ex;
                r.SetErrMsgFromBytes(res.content, (int)res.status);
                return(r);
            }

            var ids = JArray.Parse(Encoding.UTF8.GetString(res.content, 0, res.content.Length));

            for (int i = 0; i < ids.Count; i++)
            {
                statements[i].id = new Guid((string)ids[i]);
            }

            r.success = true;
            r.content = new StatementsResult(statements);

            return(r);
        }