Skip to content

Commit

Permalink
Add simple implementation of star/unstar feature via fever api
Browse files Browse the repository at this point in the history
  • Loading branch information
christianschmidt committed May 29, 2013
1 parent 331fe28 commit 8b25fde
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
13 changes: 13 additions & 0 deletions app/commands/stories/mark_as_starred.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require_relative "../../repositories/story_repository"

class MarkAsStarred
def initialize(story_id, repository = StoryRepository)
@story_id = story_id
@repo = repository
end

def mark_as_starred
@repo.fetch(@story_id).update_attributes(is_starred: true)
end
end

14 changes: 14 additions & 0 deletions app/commands/stories/mark_as_unstarred.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require_relative "../../repositories/story_repository"

class MarkAsUnstarred
def initialize(story_id, repository = StoryRepository)
@story_id = story_id
@repo = repository
end

def mark_as_unstarred
@repo.fetch(@story_id).update_attributes(is_starred: false)
end
end


13 changes: 12 additions & 1 deletion fever_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
require_relative "app/commands/stories/mark_as_read"
require_relative "app/commands/stories/mark_as_unread"

require_relative "app/commands/stories/mark_as_starred"
require_relative "app/commands/stories/mark_as_unstarred"

class FeverAPI < Sinatra::Base
configure do
set :database_file, "config/database.yml"
Expand Down Expand Up @@ -76,7 +79,7 @@ def get_response(params, is_json = true)
end

if keys.include?(:saved_item_ids)
response[:saved_item_ids] = ""
response[:saved_item_ids] = starred_stories.map{|s| s.id}.join(",")
end

if params[:mark] == "item"
Expand All @@ -85,6 +88,10 @@ def get_response(params, is_json = true)
MarkAsRead.new(params[:id]).mark_as_read
when "unread"
MarkAsUnread.new(params[:id]).mark_as_unread
when "saved"
MarkAsStarred.new(params[:id]).mark_as_starred
when "unsaved"
MarkAsUnstarred.new(params[:id]).mark_as_unstarred
end
end

Expand All @@ -99,6 +106,10 @@ def unread_stories(since_id = nil)
end
end

def starred_stories
StoryRepository.starred
end

def feeds
FeedRepository.list
end
Expand Down

0 comments on commit 8b25fde

Please sign in to comment.