class Rooftop::Configuration

Attributes

advanced_options[R]
api_path[R]
api_token[RW]
cache_logger[RW]
cache_store[RW]
connection[R]
connection_path[R]
extra_headers[R]
logger[RW]
perform_caching[RW]
post_type_mapping[RW]
proxy[RW]
site_name[RW]
ssl_options[RW]
url[RW]
user_agent[R]

Public Class Methods

new() click to toggle source
# File lib/rooftop.rb, line 52
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
  @post_type_mapping = {}
  @logger = nil
end

Public Instance Methods

advanced_options=(opts) click to toggle source
# File lib/rooftop.rb, line 75
def advanced_options=(opts)
  @advanced_options = opts || @advanced_options
end
api_path=(path) click to toggle source
# File lib/rooftop.rb, line 67
def api_path=(path)
  @api_path = path || @api_path
end
configure_connection() click to toggle source
# File lib/rooftop.rb, line 91
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, send_only_modified_attributes: true do |c|
    c.use Rooftop::EmbedMiddleware

    c.use Rooftop::PaginationMiddleware

    if @logger
      c.use Rooftop::DebugMiddleware
    end


    #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
extra_headers=(headers) click to toggle source
# File lib/rooftop.rb, line 71
def extra_headers=(headers)
  @extra_headers = headers || @extra_headers
end
to_hash() click to toggle source

Return the Configuration object as a hash, with symbols as keys. @return [Hash]

# File lib/rooftop.rb, line 87
def to_hash
  Hash[instance_variables.map { |name| [name.to_s.gsub("@","").to_sym, instance_variable_get(name)] } ]
end
user_agent=(agent) click to toggle source
# File lib/rooftop.rb, line 79
def user_agent=(agent)
  @user_agent = agent || @user_agent
end