Class: Vermillion::Helper::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/client/helper/endpoint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_path) ⇒ Endpoint

Creates the Endpoint object with default values for internal variables Params:

initial_path

Starting point of the URL this class will build



10
11
12
13
14
# File 'lib/client/helper/endpoint.rb', line 10

def initialize(initial_path)
  @path = { default: initial_path }
  @server = nil
  @protocol = "http://"
end

Instance Attribute Details

#server=(value) ⇒ Object (writeonly)

Set the @server variable externally



5
6
7
# File 'lib/client/helper/endpoint.rb', line 5

def server=(value)
  @server = value
end

Instance Method Details

#add(key, value) ⇒ Object

Add a section to the path Params:

key

Symbol, the key to identify the section

value

Any value to store with the associated key



27
28
29
# File 'lib/client/helper/endpoint.rb', line 27

def add(key, value)
  @path[key.to_sym] = value
end

#delete(key) ⇒ Object

Deletes a value from the internal hash based on a key Params:

key

Symbol, the key to identify the section



41
42
43
# File 'lib/client/helper/endpoint.rb', line 41

def delete(key)
  @path.delete(key)
end

#exists?(key) ⇒ Boolean

Checks whether a key exists Params:

key

Symbol, the key to identify the section

Returns:

  • (Boolean)


48
49
50
# File 'lib/client/helper/endpoint.rb', line 48

def exists?(key)
  @path.key? key
end

#get(key) ⇒ Object

Return a value based on the provided key Params:

key

Symbol, the key to identify the section



34
35
36
# File 'lib/client/helper/endpoint.rb', line 34

def get(key)
  @path[key.to_sym]
end

#protocol=(use_https) ⇒ Object

Set endpoint protocol Params:

use_https

Boolean value for whether to use HTTPS



19
20
21
# File 'lib/client/helper/endpoint.rb', line 19

def protocol=(use_https)
  @protocol = 'https://' if use_https
end

#to_sObject

Override the to_s method to return an endpoint fragment



53
54
55
56
57
58
59
# File 'lib/client/helper/endpoint.rb', line 53

def to_s
  output = @protocol + @server
  @path.each_pair do |_k, value|
    output += value
  end
  output
end