Class: W3cApi::Client
- Inherits:
-
Object
- Object
- W3cApi::Client
- Defined in:
- lib/w3c_api/client.rb
Constant Summary collapse
- API_ENDPOINT =
'https://api.w3.org'
Instance Attribute Summary collapse
-
#last_response ⇒ Object
readonly
Returns the value of attribute last_response.
Instance Method Summary collapse
- #affiliation(id, options = {}) ⇒ Object
- #affiliation_participants(id, options = {}) ⇒ Object
- #affiliation_participations(id, options = {}) ⇒ Object
-
#affiliations(options = {}) ⇒ Object
Affiliation methods.
- #ecosystem(shortname, options = {}) ⇒ Object
- #ecosystem_evangelists(shortname, options = {}) ⇒ Object
- #ecosystem_groups(shortname, options = {}) ⇒ Object
- #ecosystem_member_organizations(shortname, options = {}) ⇒ Object
-
#ecosystems(options = {}) ⇒ Object
Ecosystem methods.
-
#get(url, params = {}) ⇒ Object
Make the get method public for testing.
- #group(id, options = {}) ⇒ Object
- #group_chairs(id, options = {}) ⇒ Object
- #group_charters(id, options = {}) ⇒ Object
- #group_participations(id, options = {}) ⇒ Object
- #group_specifications(id, options = {}) ⇒ Object
- #group_team_contacts(id, options = {}) ⇒ Object
- #group_users(id, options = {}) ⇒ Object
-
#groups(options = {}) ⇒ Object
Group methods.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#participation(id, options = {}) ⇒ Object
Participation methods.
- #participation_participants(id, options = {}) ⇒ Object
-
#series(options = {}) ⇒ Object
Series methods.
- #series_by_shortname(shortname, options = {}) ⇒ Object
- #series_specifications(shortname, options = {}) ⇒ Object
- #specification(shortname, options = {}) ⇒ Object
- #specification_superseded_by(shortname, options = {}) ⇒ Object
- #specification_supersedes(shortname, options = {}) ⇒ Object
- #specification_version(shortname, version, options = {}) ⇒ Object
- #specification_versions(shortname, options = {}) ⇒ Object
-
#specifications(options = {}) ⇒ Object
Specification methods.
- #specifications_by_status(status, options = {}) ⇒ Object
- #translation(id, options = {}) ⇒ Object
-
#translations(options = {}) ⇒ Object
Translation methods.
- #user(id, options = {}) ⇒ Object
- #user_affiliations(id, options = {}) ⇒ Object
- #user_chair_of_groups(id, options = {}) ⇒ Object
- #user_groups(id, options = {}) ⇒ Object
- #user_participations(id, options = {}) ⇒ Object
- #user_specifications(id, options = {}) ⇒ Object
- #user_team_contact_of_groups(id, options = {}) ⇒ Object
-
#users(options = {}) ⇒ Object
User methods.
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( = {}) @api_endpoint = [:api_endpoint] || API_ENDPOINT @connection = create_connection @params_default = { page: 1, items: 3000 } @debug = !ENV['DEBUG_API'].nil? end |
Instance Attribute Details
#last_response ⇒ Object (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, = {}) response = get("affiliations/#{id}", ) 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, = {}) response = get("affiliations/#{id}/participants", ) 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, = {}) response = get("affiliations/#{id}/participations", ) 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( = {}) response = get('affiliations', .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, = {}) response = get("ecosystems/#{shortname}", ) 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, = {}) response = get("ecosystems/#{shortname}/evangelists", ) 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, = {}) response = get("ecosystems/#{shortname}/groups", ) 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, = {}) response = get("ecosystems/#{shortname}/member-organizations", ) 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( = {}) response = get('ecosystems', ) 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, = {}) response = get("groups/#{id}", ) 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, = {}) response = get("groups/#{id}/chairs", ) 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, = {}) response = get("groups/#{id}/charters", ) 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, = {}) response = get("groups/#{id}/participations", ) 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, = {}) response = get("groups/#{id}/specifications", ) 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, = {}) response = get("groups/#{id}/teamcontacts", ) 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, = {}) response = get("groups/#{id}/users", ) 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( = {}) response = get('groups', ) 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, = {}) response = get("participations/#{id}", ) 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, = {}) response = get("participations/#{id}/participants", ) 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( = {}) response = get('specification-series', .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, = {}) response = get("specification-series/#{shortname}", ) 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, = {}) response = get("specification-series/#{shortname}/specifications", .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, = {}) response = get("specifications/#{shortname}", ) 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, = {}) response = get("specifications/#{shortname}/superseded", ) 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, = {}) response = get("specifications/#{shortname}/supersedes", ) 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, = {}) response = get("specifications/#{shortname}/versions/#{version}", ) 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, = {}) response = get("specifications/#{shortname}/versions", ) 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( = {}) response = get('specifications', .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, = {}) response = get("specifications-by-status/#{status}", .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, = {}) response = get("translations/#{id}", ) 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( = {}) response = get('translations', .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, = {}) response = get("users/#{id}", ) 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, = {}) response = get("users/#{id}/affiliations", ) 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, = {}) response = get("users/#{id}/chair-of-groups", ) 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, = {}) response = get("users/#{id}/groups", ) 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, = {}) response = get("users/#{id}/participations", ) 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, = {}) response = get("users/#{id}/specifications", ) 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, = {}) response = get("users/#{id}/team-contact-of-groups", ) 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
130 131 132 133 |
# File 'lib/w3c_api/client.rb', line 130 def users( = {}) raise ArgumentError, 'The W3C API does not support fetching all users. You must provide a specific user ID with the user method.' end |