Class: W3cApi::Models::Affiliation

Inherits:
Base
  • Object
show all
Defined in:
lib/w3c_api/models/affiliation.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

transform_keys

Class Method Details

.from_response(response) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/w3c_api/models/affiliation.rb', line 67

def self.from_response(response)
  transformed_response = transform_keys(response)

  affiliation = new
  transformed_response.each do |key, value|
    case key
    when :_links
      links = value.each_with_object({}) do |(link_name, link_data), acc|
        acc[link_name] = Link.new(href: link_data[:href], title: link_data[:title])
      end
      affiliation._links = AffiliationLinks.new(links)
    else
      affiliation.send("#{key}=", value) if affiliation.respond_to?("#{key}=")
    end
  end
  affiliation
end

Instance Method Details

#participants(client = nil) ⇒ Object

Get participants of this affiliation



54
55
56
57
58
# File 'lib/w3c_api/models/affiliation.rb', line 54

def participants(client = nil)
  return nil unless client && _links&.participants

  client.affiliation_participants(id)
end

#participations(client = nil) ⇒ Object

Get participations of this affiliation



61
62
63
64
65
# File 'lib/w3c_api/models/affiliation.rb', line 61

def participations(client = nil)
  return nil unless client && _links&.participations

  client.affiliation_participations(id)
end