Class: ShafClient

Inherits:
Object
  • Object
show all
Defined in:
lib/shaf_client.rb,
lib/shaf_client/form.rb,
lib/shaf_client/link.rb,
lib/shaf_client/curie.rb,
lib/shaf_client/error.rb,
lib/shaf_client/resource.rb,
lib/shaf_client/api_error.rb,
lib/shaf_client/base_resource.rb,
lib/shaf_client/empty_resource.rb,
lib/shaf_client/resource_mapper.rb,
lib/shaf_client/unknown_resource.rb,
lib/shaf_client/middleware/redirect.rb

Defined Under Namespace

Modules: Middleware Classes: AmbiguousRelError, ApiError, BaseResource, Curie, EmptyResource, Error, Form, Link, Resource, ResourceMapper, UnSupportedContentType, UnknownResource

Constant Summary collapse

MIME_TYPE_JSON =
'application/json'
MIME_TYPE_HAL =
'application/hal+json'
DEFAULT_ADAPTER =
:net_http

Instance Method Summary collapse

Constructor Details

#initialize(root_uri, **options) ⇒ ShafClient

Returns a new instance of ShafClient.



19
20
21
22
23
24
25
26
# File 'lib/shaf_client.rb', line 19

def initialize(root_uri, **options)
  @root_uri = root_uri.dup
  @options = options

  setup_default_headers
  setup_basic_auth
  setup_client
end

Instance Method Details

#get_doc(uri, **options) ⇒ Object



32
33
34
35
# File 'lib/shaf_client.rb', line 32

def get_doc(uri, **options)
  response = request(method: :get, uri: uri, opts: options)
  response&.body || ''
end

#get_root(**options) ⇒ Object



28
29
30
# File 'lib/shaf_client.rb', line 28

def get_root(**options)
  get(@root_uri, **options)
end

#stubsObject



53
54
55
56
# File 'lib/shaf_client.rb', line 53

def stubs
  return unless @adapter == :test
  @stubs ||= Faraday::Adapter::Test::Stubs.new
end