Class: Scanii::Base

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.

Raises:

  • (ArgumentError)


44
45
46
47
48
49
# File 'lib/scanii.rb', line 44

def initialize(params={})
  raise ArgumentError.new(":api_key is a required argument to initialize Scanii") if params.fetch(:api_key).nil?
  raise ArgumentError.new(":api_secret is a required argument to initialize Scanii") if params.fetch(:api_secret).nil?
  @api_key = params.fetch(:api_key)
  @api_secret = params.fetch(:api_secret)
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



38
39
40
# File 'lib/scanii.rb', line 38

def api_key
  @api_key
end

#api_secretObject

Returns the value of attribute api_secret.



38
39
40
# File 'lib/scanii.rb', line 38

def api_secret
  @api_secret
end

#checksumObject

Returns the value of attribute checksum.



38
39
40
# File 'lib/scanii.rb', line 38

def checksum
  @checksum
end

#content_lengthObject

Returns the value of attribute content_length.



38
39
40
# File 'lib/scanii.rb', line 38

def content_length
  @content_length
end

#content_typeObject

Returns the value of attribute content_type.



38
39
40
# File 'lib/scanii.rb', line 38

def content_type
  @content_type
end

#creation_dateObject

Returns the value of attribute creation_date.



38
39
40
# File 'lib/scanii.rb', line 38

def creation_date
  @creation_date
end

#findingsObject

Returns the value of attribute findings.



38
39
40
# File 'lib/scanii.rb', line 38

def findings
  @findings
end

#idObject

Returns the value of attribute id.



38
39
40
# File 'lib/scanii.rb', line 38

def id
  @id
end

#metadataObject

Returns the value of attribute metadata.



38
39
40
# File 'lib/scanii.rb', line 38

def 
  @metadata
end

#responseObject

Returns the value of attribute response.



38
39
40
# File 'lib/scanii.rb', line 38

def response
  @response
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Scanii::Base)

    the object that the method was called on



40
41
42
# File 'lib/scanii.rb', line 40

def self.configure
  yield self
end

Instance Method Details

#scan(file) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/scanii.rb', line 51

def scan(file)
  response = RestClient::Request.execute method: :post, url: 'https://api.scanii.com/v2.1/files', 
    user: @api_key,
    password: @api_secret,
    payload: {file: File.new(file)}
  @response = JSON(response)
  @id = @response["id"]
  @checksum = @response["checksum"]
  @content_length = @response["content_length"]
  @findings = @response["findings"]
  @creation_date = @response["creation_date"]
  @content_type = @response["content_type"]
  @metadata = @response["metadata"]
  self
end