Class: Rooftop::Configuration
- Inherits:
-
Object
- Object
- Rooftop::Configuration
- Defined in:
- lib/rooftop.rb
Instance Attribute Summary collapse
-
#advanced_options ⇒ Object
Returns the value of attribute advanced_options.
-
#api_path ⇒ Object
Returns the value of attribute api_path.
-
#api_token ⇒ Object
Returns the value of attribute api_token.
-
#cache_logger ⇒ Object
Returns the value of attribute cache_logger.
-
#cache_store ⇒ Object
Returns the value of attribute cache_store.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#connection_path ⇒ Object
readonly
Returns the value of attribute connection_path.
-
#extra_headers ⇒ Object
Returns the value of attribute extra_headers.
-
#perform_caching ⇒ Object
Returns the value of attribute perform_caching.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#site_name ⇒ Object
Returns the value of attribute site_name.
-
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #configure_connection ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#to_hash ⇒ Hash
Return the Configuration object as a hash, with symbols as keys.
Constructor Details
#initialize ⇒ Configuration
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 = {} @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 = {} @proxy = nil end |
Instance Attribute Details
#advanced_options ⇒ Object
Returns the value of attribute advanced_options.
29 30 31 |
# File 'lib/rooftop.rb', line 29 def end |
#api_path ⇒ Object
Returns the value of attribute api_path.
29 30 31 |
# File 'lib/rooftop.rb', line 29 def api_path @api_path end |
#api_token ⇒ Object
Returns the value of attribute api_token.
28 29 30 |
# File 'lib/rooftop.rb', line 28 def api_token @api_token end |
#cache_logger ⇒ Object
Returns the value of attribute cache_logger.
28 29 30 |
# File 'lib/rooftop.rb', line 28 def cache_logger @cache_logger end |
#cache_store ⇒ Object
Returns the value of attribute cache_store.
28 29 30 |
# File 'lib/rooftop.rb', line 28 def cache_store @cache_store end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
29 30 31 |
# File 'lib/rooftop.rb', line 29 def connection @connection end |
#connection_path ⇒ Object (readonly)
Returns the value of attribute connection_path.
29 30 31 |
# File 'lib/rooftop.rb', line 29 def connection_path @connection_path end |
#extra_headers ⇒ Object
Returns the value of attribute extra_headers.
29 30 31 |
# File 'lib/rooftop.rb', line 29 def extra_headers @extra_headers end |
#perform_caching ⇒ Object
Returns the value of attribute perform_caching.
28 29 30 |
# File 'lib/rooftop.rb', line 28 def perform_caching @perform_caching end |
#proxy ⇒ Object
Returns the value of attribute proxy.
28 29 30 |
# File 'lib/rooftop.rb', line 28 def proxy @proxy end |
#site_name ⇒ Object
Returns the value of attribute site_name.
28 29 30 |
# File 'lib/rooftop.rb', line 28 def site_name @site_name end |
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
28 29 30 |
# File 'lib/rooftop.rb', line 28 def end |
#url ⇒ Object
Returns the value of attribute url.
28 29 30 |
# File 'lib/rooftop.rb', line 28 def url @url end |
#user_agent ⇒ Object
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_connection ⇒ Object
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: , 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_hash ⇒ Hash
Return the Configuration object as a hash, with symbols as keys.
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 |