Class: NHApi::Doujin

Inherits:
Object
  • Object
show all
Defined in:
lib/nh_api/doujin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Doujin

Returns a new instance of Doujin.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/nh_api/doujin.rb', line 10

def initialize(attributes)
  @id = attributes["id"]
  @media_id = attributes["media_id"]
  @title = attributes["title"]
  @pages = build_pages(attributes["images"]["pages"])
  @thumbnail = NHApi::Thumbnail.new(attributes["images"]["thumbnail"].merge(media_id: media_id))
  @cover = NHApi::Cover.new(attributes["images"]["cover"].merge(media_id: media_id))
  @upload_date = attributes["upload_date"]
  @tags = attributes["tags"]
  @num_pages = attributes["num_pages"]
  @num_favorites = attributes["num_favorites"]
end

Instance Attribute Details

#coverObject (readonly)

Returns the value of attribute cover.



8
9
10
# File 'lib/nh_api/doujin.rb', line 8

def cover
  @cover
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/nh_api/doujin.rb', line 8

def id
  @id
end

#media_idObject (readonly)

Returns the value of attribute media_id.



8
9
10
# File 'lib/nh_api/doujin.rb', line 8

def media_id
  @media_id
end

#num_favoritesObject (readonly)

Returns the value of attribute num_favorites.



8
9
10
# File 'lib/nh_api/doujin.rb', line 8

def num_favorites
  @num_favorites
end

#num_pagesObject (readonly)

Returns the value of attribute num_pages.



8
9
10
# File 'lib/nh_api/doujin.rb', line 8

def num_pages
  @num_pages
end

#pagesObject (readonly)

Returns the value of attribute pages.



8
9
10
# File 'lib/nh_api/doujin.rb', line 8

def pages
  @pages
end

#tagsObject (readonly)

Returns the value of attribute tags.



8
9
10
# File 'lib/nh_api/doujin.rb', line 8

def tags
  @tags
end

#thumbnailObject (readonly)

Returns the value of attribute thumbnail.



8
9
10
# File 'lib/nh_api/doujin.rb', line 8

def thumbnail
  @thumbnail
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/nh_api/doujin.rb', line 8

def title
  @title
end

#upload_dateObject (readonly)

Returns the value of attribute upload_date.



8
9
10
# File 'lib/nh_api/doujin.rb', line 8

def upload_date
  @upload_date
end

Class Method Details

.all(page = 1) ⇒ Object



29
30
31
32
33
# File 'lib/nh_api/doujin.rb', line 29

def self.all(page = 1)
  response = Faraday.get("#{API_URL}galleries/all?page=#{page}")
  doujins = JSON.parse(response.body)["result"]
  doujins.map { |attributes| new(attributes) }
end

.find(id) ⇒ Object



23
24
25
26
27
# File 'lib/nh_api/doujin.rb', line 23

def self.find(id)
  response = Faraday.get("#{API_URL}/gallery/#{id}")
  attributes = JSON.parse(response.body)
  new(attributes)
end

Instance Method Details



35
36
37
38
39
# File 'lib/nh_api/doujin.rb', line 35

def related
  response = Faraday.get("#{API_URL}gallery/#{id}/related")
  doujins = JSON.parse(response.body)["result"]
  doujins.map { |attributes| NHApi::Doujin.new(attributes) }
end