Class: W3cApi::Client

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

Constant Summary collapse

API_ENDPOINT =
'https://api.w3.org'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
# File 'lib/w3c_api/client.rb', line 19

def initialize(options = {})
  @api_endpoint = options[:api_endpoint] || API_ENDPOINT
  @connection = create_connection
  @params_default = { page: 1, items: 3000 }
  @debug = !ENV['DEBUG_API'].nil?
end

Instance Attribute Details

#last_responseObject (readonly)

Returns the value of attribute last_response.



17
18
19
# File 'lib/w3c_api/client.rb', line 17

def last_response
  @last_response
end

Instance Method Details

#affiliation(id, options = {}) ⇒ Object



204
205
206
207
# File 'lib/w3c_api/client.rb', line 204

def affiliation(id, options = {})
  response = get("affiliations/#{id}", options)
  Models::Affiliation.from_response(response)
end

#affiliation_participants(id, options = {}) ⇒ Object



209
210
211
212
# File 'lib/w3c_api/client.rb', line 209

def affiliation_participants(id, options = {})
  response = get("affiliations/#{id}/participants", options)
  Models::Users.from_response(response['_links']['participants'])
end

#affiliation_participations(id, options = {}) ⇒ Object



214
215
216
217
# File 'lib/w3c_api/client.rb', line 214

def affiliation_participations(id, options = {})
  response = get("affiliations/#{id}/participations", options)
  Models::Participations.from_response(response['_links']['participations'])
end

#affiliations(options = {}) ⇒ Object

Affiliation methods



199
200
201
202
# File 'lib/w3c_api/client.rb', line 199

def affiliations(options = {})
  response = get('affiliations', options.merge(@params_default))
  Models::Affiliations.from_response(response['_links']['affiliations'])
end

#ecosystem(shortname, options = {}) ⇒ Object



226
227
228
229
# File 'lib/w3c_api/client.rb', line 226

def ecosystem(shortname, options = {})
  response = get("ecosystems/#{shortname}", options)
  Models::Ecosystem.from_response(response)
end

#ecosystem_evangelists(shortname, options = {}) ⇒ Object



236
237
238
239
# File 'lib/w3c_api/client.rb', line 236

def ecosystem_evangelists(shortname, options = {})
  response = get("ecosystems/#{shortname}/evangelists", options)
  Models::Users.from_response(response['_links']['users'])
end

#ecosystem_groups(shortname, options = {}) ⇒ Object



231
232
233
234
# File 'lib/w3c_api/client.rb', line 231

def ecosystem_groups(shortname, options = {})
  response = get("ecosystems/#{shortname}/groups", options)
  Models::Groups.from_response(response['_links']['groups'])
end

#ecosystem_member_organizations(shortname, options = {}) ⇒ Object



241
242
243
244
# File 'lib/w3c_api/client.rb', line 241

def ecosystem_member_organizations(shortname, options = {})
  response = get("ecosystems/#{shortname}/member-organizations", options)
  Models::Affiliations.from_response(response['_links']['affiliations'])
end

#ecosystems(options = {}) ⇒ Object

Ecosystem methods



221
222
223
224
# File 'lib/w3c_api/client.rb', line 221

def ecosystems(options = {})
  response = get('ecosystems', options)
  Models::Ecosystems.from_response(response['_links']['ecosystems'])
end

#get(url, params = {}) ⇒ Object

Make the get method public for testing



259
260
261
262
# File 'lib/w3c_api/client.rb', line 259

def get(url, params = {})
  @last_response = @connection.get(url, params)
  handle_response(@last_response, url)
end

#group(id, options = {}) ⇒ Object



87
88
89
90
# File 'lib/w3c_api/client.rb', line 87

def group(id, options = {})
  response = get("groups/#{id}", options)
  Models::Group.from_response(response)
end

#group_chairs(id, options = {}) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/w3c_api/client.rb', line 107

def group_chairs(id, options = {})
  response = get("groups/#{id}/chairs", options)
  Models::Users.from_response(response['_links']['chairs'])
