Esempio n. 1
0
        protected override async System.Threading.Tasks.Task <Gist> SaveGist()
        {
            if (Gist == null)
            {
                throw new InvalidOperationException("Missing Gist context to update!");
            }

            var gistUpdate = new GistUpdate {
                Description = Description ?? string.Empty
            };

            foreach (var file in Gist.Files)
            {
                gistUpdate.Files[file.Key] = null;
            }

            foreach (var file in Files)
            {
                gistUpdate.Files[file.Name] = new GistFileUpdate {
                    Content = file.Content
                }
            }
            ;

            using (_alertDialogFactory.Activate("Updating Gist..."))
                return(await _sessionService.GitHubClient.Gist.Edit(Gist.Id, gistUpdate));
        }
Esempio n. 2
0
        /// <summary>
        /// Edits a gist
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/gists/#delete-a-gist
        /// </remarks>
        /// <param name="id">The id of the gist</param>
        /// <param name="gistUpdate">The update to the gist</param>
        public IObservable <Gist> Edit(string id, GistUpdate gistUpdate)
        {
            Ensure.ArgumentNotNull(id, nameof(id));
            Ensure.ArgumentNotNull(gistUpdate, nameof(gistUpdate));

            return(_client.Edit(id, gistUpdate).ToObservable());
        }
Esempio n. 3
0
    public async Task CanCreateEditAndDeleteAGist()
    {
        var newGist = new NewGist {
            Description = "my new gist", Public = true
        };

        newGist.Files.Add("myGistTestFile.cs", "new GistsClient(connection).Create();");

        var createdGist = await _fixture.Create(newGist);

        Assert.NotNull(createdGist);
        Assert.Equal(newGist.Description, createdGist.Description);
        Assert.Equal(newGist.Public, createdGist.Public);

        var gistUpdate = new GistUpdate {
            Description = "my newly updated gist"
        };
        var gistFileUpdate = new GistFileUpdate
        {
            NewFileName = "myNewGistTestFile.cs",
            Content     = "new GistsClient(connection).Edit();"
        };

        gistUpdate.Files.Add("myGistTestFile.cs", gistFileUpdate);

        var updatedGist = await _fixture.Edit(createdGist.Id, gistUpdate);

        Assert.NotNull(updatedGist);
        Assert.Equal(updatedGist.Description, gistUpdate.Description);

        await _fixture.Delete(createdGist.Id);
    }
Esempio n. 4
0
        public async Task DeleteGistFileAsync(string gistId, string fileName)
        {
            var update = new GistUpdate();

            update.Files.Add(fileName, new GistFileUpdate {
                Content = null, NewFileName = null
            });
            await gistClient.Edit(gistId, update);
        }
Esempio n. 5
0
        public async Task RenameGistFileAsync(string gistId, string originalFileName, string newFileName, string content)
        {
            var update = new GistUpdate();

            update.Files.Add(originalFileName, new GistFileUpdate {
                Content = content, NewFileName = newFileName
            });
            await gistClient.Edit(gistId, update);
        }
Esempio n. 6
0
        public async Task CreateGistFileAsync(string gistId, string fileName, string fileContent)
        {
            var update = new GistUpdate();

            update.Files.Add(fileName, new GistFileUpdate {
                Content = fileContent, NewFileName = fileName
            });
            await gistClient.Edit(gistId, update);
        }
Esempio n. 7
0
        public static async Task <Gist> GistStrategyUpdate(string id, string name, string description, params string[] contents)
        {
            var newGist = new GistUpdate()
            {
                Description = description
            };

            contents.ForEach((content, i) => newGist.Files.Add(MakeStrategyName(name, i), new GistFileUpdate {
                Content = content
            }));
            return(await ClientFactory().Gist.Edit(id, newGist));
        }
Esempio n. 8
0
        public static async Task <Gist> GistStrategyRestoreByName(string name)
        {
            Gist gist = (await GistStrategyFindByName(name, true)).SingleOrDefault();

            if (gist == null)
            {
                throw new Exception(new { gistArchive = name, message = "Not found" } +"");
            }
            var newGist = new GistUpdate();

            gist.Files.ForEach((file, i) => newGist.Files.Add(file.Key, new GistFileUpdate {
                NewFileName = file.Key.Replace(prefix_, prefix), Content = file.Value.Content
            }));
            return(await ClientFactory().Gist.Edit(gist.Id, newGist));
        }
