Class: Levelup::Requests::ListAppLocations

Inherits:
Base show all
Defined in:
lib/levelup/requests/list_app_locations.rb

Overview

Represents a request to list all locations under a specified app. The list is paginated.

Constant Summary

Constants inherited from Base

Base::ALLOWED_REQUEST_METHODS

Instance Method Summary collapse

Methods inherited from Base

#body, #headers, instance_variables_excluded_from_hash

Methods inherited from Templates::DataParcel

excluded?, #initialize, instance_variables_excluded_from_hash

Constructor Details

This class inherits a constructor from Levelup::Templates::DataParcel

Instance Method Details

#auth_typeObject


5
6
7
# File 'lib/levelup/requests/list_app_locations.rb', line 5

def auth_type
  :none
end

#response_from_hash(hash) ⇒ Object


9
10
11
12
13
14
15
16
17
# File 'lib/levelup/requests/list_app_locations.rb', line 9

def response_from_hash(hash)
  if hash.nil? # no locations found for this app
    Responses::SuccessPaginated.new(locations: [])
  else
    locations =
      hash.map { |location| OpenStruct.new(location['location']) }
    Responses::SuccessPaginated.new(locations: locations)
  end
end

#send_to_api(method, endpoint) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/levelup/requests/list_app_locations.rb', line 19

def send_to_api(method, endpoint)
  send_via_httparty(method, endpoint) do |response|
    paginated_response = response_from_hash(response)

    if response.headers['Link']
      paginated_response.next_page =
        /\<([^>]+)\>/.match(response.headers['Link'])[1]
      paginated_response.next_page_request = ListAppLocations.new
    end

    paginated_response
  end
end