Coder Social home page Coder Social logo

serviceclients.bitbucket's Introduction

ServiceClients.Bitbucket

C# service client for the Bitbucket v2.0 API.

See the reference at https://confluence.atlassian.com/display/BITBUCKET/Version+2

Curently the API is covering the repository, pull requests, commit, branch restriction, diff, teams and user resources.

In case of API changes or if you find a bug, create an issue.

If you like this library and want to improve it, contributions are always welcomed.

Usage

using System;
using System.Collections.Generic;
using System.Diagnostics;
using IsKernel.ServiceClients.Bitbucket.Clients.Abstract;
using IsKernel.ServiceClients.Bitbucket.Clients.Concrete;
using IsKernel.ServiceClients.Bitbucket.Contracts.Repositories;
using IsKernel.ServiceClients.Bitbucket.Contracts.Requests;
using IsKernel.ServiceClients.Bitbucket.Contracts.Responses;
using IsKernel.ServiceClients.Bitbucket.Contracts.Users;

namespace IsKernel.ServiceClients.Bitbucket.ConsoleExample
{
	public class Program
	{
		private const string API_KEY = "your api key";
		private const string API_KEY_SECRET = "your secret api key";
		
		public static IBitbucketClient AuthenticateWithUserPassword(IBitbucketAuthenticationClient authClient)
		{
			Console.WriteLine("User : ");
			var user = Console.ReadLine();
			Console.WriteLine("Password : ");
			var password = Console.ReadLine();
			IBitbucketClient client = authClient.AuthentificateWithLogin(user, password);
			return client;
		}
		
		public static IBitbucketClient AuthenticateWithOauth(IBitbucketAuthenticationClient authClient)
		{
			Uri uri = authClient.RequestTokenAsync().Result;
			var uriString = uri.ToString();
			Process.Start(uriString);
			Console.WriteLine("Enter verifier: ");
			var verifier = Console.ReadLine();
			IBitbucketClient client = authClient.AuthentificateAsync(verifier).Result;
			return client;
		}
		
		public static void Main(string[] args)
		{
			IBitbucketAuthenticationClient authClient = new BitbucketAuthenticationClient(API_KEY, API_KEY_SECRET);
			IBitbucketClient client = AuthenticateWithOauth(authClient);
			
			Console.WriteLine("Bitbucket username: ");
			var username = Console.ReadLine();
			
			//Show profile
			User user = client.UserClient.GetProfileAsync(username).Result;
			Console.WriteLine("The user {0} created his profile on {1}", user.Username, user.CreatedOn); 
			
			//Show repositories
			PaginatedRequest request = new PaginatedRequest(10, 1);
			var repositories = new List<Repository>();
			
			PaginatedResponse<Repository> response 
							= client.RepositoryClient.GetAllAsync(username, request).Result;
			repositories.AddRange(response.Values);
			while(response.NextPageUrl != null)
			{
				request.Page.Value++;
				response = client.RepositoryClient.GetAllAsync(username, request).Result;
				repositories.AddRange(response.Values);
			}
			Console.WriteLine("He has {0} repositories : ", response.Total);
			foreach (var element in repositories) 
			{
				Console.WriteLine(element.Name + " " + element.Language + " " + element.CreatedOn);
			}
			
			
			Console.Write("Press any key to continue . . . ");
			Console.ReadKey(true);
		}
	}
}

Status:

  • Authentification : Done, tested
  • Repository resource : Done, tested
  • Pull requests resource : Done, tested
  • Commit resource : Done, tested
  • Branch-restrictions resource : Done, tested
  • Diff resource : Done, tested
  • Teams resource : Done, tested
  • Users resource : Done, tested

Version

1.0

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.