Class: Apiwork::Introspection::API::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/apiwork/introspection/api/resource.rb

Overview

Wraps resource definitions.

Examples:

resource = api.resources[:invoices]

resource.identifier # => "invoices"
resource.path # => "invoices"
resource.parent_identifiers # => []
resource.resources # => {} or nested resources

resource.actions.each_value do |action|
  action.request # => Action::Request
  action.response # => Action::Response
end

Instance Method Summary collapse

Constructor Details

#initialize(dump) ⇒ Resource

Returns a new instance of Resource.



22
23
24
# File 'lib/apiwork/introspection/api/resource.rb', line 22

def initialize(dump)
  @dump = dump
end

Instance Method Details

#actionsHash{Symbol => Introspection::Action}

The actions for this resource.

Returns:

See Also:



63
64
65
# File 'lib/apiwork/introspection/api/resource.rb', line 63

def actions
  @actions ||= @dump[:actions].transform_values { |dump| Action.new(dump) }
end

#identifierString

The identifier for this resource.

Returns:

  • (String)


38
39
40
# File 'lib/apiwork/introspection/api/resource.rb', line 38

def identifier
  @dump[:identifier]
end

#parent_identifiersArray<String>

The parent identifiers for this resource.

Returns:

  • (Array<String>)


54
55
56
# File 'lib/apiwork/introspection/api/resource.rb', line 54

def parent_identifiers
  @dump[:parent_identifiers]
end

#pathString

The path for this resource.

Returns:

  • (String)


46
47
48
# File 'lib/apiwork/introspection/api/resource.rb', line 46

def path
  @dump[:path]
end

#resourcesHash{Symbol => Resource}

The nested resources for this resource.

Returns:



71
72
73
# File 'lib/apiwork/introspection/api/resource.rb', line 71

def resources
  @resources ||= @dump[:resources].transform_values { |dump| Resource.new(dump) }
end

#scopeString?

The scope for this resource.

Returns:

  • (String, nil)


30
31
32
# File 'lib/apiwork/introspection/api/resource.rb', line 30

def scope
  @dump[:scope]
end

#to_hHash

Converts this resource to a hash.

Returns:

  • (Hash)


79
80
81
82
83
84
85
86
87
88
# File 'lib/apiwork/introspection/api/resource.rb', line 79

def to_h
  {
    actions: actions.transform_values(&:to_h),
    identifier: identifier,
    parent_identifiers: parent_identifiers,
    path: path,
    resources: resources.transform_values(&:to_h),
    scope: scope,
  }
end