Class: PRXAccess::PRXHyperResource::Link

Inherits:
HyperResource::Link
  • Object
show all
Defined in:
lib/prx_access/prx_hyper_resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, link_spec = {}) ⇒ Link

Returns a new instance of Link.



19
20
21
22
23
# File 'lib/prx_access/prx_hyper_resource.rb', line 19

def initialize(resource, link_spec={})
  super
  self.type = link_spec['type']
  self.profile = link_spec['profile']
end

Instance Attribute Details

#profileObject

Returns the value of attribute profile.



17
18
19
# File 'lib/prx_access/prx_hyper_resource.rb', line 17

def profile
  @profile
end

#typeObject

Returns the value of attribute type.



17
18
19
# File 'lib/prx_access/prx_hyper_resource.rb', line 17

def type
  @type
end

Instance Method Details

#headers(*args) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/prx_access/prx_hyper_resource.rb', line 32

def headers(*args)
  super.tap do |res|
    if args.count > 0
      res.type = self.type
      res.profile = self.profile
    end
  end
end

#patch_response(attrs = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/prx_access/prx_hyper_resource.rb', line 67

def patch_response(attrs=nil)
  attrs ||= self.resource.attributes.changed_attributes
  attrs = (self.resource.default_attributes || {}).merge(attrs)

  # adding this line to call outgoing_body_filter
  attrs = resource.outgoing_body_filter(attrs)

  response = faraday_connection.patch do |req|
    req.body = self.resource.adapter.serialize(attrs)
  end
  response
end

#post_response(attrs = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/prx_access/prx_hyper_resource.rb', line 41

def post_response(attrs=nil)
  attrs ||= self.resource.attributes
  attrs = (self.resource.default_attributes || {}).merge(attrs)

  # adding this line to call outgoing_body_filter
  attrs = resource.outgoing_body_filter(attrs)

  response = faraday_connection.post do |req|
    req.body = self.resource.adapter.serialize(attrs)
  end
  response
end

#put_response(attrs = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/prx_access/prx_hyper_resource.rb', line 54

def put_response(attrs=nil)
  attrs ||= self.resource.attributes
  attrs = (self.resource.default_attributes || {}).merge(attrs)

  # adding this line to call outgoing_body_filter
  attrs = resource.outgoing_body_filter(attrs)

  response = faraday_connection.put do |req|
    req.body = self.resource.adapter.serialize(attrs)
  end
  response
end

#where(params) ⇒ Object



25
26
27
28
29
30
# File 'lib/prx_access/prx_hyper_resource.rb', line 25

def where(params)
  super.tap do |res|
    res.type = self.type
    res.profile = self.profile
  end
end