Module: ApiNavigator

Defined in:
lib/api_navigator.rb,
lib/api_navigator/link.rb,
lib/api_navigator/curie.rb,
lib/api_navigator/version.rb,
lib/api_navigator/resource.rb,
lib/api_navigator/attributes.rb,
lib/api_navigator/entry_point.rb,
lib/api_navigator/collection_hash.rb,
lib/api_navigator/link_collection.rb,
lib/api_navigator/resources/member_resource.rb,
lib/api_navigator/resources/collection_resource.rb

Overview

@author [martinschweizer]

Returns:

  • (martinschweizer)

Defined Under Namespace

Modules: Resources Classes: Attributes, CollectionHash, ConnectionAlreadyInitializedError, Curie, EntryPoint, InvalidRepresentationError, Link, LinkCollection, Resource

Constant Summary collapse

ClientResourceClasses =
{}
VERSION =
'0.0.1'.freeze

Class Method Summary collapse

Class Method Details

.new(url, client_identifier = nil, &block) ⇒ Object

@param url [String] The base url @param &block [type] Block for configuring the navitgator

@return [ApiNavigator::EntryPoint] Then entrypoint hoocking it all up



23
24
25
# File 'lib/api_navigator.rb', line 23

def self.new(url, client_identifier=nil, &block)
  ApiNavigator::EntryPoint.new(url, client_identifier, &block)
end

.register(client_identifier) ⇒ Object



28
29
30
31
32
# File 'lib/api_navigator.rb', line 28

def register(client_identifier)
  raise "Already registered client_identifier: #{client_identifier}" if ClientResourceClasses.include?(client_identifier)

  ClientResourceClasses[client_identifier] = {}
end

.register_resource(identifier, resource_class, client_identifier:) ⇒ Object



34
35
36
# File 'lib/api_navigator.rb', line 34

def register_resource(identifier, resource_class, client_identifier:)
  ClientResourceClasses.fetch(client_identifier)[identifier] = resource_class
end

.resource_class(identifier, client_identifier:) ⇒ Object



38
39
40
41
42
# File 'lib/api_navigator.rb', line 38

def resource_class(identifier, client_identifier:)
  result = ClientResourceClasses.fetch(client_identifier, {}).fetch(identifier, nil)

  result.nil? ? ApiNavigator::Resources::MemberResource : result
end