module Type0

Constants

VERSION

Public Class Methods

decrypt(encrypted, key) click to toggle source
# File lib/type0.rb, line 39
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
encrypt(token, key) click to toggle source
# File lib/type0.rb, line 56
def self.encrypt(token, key)
           aes = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
               aes.encrypt
               aes.key = Digest::SHA256.digest(key) 
               aes.iv  = '1234567890123456'
           encrypted = Base64.encode64( aes.update(token) << aes.final )
end
initialize(file) click to toggle source
# 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?
             $appid = config["AppId"] unless config["AppId"].nil?
             $app_key = config["AppKey"] 
         encrypted_value = self.request_token($appid)
        $token = self.decrypt(encrypted_value, $app_key)    
     end     
end
messages() click to toggle source
# File lib/type0.rb, line 49
def self.messages
   key = self.encrypt($appid.to_s, $app_key)
   uri = URI("https://typezero.herokuapp.com/api/messages/#{$token}/#{key.strip}") 
   res = Net::HTTP.get_response(uri)
   res = JSON.parse(res.body)
end
request_token(app_key) click to toggle source
# File lib/type0.rb, line 27
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) click to toggle source
# File lib/type0.rb, line 33
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" =>$appid, "from" => from, "to" => to ,"subject" =>subject, "body" => body, "cc" => cc , "bcc" => bcc })
       puts res.body
end