Class: Yandex::Webmaster::Configuration
- Defined in:
- lib/yandex-webmaster/configuration.rb
Constant Summary collapse
- VALID_OPTIONS_KEYS =
[ :adapter, :app_id, :app_password, :oauth_token, :endpoint, :site, :ssl, :user_agent, :connection_options ].freeze
- DEFAULT_ADAPTER =
Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test
:net_http
- DEFAULT_APP_ID =
By default, don’t set an application id
nil
- DEFAULT_APP_PASSWORD =
By default, don’t set an application password
nil
- DEFAULT_OAUTH_TOKEN =
By default, don’t set a user oauth access token
nil
- DEFAULT_ENDPOINT =
The api endpoint used to connect to Yandex.Webmaster if none is set
'https://webmaster.yandex.ru/api/v2/'.freeze
- DEFAULT_SITE =
The web endpoint used to connect to Yandex.Webmaster if none is set
'https://oauth.yandex.ru/'.freeze
- DEFAULT_SSL =
The default SSL configuration
{}
- DEFAULT_USER_AGENT =
The value sent in the http header for ‘User-Agent’ if none is set
"Webmaster Ruby Gem #{Yandex::Webmaster::Version::STRING}".freeze
- DEFAULT_CONNECTION_OPTIONS =
By default uses the Faraday connection options if none is set
{}
Instance Method Summary collapse
-
#configure {|_self| ... } ⇒ Object
Convenience method to allow for global setting of configuration options.
- #current ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #keys ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
Responds to attribute query or attribute clear.
-
#reset! ⇒ Object
Reset configuration options to their defaults.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
49 50 51 52 53 54 |
# File 'lib/yandex-webmaster/configuration.rb', line 49 def initialize( = {}) raise ArgumentError if (.symbolize_keys!.keys - VALID_OPTIONS_KEYS).any? self.reset! .each { |k,v| send("#{k}=", v) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Responds to attribute query or attribute clear
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/yandex-webmaster/configuration.rb', line 87 def method_missing(method, *args, &block) # :nodoc: case method.to_s when /^(.*)\?$/ return !!self.send($1.to_s) when /^clear_(.*)$/ self.send("#{$1.to_s}=", nil) else super end end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
Convenience method to allow for global setting of configuration options
81 82 83 |
# File 'lib/yandex-webmaster/configuration.rb', line 81 def configure yield self end |
#current ⇒ Object
60 61 62 |
# File 'lib/yandex-webmaster/configuration.rb', line 60 def current VALID_OPTIONS_KEYS.inject({}) { |h, k| h[k] = send(k); h } end |
#keys ⇒ Object
56 57 58 |
# File 'lib/yandex-webmaster/configuration.rb', line 56 def keys VALID_OPTIONS_KEYS end |
#reset! ⇒ Object
Reset configuration options to their defaults
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/yandex-webmaster/configuration.rb', line 66 def reset! self.adapter = DEFAULT_ADAPTER self.app_id = DEFAULT_APP_ID self.app_password = DEFAULT_APP_PASSWORD self.oauth_token = DEFAULT_OAUTH_TOKEN self.endpoint = DEFAULT_ENDPOINT self.site = DEFAULT_SITE self.ssl = DEFAULT_SSL self.user_agent = DEFAULT_USER_AGENT self. = DEFAULT_CONNECTION_OPTIONS self end |