Class: WebpurifyApi::Base
- Inherits:
-
Object
- Object
- WebpurifyApi::Base
- Defined in:
- lib/webpurify_api/base.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #error_message_for(code) ⇒ Object
-
#initialize(api_key: nil, live: nil, endpoint: nil) ⇒ Base
constructor
A new instance of Base.
- #live? ⇒ Boolean
- #logger ⇒ Object
- #logger=(val) ⇒ Object
Constructor Details
#initialize(api_key: nil, live: nil, endpoint: nil) ⇒ Base
Returns a new instance of Base.
4 5 6 7 8 |
# File 'lib/webpurify_api/base.rb', line 4 def initialize(api_key: nil, live: nil, endpoint: nil) self.api_key = api_key || ENV['WEBPURIFY_APIKEY'] self.live = live.nil? ? ENV['WEBPURIFY_LIVE'].to_s == 'true' : live self.endpoint = endpoint if endpoint end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
2 3 4 |
# File 'lib/webpurify_api/base.rb', line 2 def api_key @api_key end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
2 3 4 |
# File 'lib/webpurify_api/base.rb', line 2 def endpoint @endpoint end |
Instance Method Details
#error_message_for(code) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/webpurify_api/base.rb', line 23 def (code) case code.to_i when 100 then "Invalid API Key" when 101 then "API Key is inactive" when 102 then "API Key is missing in request" when 103 then "Not a valid URL" when 105 then "Unable to locate image" when 106 then "Out of Requests" else "Unknown error #{code}" end end |
#live? ⇒ Boolean
10 11 12 |
# File 'lib/webpurify_api/base.rb', line 10 def live? !!self.live end |
#logger ⇒ Object
14 15 16 17 |
# File 'lib/webpurify_api/base.rb', line 14 def logger return @logger if defined?(@logger) @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) end |
#logger=(val) ⇒ Object
19 20 21 |
# File 'lib/webpurify_api/base.rb', line 19 def logger=(val) @logger = val end |