Class: Stratagem::Client

Inherits:
Object show all
Defined in:
lib/stratagem/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(authentication) ⇒ Client

Returns a new instance of Client.



5
6
7
# File 'lib/stratagem/client.rb', line 5

def initialize(authentication)
  @authentication = authentication
end

Instance Method Details

#send(snapshot) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stratagem/client.rb', line 9

def send(snapshot)
  Stratagem.logger.debug "Sending report to server"
  url = URI.parse("#{@authentication.base_url}/snapshots")
  req = Net::HTTPS::Post.new(url.path)
  
  req.set_form_data({
    'auth_token' => @authentication.credentials[:token],
    'project_id' => @authentication.credentials[:project],
    'timestamp' => snapshot.timestamp.to_i,
    'model' => snapshot.model.export.to_json
  }, ';')
  res = Net::HTTPS.new(url.host, url.port).start {|http| http.request(req) }
  puts "response:"
  case res
  when Net::HTTPSuccess, Net::HTTPRedirection
    puts "Visit #{@authentication.base_url} for your security posture."
    # OK
  else
    res.error!
  end

  Stratagem.logger.phase('complete')
end