Module: Fera::API
- Defined in:
- lib/fera/api.rb,
lib/fera/api/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- DEFAULT_HEADERS =
{ 'Api-Client' => "fera_ruby_sdk-#{ API::VERSION }", }
- VERSION =
"0.1.3"
Class Method Summary collapse
-
.configure(api_key, api_url: nil, strict_mode: false, debug_mode: false) ⇒ Object, ::Fera::API
Result of the block operation if given, otherwise self.
- .debug_mode? ⇒ Boolean
- .revoke_token!(client_id:, client_secret:, auth_token:) ⇒ Object
Class Method Details
.configure(api_key, api_url: nil, strict_mode: false, debug_mode: false) ⇒ Object, ::Fera::API
Returns Result of the block operation if given, otherwise self.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fera/api.rb', line 22 def self.configure(api_key, api_url: nil, strict_mode: false, debug_mode: false) previous_base_site = Base.site previous_base_headers = Base.headers api_url ||= 'https://api.fera.ai' Base.site = "#{ api_url.chomp('/') }/v3/private" @debug_mode = debug_mode if api_key =~ /^sk_/ Base.headers['Secret-Key'] = api_key elsif api_key =~ /^pk_/ Base.headers['Public-Key'] = api_key else Base.headers['Authorization'] = "Bearer #{ api_key }" end Base.headers['Strict-Mode'] = strict_mode if strict_mode if block_given? begin result = yield ensure Base.site = previous_base_site previous_base_headers.each do |key, value| Base.headers[key] = value end end result else self end end |
.debug_mode? ⇒ Boolean
57 |
# File 'lib/fera/api.rb', line 57 def self.debug_mode?; @debug_mode; end |
.revoke_token!(client_id:, client_secret:, auth_token:) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fera/api.rb', line 59 def self.revoke_token!(client_id:, client_secret:, auth_token:) previous_site = Base.site Base.site = "https://app.fera.ai" body = { client_id: client_id, client_secret: client_secret, token: auth_token } result = Base.connection.post("https://app.fera.ai/oauth/revoke", body.to_json) Base.site = previous_site result end |