Class: MedlineplusRuby::API::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/medlineplus_ruby/api/request.rb

Overview

MedlinePlus Connect is rate limited to 100 req/minute. Once this limit is

reached, service will not be restored for 300 seconds, or whenever the
request rate falls below 100/min, whichever is longer.

Constant Summary collapse

API_URI =

Base location from which to make API requests.

'https://apps.nlm.nih.gov/medlineplus/services/mpconnect_service.cfm'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_payload_handler) ⇒ Request

Returns a new instance of Request.



23
24
25
# File 'lib/medlineplus_ruby/api/request.rb', line 23

def initialize(response_payload_handler)
  @response_payload = response_payload_handler
end

Instance Attribute Details

#response_payloadObject (readonly)

Object to handle resulting response body.



17
18
19
# File 'lib/medlineplus_ruby/api/request.rb', line 17

def response_payload
  @response_payload
end

Class Method Details

.buildObject



19
20
21
# File 'lib/medlineplus_ruby/api/request.rb', line 19

def self.build
  new ResponsePayload.new
end

Instance Method Details

#get_request(req_params = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/medlineplus_ruby/api/request.rb', line 27

def get_request(req_params = {})

  response = RestClient.get API_URI, { params: req_params }

  # TODO: Check for failures and/or rate limitations, and return an
  #  appropriate response. Provide an error message, or extract something
  #  meaningful from the response if provided. Note: it appears as though
  #  the National Library of Medicine has no such rate limitation at this
  #  time.
  raise MedlineplusRuby::Error,
    MedlineplusRuby::API::ResponseMessage::ERROR_NO_RESPONSE if response.nil? || response.empty?

  @response_payload.respond response.body
end