Class: WebpurifyApi::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/webpurify_api/base.rb

Direct Known Subclasses

Image, Video

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keyObject

Returns the value of attribute api_key.



2
3
4
# File 'lib/webpurify_api/base.rb', line 2

def api_key
  @api_key
end

#endpointObject

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 error_message_for(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

Returns:

  • (Boolean)


10
11
12
# File 'lib/webpurify_api/base.rb', line 10

def live?
  !!self.live
end

#loggerObject



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