Sha256: 72eda25155ad024f9d23039c6380077d9364cbc0fa367ca856557bf878173631

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

require 'uri'

module Appfuel
  module WebApi
    class HttpModel
      include Appfuel::Application::AppContainer
      class << self
        def container_class_type
          'web_api'
        end

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

        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

        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

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

        def inherited(klass)
          stage_class_for_registration(klass)
        end
      end

      attr_reader :config, :url, :adapter

      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

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
appfuel-0.3.3 lib/appfuel/storage/web_api/http_model.rb
appfuel-0.3.2 lib/appfuel/storage/web_api/http_model.rb
appfuel-0.3.1 lib/appfuel/storage/web_api/http_model.rb
appfuel-0.3.0 lib/appfuel/storage/web_api/http_model.rb