Class: CryptopusAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/adapters/cryptopus_adapter.rb

Instance Method Summary collapse

Instance Method Details

#find_encryptable_by_name(name) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/adapters/cryptopus_adapter.rb', line 48

def find_encryptable_by_name(name)
  secret_encryptable = Encryptable.find_by_name_and_folder_id(name, session_adapter.selected_folder.id)

  raise CryptopusEncryptableNotFoundError unless secret_encryptable

  secret_encryptable
end

#get(path) ⇒ Object



16
17
18
19
20
# File 'lib/adapters/cryptopus_adapter.rb', line 16

def get(path)
  uri = URI("#{root_url}/#{path}")
  request = new_request(:get, uri)
  send_request(request, uri)
end

#patch(path, body) ⇒ Object



29
30
31
32
33
34
# File 'lib/adapters/cryptopus_adapter.rb', line 29

def patch(path, body)
  uri = URI("#{root_url}/#{path}")
  request = new_request(:patch, uri)
  request.body = body
  send_request(request, uri)
end

#post(path, body) ⇒ Object



22
23
24
25
26
27
# File 'lib/adapters/cryptopus_adapter.rb', line 22

def post(path, body)
  uri = URI("#{root_url}/#{path}")
  request = new_request(:post, uri)
  request.body = body
  send_request(request, uri)
end

#renewed_auth_tokenObject



56
57
58
59
# File 'lib/adapters/cryptopus_adapter.rb', line 56

def renewed_auth_token
  json = get("api_users/#{current_user_id}/token")
  JSON.parse(json)['token']
end

#root_urlObject



10
11
12
13
14
# File 'lib/adapters/cryptopus_adapter.rb', line 10

def root_url
  raise SessionMissingError unless session_adapter.session_data[:url]

  @root_url ||= "#{session_adapter.session_data[:url]}/api"
end

#save_secret(secret) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/adapters/cryptopus_adapter.rb', line 36

def save_secret(secret)
  secret_encryptable = secret.to_encryptable
  secret_encryptable.folder = session_adapter.selected_folder.id
  persisted_secret = Encryptable.find_by_name_and_folder_id(secret.name,
                                                            session_adapter.selected_folder.id)
  if persisted_secret
    patch("encryptables/#{persisted_secret.id}", secret_encryptable.to_json)
  else
    post('encryptables', secret_encryptable.to_json)
  end
end