atlas_rb 0.0.87 → 0.0.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc46e02febd818ebeae248bdfe2cd09bb98621bea3c03b9bb63c6e6b00047da6
4
- data.tar.gz: 8b933b86bc86d6127789d22b6585bef3bb590b5ca40a14ae50cb456356d0de26
3
+ metadata.gz: a987c6f2b9d67ba84bfb29752682c630a47d69e943af83d44f5957136b2ae680
4
+ data.tar.gz: 5b2eea6ac511508959d56be1d7dce4306a2187eba6eeb5e1e4556ed7efe3fc9c
5
5
  SHA512:
6
- metadata.gz: 642f8e95f4113401726f28d4221e79e9e7225463a94d633426775cf57e969f07bc0414446d6ebf0fd859d7e334f235ff7dc3b04639729b7b27472adfbd09fc4d
7
- data.tar.gz: fa7d393184858673d6f9ea6138cdc77bd01d7f62f73298d16018935f49b079eea9055fdfd282b2098b7327bdcc3d1b1a8f5c673c5a7eaf52620efa12c54216e0
6
+ metadata.gz: b0279a6e5f20724c89a4e5bb31232e33c9860f4a28ee416a34539e279715e43c8229e436f41a696cc56d762049e4b69abde7a21ba72adaf687bebc5330044e8c
7
+ data.tar.gz: a480b47e2927b337e222d4890d5903b366acebfc27283d366d3967fb98c53a96a84ff039c590ba1a2d67751982c8dd379123a2ad86391e84cf4f937c30225956
data/.version CHANGED
@@ -1 +1 @@
1
- 0.0.87
1
+ 0.0.89
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atlas_rb (0.0.87)
4
+ atlas_rb (0.0.89)
5
5
  faraday (~> 2.7)
6
6
  faraday-follow_redirects (~> 0.3.0)
7
7
  faraday-multipart (~> 1)
@@ -23,7 +23,7 @@ GEM
23
23
  net-http (~> 0.5)
24
24
  hashie (5.1.0)
25
25
  logger
26
- json (2.19.4)
26
+ json (2.19.5)
27
27
  logger (1.7.0)
28
28
  multipart-post (2.4.1)
29
29
  net-http (0.9.1)
@@ -62,14 +62,17 @@ module AtlasRb
62
62
 
63
63
  # List the Works in a Collection.
64
64
  #
65
+ # The endpoint returns just the noids; resolve each through
66
+ # {Resource.find} (or {Work.find}) when a full payload is needed.
67
+ #
65
68
  # @param id [String] the Collection ID.
66
- # @return [Array<AtlasRb::Mash>] the child listing from
67
- # `GET /collections/<id>/children`, one entry per Work.
69
+ # @return [Array<String>] child noids from `GET /collections/<id>/children`.
68
70
  #
69
71
  # @example
70
- # AtlasRb::Collection.children("col-456").each { |work| puts work.noid }
72
+ # AtlasRb::Collection.children("col-456")
73
+ # # => ["w-789", "w-790"]
71
74
  def self.children(id)
72
- JSON.parse(connection({}).get(ROUTE + id + '/children')&.body).map { |entry| AtlasRb::Mash.new(entry) }
75
+ JSON.parse(connection({}).get(ROUTE + id + '/children')&.body)
73
76
  end
74
77
 
75
78
  # Replace a Collection's metadata by uploading a MODS XML document.
@@ -66,14 +66,18 @@ module AtlasRb
66
66
 
67
67
  # List the immediate children (sub-Communities and Collections) of a Community.
68
68
  #
69
+ # The endpoint returns just the noids; resolve each through
70
+ # {Resource.find} (which dispatches by type) when richer payloads are
71
+ # needed.
72
+ #
69
73
  # @param id [String] the parent Community ID.
70
- # @return [Array<AtlasRb::Mash>] the child listing from
71
- # `GET /communities/<id>/children`, one entry per child.
74
+ # @return [Array<String>] child noids from `GET /communities/<id>/children`.
72
75
  #
73
76
  # @example
74
- # AtlasRb::Community.children("c-123").each { |child| puts child.noid }
77
+ # AtlasRb::Community.children("c-123")
78
+ # # => ["fn106x926", "kw52j804p"]
75
79
  def self.children(id)
76
- JSON.parse(connection({}).get(ROUTE + id + '/children')&.body).map { |entry| AtlasRb::Mash.new(entry) }
80
+ JSON.parse(connection({}).get(ROUTE + id + '/children')&.body)
77
81
  end
78
82
 
79
83
  # Replace a Community's metadata by uploading a MODS XML document.
@@ -29,14 +29,16 @@ module AtlasRb
29
29
  # @example Fetching a community
30
30
  # AtlasRb::Community.connection({}).get('/communities/abc123')
