Module: AtlasRb::FaradayHelper
- Included in:
- Authentication, Reset, Resource
- Defined in:
- lib/atlas_rb/faraday_helper.rb
Overview
HTTP transport helpers shared by every resource class.
Every Atlas request reads two environment variables:
ATLAS_URL— base URL of the Atlas API (e.g.https://atlas.example.edu).ATLAS_TOKEN— bearer token used in theAuthorizationheader.
Most calls also identify the acting user via a User: NUID <nuid> header.
Resource classes typically pass nuid = nil (anonymous / system context);
Authentication is the only place where a real NUID is currently
threaded through.
The module is mixed in via extend, so its methods become class methods on
the host (e.g. AtlasRb::Work.connection({})).
Instance Method Summary collapse
-
#connection(params, nuid = nil) ⇒ Faraday::Connection
Build a JSON-content Faraday connection to the Atlas API.
-
#multipart(nuid = nil) ⇒ Faraday::Connection
Build a multipart Faraday connection used for binary and XML uploads.
Instance Method Details
#connection(params, nuid = nil) ⇒ Faraday::Connection
Build a JSON-content Faraday connection to the Atlas API.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/atlas_rb/faraday_helper.rb', line 31 def connection(params, nuid=nil) Faraday.new( url: ENV.fetch("ATLAS_URL", nil), params: params, headers: { "Content-Type" => "application/json", "Authorization" => "Bearer #{ENV.fetch("ATLAS_TOKEN", nil)}", "User" => "NUID #{nuid}" } ) do |f| f.response :follow_redirects f.adapter Faraday.default_adapter end end |
#multipart(nuid = nil) ⇒ Faraday::Connection
Build a multipart Faraday connection used for binary and XML uploads.
The same ATLAS_URL / ATLAS_TOKEN env vars apply. Unlike #connection,
the Content-Type is set automatically by the multipart middleware, and
callers pass a payload hash whose values may include
Faraday::Multipart::FilePart instances.
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/atlas_rb/faraday_helper.rb', line 64 def multipart(nuid=nil) Faraday.new( url: ENV.fetch("ATLAS_URL", nil), headers: { "Authorization" => "Bearer #{ENV.fetch("ATLAS_TOKEN", nil)}", "User" => "NUID #{nuid}" } ) do |f| f.request :multipart f.request :url_encoded end end |