Class: Ezid::Request Abstract Private
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Ezid::Request
- Extended by:
- Forwardable
- Defined in:
- lib/ezid/requests/request.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A request to the EZID service.
Direct Known Subclasses
BatchDownloadRequest, IdentifierRequest, LoginRequest, LogoutRequest, MintIdentifierRequest, ServerStatusRequest
Constant Summary collapse
- GET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
HTTP methods
Net::HTTP::Get
- PUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Net::HTTP::Put
- POST =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Net::HTTP::Post
- DELETE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Net::HTTP::Delete
- RETRIABLE_SERVER_ERRORS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[500 502 503 504].freeze
- RETRIES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
ENV.fetch('EZID_REQUEST_RETRIES', '2').to_i
Class Attribute Summary collapse
- .http_method ⇒ Object private
- .path ⇒ Object private
- .response_class ⇒ Object private
Instance Attribute Summary collapse
- #client ⇒ Object readonly private
Class Method Summary collapse
Instance Method Summary collapse
- #authentication_required? ⇒ Boolean private
-
#execute ⇒ Ezid::Response
private
Executes the request and returns the response.
- #handle_response(http_response) ⇒ Object private
- #has_metadata? ⇒ Boolean private
-
#initialize(client, *args) ⇒ Request
constructor
private
A new instance of Request.
-
#path ⇒ String
private
HTTP request path.
-
#query ⇒ String
private
HTTP request query string.
-
#response_class ⇒ Class
private
Class to wrap Net::HTTPResponse.
- #short_name ⇒ Object private
-
#uri ⇒ URI
private
The request URI.
Constructor Details
#initialize(client, *args) ⇒ Request
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Request.
47 48 49 50 51 |
# File 'lib/ezid/requests/request.rb', line 47 def initialize(client, *args) @client = client super build_request set_content_type('text/plain', charset: 'UTF-8') end |
Class Attribute Details
.http_method ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 |
# File 'lib/ezid/requests/request.rb', line 30 def http_method @http_method end |
.path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 |
# File 'lib/ezid/requests/request.rb', line 30 def path @path end |
.response_class ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 |
# File 'lib/ezid/requests/request.rb', line 30 def response_class @response_class end |
Instance Attribute Details
#client ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/ezid/requests/request.rb', line 43 def client @client end |
Class Method Details
.execute(client, *args) {|request| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 |
# File 'lib/ezid/requests/request.rb', line 32 def execute(client, *args) request = new(client, *args) yield request if block_given? request.execute end |
.short_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 |
# File 'lib/ezid/requests/request.rb', line 38 def short_name name.split('::').last.sub('Request', '') end |
Instance Method Details
#authentication_required? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
108 109 110 |
# File 'lib/ezid/requests/request.rb', line 108 def authentication_required? true end |
#execute ⇒ Ezid::Response
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Executes the request and returns the response
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ezid/requests/request.rb', line 55 def execute retries = 0 begin http_response = get_response_for_request if RETRIABLE_SERVER_ERRORS.include? http_response.code raise ServerError, "#{http_response.code} #{http_response.msg}" end response_class.new(http_response) rescue ServerError, UnexpectedResponseError => e if retries < RETRIES logger.error "EZID error: #{e}" retries += 1 logger.info "Retry (#{retries} of #{RETRIES}) of #{short_name} #{path} in #{config.retry_interval} seconds ..." sleep config.retry_interval retry else raise end end end |
#handle_response(http_response) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
116 117 118 119 120 |
# File 'lib/ezid/requests/request.rb', line 116 def handle_response(http_response) response_class.new(http_response).tap do |response| yield response if block_given? end end |
#has_metadata? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
112 113 114 |
# File 'lib/ezid/requests/request.rb', line 112 def !.empty? rescue false end |
#path ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
HTTP request path
90 91 92 |
# File 'lib/ezid/requests/request.rb', line 90 def path self.class.path end |
#query ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
HTTP request query string
102 |
# File 'lib/ezid/requests/request.rb', line 102 def query; end |
#response_class ⇒ Class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Class to wrap Net::HTTPResponse
96 97 98 |
# File 'lib/ezid/requests/request.rb', line 96 def response_class self.class.response_class || Response end |
#short_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
104 105 106 |
# File 'lib/ezid/requests/request.rb', line 104 def short_name self.class.short_name end |
#uri ⇒ URI
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The request URI
84 85 86 |
# File 'lib/ezid/requests/request.rb', line 84 def uri @uri ||= build_uri end |