Exemplo n.º 1
0
        public static async Task <ISimpleResponse <T> > SendMessage <T>(ISimpleRestClient client, ISimpleMessage message)
        {
            T messageTypeToReturn        = Activator.CreateInstance <T>();
            ISimpleResponse <T> toReturn = new SimpleResponse <T>();

            HttpClient restClient = new HttpClient();

            Windows.Web.Http.HttpMethod method = message.HttpMethod == HttpMethod.Get ? Windows.Web.Http.HttpMethod.Get : Windows.Web.Http.HttpMethod.Post;

            // Add Global Request Parameters
            foreach (var globalRequestParameter in client.GlobalRequestParameters)
            {
                message.Parameters[globalRequestParameter.Key] = globalRequestParameter.Value;
            }

            Uri uriWithQueryString = await MessageHelper.BuildUri(baseUrl : client.BaseUrl, endPointPath : message.EndPointPath, queryStringParameters : message.Parameters);

            HttpRequestMessage requestMessage = new HttpRequestMessage(method, uriWithQueryString);

            // Add Headers
            foreach (var header in client.Headers)
            {
                requestMessage.Headers.Add(header.Key, header.Value);
            }


            HttpResponseMessage response = await restClient.SendRequestAsync(requestMessage);

            toReturn.DataRaw       = response.Content;
            toReturn.DataConverted = Deserializer.JsonToObject <T>(response.Content.ToString());


            return(toReturn);
        }
Exemplo n.º 2
0
        public JiraClient(string baseUrl, string username, string password, bool useTempo, string tempoToken)
        {
            var url = baseUrl + (baseUrl.EndsWith("/") ? "" : "/") + "rest/api/2";

            jiraClient = SimpleRestClient.WithBasicAuthentication(url, username, password, GetErrorMessages);

            try
            {
                myUser = GetCurrentUser();
            }
            catch (Exception e)
            {
                throw new ConnectionError(ConnectionError.Type.Jira, "Error connecting to jira", e);
            }

            if (useTempo)
            {
                tempoClient = SimpleRestClient.WithBearerAuthentication("https://api.tempo.io/core/3", tempoToken, null);

                try
                {
                    var queryDate = DateTime.UtcNow;
                    tempoClient.Get <TempoWorkLogSearch>(HttpStatusCode.OK, $"worklogs/user/{myUser.accountId}?from={queryDate:yyyy-MM-dd}&to={queryDate:yyyy-MM-dd}");
                }
                catch (Exception e)
                {
                    throw new ConnectionError(ConnectionError.Type.Tempo, "Error connecting to tempo", e);
                }
            }
            else
            {
                tempoClient = null;
            }
        }
Exemplo n.º 3
0
        protected MovesClient(ISimpleRestClient restClient)
            : base(restClient)
        {
            AuthenticationBaseUrl = "https://api.moves-app.com/oauth/v1/";

            Places    = new PlaceEndpoint(RestClient);
            Profile   = new ProfileEndpoint(RestClient);
            Storyline = new StorylineEndpoint(RestClient);
            Summary   = new SummaryEndpoint(RestClient);
            Activity  = new ActivityEndpoint(RestClient);
        }
Exemplo n.º 4
0
        public JiraRestClient(string baseUrl, string username, string password, bool useTempo)
        {
            var url = baseUrl + (baseUrl.EndsWith("/") ? "" : "/") + "rest/";

            restClient = new SimpleRestClient(url, username, password, GetErrorMessages);
            myUser     = GetCurrentUser();
            if (useTempo)
            {
                try
                {
                    //NOTE THIS IS NOT THE RIGHT TYPE, BUT NOT EXPECTING VALID DATA ANYWAY
                    restClient.Get <List <string> >(HttpStatusCode.OK, "tempo-timesheets/3/worklogs?dateFrom=1990-01-01&dateTo=1990-01-02");
                    HasTempo = true;
                }
                catch (Exception)
                {
                    HasTempo = false;
                }
            }
            else
            {
                HasTempo = false;
            }
        }
 public MunicipalityTaxController(ILogger <MunicipalityTaxController> logger,
                                  ISimpleRestClient simpleRestClient)
 {
     this._logger          = logger;
     this.simpleRestClient = simpleRestClient;
 }
Exemplo n.º 6
0
 public SummaryEndpoint(ISimpleRestClient restClient)
     : base(restClient, "summary")
 {
 }
Exemplo n.º 7
0
 public JiraRestClient(string baseUrl, string username, string password)
 {
     var url = baseUrl + (baseUrl.EndsWith("/") ? "" : "/") + "rest/api/2/";
     restClient = new SimpleRestClient(url, username, password, GetErrorMessages);
 }
Exemplo n.º 8
0
 public PlaceEndpoint(ISimpleRestClient restClient)
     : base(restClient, "places")
 {
 }
Exemplo n.º 9
0
 public DailyEndpointBase(ISimpleRestClient restClient, string apiName)
     : base(restClient)
 {
     this.ApiName = apiName;
 }
Exemplo n.º 10
0
 public ProfileEndpoint(ISimpleRestClient restClient)
     : base(restClient)
 {
 }
Exemplo n.º 11
0
 public StorylineEndpoint(ISimpleRestClient restClient)
     : base(restClient, "storyline")
 {
 }
Exemplo n.º 12
0
 public EndpointBase(ISimpleRestClient restClient)
 {
     RestClient = restClient;
 }
Exemplo n.º 13
0
 public ActivityEndpoint(ISimpleRestClient restClient)
     : base(restClient, "activities")
 {
 }
Exemplo n.º 14
0
 private MovesClient CreateMovesClient(ISimpleRestClient restClient)
 {
     return(new TestableMovesClient(restClient));
 }
Exemplo n.º 15
0
 public TestableMovesClient(ISimpleRestClient restClient)
     : base(restClient)
 {
 }