github.com/hyperledger/aries-framework-go@v0.3.2/pkg/client/messagepickup/client.go (about) 1 /* 2 Copyright Scoir Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package messagepickup 8 9 import ( 10 "errors" 11 "fmt" 12 13 "github.com/hyperledger/aries-framework-go/pkg/didcomm/common/service" 14 "github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/messagepickup" 15 ) 16 17 type provider interface { 18 Service(id string) (interface{}, error) 19 } 20 21 // Client enable access to message pickup api. 22 type Client struct { 23 service.Event 24 messagepickupSvc protocolService 25 } 26 27 type protocolService interface { 28 // DIDComm service 29 service.DIDComm 30 31 StatusRequest(connectionID string) (*messagepickup.Status, error) 32 33 BatchPickup(connectionID string, size int) (int, error) 34 35 Noop(connectionID string) error 36 } 37 38 // New return new instance of messagepickup client. 39 func New(ctx provider) (*Client, error) { 40 svc, err := ctx.Service(messagepickup.MessagePickup) 41 if err != nil { 42 return nil, fmt.Errorf("failed to create msg pickup service: %w", err) 43 } 44 45 messagepickupSvc, ok := svc.(protocolService) 46 if !ok { 47 return nil, errors.New("cast service to message pickup service failed") 48 } 49 50 return &Client{ 51 Event: messagepickupSvc, 52 messagepickupSvc: messagepickupSvc, 53 }, nil 54 } 55 56 // StatusRequest request a status message. 57 func (r *Client) StatusRequest(connectionID string) (*messagepickup.Status, error) { 58 sts, err := r.messagepickupSvc.StatusRequest(connectionID) 59 if err != nil { 60 return nil, fmt.Errorf("message pickup client - status request: %w", err) 61 } 62 63 return sts, nil 64 } 65 66 // BatchPickup request to have multiple waiting messages sent inside a batch message 67 // to the DID. 68 func (r *Client) BatchPickup(connectionID string, size int) (int, error) { 69 count, err := r.messagepickupSvc.BatchPickup(connectionID, size) 70 if err != nil { 71 return -1, fmt.Errorf("message pickup client - batch pickup: %w", err) 72 } 73 74 return count, nil 75 } 76 77 // Noop a message to reestablish a connection when there is no other reason to message the mediator. 78 func (r *Client) Noop(connectionID string) error { 79 return r.messagepickupSvc.Noop(connectionID) 80 }