Skip to content

Commit

Permalink
fixed errors reference hummingbird-me#734
Browse files Browse the repository at this point in the history
  • Loading branch information
toyhammered committed Jul 4, 2016
1 parent 168eda1 commit d5b0293
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
7 changes: 4 additions & 3 deletions server/lib/data_import/my_anime_list.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module DataImport
class MyAnimeList
MDL_HOST = "https://hbv3-mal-api.herokuapp.com/2.1" # 2.1 is the api version, MAYBE add graceful decay to check from v1 if it can't find?
ATARASHII_API_HOST = "https://hbv3-mal-api.herokuapp.com/2.1/"

include DataImport::Media
include DataImport::HTTP
Expand All @@ -13,7 +13,8 @@ def initialize(opts = {})
end

def get_media(external_id) # anime/1234 or manga/1234
media = Mapping.lookup('myanimelist/anime', external_id) || Anime.new # not sure if the lookup is correct
type = external_id.split('/') # going to be used when adding manga
media = Mapping.lookup('myanimelist', external_id) || type.first.classify.constantize.new # should return Anime.new or Manga.new

get(external_id) do |response|
details = Extractor::Media.new(response)
Expand All @@ -36,7 +37,7 @@ def get(url, opts = {})

def build_url(path)
return path if path.include?('://')
"#{MDL_HOST}#{path}"
"#{ATARASHII_API_HOST}#{path}"
end

end # end of class
Expand Down
10 changes: 7 additions & 3 deletions server/lib/data_import/my_anime_list/extractor/media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@ def synopsis
end

def youtube_video_id
data['preview']
data['preview'].split('/').last
end

def poster_image
data['image_url']
end

def age_rating_guide
rating = data['classification'].split(' - ')[0]
rating = data['classification'].split(' - ')

case rating
return "Violence, Profanity" if rating[0] == 'R'
return rating[1] if rating[1].present?

# fallback
case rating[0]
when 'G' then 'All Ages'
when 'PG' then 'Children'
when 'PG13', 'PG-13' then 'Teens 13 or older'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
end

describe '#youtube_video_id' do
it 'should return a youtube link' do
expect(subject.youtube_video_id).to eq('http://www.youtube.com/embed/qig4KOK2R2g')
it 'should return the end of the youtube link' do
expect(subject.youtube_video_id).to eq('qig4KOK2R2g')
end
end

Expand All @@ -89,6 +89,12 @@
end

describe '#age_rating_guide' do

it 'should do case statement if rating[1] does not exist' do
subject = described_class.new({classification: 'G'}.to_json)
expect(subject.age_rating_guide).to eq('All Ages')
end

it 'should extract the G rating description' do
subject = described_class.new({classification: 'G - All Ages'}.to_json)
expect(subject.age_rating_guide).to eq('All Ages')
Expand Down
12 changes: 6 additions & 6 deletions server/spec/lib/data_import/my_anime_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
subject { described_class.new }

before do
host = described_class::MDL_HOST
stub_request(:get, "#{host}/anime/1").
host = described_class::ATARASHII_API_HOST
stub_request(:get, "#{host}anime/1").
to_return(body: fixture('my_anime_list/cowboy-bebop-tv.json'))
stub_request(:get, "#{host}/anime/5").
stub_request(:get, "#{host}anime/5").
to_return(body: fixture('my_anime_list/cowboy-bebop-movie.json'))
stub_request(:get, "http://cdn.myanimelist.net/images/anime/4/19644.jpg").
to_return(body: fixture('image.jpg'), headers: {
Expand All @@ -18,18 +18,18 @@
describe '#get_media' do
it 'should yield a Media object' do
expect { |b|
subject.get_media('/anime/1', &b)
subject.get_media('anime/1', &b)
subject.run
}.to yield_with_args(Media)
end
it 'should have assigned attributes onto the yielded object' do
subject.get_media('/anime/1') do |media|
subject.get_media('anime/1') do |media|
expect(media.canonical_title).to eq('Cowboy Bebop')
end
subject.run
end
it 'should be valid' do
subject.get_media('/anime/1') do |media|
subject.get_media('anime/1') do |media|
expect(media).to be_valid
end
subject.run
Expand Down

0 comments on commit d5b0293

Please sign in to comment.