Class | ApipieBindings::API |
In: |
lib/apipie_bindings/api.rb
|
Parent: | Object |
apidoc_cache_name | [R] | |
dry_run | [W] | |
fake_responses | [R] | |
language | [R] |
Creates new API bindings instance @param [Hash] config API bindings configuration @option config [String] :uri base URL of the server @option config [String] :username username to access the API @option config [String] :password username to access the API @option config [Hash] :oauth options to access API using OAuth
* *:consumer_key* (String) OAuth key * *:consumer_secret* (String) OAuth secret * *:options* (Hash) options passed to OAuth
@option config [AbstractCredentials] :credentials object implementing {AbstractCredentials}
interface e.g. {https://github.com/theforeman/hammer-cli-foreman/blob/master/lib/hammer_cli_foreman/credentials.rb HammerCLIForeman::BasicCredentials} This is prefered way to pass credentials. Credentials acquired form :credentials object take precedence over explicite params
@option config [Hash] :headers additional headers to send with the requests @option config [String] :api_version (‘1’) version of the API @option config [String] :language prefered locale for the API description @option config [String] :apidoc_cache_base_dir (’~/.cache/apipie_bindings’) base
directory for building apidoc_cache_dir
@option config [String] :apidoc_cache_dir (apidoc_cache_base_dir+’/<URI>’) where
to cache the JSON description of the API
@option config [String] :apidoc_cache_name (‘default.json’) name of te cache file.
If there is cache in the :apidoc_cache_dir, it is used.
@option config [String] :apidoc_authenticated (true) whether or not does the call to
obtain API description use authentication. It is useful to avoid unnecessary prompts for credentials
@option config [Hash] :fake_responses ({}) responses to return if used in dry run mode @option config [Bool] :dry_run (false) dry run mode allows to test your scripts
and not touch the API. The results are taken form exemples in the API description or from the :fake_responses
@option config [Bool] :aggressive_cache_checking (false) check before every request
if the local cache of API description (JSON) is up to date. By default it is checked *after* each API request
@option config [Object] :logger (Logger.new(STDERR)) custom logger class @option config [Number] :timeout API request timeout in seconds @param [Hash] options params that are passed to ResClient as-is @raise [ApipieBindings::ConfigurationError] when no +:uri+ or +:apidoc_cache_dir+ is provided @example connect to a server
ApipieBindings::API.new({:uri => 'http://localhost:3000/', :username => 'admin', :password => 'changeme', :api_version => '2', :aggressive_cache_checking => true})
@example connect with a local API description
ApipieBindings::API.new({:apidoc_cache_dir => 'test/unit/data', :apidoc_cache_name => 'architecture'})
Call an action in the API. It finds most fitting route based on given parameters with other attributes neccessary to do an API call. If in dry_run mode {initialize} it finds fake response data in examples or user provided data. At the end when the response format is JSON it is parsed and returned as ruby objects. If server supports checksum sending the internal cache with API description is checked and updated if needed @param [Symbol] resource_name name of the resource @param [Symbol] action_name name of the action @param [Hash] params parameters to be send in the request @param [Hash] headers extra headers to be sent with the request @param [Hash] options options to influence the how the call is processed
* *:response* (Symbol) *:raw* - skip parsing JSON in response * *:with_authentication* (Bool) *true* - use rest client with/without auth configuration
@example show user data
call(:users, :show, :id => 1)
Low level call to the API. Suitable for calling actions not covered by apipie documentation. For all other cases use {call} @param [String] http_method one of get, put, post, destroy, patch @param [String] path URL path that should be called @param [Hash] params parameters to be send in the request @param [Hash] headers extra headers to be sent with the request @param [Hash] options options to influence the how the call is processed
* *:response* (Symbol) *:raw* - skip parsing JSON in response * *:reduce_response_log* (Bool) - do not show response content in the log. * *:with_authentication* (Bool) *true* - use rest client with/without auth configuration
@example show user data
http_call('get', '/api/users/1')