Module: SBF::Client::Api::Request
- Includes:
- HTTMultiParty
- Defined in:
- lib/stbaldricks/request.rb
Class Method Summary collapse
- .file_post_request(path:, params: {}, file:, filename:) ⇒ Object
-
.get_request(path, params = {}) ⇒ HTTParty::Response
Makes a HTTP GET request to the specified path with specified params and authentication credentials based on the configured client class.
- .options(auth: nil, type: :get, query: nil, body: nil) ⇒ Object
-
.post_request(path, params = {}) ⇒ HTTParty::Response
Makes a HTTP POST request to the specified path with specified params and authentication credentials based on the configured client class.
Class Method Details
.file_post_request(path:, params: {}, file:, filename:) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/stbaldricks/request.rb', line 60 def self.file_post_request(path:, params: {}, file:, filename:) raise SBF::Client::InvalidURIError, "Invalid URI: #{path}" unless valid_uri?(path) raise SBF::Client::Error, 'Not yet authenticated' if user_token.nil? raise SBF::Client::Error, 'Invalid File' unless file.is_a?(File) || file.is_a?(Tempfile) request_log('POST', path, params) do post(path, (body: params.merge(file: file, original_filename: filename), type: :file_post, auth: user_token)) end end |
.get_request(path, params = {}) ⇒ HTTParty::Response
Makes a HTTP GET request to the specified path with specified params and authentication credentials based on the configured client class. This method isn’t intended to be used by a user and is for internal use only
36 37 38 39 40 41 42 |
# File 'lib/stbaldricks/request.rb', line 36 def self.get_request(path, params = {}) raise SBF::Client::InvalidURIError, "Invalid URI: #{path}" unless valid_uri?(path) request_log('GET', path, params) do get(path, (query: params, auth: user_token || general_token)) end end |
.options(auth: nil, type: :get, query: nil, body: nil) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/stbaldricks/request.rb', line 70 def self.(auth: nil, type: :get, query: nil, body: nil) {}.tap do || .merge!(base_uri: SBF::Client::Configuration.base_uri, headers: { 'Accept' => 'application/json', 'X-Request-Id' => SBF::Client::Configuration.request_id }, verify: verify_ssl_peer?) [:body] = body if body [:query] = query if query [:headers]['Content-Type'] = 'application/json' if type == :post [:headers]['Content-Type'] = 'multipart/form-data' if type == :file_post [:headers]['Authorization'] = "Bearer #{auth}" if auth end end |
.post_request(path, params = {}) ⇒ HTTParty::Response
Makes a HTTP POST request to the specified path with specified params and authentication credentials based on the configured client class. Raises an error if the client library isn’t configured with user specific credentials. This method isn’t intended to be used by a user and is for internal use only
52 53 54 55 56 57 58 |
# File 'lib/stbaldricks/request.rb', line 52 def self.post_request(path, params = {}) raise SBF::Client::InvalidURIError, "Invalid URI: #{path}" unless valid_uri?(path) request_log('POST', path, params) do post(path, (body: params.to_json, type: :post, auth: user_token || general_token)) end end |