コード例 #1
0
        private async Task <Push> InternalSendPushAsync(BasePush parameters, PushTarget target, string identifier)
        {
            switch (target)
            {
            case PushTarget.Device:
                parameters.DeviceIndentifier = identifier;
                break;

            case PushTarget.Email:
                parameters.Email = identifier;
                break;

            case PushTarget.Channel:
                parameters.ChannelTag = identifier;
                break;

            case PushTarget.Client:
                parameters.ClientIdentifier = identifier;
                break;
            }

            var pushModel = await RequestClient.SendAsync <PushModel>("/v2/pushes", HttpMethod.Post, parameters)
                            .ConfigureAwait(false);

            return(new Push(pushModel, RequestClient));
        }
コード例 #2
0
ファイル: Devices.cs プロジェクト: k-boyle/Pusharp
        internal async Task <IReadOnlyCollection <DeviceModel> > InternalGetDevicesAsync(double after)
        {
            var devicesModel = await RequestClient.SendAsync <DevicesModel>($"/v2/devices?modified_after={after}", HttpMethod.Get, null)
                               .ConfigureAwait(false);

            return(devicesModel.Models);
        }
コード例 #3
0
        public async Task <Chat> CreateChatAsync(ChatParameters parameters)
        {
            var chatModel = await RequestClient.SendAsync <ChatModel>("/v2/chats", HttpMethod.Post, parameters)
                            .ConfigureAwait(false);

            return(new Chat(chatModel, this));
        }
コード例 #4
0
        public async Task ConnectAsync()
        {
            var authentication = await RequestClient.SendAsync <CurrentUserModel>("/v2/users/me", HttpMethod.Get, null).ConfigureAwait(false);

            CurrentUser = new CurrentUser(authentication, RequestClient);

            var socket = new WebSocket(this, _config, _serializer);
            await socket.ConnectAsync();

            if (_config.UseCache)
            {
                await InternalLogAsync(new LogMessage(LogLevel.Verbose, "Building cache"));

                var devices = await GetDevicesAsync();

                foreach (var device in devices)
                {
                    _devices[device.Identifier] = device;
                }

                var pushes = await GetPushesAsync(null);

                foreach (var push in pushes)
                {
                    _pushes[push.Identifier] = push;
                }

                await InternalLogAsync(new LogMessage(LogLevel.Verbose, "Cache built"));
            }

            await InternalReadyAsync();
        }
コード例 #5
0
ファイル: Devices.cs プロジェクト: k-boyle/Pusharp
        public async Task <Device> GetDeviceAsync(string identifier)
        {
            var deviceModel = await RequestClient
                              .SendAsync <DeviceModel>($"/v2/devices/{identifier}", HttpMethod.Get, null)
                              .ConfigureAwait(false);

            return(new Device(deviceModel, this));
        }
コード例 #6
0
        public async Task <ChannelInfo> GetChannelInfoAsync(ChannelInfoParameters channelInfoParameters)
        {
            var channelInfoModel = await RequestClient
                                   .SendAsync <ChannelInfoModel>("/v2/channel-info", HttpMethod.Get, channelInfoParameters)
                                   .ConfigureAwait(false);

            return(new ChannelInfo(channelInfoModel, RequestClient));
        }
コード例 #7
0
        public async Task <Subscription> CreateSubscriptionAsync(SubscriptionParameters subscriptionParameters)
        {
            var subscriptionModel = await RequestClient
                                    .SendAsync <SubscriptionModel>("/v2/subscriptions", HttpMethod.Post, subscriptionParameters)
                                    .ConfigureAwait(false);

            return(new Subscription(subscriptionModel, this));
        }
コード例 #8
0
ファイル: Devices.cs プロジェクト: k-boyle/Pusharp
        /// <summary>
        ///     Creates a device under the client's account.
        /// </summary>
        /// <param name="deviceParameters">The <see cref="DeviceParameters" /> to set up the new device with.</param>
        /// <returns>
        ///     A <see cref="Task" /> representing the asynchronous post operation. This task will resolve with a
        ///     <see cref="Device" /> entity representing the created device.
        /// </returns>
        public async Task <Device> CreateDeviceAsync(DeviceParameters deviceParameters)
        {
            var deviceModel = await RequestClient.SendAsync <DeviceModel>("/v2/devices", HttpMethod.Post, deviceParameters)
                              .ConfigureAwait(false);

            var device = new Device(deviceModel, this);

            return(device);
        }
