Class: Apiwork::API::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/apiwork/api/info.rb,
lib/apiwork/api/info/server.rb,
lib/apiwork/api/info/contact.rb,
lib/apiwork/api/info/license.rb

Overview

Block context for defining API metadata.

Used within the ‘info` block in Base.

Defined Under Namespace

Classes: Contact, License, Server

Instance Method Summary collapse

Constructor Details

#initializeInfo

Returns a new instance of Info.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/apiwork/api/info.rb', line 10

def initialize
  @contact = nil
  @deprecated = false
  @description = nil
  @license = nil
  @servers = []
  @summary = nil
  @tags = []
  @terms_of_service = nil
  @title = nil
  @version = nil
end

Instance Method Details

#contact {|contact| ... } ⇒ Contact?

The API contact.

Examples:

instance_eval style

contact do
  name 'Support'
  email 'support@example.com'
end

yield style

contact do |contact|
  contact.name 'Support'
  contact.email 'support@example.com'
end

Yields:

  • block for defining contact info

Yield Parameters:

Returns:



89
90
91
92
93
94
95
# File 'lib/apiwork/api/info.rb', line 89

def contact(&block)
  return @contact unless block

  @contact = Contact.new
  block.arity.positive? ? yield(@contact) : @contact.instance_eval(&block)
  @contact
end

#deprecated!void

This method returns an undefined value.

Marks the API as deprecated.

Examples:

info do
  deprecated!
end


208
209
210
# File 'lib/apiwork/api/info.rb', line 208

def deprecated!
  @deprecated = true
end

#deprecated?Boolean

Whether the API is deprecated.

Returns:

  • (Boolean)


216
217
218
# File 'lib/apiwork/api/info.rb', line 216

def deprecated?
  @deprecated
end

#description(value = nil) ⇒ String?

The API description.

Examples:

description 'Full-featured API for managing invoices and payments.'
info.description # => "Full-featured..."

Parameters:

  • value (String, nil) (defaults to: nil)

    (nil) The description.

Returns:

  • (String, nil)


177
178
179
180
181
# File 'lib/apiwork/api/info.rb', line 177

def description(value = nil)
  return @description if value.nil?

  @description = value
end

#license {|license| ... } ⇒ License?

The API license.

Examples:

instance_eval style

license do
  name 'MIT'
  url 'https://opensource.org/licenses/MIT'
end

yield style

license do |license|
  license.name 'MIT'
  license.url 'https://opensource.org/licenses/MIT'
end

Yields:

  • block for defining license info

Yield Parameters:

Returns:



115
116
117
118
119
120
121
# File 'lib/apiwork/api/info.rb', line 115

def license(&block)
  return @license unless block

  @license = License.new
  block.arity.positive? ? yield(@license) : @license.instance_eval(&block)
  @license
end

#server {|server| ... } ⇒ Array<Server>

Defines a server for the API.

Can be called multiple times.

Examples:

instance_eval style

server do
  url 'https://api.example.com'
  description 'Production'
end

yield style

server do |server|
  server.url 'https://api.example.com'
  server.description 'Production'
end

Yields:

  • block for defining server info

Yield Parameters:

Returns:



143
144
145
146
147
148
149
# File 'lib/apiwork/api/info.rb', line 143

def server(&block)
  return @servers unless block

  server = Server.new
  block.arity.positive? ? yield(server) : server.instance_eval(&block)
  @servers << server
end

#summary(value = nil) ⇒ String?

The API summary.

Examples:

summary 'Invoice management API'
info.summary # => "Invoice management API"

Parameters:

  • value (String, nil) (defaults to: nil)

    (nil) The summary.

Returns:

  • (String, nil)


161
162
163
164
165
# File 'lib/apiwork/api/info.rb', line 161

def summary(value = nil)
  return @summary if value.nil?

  @summary = value
end

#tags(*values) ⇒ Array<String>

The API tags.

Examples:

tags 'invoices', 'payments'
info.tags # => ["invoices", "payments"]

Parameters:

  • values (Array<String>)

    The tags.

Returns:

  • (Array<String>)


193
194
195
196
197
# File 'lib/apiwork/api/info.rb', line 193

def tags(*values)
  return @tags if values.empty?

  @tags = values.flatten
end

#terms_of_service(value = nil) ⇒ String?

The API terms of service.

Examples:

terms_of_service 'https://example.com/terms'
info.terms_of_service # => "https://example.com/terms"

Parameters:

  • value (String, nil) (defaults to: nil)

    (nil) The URL to terms of service.

Returns:

  • (String, nil)


65
66
67
68
69
# File 'lib/apiwork/api/info.rb', line 65

def terms_of_service(value = nil)
  return @terms_of_service if value.nil?

  @terms_of_service = value
end

#title(value = nil) ⇒ String?

The API title.

Examples:

title 'Invoice API'
info.title # => "Invoice API"

Parameters:

  • value (String, nil) (defaults to: nil)

    (nil) The title.

Returns:

  • (String, nil)


33
34
35
36
37
# File 'lib/apiwork/api/info.rb', line 33

def title(value = nil)
  return @title if value.nil?

  @title = value
end

#version(value = nil) ⇒ String?

The API version.

Examples:

version '1.0.0'
info.version # => "1.0.0"

Parameters:

  • value (String, nil) (defaults to: nil)

    (nil) The version.

Returns:

  • (String, nil)


49
50
51
52
53
# File 'lib/apiwork/api/info.rb', line 49

def version(value = nil)
  return @version if value.nil?

  @version = value
end