Class: Spectre::Http::SpectreHttpRequest

Inherits:
Object
  • Object
show all
Includes:
Delegate
Defined in:
lib/spectre/http.rb,
lib/spectre/http/keystone.rb

Defined Under Namespace

Classes: Headers

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ SpectreHttpRequest

Returns a new instance of SpectreHttpRequest.



60
61
62
# File 'lib/spectre/http.rb', line 60

def initialize request
  @__req = request
end

Instance Method Details

#authenticate(method) ⇒ Object Also known as: auth



143
144
145
# File 'lib/spectre/http.rb', line 143

def authenticate method
  @__req['auth'] = method
end

#basic_auth(username, password) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/spectre/http.rb', line 87

def basic_auth username, password
  @__req['basic_auth'] = {
    'username' => username,
    'password' => password,
  }

  @__req['auth'] = 'basic_auth'
end

#body(body_content) ⇒ Object



131
132
133
# File 'lib/spectre/http.rb', line 131

def body body_content
  @__req['body'] = body_content.to_s
end

#certificate(path) ⇒ Object Also known as: cert



151
152
153
# File 'lib/spectre/http.rb', line 151

def certificate path
  @__req['cert'] = path
end

#content_type(media_type) ⇒ Object Also known as: media_type



121
122
123
# File 'lib/spectre/http.rb', line 121

def content_type media_type
  @__req['content_type'] = media_type
end

#endpoint(name) ⇒ Object



64
65
66
# File 'lib/spectre/http.rb', line 64

def endpoint name
  @__req['endpoint'] = name
end

#ensure_success!Object



135
136
137
# File 'lib/spectre/http.rb', line 135

def ensure_success!
  @__req['ensure_success'] = true
end

#ensure_success?Boolean

Returns:

  • (Boolean)


139
140
141
# File 'lib/spectre/http.rb', line 139

def ensure_success?
  @__req['ensure_success']
end

#header(name, value) ⇒ Object



104
105
106
# File 'lib/spectre/http.rb', line 104

def header name, value
  @__req['headers'].append [name.to_sym, value.to_s.strip]
end

#json(data) ⇒ Object



125
126
127
128
129
# File 'lib/spectre/http.rb', line 125

def json data
  body JSON.pretty_generate(data)

  content_type('application/json') unless @__req['content_type']
end

#keystone(url, username, password, project, domain, cert = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/spectre/http/keystone.rb', line 6

def keystone url, username, password, project, domain, cert = nil
  @__req['keystone'] = {} unless @__req.key? 'keystone'

  @__req['keystone']['url'] = url
  @__req['keystone']['username'] = username
  @__req['keystone']['password'] = password
  @__req['keystone']['project'] = project
  @__req['keystone']['domain'] = domain
  @__req['keystone']['cert'] = cert

  @__req['auth'] = 'keystone'
end

#method(method_name) ⇒ Object



68
69
70
# File 'lib/spectre/http.rb', line 68

def method method_name
  @__req['method'] = method_name.upcase
end

#no_auth!Object



147
148
149
# File 'lib/spectre/http.rb', line 147

def no_auth!
  @__req['auth'] = 'none'
end

#no_log!Object



159
160
161
# File 'lib/spectre/http.rb', line 159

def no_log!
  @__req['no_log'] = true
end

#path(url_path) ⇒ Object



83
84
85
# File 'lib/spectre/http.rb', line 83

def path url_path
  @__req['path'] = url_path
end

#query(name = nil, value = nil, **kwargs) ⇒ Object Also known as: param



108
109
110
111
# File 'lib/spectre/http.rb', line 108

def query name = nil, value = nil, **kwargs
  @__req['query'].append [name, value.to_s.strip] unless name.nil?
  @__req['query'] += kwargs.map { |key, val| [key.to_s, val] } if kwargs.any?
end

#retries(count) ⇒ Object



100
101
102
# File 'lib/spectre/http.rb', line 100

def retries count
  @__req['retries'] = count
end

#timeout(seconds) ⇒ Object



96
97
98
# File 'lib/spectre/http.rb', line 96

def timeout seconds
  @__req['timeout'] = seconds
end

#to_sObject



163
164
165
# File 'lib/spectre/http.rb', line 163

def to_s
  @__req.to_s
end

#url(base_url) ⇒ Object



79
80
81
# File 'lib/spectre/http.rb', line 79

def url base_url
  @__req['base_url'] = base_url
end

#use_ssl!Object



155
156
157
# File 'lib/spectre/http.rb', line 155

def use_ssl!
  @__req['use_ssl'] = true
end

#with(**params) ⇒ Object



117
118
119
# File 'lib/spectre/http.rb', line 117

def with **params
  @__req['params'].merge! params
end