Class: TeamCity::Headers

Inherits:
Object
  • Object
show all
Defined in:
lib/teamcity/headers.rb

Defined Under Namespace

Classes: Json, Text, Xml

Constant Summary collapse

VALID_FORMATS =
[ :json, :xml, :text ]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Headers

Returns a new instance of Headers.

Yields:

  • (_self)

Yield Parameters:



19
20
21
# File 'lib/teamcity/headers.rb', line 19

def initialize
  yield(self) if block_given?
end

Instance Attribute Details

#acceptObject

Returns the value of attribute accept.



17
18
19
# File 'lib/teamcity/headers.rb', line 17

def accept
  @accept
end

#content_typeObject

Returns the value of attribute content_type.



17
18
19
# File 'lib/teamcity/headers.rb', line 17

def content_type
  @content_type
end

Class Method Details

.build(opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
# File 'lib/teamcity/headers.rb', line 6

def self.build(opts={})
  accept_format = opts.fetch(:accept){ :json }
  content_type_format = opts.fetch(:content_type){ :json }
  raise ArgumentError, "Invalid format for :accept, valid formats: #{VALID_FORMATS}" unless VALID_FORMATS.include?(accept_format)
  raise ArgumentError, "Invalid format for :content_type, valid format: #{VALID_FORMATS}" unless VALID_FORMATS.include?(content_type_format)
  new do |headers|
    headers.accept = self.const_get(accept_format.to_s.capitalize).accept
    headers.content_type = self.const_get(content_type_format.to_s.capitalize).content_type
  end
end

Instance Method Details

#to_hashObject



23
24
25
26
27
28
# File 'lib/teamcity/headers.rb', line 23

def to_hash
  {
    'Accept' => accept,
    'Content-Type' => content_type
  }
end