Class: Svelte::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/svelte/service.rb

Overview

Dynamically generates a client to consume a Swagger API

Class Method Summary collapse

Class Method Details

.create(url: nil, json: nil, module_name:, options: {}) ⇒ Module

Note:

Either url or json need to be provided. url will take precedence over json

Generate a Service via URL or JSON.

Parameters:

  • url (String) (defaults to: nil)

    full URL of the Swagger API spec

  • json (String) (defaults to: nil)

    full Swagger API spec as a String

  • module_name (String)

    constant name where Svelte will build the functionality on top of

  • options (Hash) (defaults to: {})

    options passed as configuration to the generated Swagger objects. :auth options will also be used here when making the initial Swagger spec request.

Returns:

  • (Module)

    A newly created Module with the module hierarchy and methods to consume the Swagger API The new module will be built on top of Svelte::Service and will have module_name as its constant name, therefore it can also be accessed via Svelte::Service::<module_name>. For example, if module_name is Comments, the new module will be built in Svelte::Service::Comments



26
27
28
29
30
31
32
33
34
# File 'lib/svelte/service.rb', line 26

def create(url: nil, json: nil, module_name:, options: {})
  headers = build_headers(options: options)
  json = get_json(url: url, headers: headers) if url

  SwaggerBuilder.new(raw_hash: JSON.parse(json.to_s),
                     module_name: module_name,
                     options: options,
                     headers: headers).make_resource
end