Module: Type0

Defined in:
lib/type0.rb,
lib/type0/version.rb

Constant Summary collapse

VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.decrypt(encrypted, key) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/type0.rb', line 38

def self.decrypt(encrypted, key)
  base64_decoded = Base64.decode64(encrypted.to_s.strip)
  aes = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
  aes.decrypt
  aes.key = Digest::SHA256.digest(key) 
  aes.iv  = '1234567890123456'
  aes.update(base64_decoded) + aes.final 
end

.initialize(file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/type0.rb', line 13

def self.initialize(file)
  parsed = begin
   config=  YAML::load(IO.read(file))
  rescue ArgumentError => e
puts "There is no secret.yml file"
  end
  unless config["AppKey"].nil?
    $app_key = config["AppKey"] 
  encrypted_value = self.request_token($app_key)
 $token = self.decrypt(encrypted_value, $app_key) 
  end     
end

.request_token(app_key) ⇒ Object



26
27
28
29
30
# File 'lib/type0.rb', line 26

def self.request_token(app_key)
  uri = URI("https://typezero.herokuapp.com/api/auth/#{$app_key}")
  res = Net::HTTP.get_response(uri)
  res = JSON.parse(res.body)['request_token']   
end

.send_mail(app_key, from, to, subject, body, cc, bcc) ⇒ Object



32
33
34
35
36
# File 'lib/type0.rb', line 32

def self.send_mail(app_key, from, to,subject, body, cc , bcc)
 uri = URI('https://typezero.herokuapp.com/api/send_mail')
res = Net::HTTP.post_form(uri, { "token" =>$token , "key" =>$app_key, "from" => from, "to" => to ,"subject" =>subject, "body" => body, "cc" => cc , "bcc" => bcc })
puts res.body
end