Class: ResoTransport::Resource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client

Returns:

  • (Object)

    the current value of client



2
3
4
# File 'lib/reso_transport/resource.rb', line 2

def client
  @client
end

#entity_setObject

Returns the value of attribute entity_set

Returns:

  • (Object)

    the current value of entity_set



2
3
4
# File 'lib/reso_transport/resource.rb', line 2

def entity_set
  @entity_set
end

#localObject

Returns the value of attribute local

Returns:

  • (Object)

    the current value of local



2
3
4
# File 'lib/reso_transport/resource.rb', line 2

def local
  @local
end

#localizationsObject

Returns the value of attribute localizations

Returns:

  • (Object)

    the current value of localizations



2
3
4
# File 'lib/reso_transport/resource.rb', line 2

def localizations
  @localizations
end

Instance Method Details

#entity_typeObject



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

def entity_type
  @entity_type ||= schema.entity_types.detect { |et| et.name == entity_set.entity_type }
end

#expandableObject



19
20
21
# File 'lib/reso_transport/resource.rb', line 19

def expandable
  entity_type.navigation_properties
end

#get(params) ⇒ Object



39
40
41
42
43
44
# File 'lib/reso_transport/resource.rb', line 39

def get(params)
  client.connection.get(url, params) do |req|
    req.headers['Accept'] = 'application/json'
    @request = req
  end
end

#inspectObject



65
66
67
# File 'lib/reso_transport/resource.rb', line 65

def inspect
  to_s
end

#localization(name) ⇒ Object



56
57
58
59
# File 'lib/reso_transport/resource.rb', line 56

def localization(name)
  self.local = localizations[name] if localizations.key?(name)
  self
end

#mdObject



31
32
33
# File 'lib/reso_transport/resource.rb', line 31

def md
  client.
end

#nameObject



7
8
9
# File 'lib/reso_transport/resource.rb', line 7

def name
  entity_set.name
end

#parse(results) ⇒ Object



35
36
37
# File 'lib/reso_transport/resource.rb', line 35

def parse(results)
  results.map { |r| entity_type.parse(r) }
end

#propertiesObject



15
16
17
# File 'lib/reso_transport/resource.rb', line 15

def properties
  entity_type.properties
end

#property(name) ⇒ Object



11
12
13
# File 'lib/reso_transport/resource.rb', line 11

def property(name)
  properties.detect { |p| p.name == name }
end

#queryObject



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

def query
  Query.new(self)
end

#requestObject



69
70
71
72
73
# File 'lib/reso_transport/resource.rb', line 69

def request
  return @request.to_h if @request.respond_to? :to_h

  {}
end

#schemaObject



27
28
29
# File 'lib/reso_transport/resource.rb', line 27

def schema
  @schema ||= md.schemas.detect { |s| s.namespace == entity_set.schema }
end

#to_sObject



61
62
63
# File 'lib/reso_transport/resource.rb', line 61

def to_s
  %(#<ResoTransport::Resource entity_set="#{name}", schema="#{schema&.namespace}">)
end

#urlObject



46
47
48
49
50
51
52
53
54
# File 'lib/reso_transport/resource.rb', line 46

def url
  return local['ResourcePath'].gsub(%r{^/}, '') if local

  raise LocalizationRequired, self if localizations.any? && local.nil?

  return "#{name}/replication" if client.use_replication_endpoint

  name
end