Formatting

This commit is contained in:
Alex Ling 2020-03-13 17:03:06 +00:00
parent 31da5acdc5
commit 2c10623731

View File

@ -29,6 +29,7 @@ module MangaDex
Hash(String, String)) Hash(String, String))
self.parse_json json_obj, lang self.parse_json json_obj, lang
end end
def to_info_json def to_info_json
JSON.build do |json| JSON.build do |json|
json.object do json.object do
@ -49,6 +50,7 @@ module MangaDex
end end
end end
end end
def parse_json(obj, lang) def parse_json(obj, lang)
begin begin
parse_strings_from_json ["lang_code", "title", "volume", parse_strings_from_json ["lang_code", "title", "volume",
@ -84,6 +86,7 @@ module MangaDex
def initialize(@id, json_obj : JSON::Any) def initialize(@id, json_obj : JSON::Any)
self.parse_json json_obj self.parse_json json_obj
end end
def to_info_json(with_chapters = true) def to_info_json(with_chapters = true)
JSON.build do |json| JSON.build do |json|
json.object do json.object do
@ -103,6 +106,7 @@ module MangaDex
end end
end end
end end
def parse_json(obj) def parse_json(obj)
begin begin
parse_strings_from_json ["cover_url", "description", "title", parse_strings_from_json ["cover_url", "description", "title",
@ -119,6 +123,7 @@ module MangaDex
@lang[row[1]] = row[0] @lang[row[1]] = row[0]
end end
end end
def get(url) def get(url)
headers = HTTP::Headers { headers = HTTP::Headers {
"User-agent" => "Mangadex.cr" "User-agent" => "Mangadex.cr"
@ -128,6 +133,7 @@ module MangaDex
"#{res.status_message}" if !res.success? "#{res.status_message}" if !res.success?
JSON.parse res.body JSON.parse res.body
end end
def get_manga(id) def get_manga(id)
obj = self.get File.join @base_url, "manga/#{id}" obj = self.get File.join @base_url, "manga/#{id}"
if obj["status"]? != "OK" if obj["status"]? != "OK"
@ -145,6 +151,7 @@ module MangaDex
raise "Failed to parse JSON" raise "Failed to parse JSON"
end end
end end
def get_chapter(chapter : Chapter) def get_chapter(chapter : Chapter)
obj = self.get File.join @base_url, "chapter/#{chapter.id}" obj = self.get File.join @base_url, "chapter/#{chapter.id}"
if obj["status"]? == "external" if obj["status"]? == "external"
@ -169,6 +176,7 @@ module MangaDex
raise "Failed to parse JSON" raise "Failed to parse JSON"
end end
end end
def get_chapter(id : String) def get_chapter(id : String)
obj = self.get File.join @base_url, "chapter/#{id}" obj = self.get File.join @base_url, "chapter/#{id}"
if obj["status"]? == "external" if obj["status"]? == "external"