Class: Appfuel::WebApi::HttpModel

Inherits:
Object
  • Object
show all
Includes:
Application::AppContainer
Defined in:
lib/appfuel/storage/web_api/http_model.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Application::AppContainer

#app_container, included, #qualify_container_key

Constructor Details

#initializeHttpModel

Returns a new instance of HttpModel.



48
49
50
51
52
53
54
55
# File 'lib/appfuel/storage/web_api/http_model.rb', line 48

def initialize
  @config = self.class.load_config
  unless @config.key?(:url)
    fail "[web_api initialize] config is missing :url"
  end
  @url = URI(@config[:url])
  @adapter = self.class.load_http_adapter
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



46
47
48
# File 'lib/appfuel/storage/web_api/http_model.rb', line 46

def adapter
  @adapter
end

#configObject (readonly)

Returns the value of attribute config.



46
47
48
# File 'lib/appfuel/storage/web_api/http_model.rb', line 46

def config
  @config
end

#urlObject (readonly)

Returns the value of attribute url.



46
47
48
# File 'lib/appfuel/storage/web_api/http_model.rb', line 46

def url
  @url
end

Class Method Details

.config_key(value = nil) ⇒ Object



12
13
14
15
# File 'lib/appfuel/storage/web_api/http_model.rb', line 12

def config_key(value = nil)
  return @config_key if value.nil?
  @config_key = value.to_sym
end

.container_class_typeObject



8
9
10
# File 'lib/appfuel/storage/web_api/http_model.rb', line 8

def container_class_type
  'web_api'
end

.inherited(klass) ⇒ Object



41
42
43
# File 'lib/appfuel/storage/web_api/http_model.rb', line 41

def inherited(klass)
  stage_class_for_registration(klass)
end

.load_configObject



17
18
19
20
21
22
23
# File 'lib/appfuel/storage/web_api/http_model.rb', line 17

def load_config
  config = app_container[:config]
  unless config.key?(config_key)
    fail "[web_api] config key (#{config_key}) not found - #{self}"
  end
  config[config_key]
end

.load_default_http_adapterObject



34
35
36
37
38
39
# File 'lib/appfuel/storage/web_api/http_model.rb', line 34

def load_default_http_adapter
  unless Kernel.const_defined?(:RestClient)
    require 'rest-client'
  end
  RestClient
end

.load_http_adapterObject



25
26
27
28
29
30
31
32
# File 'lib/appfuel/storage/web_api/http_model.rb', line 25

def load_http_adapter
  container = app_container
  if container.key?('web_api.http_adapter')
    container['web_api.http_adapter']
  else
    load_default_http_adapter
  end
end