Class: Rooftop::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rooftop.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rooftop.rb', line 36

def initialize
  @extra_headers = {}
  @connection ||= Her::API.new
  @advanced_options = {}
  @api_path = "/wp-json/"
  @user_agent = "Rooftop CMS Ruby client #{Rooftop::VERSION} (http://github.com/rooftopcms/rooftop-ruby)"
  @perform_caching = false
  @cache_store = ActiveSupport::Cache.lookup_store(:memory_store)
  @cache_logger = nil
  @ssl_options = {}
  @proxy = nil
end

Instance Attribute Details

#advanced_optionsObject

Returns the value of attribute advanced_options.



29
30
31
# File 'lib/rooftop.rb', line 29

def advanced_options
  @advanced_options
end

#api_pathObject

Returns the value of attribute api_path.



29
30
31
# File 'lib/rooftop.rb', line 29

def api_path
  @api_path
end

#api_tokenObject

Returns the value of attribute api_token.



28
29
30
# File 'lib/rooftop.rb', line 28

def api_token
  @api_token
end

#cache_loggerObject

Returns the value of attribute cache_logger.



28
29
30
# File 'lib/rooftop.rb', line 28

def cache_logger
  @cache_logger
end

#cache_storeObject

Returns the value of attribute cache_store.



28
29
30
# File 'lib/rooftop.rb', line 28

def cache_store
  @cache_store
end

#connectionObject (readonly)

Returns the value of attribute connection.



29
30
31
# File 'lib/rooftop.rb', line 29

def connection
  @connection
end

#connection_pathObject (readonly)

Returns the value of attribute connection_path.



29
30
31
# File 'lib/rooftop.rb', line 29

def connection_path
  @connection_path
end

#extra_headersObject

Returns the value of attribute extra_headers.



29
30
31
# File 'lib/rooftop.rb', line 29

def extra_headers
  @extra_headers
end

#perform_cachingObject

Returns the value of attribute perform_caching.



28
29
30
# File 'lib/rooftop.rb', line 28

def perform_caching
  @perform_caching
end

#proxyObject

Returns the value of attribute proxy.



28
29
30
# File 'lib/rooftop.rb', line 28

def proxy
  @proxy
end

#site_nameObject

Returns the value of attribute site_name.



28
29
30
# File 'lib/rooftop.rb', line 28

def site_name
  @site_name
end

#ssl_optionsObject

Returns the value of attribute ssl_options.



28
29
30
# File 'lib/rooftop.rb', line 28

def ssl_options
  @ssl_options
end

#urlObject

Returns the value of attribute url.



28
29
30
# File 'lib/rooftop.rb', line 28

def url
  @url
end

#user_agentObject

Returns the value of attribute user_agent.



29
30
31
# File 'lib/rooftop.rb', line 29

def user_agent
  @user_agent
end

Instance Method Details

#configure_connectionObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rooftop.rb', line 75

def configure_connection
  if @api_token.nil? || @url.nil?
    raise ArgumentError, "You need to configure Rooftop before instantiating a class with a Rooftop mixin"
  end

  @connection_path = "#{@url}#{@api_path}"

  @connection.setup url: @connection_path, ssl: @ssl_options, proxy: @proxy do |c|
    #Headers
    c.use Rooftop::Headers

    # Caching
    if @perform_caching
      c.use Faraday::HttpCache, store: @cache_store, serializer: Marshal, logger: @cache_logger
    end

    # Request
    c.use Faraday::Request::UrlEncoded


    # Response
    c.use Her::Middleware::DefaultParseJSON

    # Adapter
    c.use Faraday::Adapter::NetHttp
  end
end

#to_hashHash

Return the Configuration object as a hash, with symbols as keys.

Returns:

  • (Hash)


71
72
73
# File 'lib/rooftop.rb', line 71

def to_hash
  Hash[instance_variables.map { |name| [name.to_s.gsub("@","").to_sym, instance_variable_get(name)] } ]
end