Class: Opushon::Body Private

Inherits:
Object
  • Object
show all
Defined in:
lib/opushon/body.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The body structure is a hash where each key is a HTTP method and each value is a sub-hash, called an option object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(get: nil, patch: nil, put: nil, post: nil, delete: nil) ⇒ Body

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Body.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/opushon/body.rb', line 31

def initialize(get: nil, patch: nil, put: nil, post: nil, delete: nil)
  unless get.nil?
    raise ArgumentError, "get #{get.inspect}" unless get.is_a?(Hash)
  end

  unless patch.nil?
    raise ArgumentError, "patch #{patch.inspect}" unless patch.is_a?(Hash)
  end

  unless put.nil?
    raise ArgumentError, "put #{put.inspect}" unless put.is_a?(Hash)
  end

  unless post.nil?
    raise ArgumentError, "post #{post.inspect}" unless post.is_a?(Hash)
  end

  unless delete.nil?
    raise ArgumentError, "delete #{delete.inspect}" unless delete.is_a?(Hash)
  end

  @get    = Option.load(get)    unless get.nil?
  @patch  = Option.load(patch)  unless patch.nil?
  @put    = Option.load(put)    unless put.nil?
  @post   = Option.load(post)   unless post.nil?
  @delete = Option.load(delete) unless delete.nil?
end

Instance Attribute Details

#deleteObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
# File 'lib/opushon/body.rb', line 29

def delete
  @delete
end

#getObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
# File 'lib/opushon/body.rb', line 29

def get
  @get
end

#patchObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
# File 'lib/opushon/body.rb', line 29

def patch
  @patch
end

#postObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
# File 'lib/opushon/body.rb', line 29

def post
  @post
end

#putObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
# File 'lib/opushon/body.rb', line 29

def put
  @put
end

Class Method Details

.load(hash) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/opushon/body.rb', line 9

def self.load(hash)
  raise ArgumentError, "hash #{hash.inspect}" unless hash.is_a?(Hash)

  get     = hash.fetch('GET',     nil)
  patch   = hash.fetch('PATCH',   nil)
  put     = hash.fetch('PUT',     nil)
  post    = hash.fetch('POST',    nil)
  delete  = hash.fetch('DELETE',  nil)

  hash = {
    get:    get,
    patch:  patch,
    put:    put,
    post:   post,
    delete: delete
  }.compact

  new(**hash)
end

Instance Method Details

#to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



59
60
61
62
63
64
65
66
67
# File 'lib/opushon/body.rb', line 59

def to_h
  {
    GET:    maybe_to_h(get),
    PATCH:  maybe_to_h(patch),
    PUT:    maybe_to_h(put),
    POST:   maybe_to_h(post),
    DELETE: maybe_to_h(delete)
  }.compact
end