Class: TeamCity::Headers
- Inherits:
-
Object
- Object
- TeamCity::Headers
- Defined in:
- lib/teamcity/headers.rb
Defined Under Namespace
Constant Summary collapse
- VALID_FORMATS =
[ :json, :xml, :text ]
Instance Attribute Summary collapse
-
#accept ⇒ Object
Returns the value of attribute accept.
-
#content_type ⇒ Object
Returns the value of attribute content_type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ Headers
constructor
A new instance of Headers.
- #to_hash ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Headers
Returns a new instance of Headers.
19 20 21 |
# File 'lib/teamcity/headers.rb', line 19 def initialize yield(self) if block_given? end |
Instance Attribute Details
#accept ⇒ Object
Returns the value of attribute accept.
17 18 19 |
# File 'lib/teamcity/headers.rb', line 17 def accept @accept end |
#content_type ⇒ Object
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
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_hash ⇒ Object
23 24 25 26 27 28 |
# File 'lib/teamcity/headers.rb', line 23 def to_hash { 'Accept' => accept, 'Content-Type' => content_type } end |