31
31
  def connection(params, nuid=nil)
32
+ headers = {
33
+ "Content-Type" => "application/json",
34
+ "Authorization" => "Bearer #{ENV.fetch("ATLAS_TOKEN", nil)}"
35
+ }
36
+ headers["User"] = "NUID #{nuid}" if nuid
37
+
32
38
  Faraday.new(
33
39
  url: ENV.fetch("ATLAS_URL", nil),
34
40
  params: params,
35
- headers: {
36
- "Content-Type" => "application/json",
37
- "Authorization" => "Bearer #{ENV.fetch("ATLAS_TOKEN", nil)}",
38
- "User" => "NUID #{nuid}"
39
- }
41
+ headers: headers
40
42
  ) do |f|
41
43
  f.response :follow_redirects
42
44
  f.adapter Faraday.default_adapter
@@ -62,12 +64,14 @@ module AtlasRb
62
64
  # }
63
65
  # AtlasRb::Blob.multipart({}).post('/files/', payload)
64
66
  def multipart(nuid=nil)
67
+ headers = {
68
+ "Authorization" => "Bearer #{ENV.fetch("ATLAS_TOKEN", nil)}"
69
+ }
70
+ headers["User"] = "NUID #{nuid}" if nuid
71
+
65
72
  Faraday.new(
66
73
  url: ENV.fetch("ATLAS_URL", nil),
67
- headers: {
68
- "Authorization" => "Bearer #{ENV.fetch("ATLAS_TOKEN", nil)}",
69
- "User" => "NUID #{nuid}"
70
- }
74
+ headers: headers
71
75
  ) do |f|
72
76
  f.request :multipart
73
77
  f.request :url_encoded
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AtlasRb
4
+ # System-user binding for Atlas's find-or-create + group-replace endpoint.
5
+ #
6
+ # Used by Cerberus on its SSO callback: given an NUID and the IdP-asserted
7
+ # group set, find-or-create the matching User row and replace its groups
8
+ # with the supplied array (full replace, not merge — the IdP's assertion
9
+ # is authoritative).
10
+ #
11
+ # The endpoint is system-only; {.find_or_create} sends bearer-token auth
12
+ # and no `User:` header. Atlas returns 403 if any `User:` header is
13
+ # present.
14
+ class User
15
+ extend AtlasRb::FaradayHelper
16
+
17
+ # Find-or-create the User keyed on NUID and replace its groups.
18
+ #
19
+ # Idempotent on `nuid`. Authoritative on `groups`.
20
+ #
21
+ # @param nuid [String] the Northeastern University ID.
22
+ # @param groups [Array<String>] full group set; replaces, not merges.
23
+ # @param name [String, nil] forwarded if the caller (e.g. Cerberus's
24
+ # SSO callback) has it; Atlas treats this field as optional.
25
+ # @param email [String, nil] forwarded if available; optional in Atlas.
26
+ # @return [AtlasRb::Mash] the resulting User record (`id`, `nuid`,
27
+ # `name`, `email`, `role`, `groups`).
28
+ #
29
+ # @example From Cerberus's SSO callback
30
+ # AtlasRb::User.find_or_create(nuid: "001234567",
31
+ # groups: ["northeastern:staff",
32
+ # "drs:editors"],
33
+ # name: "Jane Doe",
34
+ # email: "j.doe@example.edu")
35
+ def self.find_or_create(nuid:, groups:, name: nil, email: nil)
36
+ body = { groups: groups }
37
+ body[:name] = name if name
38
+ body[:email] = email if email
39
+
40
+ response = connection({}).put("/users/by_nuid/#{nuid}", body.to_json)
41
+ AtlasRb::Mash.new(JSON.parse(response.body))["user"]
42
+ end
43
+ end
44
+ end
data/lib/atlas_rb.rb CHANGED
@@ -13,6 +13,7 @@ require_relative "atlas_rb/collection"
13
13
  require_relative "atlas_rb/work"
14
14
  require_relative "atlas_rb/file_set"
15
15
  require_relative "atlas_rb/blob"
16
+ require_relative "atlas_rb/user"
16
17
 
17
18
  # Ruby client for the Atlas API — Northeastern University's institutional
18
19
  # digital repository.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlas_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.87
4
+ version: 0.0.89
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cliff
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-04-27 00:00:00.000000000 Z
11
+ date: 2026-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -122,6 +122,7 @@ files:
122
122
  - lib/atlas_rb/file_set.rb
123
123
  - lib/atlas_rb/mash.rb
124
124
  - lib/atlas_rb/resource.rb
125
+ - lib/atlas_rb/user.rb
125
126
  - lib/atlas_rb/version.rb
126
127
  - lib/atlas_rb/work.rb
127
128
  - sig/atlas_rb.rbs