class HaveAPI::ClientExample
All client example classes should inherit this class. Depending on the client, the subclass may choose to implement either method ‘example` or `request` and `response`. `example` should be implemented if the client example shows only the request or the request and response should be coupled together.
Methods ‘example`, `request` and `response` take one argument, the example to describe.
Attributes
Public Class Methods
Shortcut to {ClientExample#auth}
# File lib/haveapi/client_example.rb, line 47 def auth(*args) new(*args[0..-3]).auth(*args[-2..]) end
@return [Array<ClientExample>] sorted array of classes
# File lib/haveapi/client_example.rb, line 57 def clients @clients.sort { |a, b| a.order <=> b.order } end
Code name is passed to the syntax highligher.
# File lib/haveapi/client_example.rb, line 25 def code(v = nil) @code = v if v @code end
Shortcut to {ClientExample#example}
# File lib/haveapi/client_example.rb, line 52 def example(*args) new(*args[0..-2]).example(args.last) end
Shortcut to {ClientExample#init}
# File lib/haveapi/client_example.rb, line 42 def init(*) new(*).init end
All subclasses have to call this method to set their label and be registered.
# File lib/haveapi/client_example.rb, line 15 def label(v = nil) if v @label = v HaveAPI::ClientExample.register(self) end @label end
# File lib/haveapi/client_example.rb, line 64 def initialize(host, base_url, version, *args) @host = host @base_url = base_url @version = version @resource_path, @resource, @action_name, @action = args end
A number used for ordering client examples.
# File lib/haveapi/client_example.rb, line 31 def order(v = nil) @order = v if v @order end
# File lib/haveapi/client_example.rb, line 36 def register(klass) @clients ||= [] @clients << klass end
Public Instance Methods
# File lib/haveapi/client_example.rb, line 73 def auth(method, desc); end
# File lib/haveapi/client_example.rb, line 71 def init; end
# File lib/haveapi/client_example.rb, line 75 def version_url File.join(base_url, "v#{version}", '/') end
Protected Instance Methods
@param password [Boolean] include password parameter @return [Hash<String, String>] parameter => example value
# File lib/haveapi/client_example.rb, line 83 def auth_token_credentials(desc, password: true) passwords = %i[password pass passwd] params = desc[:resources][:token][:actions]['request'][:input][:parameters].keys - %i[lifetime interval] unless password params.reject! { |param| passwords.include?(param) } end params.to_h do |param| value = if passwords.include?(param) 'secret' else param end [param, value] end end