mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Added new save/unsave stories by story_hash endpoint for @jaredsinclair. Also cleaned up API docs to show deprecated vs new story hash urls.
This commit is contained in:
parent
1cf708a430
commit
9b5dbc1822
5 changed files with 94 additions and 40 deletions
|
@ -29,7 +29,9 @@ urlpatterns = patterns('',
|
|||
url(r'^mark_story_as_unread', views.mark_story_as_unread),
|
||||
url(r'^mark_story_hash_as_unread', views.mark_story_hash_as_unread, name='mark-story-hash-as-unread'),
|
||||
url(r'^mark_story_as_starred', views.mark_story_as_starred),
|
||||
url(r'^mark_story_hash_as_starred', views.mark_story_hash_as_starred),
|
||||
url(r'^mark_story_as_unstarred', views.mark_story_as_unstarred),
|
||||
url(r'^mark_story_hash_as_unstarred', views.mark_story_hash_as_unstarred),
|
||||
url(r'^mark_feed_as_read', views.mark_feed_as_read),
|
||||
url(r'^delete_feed_by_url', views.delete_feed_by_url, name='delete-feed-by-url'),
|
||||
url(r'^delete_feed', views.delete_feed, name='delete-feed'),
|
||||
|
|
|
@ -1759,12 +1759,25 @@ def iframe_buster(request):
|
|||
@ajax_login_required
|
||||
@json.json_view
|
||||
def mark_story_as_starred(request):
|
||||
code = 1
|
||||
feed_id = int(request.REQUEST['feed_id'])
|
||||
story_id = request.REQUEST['story_id']
|
||||
user_tags = request.REQUEST.getlist('user_tags')
|
||||
message = ""
|
||||
story, _ = MStory.find_story(story_feed_id=feed_id, story_id=story_id)
|
||||
return _mark_story_as_starred(request)
|
||||
|
||||
@required_params('story_hash')
|
||||
@ajax_login_required
|
||||
@json.json_view
|
||||
def mark_story_hash_as_starred(request):
|
||||
return _mark_story_as_starred(request)
|
||||
|
||||
def _mark_story_as_starred(request):
|
||||
code = 1
|
||||
feed_id = int(request.REQUEST.get('feed_id', 0))
|
||||
story_id = request.REQUEST.get('story_id', None)
|
||||
story_hash = request.REQUEST.get('story_hash', None)
|
||||
user_tags = request.REQUEST.getlist('user_tags')
|
||||
message = ""
|
||||
if story_hash:
|
||||
story, _ = MStory.find_story(story_hash=story_hash)
|
||||
else:
|
||||
story, _ = MStory.find_story(story_feed_id=feed_id, story_id=story_id)
|
||||
|
||||
if not story:
|
||||
return {'code': -1, 'message': "Could not find story to save."}
|
||||
|
@ -1807,13 +1820,25 @@ def mark_story_as_starred(request):
|
|||
@ajax_login_required
|
||||
@json.json_view
|
||||
def mark_story_as_unstarred(request):
|
||||
code = 1
|
||||
story_id = request.POST['story_id']
|
||||
starred_counts = None
|
||||
return _mark_story_as_unstarred(request)
|
||||
|
||||
starred_story = MStarredStory.objects(user_id=request.user.pk, story_guid=story_id)
|
||||
if not starred_story:
|
||||
starred_story = MStarredStory.objects(user_id=request.user.pk, story_hash=story_id)
|
||||
@required_params('story_hash')
|
||||
@ajax_login_required
|
||||
@json.json_view
|
||||
def mark_story_hash_as_unstarred(request):
|
||||
return _mark_story_as_unstarred(request)
|
||||
|
||||
def _mark_story_as_unstarred(request):
|
||||
code = 1
|
||||
story_id = request.POST.get('story_id', None)
|
||||
story_hash = request.REQUEST.get('story_hash', None)
|
||||
starred_counts = None
|
||||
starred_story = None
|
||||
|
||||
if story_id:
|
||||
starred_story = MStarredStory.objects(user_id=request.user.pk, story_guid=story_id)
|
||||
if not story_id or not starred_story:
|
||||
starred_story = MStarredStory.objects(user_id=request.user.pk, story_hash=story_hash or story_id)
|
||||
if starred_story:
|
||||
starred_story = starred_story[0]
|
||||
logging.user(request, "~FCUnstarring: ~SB%s" % (starred_story.story_title[:50]))
|
||||
|
|
|
@ -1739,11 +1739,14 @@ class MStory(mongo.Document):
|
|||
return extra_stories_count
|
||||
|
||||
@classmethod
|
||||
def find_story(cls, story_feed_id, story_id, original_only=False):
|
||||
def find_story(cls, story_feed_id=None, story_id=None, story_hash=None, original_only=False):
|
||||
from apps.social.models import MSharedStory
|
||||
original_found = False
|
||||
if story_hash:
|
||||
story_id = story_hash
|
||||
story_hash = cls.ensure_story_hash(story_id, story_feed_id)
|
||||
|
||||
if not story_feed_id:
|
||||
feed_id, _ = cls.split_story_hash(story_hash)
|
||||
if isinstance(story_id, ObjectId):
|
||||
story = cls.objects(id=story_id).limit(1).first()
|
||||
else:
|
||||
|
|
|
@ -243,9 +243,8 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
if (callback) callback(data);
|
||||
};
|
||||
|
||||
this.make_request('/reader/mark_story_as_starred', {
|
||||
story_id: story_id,
|
||||
feed_id: story.get('story_feed_id'),
|
||||
this.make_request('/reader/mark_story_hash_as_starred', {
|
||||
story_hash: story.get('story_hash'),
|
||||
user_tags: story.get('user_tags')
|
||||
}, pre_callback);
|
||||
},
|
||||
|
@ -267,8 +266,8 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
if (callback) callback(data);
|
||||
};
|
||||
|
||||
this.make_request('/reader/mark_story_as_unstarred', {
|
||||
story_id: story_id
|
||||
this.make_request('/reader/mark_story_hash_as_unstarred', {
|
||||
story_hash: story.get('story_hash')
|
||||
}, pre_callback);
|
||||
},
|
||||
|
||||
|
|
|
@ -305,30 +305,11 @@
|
|||
example: >
|
||||
story_hash=123:a1d62b&story_hash=1456789:4e3c12
|
||||
|
||||
- url: /reader/mark_story_hash_as_unread
|
||||
method: POST
|
||||
short_desc: "Mark a story as unread."
|
||||
long_desc:
|
||||
- "Mark a single story as unread using its unique story_hash."
|
||||
- "Premium users can mark up to 30 days as unread. Free users only have 15 days."
|
||||
- >
|
||||
If a story is too old to mark as read, look for (and display to the user) the
|
||||
`message` parameter returned back to you.
|
||||
tips:
|
||||
- >
|
||||
This endpoint is newer than all of the other mark as read endpoints, so use this one.
|
||||
The other endpoints are maintained for old clients to use.
|
||||
params:
|
||||
- key: story_hash
|
||||
desc: "A story hash to mark as unread."
|
||||
required: true
|
||||
example: >
|
||||
story_hash=123:a1d62b
|
||||
|
||||
- url: /reader/mark_story_as_read
|
||||
method: POST
|
||||
short_desc: "Mark a story as read (deprecated)."
|
||||
long_desc:
|
||||
- "<b>Deprecated! Just send the `story_hash` to `mark_story_hashes_as_read`.</b>"
|
||||
- "Mark stories as read (deprecated)."
|
||||
- "Multiple story ids can be sent at once."
|
||||
- "Each story must be from the same feed."
|
||||
|
@ -350,6 +331,7 @@
|
|||
method: POST
|
||||
short_desc: "Mark stories from multiple feeds as read (deprecated)."
|
||||
long_desc:
|
||||
- "<b>Deprecated! Just send the `story_hash` to `mark_story_hashes_as_read`.</b>"
|
||||
- "Marks multiple stories as read."
|
||||
- "Multiple story ids can be sent at once."
|
||||
- "Multiple feeds can be sent."
|
||||
|
@ -366,6 +348,7 @@
|
|||
method: POST
|
||||
short_desc: "Mark stories from a blurblog as read (deprecated)."
|
||||
long_desc:
|
||||
- "<b>Deprecated! Just send the `story_hash` to `mark_story_hashes_as_read`.</b>"
|
||||
- "Marks multiple stories as read."
|
||||
- "Multiple story ids can be sent at once."
|
||||
- "Multiple feeds can be sent."
|
||||
|
@ -392,7 +375,27 @@
|
|||
desc: "Feed id that the story is from."
|
||||
required: true
|
||||
example: "42"
|
||||
|
||||
|
||||
- url: /reader/mark_story_hash_as_unread
|
||||
method: POST
|
||||
short_desc: "Mark a story as unread."
|
||||
long_desc:
|
||||
- "Mark a single story as unread using its unique story_hash."
|
||||
- "Premium users can mark up to 30 days as unread. Free users only have 15 days."
|
||||
- >
|
||||
If a story is too old to mark as read, look for (and display to the user) the
|
||||
`message` parameter returned back to you.
|
||||
tips:
|
||||
- >
|
||||
This endpoint is newer than all of the other mark as read endpoints, so use this one.
|
||||
The other endpoints are maintained for old clients to use.
|
||||
params:
|
||||
- key: story_hash
|
||||
desc: "A story hash to mark as unread."
|
||||
required: true
|
||||
example: >
|
||||
story_hash=123:a1d62b
|
||||
|
||||
- url: /reader/mark_story_as_starred
|
||||
method: POST
|
||||
short_desc: "Mark a story as starred (saved)."
|
||||
|
@ -407,6 +410,17 @@
|
|||
desc: "Feed id that the story is from."
|
||||
required: true
|
||||
example: "42"
|
||||
|
||||
- url: /reader/mark_story_hash_as_starred
|
||||
method: POST
|
||||
short_desc: "Mark a story as starred (saved)."
|
||||
long_desc:
|
||||
- "Mark a story as starred (saved)."
|
||||
params:
|
||||
- key: story_hash
|
||||
desc: "Story to save, specified by hash."
|
||||
required: true
|
||||
example: "64:a295ed"
|
||||
|
||||
- url: /reader/mark_story_as_unstarred
|
||||
method: POST
|
||||
|
@ -423,6 +437,17 @@
|
|||
required: true
|
||||
example: "42"
|
||||
|
||||
- url: /reader/mark_story_hash_as_unstarred
|
||||
method: POST
|
||||
short_desc: "Mark a story as unstarred (unsaved)."
|
||||
long_desc:
|
||||
- "Mark a story as unstarred (unsaved)."
|
||||
params:
|
||||
- key: story_hash
|
||||
desc: "Story to unsave, specified by hash."
|
||||
required: true
|
||||
example: "64:a295ed"
|
||||
|
||||
- url: /reader/mark_feed_as_read
|
||||
method: POST
|
||||
short_desc: "Mark a list of feeds as read."
|
||||
|
|
Loading…
Add table
Reference in a new issue