Guest User

Untitled

a guest
Nov 23rd, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. require 'fileutils'
  2. require 'json'
  3.  
  4. class User
  5. def initialize
  6. FileUtils.mkdir_p(File.expand_path('~/ifttt'))
  7. @file = File.open(File.expand_path('~/ifttt/users.json'), 'w+')
  8. @data = File.read(File.expand_path('~/ifttt/users.json'))
  9. if @data.length > 0
  10. @data_hash = JSON.parse(@data)
  11. else
  12. @data_hash = {}
  13. end
  14. end
  15.  
  16. def create_user(email, teams)
  17. if @data_hash.has_key?(email)
  18. puts 'user already exists'
  19. else
  20. @data_hash[email] = {'teams'=>[],'partners'=>[]}
  21. @data_hash[email].store('teams', teams)
  22. end
  23. @file.write(@data_hash.to_json)
  24. end
  25. end
Advertisement
Add Comment
Please, Sign In to add comment