Class: ProbeDockRSpec::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/probe_dock_rspec/server.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



18
19
20
21
22
23
24
# File 'lib/probe_dock_rspec/server.rb', line 18

def initialize options = {}
  @name = options[:name].to_s.strip
  @api_url = options[:api_url].to_s if options[:api_url]
  @api_token = options[:api_token].to_s if options[:api_token]
  @api_version = options[:api_version] || 1
  @project_api_id = options[:project_api_id].to_s if options[:project_api_id]
end

Instance Attribute Details

#api_tokenObject (readonly)

Returns the value of attribute api_token.



7
8
9
# File 'lib/probe_dock_rspec/server.rb', line 7

def api_token
  @api_token
end

#api_urlObject (readonly)

Returns the value of attribute api_url.



7
8
9
# File 'lib/probe_dock_rspec/server.rb', line 7

def api_url
  @api_url
end

#api_versionObject (readonly)

Returns the value of attribute api_version.



7
8
9
# File 'lib/probe_dock_rspec/server.rb', line 7

def api_version
  @api_version
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/probe_dock_rspec/server.rb', line 7

def name
  @name
end

#project_api_idObject (readonly)

Returns the value of attribute project_api_id.



7
8
9
# File 'lib/probe_dock_rspec/server.rb', line 7

def project_api_id
  @project_api_id
end

Instance Method Details

#payload_optionsObject



26
27
28
# File 'lib/probe_dock_rspec/server.rb', line 26

def payload_options
  { version: @api_version }
end

#upload(payload) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/probe_dock_rspec/server.rb', line 30

def upload payload
  validate!

  body = Oj.dump payload, mode: :strict
  res = HTTParty.post payload_uri, body: body, headers: payload_headers

  if res.code != 202
    raise Error.new("Expected HTTP 202 Accepted when submitting payload, got #{res.code}", res)
  end
end