Class: PixivApi::Configuration
- Inherits:
-
Hash
- Object
- Hash
- PixivApi::Configuration
show all
- Defined in:
- lib/pixiv_api/configuration.rb
Defined Under Namespace
Classes: InvalidKeyError, MissingConfigurationError
Constant Summary
collapse
- REQUIRED_KEYS =
%i(
client_id client_secret site authorize_url token_url
)
- OPTIONAL_KEYS =
%i(
cache_dir
)
Instance Method Summary
collapse
Instance Method Details
#[]=(key, value) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/pixiv_api/configuration.rb', line 26
def []=(key, value)
if allowed_keys.include?(key)
super
else
raise InvalidKeyError, "#{key} is not configuration key."
end
end
|
#cache_dir ⇒ Object
22
23
24
|
# File 'lib/pixiv_api/configuration.rb', line 22
def cache_dir
self[:cache_dir] || Dir.mktmpdir('pixiv-api')
end
|
#require_keys! ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/pixiv_api/configuration.rb', line 34
def require_keys!
REQUIRED_KEYS.each do |key|
raise MissingConfigurationError, "configuration requires '#{key}'" unless self[key]
end
self
end
|