Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major Additions - Characters and Staff #26

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Update the documentation!
- Add to_xml methods to character and people
- Update the to_xml method for anime
- Add character attribute to manga results
- Add staff attribute to manga
- Interface to search for manga serialisation and anime producer
- Cleaner interface to returning full list of search results.
70 changes: 69 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
require 'json'
require './my_anime_list'


class App < Sinatra::Base

configure do
Expand Down Expand Up @@ -142,6 +141,57 @@ class App < Sinatra::Base
end
end

# GET /character/#{character_id}

get '/character/:id' do
pass unless params[:id] =~ /^\d+$/

if params[:mine] == '1'
authenticate unless session['cookie_string']
character = MyAnimeList::Character.scrape_character(params[:id], session['cookie_string'])
else
character = MyAnimeList::Character.scrape_character(params[:id])

# Caching.
expires 3600, :public, :must_revalidate
last_modified Time.now
etag "character/#{character.id}"
end

case params[:format]
when 'xml'
# TO DO
character.to_xml
else
params[:callback].nil? ? character.to_json : "#{params[:callback]}(#{character.to_json})"
end
end

# GET /people/#{person_id}

get '/people/:id' do
pass unless params[:id] =~ /^\d+$/

if params[:mine] == '1'
authenticate unless session['cookie_string']
person = MyAnimeList::People.scrape_person(params[:id], session['cookie_string'])
else
person = MyAnimeList::People.scrape_person(params[:id])

# Caching.
expires 3600, :public, :must_revalidate
last_modified Time.now
etag "people/#{person.id}"
end

case params[:format]
when 'xml'
# TO DO
person.to_xml
else
params[:callback].nil? ? person.to_json : "#{params[:callback]}(#{person.to_json})"
end
end

# POST /animelist/anime
# Adds an anime to a user's anime list.
Expand Down Expand Up @@ -295,6 +345,24 @@ class App < Sinatra::Base
anime = MyAnimeList::Anime.top(
:type => params[:type],
:page => params[:page],
:per_page => params[:per_page],
:from => params[:from]
)

case params[:format]
when 'xml'
anime.to_xml
else
params[:callback].nil? ? anime.to_json : "#{params[:callback]}(#{anime.to_json})"
end
end

# GET /anime/upcoming
# Get upcoming anime - sorted by start date
get '/anime/upcoming' do
anime = MyAnimeList::Anime.upcoming(
:start_date => params[:type],
:page => params[:page],
:per_page => params[:per_page]
)

Expand Down
4 changes: 3 additions & 1 deletion my_anime_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
require './my_anime_list/anime_list'
require './my_anime_list/manga'
require './my_anime_list/manga_list'
require './my_anime_list/character'
require './my_anime_list/people'

module MyAnimeList

Expand Down Expand Up @@ -57,4 +59,4 @@ def initialize(message, original_exception = nil)
def to_s; @message; end
end

end
end
Loading