Module: Cloudflair::Communication

Included in:
Cloudflair, Analytics, Entity, PurgeCache
Defined in:
lib/cloudflair/communication.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



17
18
19
# File 'lib/cloudflair/communication.rb', line 17

def connection
  Cloudflair::Connection.new
end

#hash_to_object(hash) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cloudflair/communication.rb', line 21

def hash_to_object(hash)
  objectified_class = Class.new
  objectified_instance = objectified_class.new
  hash.each do |k, v|
    variable_name = sanitize_variable_name(k)
    variable_name = "_#{variable_name}" if objectified_instance.methods.map(&:to_s).include?(variable_name)

    objectified_instance.instance_variable_set("@#{variable_name}", v)
    objectified_class.send :define_method, variable_name, proc { instance_variable_get("@#{variable_name}") }
  end
  objectified_instance
end

#response(response) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/cloudflair/communication.rb', line 9

def response(response)
  return nil if response.status == 304

  raise_on_http_error response.status

  read response
end