Class: Growatt::RequestPagination::DataPager

Inherits:
WrAPI::RequestPagination::DefaultPager
  • Object
show all
Defined in:
lib/growatt/pagination.rb

Overview

Custom data pager for processing API responses. Inherits from ‘WrAPI::RequestPagination::DefaultPager` and extracts relevant data from responses.

Class Method Summary collapse

Class Method Details

.data(body) ⇒ Hash

Extracts the relevant data from the API response body.

Examples:

Extracting data from a response

response = { "back" => { "items" => [...] } }
Growatt::RequestPagination::DataPager.data(response)
# => { "items" => [...] }

Parameters:

  • body (String, Hash)

    The response body from an API request.

Returns:

  • (Hash)

    The parsed response data.



21
22
23
24
25
26
27
28
29
# File 'lib/growatt/pagination.rb', line 21

def self.data(body)
  # If the body is a Hash, return the 'back' key if it exists
  if body.is_a? Hash
    body['back'] || body
  else
    # If the body is a String, parse it as JSON
    JSON.parse(body)
  end
end