Class: Smartsheet::API::EndpointSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/smartsheet/api/endpoint_spec.rb

Overview

Specification for a single endpoint's configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, **spec) ⇒ EndpointSpec

Returns a new instance of EndpointSpec.

Parameters:

  • method (Symbol)

    The HTTP method for the endpoint; one of [:get, :put, :post, :delete]

  • url_segments (Array<String, Symbol>)

    The segments of the endpoint URL; strings are added as literal segments, while symbols are mapped to corresponding values in a request specification

  • **spec (Hash{Symbol=>Object})

    Optional params, the following of which are supported:

    • :no_auth - If specified as a key, the endpoint can be called without authentication. To preserve meaning, it is recommended to associate :no_auth with the value true.

    • :body_type - If specified as a key, the endpoint will require a body to be provided by the request. When associated with :json, it will expect a JSON formattable body. When associated with :file, it will expect file upload parameters.

    • :headers - When specified, this is expected to be a map of static HTTP headers that will be attached to each request.



27
28
29
30
31
# File 'lib/smartsheet/api/endpoint_spec.rb', line 27

def initialize(method, url, **spec)
  @method = method
  @url_segments = url
  @spec = spec
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



7
8
9
# File 'lib/smartsheet/api/endpoint_spec.rb', line 7

def method
  @method
end

#specObject (readonly)

Returns the value of attribute spec.



7
8
9
# File 'lib/smartsheet/api/endpoint_spec.rb', line 7

def spec
  @spec
end

#url_segmentsObject (readonly)

Returns the value of attribute url_segments.



7
8
9
# File 'lib/smartsheet/api/endpoint_spec.rb', line 7

def url_segments
  @url_segments
end

Instance Method Details

#headersObject



49
50
51
# File 'lib/smartsheet/api/endpoint_spec.rb', line 49

def headers
  spec.key?(:headers) ? spec[:headers] : {}
end

#requires_auth?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/smartsheet/api/endpoint_spec.rb', line 33

def requires_auth?
  !spec.key?(:no_auth)
end

#requires_body?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/smartsheet/api/endpoint_spec.rb', line 37

def requires_body?
  spec.key? :body_type
end

#sending_file?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/smartsheet/api/endpoint_spec.rb', line 41

def sending_file?
  requires_body? && spec[:body_type] == :file
end

#sending_json?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/smartsheet/api/endpoint_spec.rb', line 45

def sending_json?
  requires_body? && spec[:body_type] == :json
end