コード例 #9
0
ファイル: Devices.cs プロジェクト: k-boyle/Pusharp
        /// <summary>
        ///     Retrieves a list of all devices under the client's account.
        /// </summary>
        /// <returns>
        ///     A <see cref="Task" /> representing the asynchronous get operation. This task will resolve with a list of
        ///     <see cref="Device" /> entities, representing the devices under the client's account.
        /// </returns>
        public async Task <IReadOnlyCollection <Device> > GetDevicesAsync()
        {
            var devicesModel = await RequestClient.SendAsync <DevicesModel>("/v2/devices", HttpMethod.Get, null)
                               .ConfigureAwait(false);

            var downloadedDevices = devicesModel.Models;

            return(downloadedDevices.Select(x => new Device(x, this)).ToImmutableList());
        }
コード例 #10
0
        public async Task <IReadOnlyCollection <Chat> > GetChatsAsync()
        {
            var chatsListModel = await RequestClient.SendAsync <ChatsListModel>("/v2/chats", HttpMethod.Get, null)
                                 .ConfigureAwait(false);

            var chatsList = chatsListModel.Chats.Select(x => new Chat(x, this));

            return(chatsList.ToImmutableList());
        }
コード例 #11
0
        public async Task <IReadOnlyCollection <Push> > GetPushesAsync(PushFilterParameters pushFilterParameters)
        {
            var pushesModel = await RequestClient.SendAsync <PushesModel>("/v2/pushes", HttpMethod.Get, pushFilterParameters)
                              .ConfigureAwait(false);

            var pushes = pushesModel.Pushes.Select(x => new Push(x, RequestClient));

            return(pushes.ToImmutableList());
        }
コード例 #12
0
        public async Task <IReadOnlyCollection <Subscription> > GetSubscriptionsAsync()
        {
            var subscriptionsModel = await RequestClient
                                     .SendAsync <SubscriptionsModel>("/v2/subscriptions", HttpMethod.Get, null)
                                     .ConfigureAwait(false);

            var subscriptions = subscriptionsModel.Subscriptions.Select(x => new Subscription(x, this));

            return(subscriptions.ToImmutableList());
        }
コード例 #13
0
        internal async Task <IReadOnlyCollection <PushModel> > InternalGetPushesAsync(Action <PushFilterParameters> pushFilterParameters, double after)
        {
            var parameters = new PushFilterParameters();

            pushFilterParameters(parameters);

            var pushesModel = await RequestClient.SendAsync <PushesModel>($"/v2/pushes?modified_after={after}", HttpMethod.Get, parameters)
                              .ConfigureAwait(false);

            return(pushesModel.Pushes);
        }
コード例 #14
0
ファイル: UploadRequest.cs プロジェクト: k-boyle/Pusharp
        public async Task <UploadRequest> CreateUploadRequestAsync(Action <UploadRequestParameters> uploadRequestParameters)
        {
            var parameters = new UploadRequestParameters();

            uploadRequestParameters(parameters);

            var uploadModel = await RequestClient
                              .SendAsync <UploadRequestModel>("/v2/upload-request", HttpMethod.Post, parameters)
                              .ConfigureAwait(false);

            return(new UploadRequest(uploadModel, RequestClient));
        }
コード例 #15
0
ファイル: Ephemerals.cs プロジェクト: k-boyle/Pusharp
 /// <summary>
 ///     Sends an SMS message to a device.
 /// </summary>
 /// <param name="smsParameters">The parameters to use when sending the message.</param>
 /// <returns>A <see cref="Task" /> representing the asynchronous send operation.</returns>
 public async Task SendSmsAsync(SmsParameters smsParameters)
 {
     await RequestClient.SendAsync("/v2/ephemerals", HttpMethod.Post, smsParameters)
     .ConfigureAwait(false);
 }