Module: PDC::Resource::RestApi::ClassMethods

Defined in:
lib/pdc/resource/rest_api.rb

Instance Method Summary collapse

Instance Method Details

#fetch(relation) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/pdc/resource/rest_api.rb', line 22

def fetch(relation)
  # TODO: handle v1/release-variant/(:release)/(:variant)
  # attributes won't contain (:release) and (:variant_id)
  params = relation.params
  resource_path = Path.new(relation.uri, params)

  uri = resource_path.expanded
  query = params.except(*resource_path.variables)
  request(:get, uri, query)
end

#request(method, path, query = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pdc/resource/rest_api.rb', line 10

def request(method, path, query = {})
  PDC.logger.debug '  >>>' + " : #{path} #{query}"
  ActiveSupport::Notifications.instrument('request.pdc', method: method) do |payload|
    response = connection.send(method) do |request|
      request.url path, query
    end
    payload[:url] = response.env.url
    payload[:status] = response.status
    PDC::Http::Result.new(response)
  end
end