Class: Psc::Connection
- Inherits:
-
Faraday::Connection
- Object
- Faraday::Connection
- Psc::Connection
- Defined in:
- lib/psc/connection.rb
Overview
A Faraday::Connection
set up for use with Patient Study
Calendar. See the README for a couple of examples.
Instance Method Summary collapse
-
#initialize(url, options) {|builder| ... } ⇒ Connection
constructor
Create a new PSC connection.
Constructor Details
#initialize(url, options) {|builder| ... } ⇒ Connection
Create a new PSC connection. This is a Faraday::Connection
with the following middleware:
- Either Faraday::HttpBasic or Faraday::PscToken
depending on the contents of the
:authenticator
option - Faraday::StringIsXml
::Faraday::Request::JSON
::Faraday::Request::UrlEncoded
::FaradayStack::ResponseXML
for content-type text/xml::FaradayStack::ResponseJSON
for content-type application/json::Faraday::Adapter::NetHttp
If a block is provided, it will receive the Faraday builder so
that you can append more middleware. If you provide your own
adapter, the net/http
adapter will not be appended.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/psc/connection.rb', line 36 def initialize(url, ) super do |builder| builder.use *authentication_middleware([:authenticator]) builder.use Psc::Faraday::StringIsXml builder.use Psc::Faraday::AcceptPscTypes builder.request :json builder.request :url_encoded builder.use FaradayStack::ResponseXML, :content_type => 'text/xml' builder.use FaradayStack::ResponseJSON, :content_type => 'application/json' if block_given? yield builder end builder.adapter :net_http unless has_adapter?(builder) end unless self.path_prefix =~ %r{/api/v1$} self.path_prefix = if self.path_prefix == '/' '/api/v1' else self.path_prefix + '/api/v1' end end end |