Skip to content

Commit

Permalink
tutorial: route renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
jell-o-fishi committed Nov 13, 2022
1 parent e438ea2 commit a3cdf0d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions examples/tutorial/reactivex/chat_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ async def channel_message(self, channel: str, content: str):

async def upload(self, file_name, content):
await self._rsocket.request_response(Payload(content, composite(
route('upload'),
route('file.upload'),
metadata_item(ensure_bytes(file_name), chat_filename_mimetype)
)))

async def download(self, file_name):
return await self._rsocket.request_response(Payload(
metadata=composite(route('download'), metadata_item(ensure_bytes(file_name), chat_filename_mimetype))))
metadata=composite(route('file.download'), metadata_item(ensure_bytes(file_name), chat_filename_mimetype))))

async def list_files(self) -> List[str]:
request = Payload(metadata=composite(route('file_names')))
request = Payload(metadata=composite(route('files')))
return await ReactiveXClient(self._rsocket).request_stream(
request
).pipe(operators.map(lambda x: utf8_decode(x.data)),
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorial/reactivex/chat_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ async def leave_channel(payload: Payload) -> Awaitable[Payload]:
chat_data.channel_users[channel_name].discard(self._session.session_id)
return create_response()

@router.response('upload')
@router.response('file.upload')
async def upload_file(payload: Payload, composite_metadata: CompositeMetadata) -> Awaitable[Payload]:
chat_data.files[get_file_name(composite_metadata)] = payload.data
return create_response()

@router.response('download')
@router.response('file.download')
async def download_file(composite_metadata: CompositeMetadata) -> Awaitable[Payload]:
file_name = get_file_name(composite_metadata)
return create_response(chat_data.files[file_name],
composite(metadata_item(ensure_bytes(file_name), chat_filename_mimetype)))

@router.stream('file_names')
@router.stream('files')
async def get_file_names() -> Publisher:
count = len(chat_data.files)
generator = ((Payload(ensure_bytes(file_name)), index == count) for (index, file_name) in
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorial/step4/chat_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ async def channel_message(self, channel: str, content: str):

async def upload(self, file_name, content):
await self._rsocket.request_response(Payload(content, composite(
route('upload'),
route('file.upload'),
metadata_item(ensure_bytes(file_name), chat_filename_mimetype)
)))

async def download(self, file_name):
return await self._rsocket.request_response(Payload(
metadata=composite(route('download'), metadata_item(ensure_bytes(file_name), chat_filename_mimetype))))
metadata=composite(route('file.download'), metadata_item(ensure_bytes(file_name), chat_filename_mimetype))))

async def list_files(self) -> List[str]:
request = Payload(metadata=composite(route('file_names')))
request = Payload(metadata=composite(route('files')))
response = await AwaitableRSocket(self._rsocket).request_stream(request)
return list(map(lambda _: utf8_decode(_.data), response))

Expand Down
6 changes: 3 additions & 3 deletions examples/tutorial/step4/chat_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ async def leave_channel(payload: Payload) -> Awaitable[Payload]:
chat_data.channel_users[channel_name].discard(self._session.session_id)
return create_response()

@router.response('upload')
@router.response('file.upload')
async def upload_file(payload: Payload, composite_metadata: CompositeMetadata) -> Awaitable[Payload]:
chat_data.files[get_file_name(composite_metadata)] = payload.data
return create_response()

@router.response('download')
@router.response('file.download')
async def download_file(composite_metadata: CompositeMetadata) -> Awaitable[Payload]:
file_name = get_file_name(composite_metadata)
return create_response(chat_data.files[file_name],
composite(metadata_item(ensure_bytes(file_name), chat_filename_mimetype)))

@router.stream('file_names')
@router.stream('files')
async def get_file_names() -> Publisher:
count = len(chat_data.files)
generator = ((Payload(ensure_bytes(file_name)), index == count) for (index, file_name) in
Expand Down
6 changes: 3 additions & 3 deletions examples/tutorial/step5/chat_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ async def channel_message(self, channel: str, content: str):

async def upload(self, file_name, content):
await self._rsocket.request_response(Payload(content, composite(
route('upload'),
route('file.upload'),
metadata_item(ensure_bytes(file_name), chat_filename_mimetype)
)))

async def download(self, file_name):
return await self._rsocket.request_response(Payload(
metadata=composite(route('download'), metadata_item(ensure_bytes(file_name), chat_filename_mimetype))))
metadata=composite(route('file.download'), metadata_item(ensure_bytes(file_name), chat_filename_mimetype))))

async def list_files(self) -> List[str]:
request = Payload(metadata=composite(route('file_names')))
request = Payload(metadata=composite(route('files')))
response = await AwaitableRSocket(self._rsocket).request_stream(request)
return list(map(lambda _: utf8_decode(_.data), response))

Expand Down
6 changes: 3 additions & 3 deletions examples/tutorial/step5/chat_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ async def leave_channel(payload: Payload) -> Awaitable[Payload]:
chat_data.channel_users[channel_name].discard(self._session.session_id)
return create_response()

@router.response('upload')
@router.response('file.upload')
async def upload_file(payload: Payload, composite_metadata: CompositeMetadata) -> Awaitable[Payload]:
chat_data.files[get_file_name(composite_metadata)] = payload.data
return create_response()

@router.response('download')
@router.response('file.download')
async def download_file(composite_metadata: CompositeMetadata) -> Awaitable[Payload]:
file_name = get_file_name(composite_metadata)
return create_response(chat_data.files[file_name],
composite(metadata_item(ensure_bytes(file_name), chat_filename_mimetype)))

@router.stream('file_names')
@router.stream('files')
async def get_file_names() -> Publisher:
count = len(chat_data.files)
generator = ((Payload(ensure_bytes(file_name)), index == count) for (index, file_name) in
Expand Down

0 comments on commit a3cdf0d

Please sign in to comment.