rescue NotFoundError
  # Return empty users collection when endpoint not found
  Models::Users.from_response([])
end

#group_charters(id, options = {}) ⇒ Object



102
103
104
105
# File 'lib/w3c_api/client.rb', line 102

def group_charters(id, options = {})
  response = get("groups/#{id}/charters", options)
  Models::Charters.from_response(response['_links']['charters'])
end

#group_participations(id, options = {}) ⇒ Object



123
124
125
126
# File 'lib/w3c_api/client.rb', line 123

def group_participations(id, options = {})
  response = get("groups/#{id}/participations", options)
  Models::Participations.from_response(response['_links']['participations'])
end

#group_specifications(id, options = {}) ⇒ Object



92
93
94
95
# File 'lib/w3c_api/client.rb', line 92

def group_specifications(id, options = {})
  response = get("groups/#{id}/specifications", options)
  Models::Specifications.from_response(response['_links']['specifications'])
end

#group_team_contacts(id, options = {}) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/w3c_api/client.rb', line 115

def group_team_contacts(id, options = {})
  response = get("groups/#{id}/teamcontacts", options)
  Models::Users.from_response(response['_links']['team-contacts'])
rescue NotFoundError
  # Return empty users collection when endpoint not found
  Models::Users.from_response([])
end

#group_users(id, options = {}) ⇒ Object



97
98
99
100
# File 'lib/w3c_api/client.rb', line 97

def group_users(id, options = {})
  response = get("groups/#{id}/users", options)
  Models::Users.from_response(response['_links']['users'])
end

#groups(options = {}) ⇒ Object

Group methods



82
83
84
85
# File 'lib/w3c_api/client.rb', line 82

def groups(options = {})
  response = get('groups', options)
  Models::Groups.from_response(response['_links']['groups'])
end

#participation(id, options = {}) ⇒ Object

Participation methods



248
249
250
251
# File 'lib/w3c_api/client.rb', line 248

def participation(id, options = {})
  response = get("participations/#{id}", options)
  Models::Participation.from_response(response)
end

#participation_participants(id, options = {}) ⇒ Object



253
254
255
256
# File 'lib/w3c_api/client.rb', line 253

def participation_participants(id, options = {})
  response = get("participations/#{id}/participants", options)
  Models::Users.from_response(response['_links']['users'])
end

#series(options = {}) ⇒ Object

Series methods



65
66
67
68
# File 'lib/w3c_api/client.rb', line 65

def series(options = {})
  response = get('specification-series', options.merge(@params_default))
  Models::Series.from_response(response['_links']['specification-series'])
end

#series_by_shortname(shortname, options = {}) ⇒ Object



70
71
72
73
# File 'lib/w3c_api/client.rb', line 70

def series_by_shortname(shortname, options = {})
  response = get("specification-series/#{shortname}", options)
  Models::Serie.from_response(response)
end

#series_specifications(shortname, options = {}) ⇒ Object



75
76
77
78
# File 'lib/w3c_api/client.rb', line 75

def series_specifications(shortname, options = {})
  response = get("specification-series/#{shortname}/specifications", options.merge(@params_default))
  Models::Specifications.from_response(response['_links']['specifications'])
end

#specification(shortname, options = {}) ⇒ Object



33
34
35
36
# File 'lib/w3c_api/client.rb', line 33

def specification(shortname, options = {})
  response = get("specifications/#{shortname}", options)
  Models::Specification.from_response(response)
end

#specification_superseded_by(shortname, options = {}) ⇒ Object



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

def specification_superseded_by(shortname, options = {})
  response = get("specifications/#{shortname}/superseded", options)
  Models::Specifications.from_response(response['_links']['specifications'])
end

#specification_supersedes(shortname, options = {}) ⇒ Object



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

def specification_supersedes(shortname, options = {})
  response = get("specifications/#{shortname}/supersedes", options)
  Models::Specifications.from_response(response['_links']['specifications'])
end

#specification_version(shortname, version, options = {}) ⇒ Object



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

def specification_version(shortname, version, options = {})
  response = get("specifications/#{shortname}/versions/#{version}", options)
  Models::SpecVersion.from_response(response)
