Class: Rollability::ClientService

Inherits:
Object
  • Object
show all
Defined in:
lib/rollability/client_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClientService

Returns a new instance of ClientService.



5
6
7
# File 'lib/rollability/client_service.rb', line 5

def initialize
  self.cache = ActiveSupport::Cache::MemoryStore.new
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



4
5
6
# File 'lib/rollability/client_service.rb', line 4

def cache
  @cache
end

Instance Method Details

#check_from_store(secret, app_name, object) ⇒ Object



9
10
11
12
13
# File 'lib/rollability/client_service.rb', line 9

def check_from_store(secret, app_name, object)
  self.cache.fetch("#{object.id}") do
    fetch_permission(secret, app_name)
  end
end

#clean_cache(object) ⇒ Object



15
16
17
# File 'lib/rollability/client_service.rb', line 15

def clean_cache(object)
  self.cache.delete("#{object.id}")
end

#fetch_permission(secret, app_name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rollability/client_service.rb', line 25

def fetch_permission(secret, app_name)
  request = Typhoeus::Request.new("#{Rollability.client_url}/#{Rollability.client_action}.json",
    method: :get,
    params: {app_name: Rollability.app_name },
    headers: { Accept: "application/json",
      Cookie: "advaya=#{CGI.escape(secret)}"
    }
  )
  response = request.on_complete do |response|
    if response.success?
      return response.body
    elsif response.timed_out?
      return '[]'
    elsif response.code == 0
      return '[]'
    else
      # Received a non-successful http response.
      return '[]'
    end
  end
  request.run
end

#push_capabilitiesObject



19
20
# File 'lib/rollability/client_service.rb', line 19

def push_capabilities
end

#push_rolesObject



22
23
# File 'lib/rollability/client_service.rb', line 22

def push_roles
end