Class: Clerk::Role

Inherits:
ApplicationRecord show all
Defined in:
app/models/clerk/role.rb

Class Method Summary collapse

Methods inherited from ApplicationRecord

clerk_table_name, clerk_table_name_nc, transaction

Class Method Details

._delete_record(constraints) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/clerk/role.rb', line 45

def self._delete_record(constraints)
  delete_id = constraints["id"]
  if delete_id.nil?
    raise ActiveRecord::RecordNotFound.new("Must pass an id to delete a role", self)
  end

  server_url = "#{Clerk.accounts_url}/roles/#{delete_id}"

  begin
    response = HTTP.auth("Bearer #{Clerk.key_secret}").delete(server_url)
  rescue
    raise Clerk::Errors::ClerkServerError.new("Failed to delete the role", self)
  end


  if response.status.code != 200
    raise Clerk::Errors::ClerkServerError.new("Failed to delete the role", self)
  end

  # overriden function returns the number of rows affected
  return 1      
end

._insert_record(values) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/clerk/role.rb', line 8

def self._insert_record(values)
  server_url = "#{Clerk.accounts_url}/roles"
  begin 
    response = HTTP.auth("Bearer #{Clerk.key_secret}").post(server_url, :json => values)
    id = JSON.parse(response.body)["id"]
  rescue
    raise Clerk::Errors::ClerkServerError.new("Failed to save the role", self)
  end        

  if response.status.code != 200 or id.nil?
    raise Clerk::Errors::ClerkServerError.new("Failed to save the role", self)
  end
  
  return id
end

._update_record(values, constraints) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/clerk/role.rb', line 24

def self._update_record(values, constraints)
  update_id = constraints["id"]
  if update_id.nil?
    raise ActiveRecord::RecordNotFound.new("Must pass an id to update a role", self)
  end

  server_url = "#{Clerk.accounts_url}/roles/#{update_id}"
  begin
    response = HTTP.auth("Bearer #{Clerk.key_secret}").patch(server_url, :json => values.merge!(constraints))
  rescue
    raise Clerk::Errors::ClerkServerError.new("Failed to update the role", self)
  end

  if response.status.code != 200
    raise Clerk::Errors::ClerkServerError.new("Failed to update the role", self)
  end

  # overriden function returns the number of rows affected
  return 1
end

.delete_allObject



74
75
76
# File 'app/models/clerk/role.rb', line 74

def self.delete_all
  raise Clerk::Errors::MethodDisabled.new("delete_all is disabled for Clerk::Role") 
end

.destroy_allObject



78
79
80
# File 'app/models/clerk/role.rb', line 78

def self.destroy_all
  raise Clerk::Errors::MethodDisabled.new("destroy_all is disabled for Clerk::Role")
end

.update_all(updates) ⇒ Object

disable bulk calls



70
71
72
# File 'app/models/clerk/role.rb', line 70

def self.update_all(updates)
  raise Clerk::Errors::MethodDisabled.new("update_all is disabled for Clerk::Role")
end