Class: Spectre::Curl::SpectreHttpRequest

Inherits:
DslClass show all
Defined in:
lib/spectre/curl.rb

Instance Method Summary collapse

Methods inherited from DslClass

#_evaluate, #_execute, #method_missing

Constructor Details

#initialize(request) ⇒ SpectreHttpRequest

Returns a new instance of SpectreHttpRequest.



9
10
11
# File 'lib/spectre/curl.rb', line 9

def initialize request
  @__req = request
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Spectre::DslClass

Instance Method Details

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



57
58
59
# File 'lib/spectre/curl.rb', line 57

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

#body(body_content) ⇒ Object



45
46
47
# File 'lib/spectre/curl.rb', line 45

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

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



61
62
63
64
# File 'lib/spectre/curl.rb', line 61

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

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



35
36
37
38
# File 'lib/spectre/curl.rb', line 35

def content_type media_type
  @__req['headers'] = [] unless @__req['headers']
  @__req['headers'].append ['Content-Type', media_type]
end

#ensure_success!Object



49
50
51
# File 'lib/spectre/curl.rb', line 49

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

#ensure_success?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/spectre/curl.rb', line 53

def ensure_success?
  @__req['ensure_success']
end

#header(name, value) ⇒ Object



25
26
27
28
# File 'lib/spectre/curl.rb', line 25

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

#json(data) ⇒ Object



40
41
42
43
# File 'lib/spectre/curl.rb', line 40

def json data
  body JSON.pretty_generate(data)
  content_type 'application/json'
end

#method(method_name) ⇒ Object



13
14
15
# File 'lib/spectre/curl.rb', line 13

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

#param(name, value) ⇒ Object



30
31
32
33
# File 'lib/spectre/curl.rb', line 30

def param name, value
  @__req['query'] = [] unless @__req['query']
  @__req['query'].append [name, value.to_s.strip]
end

#path(url_path) ⇒ Object



21
22
23
# File 'lib/spectre/curl.rb', line 21

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

#url(base_url) ⇒ Object



17
18
19
# File 'lib/spectre/curl.rb', line 17

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

#use_ssl!Object



66
67
68
# File 'lib/spectre/curl.rb', line 66

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