Class: Mayak::Http::Request

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mayak/http/request.rb

Constant Summary collapse

CONTENT_TYPE_HEADER =
T.let("Content-Type", String)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.delete(url:, headers: {}, body: nil) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/mayak/http/request.rb', line 100

def self.delete(url:, headers: {}, body: nil)
  Mayak::Http::Request.new(
    verb:    Mayak::Http::Verb::Delete,
    url:     url,
    headers: headers,
    body:    body
  )
end

.get(url:, headers: {}, body: nil) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/mayak/http/request.rb', line 50

def self.get(url:, headers: {}, body: nil)
  Mayak::Http::Request.new(
    verb:    Mayak::Http::Verb::Get,
    url:     url,
    headers: headers,
    body:    body
  )
end

.head(url:, headers: {}, body: nil) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/mayak/http/request.rb', line 60

def self.head(url:, headers: {}, body: nil)
  Mayak::Http::Request.new(
    verb:    Mayak::Http::Verb::Head,
    url:     url,
    headers: headers,
    body:    body
  )
end

.patch(url:, headers: {}, body: nil) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/mayak/http/request.rb', line 90

def self.patch(url:, headers: {}, body: nil)
  Mayak::Http::Request.new(
    verb:    Mayak::Http::Verb::Patch,
    url:     url,
    headers: headers,
    body:    body
  )
end

.post(url:, headers: {}, body: nil) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/mayak/http/request.rb', line 70

def self.post(url:, headers: {}, body: nil)
  Mayak::Http::Request.new(
    verb:    Mayak::Http::Verb::Post,
    url:     url,
    headers: headers,
    body:    body
  )
end

.put(url:, headers: {}, body: nil) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/mayak/http/request.rb', line 80

def self.put(url:, headers: {}, body: nil)
  Mayak::Http::Request.new(
    verb:    Mayak::Http::Verb::Put,
    url:     url,
    headers: headers,
    body:    body
  )
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
# File 'lib/mayak/http/request.rb', line 20

def ==(other)
  verb == other.verb && url.to_s == other.url.to_s && headers == other.headers && body == other.body
end

#content_typeObject



35
36
37
# File 'lib/mayak/http/request.rb', line 35

def content_type
  headers[CONTENT_TYPE_HEADER]
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/mayak/http/request.rb', line 25

def eql?(other)
  self == other
end

#hashObject



30
31
32
# File 'lib/mayak/http/request.rb', line 30

def hash
  [verb, url.to_s, headers, body].hash
end

#with_content_type(type) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/mayak/http/request.rb', line 40

def with_content_type(type)
  Mayak::Http::Request.new(
    verb:    verb,
    url:     url,
    headers: headers.merge(CONTENT_TYPE_HEADER => type),
    body:    body
  )
end