Esempio n. 9
0
        private void UpdateGist(List <Item> items)
        {
            var jsonContents   = JsonConvert.SerializeObject(items, Formatting.Indented);
            var gistFileUpdate = new GistFileUpdate();

            gistFileUpdate.Content     = jsonContents;
            gistFileUpdate.NewFileName = "todolist.json";
            var gistUpdate = new GistUpdate();

            gistUpdate.Description = "todolist";
            gistUpdate.Files.Add("todolist.json", gistFileUpdate);
            _githubClient.Gist
            .Edit(_gistId, gistUpdate)
            .GetAwaiter()
            .GetResult();
        }
Esempio n. 10
0
        public GistEditViewController(Gist gist)
            : base(UITableViewStyle.Grouped, true)
        {
            Title         = "Edit Gist";
            _originalGist = gist;

            _model             = new GistUpdate();
            _model.Description = gist.Description;

            if (gist.Files != null)
            {
                foreach (var f in gist.Files)
                {
                    _model.Files.Add(f.Key, new GistFileUpdate {
                        Content = f.Value.Content
                    });
                }
            }
        }
Esempio n. 11
0
        public void PostsToTheCorrectUrl()
        {
            var connection = Substitute.For <IApiConnection>();
            var client     = new GistsClient(connection);

            var updateGist = new GistUpdate();

            updateGist.Description = "my newly updated gist";
            var gistFileUpdate = new GistFileUpdate
            {
                NewFileName = "myNewGistTestFile.cs",
                Content     = "new GistsClient(connection).Edit();"
            };

            updateGist.Files.Add("myGistTestFile.cs", gistFileUpdate);

            client.Edit("1", updateGist);

            connection.Received().Patch <Gist>(Arg.Is <Uri>(u => u.ToString() == "gists/1"), Arg.Any <object>());
        }
Esempio n. 12
0
 public async Task Edit(GistUpdate editModel)
 {
     Gist = await this.GetApplication().GitHubClient.Gist.Edit(Id, editModel);
 }
        /// <summary>
        /// Edits a gist
        /// </summary>
        /// <remarks>
        /// http://developer.github.com/v3/gists/#delete-a-gist
        /// </remarks>
        /// <param name="id">The id of the gist</param>
        /// <param name="gistUpdate">The update to the gist</param>
        public IObservable<Gist> Edit(string id, GistUpdate gistUpdate)
        {
            Ensure.ArgumentNotNull(id, "id");
            Ensure.ArgumentNotNull(gistUpdate, "gistUpdate");

            return _client.Edit(id, gistUpdate).ToObservable();
        }
Esempio n. 14
0
        public static async void PutNewJsonGists(string json)
        {
            var token = "";

            try
            {
                StreamReader sr = new StreamReader("token.txt");
                token = sr.ReadLine();
                sr.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("nie znaleziono pliku token.txt, nie można zaktualizować planu na gist");
                throw ex;
            }

            string idTimetable     = "1f97642898f77f65550ff551eca089ca";; //timetable.json
            string idTimetableDate = "db635e765ddfb8b0405d680ac49c6d50";; //timetable_date.json
            var    github          = new GitHubClient(new Octokit.ProductHeaderValue("Parserv2"));

            async Task <bool> sendPatch(string content, string id, string filename)
            {
                var basicAuth = new Credentials("silvernetgroup", token);

                github.Credentials = basicAuth;

                GistUpdate gistUpdate = new GistUpdate()
                {
                    Description = ""
                };

                gistUpdate.Files.Add(filename, new GistFileUpdate()
                {
                    Content = content
                });
                try
                {
                    Gist g = await github.Gist.Edit(id, gistUpdate);
                }
                catch (Exception ex)
                {
                    return(false);
                }
                return(true);
            }

            if (await sendPatch(json, idTimetable, "timetable.json"))
            {
                MessageBox.Show("Timetable updated");
            }
            else
            {
                MessageBox.Show("Nie zaktualizowano planu");
            }

            // To get correct format of date string
            dynamic  deserializedJson = JsonConvert.DeserializeObject(json);
            DateTime date             = deserializedJson.Date;

            if (await sendPatch(JsonConvert.SerializeObject(date), idTimetableDate, "timetable_date.json"))
            {
                MessageBox.Show("Date updated " + date.ToString());
            }
            else
            {
                MessageBox.Show("Nie zaktualizowano daty");
            }
        }