end

#specification_versions(shortname, options = {}) ⇒ Object



38
39
40
41
# File 'lib/w3c_api/client.rb', line 38

def specification_versions(shortname, options = {})
  response = get("specifications/#{shortname}/versions", options)
  Models::SpecVersions.from_response(response['_links']['version-history'])
end

#specifications(options = {}) ⇒ Object

Specification methods



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

def specifications(options = {})
  response = get('specifications', options.merge(@params_default))
  Models::Specifications.from_response(response['_links']['specifications'])
end

#specifications_by_status(status, options = {}) ⇒ Object



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

def specifications_by_status(status, options = {})
  response = get("specifications-by-status/#{status}", options.merge(@params_default))
  Models::Specifications.from_response(response['_links']['specifications'])
end

#translation(id, options = {}) ⇒ Object



192
193
194
195
# File 'lib/w3c_api/client.rb', line 192

def translation(id, options = {})
  response = get("translations/#{id}", options)
  Models::Translation.from_response(response)
end

#translations(options = {}) ⇒ Object

Translation methods



187
188
189
190
# File 'lib/w3c_api/client.rb', line 187

def translations(options = {})
  response = get('translations', options.merge(embed: true))
  Models::Translations.from_response(response['_links']['translations'])
end

#user(id, options = {}) ⇒ Object



135
136
137
138
# File 'lib/w3c_api/client.rb', line 135

def user(id, options = {})
  response = get("users/#{id}", options)
  Models::User.from_response(response)
end

#user_affiliations(id, options = {}) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/w3c_api/client.rb', line 153

def user_affiliations(id, options = {})
  response = get("users/#{id}/affiliations", options)
  Models::Affiliations.from_response(response['_links']['affiliations'])
rescue NotFoundError
  # Return empty affiliations collection when endpoint not found
  Models::Affiliations.from_response([])
end

#user_chair_of_groups(id, options = {}) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/w3c_api/client.rb', line 169

def user_chair_of_groups(id, options = {})
  response = get("users/#{id}/chair-of-groups", options)
  Models::Groups.from_response(response['_links']['groups'])
rescue NotFoundError
  # Return empty groups collection when endpoint not found
  Models::Groups.from_response([])
end

#user_groups(id, options = {}) ⇒ Object



148
149
150
151
# File 'lib/w3c_api/client.rb', line 148

def user_groups(id, options = {})
  response = get("users/#{id}/groups", options)
  Models::Groups.from_response(response['_links']['groups'])
end

#user_participations(id, options = {}) ⇒ Object



161
162
163
164
165
166
167
# File 'lib/w3c_api/client.rb', line 161

def user_participations(id, options = {})
  response = get("users/#{id}/participations", options)
  Models::Participations.from_response(response['_links']['participations'])
rescue NotFoundError
  # Return empty participations collection when endpoint not found
  Models::Participations.from_response([])
end

#user_specifications(id, options = {}) ⇒ Object



140
141
142
143
144
145
146
# File 'lib/w3c_api/client.rb', line 140

def user_specifications(id, options = {})
  response = get("users/#{id}/specifications", options)
  Models::Specifications.from_response(response['_links']['specifications'])
rescue NotFoundError
  # Return empty specifications collection when endpoint not found
  Models::Specifications.from_response([])
end

#user_team_contact_of_groups(id, options = {}) ⇒ Object



177
178
179
180
181
182
183
# File 'lib/w3c_api/client.rb', line 177

def user_team_contact_of_groups(id, options = {})
  response = get("users/#{id}/team-contact-of-groups", options)
  Models::Groups.from_response(response['_links']['groups'])
rescue NotFoundError
  # Return empty groups collection when endpoint not found
  Models::Groups.from_response([])
end

#users(options = {}) ⇒ Object

User methods

Raises:

  • (ArgumentError)


130
131
132
133
# File 'lib/w3c_api/client.rb', line 130

def users(options = {})
  raise ArgumentError,
        'The W3C API does not support fetching all users. You must provide a specific user ID with the user method.'
end