Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'fileutils'
- require 'json'
- class User
- def initialize
- FileUtils.mkdir_p(File.expand_path('~/ifttt'))
- @file = File.open(File.expand_path('~/ifttt/users.json'), 'w+')
- @data = File.read(File.expand_path('~/ifttt/users.json'))
- if @data.length > 0
- @data_hash = JSON.parse(@data)
- else
- @data_hash = {}
- end
- end
- def create_user(email, teams)
- if @data_hash.has_key?(email)
- puts 'user already exists'
- else
- @data_hash[email] = {'teams'=>[],'partners'=>[]}
- @data_hash[email].store('teams', teams)
- end
- @file.write(@data_hash.to_json)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment