Class: PixivApi::Response::Work

Inherits:
Identity show all
Defined in:
lib/pixiv_api/response/work.rb

Direct Known Subclasses

Illustration, Manga, Ugoira

Instance Attribute Summary collapse

Attributes inherited from PixivApi::Response

#attributes, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Identity

#initialize

Methods inherited from PixivApi::Response

#[], attr_reader, define_attribute_method, define_attributes_method, define_blob_method, define_time_method, #initialize

Constructor Details

This class inherits a constructor from PixivApi::Response::Identity

Instance Attribute Details

#age_limitObject (readonly)

Returns the value of attribute age_limit.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def age_limit
  @age_limit
end

#book_styleObject (readonly)

Returns the value of attribute book_style.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def book_style
  @book_style
end

#captionObject (readonly)

Returns the value of attribute caption.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def caption
  @caption
end

#favorite_idObject (readonly)

Returns the value of attribute favorite_id.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def favorite_id
  @favorite_id
end

#heightObject (readonly)

Returns the value of attribute height.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def height
  @height
end

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def id
  @id
end

#is_linkedObject (readonly)

Returns the value of attribute is_linked.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def is_linked
  @is_linked
end

#is_mangaObject (readonly)

Returns the value of attribute is_manga.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def is_manga
  @is_manga
end

#metadataObject (readonly)

Returns the value of attribute metadata.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def 
  @metadata
end

#page_countObject (readonly)

Returns the value of attribute page_count.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def page_count
  @page_count
end

#publicityObject (readonly)

Returns the value of attribute publicity.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def publicity
  @publicity
end

#statsObject (readonly)

Returns the value of attribute stats.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def stats
  @stats
end

#titleObject (readonly)

Returns the value of attribute title.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def title
  @title
end

#toolsObject (readonly)

Returns the value of attribute tools.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def tools
  @tools
end

#typeObject (readonly)

Returns the value of attribute type.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def type
  @type
end

#widthObject (readonly)

Returns the value of attribute width.



21
22
23
# File 'lib/pixiv_api/response/work.rb', line 21

def width
  @width
end

Class Method Details

.from_response(response, *args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pixiv_api/response/work.rb', line 4

def self.from_response(response, *args)
  attributes = args.extract_options!

  base = case attributes['type']
         when 'illustration'
           Illustration
         when 'manga'
           Manga
         when 'ugoira'
           Ugoira
         else
           raise NotImplementedError, 'unknown type given.'
         end

  base.new(response, attributes)
end

Instance Method Details

#pagesObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/pixiv_api/response/work.rb', line 32

def pages
  @attributes['metadata']['pages'].map do |base, memo|
    base['image_urls'].each_with_object({}) do |(key, value), memo|
      memo[key] = blob_image_url(value)
    end
  end
rescue
  # XXX: workの種類によってはエラーが起こる?
  []
end