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.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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

Instance Attribute Details

#advanced_optionsObject

Returns the value of attribute advanced_options.



45
46
47
# File 'lib/rooftop.rb', line 45

def advanced_options
  @advanced_options
end

#api_pathObject

Returns the value of attribute api_path.



45
46
47
# File 'lib/rooftop.rb', line 45

def api_path
  @api_path
end

#api_tokenObject

Returns the value of attribute api_token.



44
45
46
# File 'lib/rooftop.rb', line 44

def api_token
  @api_token
end

#cache_loggerObject

Returns the value of attribute cache_logger.



44
45
46
# File 'lib/rooftop.rb', line 44

def cache_logger
  @cache_logger
end

#cache_storeObject

Returns the value of attribute cache_store.



44
45
46
# File 'lib/rooftop.rb', line 44

def cache_store
  @cache_store
end

#connectionObject (readonly)

Returns the value of attribute connection.



45
46
47
# File 'lib/rooftop.rb', line 45

def connection
  @connection
end

#connection_pathObject (readonly)

Returns the value of attribute connection_path.



45
46
47
# File 'lib/rooftop.rb', line 45

def connection_path
  @connection_path
end

#extra_headersObject

Returns the value of attribute extra_headers.



45
46
47
# File 'lib/rooftop.rb', line 45

def extra_headers
  @extra_headers
end

#loggerObject

Returns the value of attribute logger.



44
45
46
# File 'lib/rooftop.rb', line 44

def logger
  @logger
end

#perform_cachingObject

Returns the value of attribute perform_caching.



44
45
46
# File 'lib/rooftop.rb', line 44

def perform_caching
  @perform_caching
end

#post_type_mappingObject

Returns the value of attribute post_type_mapping.



44
45
46
# File 'lib/rooftop.rb', line 44

def post_type_mapping
  @post_type_mapping
end

#proxyObject

Returns the value of attribute proxy.



44
45
46
# File 'lib/rooftop.rb', line 44

def proxy
  @proxy
end

#site_nameObject

Returns the value of attribute site_name.



44
45
46
# File 'lib/rooftop.rb', line 44

def site_name
  @site_name
end

#ssl_optionsObject

Returns the value of attribute ssl_options.



44
45
46
# File 'lib/rooftop.rb', line 44

def ssl_options
  @ssl_options
end

#urlObject

Returns the value of attribute url.



44
45
46
# File 'lib/rooftop.rb', line 44

def url
  @url
end

#user_agentObject

Returns the value of attribute user_agent.



45
46
47
# File 'lib/rooftop.rb', line 45

def user_agent
  @user_agent
end

Instance Method Details

#configure_connectionObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 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

#to_hashHash

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

Returns:

  • (Hash)


87
88
89
# 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