Class: Coca::Delegate
Instance Attribute Summary collapse
- #host ⇒ Object
-
#name ⇒ Object
writeonly
Sets the attribute name.
- #port ⇒ Object
- #protocol ⇒ Object
- #ttl ⇒ Object
Instance Method Summary collapse
- #authenticate(scope, credentials) ⇒ Object
- #base_uri ⇒ Object
- #host_url_with_port ⇒ Object
-
#initialize(name = '') {|_self| ... } ⇒ Delegate
constructor
A new instance of Delegate.
- #ip_address ⇒ Object
- #path ⇒ Object
- #url ⇒ Object
- #valid_referer?(referer) ⇒ Boolean
Constructor Details
#initialize(name = '') {|_self| ... } ⇒ Delegate
Returns a new instance of Delegate.
9 10 11 12 |
# File 'lib/coca/delegate.rb', line 9 def initialize(name='') @name = name yield self if block_given? end |
Instance Attribute Details
#host ⇒ Object
18 19 20 |
# File 'lib/coca/delegate.rb', line 18 def host @host ||= "localhost" end |
#name=(value) ⇒ Object (writeonly)
Sets the attribute name
7 8 9 |
# File 'lib/coca/delegate.rb', line 7 def name=(value) @name = value end |
#port ⇒ Object
22 23 24 |
# File 'lib/coca/delegate.rb', line 22 def port @port end |
#protocol ⇒ Object
26 27 28 |
# File 'lib/coca/delegate.rb', line 26 def protocol @protocol ||= 'https' end |
#ttl ⇒ Object
14 15 16 |
# File 'lib/coca/delegate.rb', line 14 def ttl @ttl ||= Coca.token_ttl end |
Instance Method Details
#authenticate(scope, credentials) ⇒ Object
56 57 58 59 |
# File 'lib/coca/delegate.rb', line 56 def authenticate(scope, credentials) response = HTTParty.get url, :scope => scope, :"#{scope}" => credentials response.body if response.code != 401 end |
#base_uri ⇒ Object
30 31 32 |
# File 'lib/coca/delegate.rb', line 30 def base_uri [host, port].compact.join(':') end |
#host_url_with_port ⇒ Object
46 47 48 49 50 |
# File 'lib/coca/delegate.rb', line 46 def host_url_with_port hup = "#{protocol}://#{host}" hup << ":#{port}" if port hup end |
#ip_address ⇒ Object
38 39 40 |
# File 'lib/coca/delegate.rb', line 38 def ip_address @ip ||= Resolv.new.getaddress(host) end |
#path ⇒ Object
34 35 36 |
# File 'lib/coca/delegate.rb', line 34 def path @path ||= "/coca/1/check" end |
#url ⇒ Object
52 53 54 |
# File 'lib/coca/delegate.rb', line 52 def url @url ||= URI.join(host_url_with_port, path).to_s end |
#valid_referer?(referer) ⇒ Boolean
42 43 44 |
# File 'lib/coca/delegate.rb', line 42 def valid_referer?(referer) !!referer && !referer.blank? && referer == ip_address end |