Class: Rollability::ClientService
- Inherits:
-
Object
- Object
- Rollability::ClientService
- Defined in:
- lib/rollability/client_service.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
Instance Method Summary collapse
- #check_from_store(secret, app_name, object) ⇒ Object
- #clean_cache(object) ⇒ Object
- #fetch_permission(secret, app_name) ⇒ Object
-
#initialize ⇒ ClientService
constructor
A new instance of ClientService.
- #push_capabilities ⇒ Object
- #push_roles ⇒ Object
Constructor Details
#initialize ⇒ ClientService
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
#cache ⇒ Object
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 (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 (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_capabilities ⇒ Object
19 20 |
# File 'lib/rollability/client_service.rb', line 19 def push_capabilities end |
#push_roles ⇒ Object
22 23 |
# File 'lib/rollability/client_service.rb', line 22 def push_roles end |