Skip to content
Snippets Groups Projects
Verified Commit 7f915e0d authored by Alexander Olofsson's avatar Alexander Olofsson
Browse files

Add support for bare resource retrieval

This is useful in cases where the object is only required as a reference
for looking up other resources.

For example;
`client.password_lists.get(5, _bare: true).passwords.search(user_name: 'root')`
parent 11130397
No related branches found
No related tags found
No related merge requests found
Pipeline #5413 failed
...@@ -44,10 +44,15 @@ module Passwordstate ...@@ -44,10 +44,15 @@ module Passwordstate
end end
def self.get(client, object, query = {}) def self.get(client, object, query = {})
object = object.send(object.class.send(index_field)) if object.is_a? Resource
if query[:_bare]
return new _client: client, index_field => object
end
path = query.fetch(:_api_path, api_path) path = query.fetch(:_api_path, api_path)
query = passwordstateify_hash query.reject { |k| k.to_s.start_with? '_' } query = passwordstateify_hash query.reject { |k| k.to_s.start_with? '_' }
object = object.send(object.class.send(index_field)) if object.is_a? Resource
resp = client.request(:get, "#{path}/#{object}", query: query).map do |data| resp = client.request(:get, "#{path}/#{object}", query: query).map do |data|
new data.merge(_client: client) new data.merge(_client: client)
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment