Class: Slash::Formats::WithSuffix

Inherits:
Format
  • Object
show all
Defined in:
lib/slash/formats.rb

Instance Attribute Summary collapse

Attributes inherited from Format

#codec, #mime

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Format

#interpret_response

Constructor Details

#initialize(mime, suffix, codec) ⇒ WithSuffix

Returns a new instance of WithSuffix.



44
45
46
47
# File 'lib/slash/formats.rb', line 44

def initialize(mime, suffix, codec)
  super(mime, codec)
  @suffix = suffix
end

Instance Attribute Details

#suffixObject (readonly)

Returns the value of attribute suffix.



42
43
44
# File 'lib/slash/formats.rb', line 42

def suffix
  @suffix
end

Class Method Details

.json(options = {}) ⇒ Object



60
61
62
63
64
# File 'lib/slash/formats.rb', line 60

def self.json(options = {})
  WithSuffix.new(options.fetch(:mime, 'application/json'),
    options.fetch(:suffix, '.json'),
    options.fetch(:codec) { JSON })
end

.xml(options = {}) ⇒ Object



54
55
56
57
58
# File 'lib/slash/formats.rb', line 54

def self.xml(options = {})
  WithSuffix.new(options.fetch(:mime, 'application/xml'),
    options.fetch(:suffix, '.xml'),
    options.fetch(:codec))
end

Instance Method Details

#prepare_request(options, &block) ⇒ Object



49
50
51
52
# File 'lib/slash/formats.rb', line 49

def prepare_request(options, &block)
  options[:path] += suffix if suffix
  super
end