Exemplo n.º 1
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task FunctionHandler(SaasafrasAppTableCreateRequest input, ILambdaContext context)
        {
            var apiKey           = System.Environment.GetEnvironmentVariable("API_KEY");
            var baseUrl          = System.Environment.GetEnvironmentVariable("BASE_URL");
            var connectionString = System.Environment.GetEnvironmentVariable("PODIO_DB_CONNECTION_STRING");

            var client = new BbcServiceClient(baseUrl, apiKey);
            SaasafrasTokenProvider token = new SaasafrasTokenProvider(input.solutionId, input.version, client);

            //var podio = new PodioCore.Podio(token);

            System.Console.WriteLine($"Entered function...");
            ILambdaSerializer serializer = new Amazon.Lambda.Serialization.Json.JsonSerializer();

            using (var _mysql = new MySqlQueryHandler(connectionString ?? "server=mpactprodata.czsyc7qltifw.us-east-2.rds.amazonaws.com;uid=admin;pwd=perilousDeity;database=podioTest"))
            {
                if (input.spaceName != "Contacts")
                {
                    await _mysql.CreatePodioAppView(input.solutionId, input.version, input.spaceName, input.appName);

                    await _mysql.CreatePodioAppTable(input.solutionId, input.version, input.spaceName, input.appName);
                }
                else
                {
                    await _mysql.CreatePodioContactsTable();

                    var http = new System.Net.Http.HttpClient();
                    http.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("OAuth2", token.TokenData.AccessToken);
                    http.BaseAddress = new Uri("https://api.podio.com/");
                    int limit  = 50;
                    int offset = 0;
                    int count  = 0;
                    do
                    {
                        var content = await http.GetStringAsync($"contact?offset={offset}&limit={limit}");

                        var contacts = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PodioContact> >(content);
                        foreach (var contact in contacts)
                        {
                            await _mysql.AddContact(
                                contact.ProfileId,
                                contact.UserId,
                                contact.Name,
                                (contact.Email?.Length ?? 0) > 0?contact.Email[0] : "",
                                (contact.Address?.Length ?? 0) > 0?contact.Address[0] : "",
                                contact.City,
                                contact.State,
                                contact.Zip,
                                contact.Type,
                                (contact.Phone?.Length ?? 0) > 0?contact.Phone[0] : ""
                                );
                        }
                        count   = contacts.Count;
                        offset += limit;
                    }while (count >= limit);
                }
            }
        }
Exemplo n.º 2
0
        static void Main()
        {
            var request = new SaasafrasAppTableCreateRequest
            {
                solutionId = "mpactprobeta",
                version    = "3.0",
                spaceName  = "Contacts"
            };
            var function = new SaasafrasAppTableCreateFunction();

            function.FunctionHandler(request, null).Wait();
        }