Class: Passwordstate::Resources::Password

Inherits:
Passwordstate::Resource show all
Defined in:
lib/passwordstate/resources/password.rb

Instance Attribute Summary

Attributes inherited from Passwordstate::Resource

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Passwordstate::Resource

api_path, #api_path, #attributes, delete, #get, get, index_field, #initialize, #inspect, passwordstate_to_ruby_field, passwordstateify_hash, post, #post, put, #put, ruby_to_passwordstate_field, #stored?

Constructor Details

This class inherits a constructor from Passwordstate::Resource

Class Method Details

.all(client, query = {}) ⇒ Object



73
74
75
# File 'lib/passwordstate/resources/password.rb', line 73

def self.all(client, query = {})
  super client, { query_all: true }.merge(query)
end

.generate(client, options = {}) ⇒ Object



81
82
83
84
85
# File 'lib/passwordstate/resources/password.rb', line 81

def self.generate(client, options = {})
  results = client.request(:get, 'generatepassword', query: options).map { |r| r['Password'] }
  return results.first if results.count == 1
  results
end

.search(client, query = {}) ⇒ Object



77
78
79
# File 'lib/passwordstate/resources/password.rb', line 77

def self.search(client, query = {})
  super client, query.merge(_api_path: 'searchpassword')
end

Instance Method Details

#add_dependency(data = {}) ⇒ Object



68
69
70
71
# File 'lib/passwordstate/resources/password.rb', line 68

def add_dependency(data = {})
  raise 'Password dependency creation only available for stored passwords' unless stored?
  client.request :post, 'dependencies', body: self.class.passwordstatify_hash(data.merge(password_id: password_id))
end

#check_inObject



53
54
55
# File 'lib/passwordstate/resources/password.rb', line 53

def check_in
  client.request :get, "passwords/#{password_id}", query: passwordstatify_hash(check_in: nil)
end

#delete(recycle = false, query = {}) ⇒ Object



64
65
66
# File 'lib/passwordstate/resources/password.rb', line 64

def delete(recycle = false, query = {})
  super query.merge(move_to_recycle_bin: recycle)
end

#historyObject



57
58
59
60
61
62
# File 'lib/passwordstate/resources/password.rb', line 57

def history
  raise 'Password history only available on stored passwords' unless stored?
  Passwordstate::ResourceList.new client, PasswordHistory,
                                  all_path: "passwordhistory/#{password_id}",
                                  only: :all
end