Class: ResoTransport::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/reso_transport/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/reso_transport/client.rb', line 6

def initialize(options)
  @use_replication_endpoint = options.fetch(:use_replication_endpoint, false)
  @endpoint                 = options.fetch(:endpoint)
  @md_file                  = options.fetch(:md_file, nil)
  @ds_file                  = options.fetch(:ds_file, nil)
  @authentication           = ensure_valid_auth_strategy(options.fetch(:authentication))
  @vendor                   = options.fetch(:vendor, {})
  @faraday_options          = options.fetch(:faraday_options, {})
  @logger                   = options.fetch(:logger, nil)
  @md_cache                 = options.fetch(:md_cache, ResoTransport::MetadataCache)
  @ds_cache                 = options.fetch(:ds_cache, ResoTransport::MetadataCache)
  @connection               = establish_connection(@endpoint)
end

Instance Attribute Details

#authenticationObject (readonly)

Returns the value of attribute authentication.



3
4
5
# File 'lib/reso_transport/client.rb', line 3

def authentication
  @authentication
end

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/reso_transport/client.rb', line 3

def connection
  @connection
end

#ds_cacheObject (readonly)

Returns the value of attribute ds_cache.



3
4
5
# File 'lib/reso_transport/client.rb', line 3

def ds_cache
  @ds_cache
end

#ds_fileObject (readonly)

Returns the value of attribute ds_file.



3
4
5
# File 'lib/reso_transport/client.rb', line 3

def ds_file
  @ds_file
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



3
4
5
# File 'lib/reso_transport/client.rb', line 3

def endpoint
  @endpoint
end

#md_cacheObject (readonly)

Returns the value of attribute md_cache.



3
4
5
# File 'lib/reso_transport/client.rb', line 3

def md_cache
  @md_cache
end

#md_fileObject (readonly)

Returns the value of attribute md_file.



3
4
5
# File 'lib/reso_transport/client.rb', line 3

def md_file
  @md_file
end

#uidObject (readonly)

Returns the value of attribute uid.



3
4
5
# File 'lib/reso_transport/client.rb', line 3

def uid
  @uid
end

#use_replication_endpointObject (readonly)

Returns the value of attribute use_replication_endpoint.



3
4
5
# File 'lib/reso_transport/client.rb', line 3

def use_replication_endpoint
  @use_replication_endpoint
end

#vendorObject (readonly)

Returns the value of attribute vendor.



3
4
5
# File 'lib/reso_transport/client.rb', line 3

def vendor
  @vendor
end

Instance Method Details

#datasystemObject



44
45
46
# File 'lib/reso_transport/client.rb', line 44

def datasystem
  @datasystem ||= Datasystem.new(self)
end

#establish_connection(url) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/reso_transport/client.rb', line 20

def establish_connection(url)
  Faraday.new(url, @faraday_options) do |faraday|
    faraday.request  :url_encoded
    faraday.response :logger, @logger || ResoTransport.configuration.logger
    faraday.use Authentication::Middleware, @authentication
    faraday.adapter Faraday.default_adapter # unless faraday.builder.send(:adapter_set?)
  end
end

#fetch(url, headers = {}) ⇒ Object



48
49
50
51
52
# File 'lib/reso_transport/client.rb', line 48

def fetch(url, headers = {})
  connection.get(url) do |req|
    req.headers.merge!(headers)
  end
end

#inspectObject



58
59
60
# File 'lib/reso_transport/client.rb', line 58

def inspect
  to_s
end

#metadataObject



40
41
42
# File 'lib/reso_transport/client.rb', line 40

def 
  @metadata ||= Metadata.new(self)
end

#resource_for(entity_set) ⇒ Object



33
34
35
36
37
38
# File 'lib/reso_transport/client.rb', line 33

def resource_for(entity_set)
  localizations = {}
  localizations = datasystem.localizations_for(entity_set.entity_type) if .datasystem?

  Resource.new(self, entity_set, localizations)
end

#resourcesObject



29
30
31
# File 'lib/reso_transport/client.rb', line 29

def resources
  @resources ||= .entity_sets.map { |es| { es.name => resource_for(es) } }.reduce(:merge!)
end

#to_sObject



54
55
56
# File 'lib/reso_transport/client.rb', line 54

def to_s
  %(#<ResoTransport::Client endpoint="#{endpoint}", md_file="#{md_file}", ds_file="#{ds_file}">)
end