Skip to content

Commit

Permalink
Merge pull request #26 from Alma-field/release/v1.0.2
Browse files Browse the repository at this point in the history
Release/v1.0.2
  • Loading branch information
Alma-field authored Oct 3, 2021
2 parents b63e297 + d10c2e2 commit 8627435
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ Twitcatting for Python
- [Japanese](https://github.com/Alma-field/twitcaspy/blob/master/README_JA.md)

## Document
- [latest (v1.0.1)](https://twitcaspy.alma-field.com/en/latest)
- [develop](https://twitcaspy.alma-field.com/en/latest)
- [latest (v1.0.2)](https://twitcaspy.alma-field.com/en/stable)
- [v1.0.2](https://twitcaspy.alma-field.com/en/1.0.2)
- [v1.0.1](https://twitcaspy.alma-field.com/en/1.0.1)
- [v1.0.0](https://twitcaspy.alma-field.com/en/1.0.0)

## Installation
The easiest way to install the latest version from PyPI is by using pip:
Expand Down
5 changes: 4 additions & 1 deletion README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ Python用Twitcattingクライアントライブラリ
- [Japanese/日本語](README_JA.md)

## ドキュメント
- [最新版 (v1.0.1)](https://twitcaspy.alma-field.com/ja/latest)
- [開発版](https://twitcaspy.alma-field.com/ja/latest)
- [最新版 (v1.0.2)](https://twitcaspy.alma-field.com/ja/stable)
- [v1.0.2](https://twitcaspy.alma-field.com/ja/1.0.2)
- [v1.0.1](https://twitcaspy.alma-field.com/ja/1.0.1)
- [v1.0.0](https://twitcaspy.alma-field.com/ja/1.0.0)

## インストール
PyPIから最新バージョンはpipを用いてインストールできます。
Expand Down
85 changes: 85 additions & 0 deletions cassettes/testpostcomment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"version": 1,
"interactions": [
{
"request": {
"method": "POST",
"uri": "https://apiv2.twitcasting.tv/movies/189037369/comments",
"body": "{\"comment\": \"\\u30e2\\u30a4\\uff01\", \"sns\": \"none\"}",
"headers": {
"User-Agent": [
"Python/3.9.1 Requests/2.25.1 twitcaspy/1.0.1"
],
"Accept-Encoding": [
"gzip, deflate"
],
"Accept": [
"*/*"
],
"Connection": [
"keep-alive"
],
"X-Api-Version": [
"2.0"
]
}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"X-WE-ARE-HIRING": [
"https://about.moi.st/ja/recruit/"
],
"Content-Type": [
"application/json;charset=utf-8"
],
"X-RateLimit-Remaining": [
"59"
],
"Content-Length": [
"49"
],
"Pragma": [
"no-cache"
],
"X-RateLimit-Reset": [
"1623846264"
],
"Expires": [
"Thu, 19 Nov 1981 08:52:00 GMT"
],
"Server": [
"Apache"
],
"Strict-Transport-Security": [
"max-age=0"
],
"Cache-Control": [
"no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
],
"Date": [
"Wed, 16 Jun 2021 12:24:24 GMT"
],
"X-Powered-By": [
"PHP/5.6.40"
],
"Set-Cookie": [
"PHPSESSID=r5ijpai75gv66iki1j2b866851; path=/"
],
"Connection": [
"close"
],
"X-RateLimit-Limit": [
"60"
]
},
"body": {
"string": "{\"movie_id\":\"189037369\",\"all_count\":2124,\"comment\":{\"id\":\"7134775954\",\"message\":\"\u30e2\u30a4\uff01\",\"from_user\":{\"id\":\"182224938\",\"screen_id\":\"twitcasting_jp\",\"name\":\"\u30c4\u30a4\u30ad\u30e3\u30b9\u516c\u5f0f\",\"image\":\"http://202-234-44-53.moi.st/image3s/pbs.twimg.com/profile_images/613625726512705536/GLlBoXcS_normal.png\",\"profile\":\"\u30c4\u30a4\u30ad\u30e3\u30b9\u306e\u516c\u5f0f\u30a2\u30ab\u30a6\u30f3\u30c8\u3067\u3059\u3002\u30c4\u30a4\u30ad\u30e3\u30b9\u306b\u95a2\u3059\u308b\u304a\u77e5\u3089\u305b\u306a\u3069\u3092\u6295\u7a3f\u3057\u307e\u3059\u3002\u306a\u304a\u3001\u304a\u554f\u3044\u5408\u308f\u305b\u306f https://t.co/4gCf7XVm7N \u307e\u3067\u304a\u9858\u3044\u3057\u307e\u3059\u3002\u516c\u5f0fFacebook\u30da\u30fc\u30b8https://t.co/bxYVwpzTJB\\n\u516c\u5f0fInstagram\\nhttps://t.co/Bm2O2J2Kfs\",\"level\":24,\"last_movie_id\":\"189037369\",\"is_live\":false,\"supporter_count\":0,\"supporting_count\":0,\"created\":0},\"created\":1479579471}}"
}
}
}
]
}
2 changes: 1 addition & 1 deletion docs/locale/ja/LC_MESSAGES/exceptions.po
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ msgstr ""

#: ../../exceptions.rst:5
msgid "Exceptions"
msgstr ""
msgstr "例外"

#: ../../exceptions.rst:7
msgid ""
Expand Down
2 changes: 1 addition & 1 deletion docs/locale/ja/LC_MESSAGES/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ msgstr "コンテンツ:"

#: ../../index.rst:7
msgid "Twitcaspy Documentation"
msgstr ""
msgstr "Twitcaspy ドキュメント"

#: ../../index.rst:20
msgid "Indices and tables"
Expand Down
17 changes: 17 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ def testgetcomments(self):
ok_(hasattr(data, 'all_count'))
ok_(hasattr(data, 'comments'))

@tape.use_cassette('testpostcomment.json')
def testpostcomment(self):
movie_id = '189037369'
data = self.api.post_comment(
movie_id=movie_id, comment='モイ!', sns='none')
ok_(hasattr(data, 'movie_id'))
eq_(data.movie_id, movie_id)
ok_(hasattr(data, 'all_count'))
ok_(hasattr(data, 'comment'))

@raises(TwitcaspyException)
@tape.use_cassette('testpostcomment_raise.json')
def testpostcomment_raise(self):
movie_id = '189037369'
data = self.api.post_comment(
movie_id=movie_id, comment='1234567890'*15, sns='none')

@tape.use_cassette('testgetsupportingstatus.json')
def testgetsupportingstatus(self):
from twitcaspy.models import User
Expand Down
2 changes: 1 addition & 1 deletion twitcaspy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
Twitcaspy : Twitcasting API library
"""
__version__ = '1.0.1'
__version__ = '1.0.2'
__author__ = 'Alma-field'
__license__ = 'MIT'

Expand Down
17 changes: 13 additions & 4 deletions twitcaspy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def request(
continue
if k not in endpoint_parameters:
log.warning(f'Unexpected parameter: {k}')
continue
params[k] = arg
log.debug("PARAMS: %r", params)

Expand All @@ -125,7 +126,8 @@ def request(
auth=self.auth.auth
)
except Exception as e:
raise TwitcaspyException(f'Failed to send request: {e}').with_traceback(sys.exc_info()[2])
raise TwitcaspyException(f'Failed to send request: {e}')\
.with_traceback(sys.exc_info()[2])

# If an error was returned, throw an exception
self.last_response = response
Expand Down Expand Up @@ -583,14 +585,16 @@ def get_comments(self, movie_id, **kwargs):
endpoint_parameters=('offset', 'limit', 'slice_id'), **kwargs)

@payload('comment', movie_id=['raw', False], all_count=['raw', False])
def post_comment(self, comment, **kwargs):
"""post_comment(comment, *, sns='none')
def post_comment(self, movie_id, comment, **kwargs):
"""post_comment(movie_id, comment, *, sns='none')
| Post a comment.
| It can be executed only on a user-by-user basis.
Parameters
----------
movie_id: :class:`str`
|movie_id|
comment: :class:`str`
| Comment text to post.
| Must be 1 to 140 characters.
Expand Down Expand Up @@ -621,11 +625,16 @@ def post_comment(self, comment, **kwargs):
----------
https://apiv2-doc.twitcasting.tv/#post-comment
"""
if not 1 <= len(hashtag) <= 140:
if not 1 <= len(comment) <= 140:
raise TwitcaspyException(
'`comment` must be in the range 1-140 characters.')
else:
post_data = {'comment': comment}
if 'sns' in kwargs:
if kwargs['sns'] in ['none', 'normal', 'reply']:
post_data['sns'] = kwargs['sns']
else:
post_data['sns'] = 'none'
return self.request(
'POST', f'/movies/{movie_id}/comments',
post_data=post_data, **kwargs)
Expand Down

0 comments on commit 8627435

Please sign in to comment.