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.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#perform_caching ⇒ Object
Returns the value of attribute perform_caching.
-
#post_type_mapping ⇒ Object
Returns the value of attribute post_type_mapping.
-
#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.
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_options ⇒ Object
Returns the value of attribute advanced_options.
45 46 47 |
# File 'lib/rooftop.rb', line 45 def @advanced_options end |
#api_path ⇒ Object
Returns the value of attribute api_path.
45 46 47 |
# File 'lib/rooftop.rb', line 45 def api_path @api_path end |
#api_token ⇒ Object
Returns the value of attribute api_token.
44 45 46 |
# File 'lib/rooftop.rb', line 44 def api_token @api_token end |
#cache_logger ⇒ Object
Returns the value of attribute cache_logger.
44 45 46 |
# File 'lib/rooftop.rb', line 44 def cache_logger @cache_logger end |
#cache_store ⇒ Object
Returns the value of attribute cache_store.
44 45 46 |
# File 'lib/rooftop.rb', line 44 def cache_store @cache_store end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
45 46 47 |
# File 'lib/rooftop.rb', line 45 def connection @connection end |
#connection_path ⇒ Object (readonly)
Returns the value of attribute connection_path.
45 46 47 |
# File 'lib/rooftop.rb', line 45 def connection_path @connection_path end |
#extra_headers ⇒ Object
Returns the value of attribute extra_headers.
45 46 47 |
# File 'lib/rooftop.rb', line 45 def extra_headers @extra_headers end |
#logger ⇒ Object
Returns the value of attribute logger.
44 45 46 |
# File 'lib/rooftop.rb', line 44 def logger @logger end |
#perform_caching ⇒ Object
Returns the value of attribute perform_caching.
44 45 46 |
# File 'lib/rooftop.rb', line 44 def perform_caching @perform_caching end |
#post_type_mapping ⇒ Object
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 |
#proxy ⇒ Object
Returns the value of attribute proxy.
44 45 46 |
# File 'lib/rooftop.rb', line 44 def proxy @proxy end |
#site_name ⇒ Object
Returns the value of attribute site_name.
44 45 46 |
# File 'lib/rooftop.rb', line 44 def site_name @site_name end |
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
44 45 46 |
# File 'lib/rooftop.rb', line 44 def @ssl_options end |
#url ⇒ Object
Returns the value of attribute url.
44 45 46 |
# File 'lib/rooftop.rb', line 44 def url @url end |
#user_agent ⇒ Object
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_connection ⇒ Object
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_hash ⇒ Hash
Return the Configuration object as a hash, with symbols as keys.
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 |