Module: Type0
- Defined in:
- lib/type0.rb,
lib/type0/version.rb
Constant Summary collapse
- VERSION =
"0.1.10"
Class Method Summary collapse
- .decrypt(encrypted, key) ⇒ Object
- .encrypt(token, key) ⇒ Object
- .initialize(file) ⇒ Object
- .messages ⇒ Object
- .request_token(app_key) ⇒ Object
- .send_mail(app_key, from, to, subject, body, cc, bcc) ⇒ Object
Class Method Details
.decrypt(encrypted, key) ⇒ Object
39 40 41 42 43 44 45 46 |
# 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) ⇒ Object
56 57 58 59 60 61 62 |
# 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) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# 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 ⇒ Object
49 50 51 52 53 54 |
# File 'lib/type0.rb', line 49 def self. 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) ⇒ Object
27 28 29 30 31 |
# 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) ⇒ Object
33 34 35 36 37 |
# 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 |