Class: Ghost::Response

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ghost/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Response

Returns a new instance of Response.



9
10
11
# File 'lib/ghost/response.rb', line 9

def initialize(raw)
  @raw = raw
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



7
8
9
# File 'lib/ghost/response.rb', line 7

def raw
  @raw
end

Instance Method Details

#dataObject



13
14
15
# File 'lib/ghost/response.rb', line 13

def data
  @data ||= raw[resource_key] || []
end

#each(&block) ⇒ Object



29
30
31
# File 'lib/ghost/response.rb', line 29

def each(&block)
  data.each(&block)
end

#firstObject



17
18
19
# File 'lib/ghost/response.rb', line 17

def first
  data.first
end

#metaObject



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

def meta
  raw["meta"]
end

#paginationObject



25
26
27
# File 'lib/ghost/response.rb', line 25

def pagination
  meta&.dig("pagination")
end

#to_aObject



33
34
35
# File 'lib/ghost/response.rb', line 33

def to_a
  data
end