lib/thinkific/user.rb in thinkific-0.0.4 vs lib/thinkific/user.rb in thinkific-0.0.5

- old
+ new

@@ -18,11 +18,33 @@ else raise 'not implemented? Expecting email.' end end - def self.create + def self.create customer={} + body = { + :first_name => customer[:first_name], + :last_name => customer[:last_name], + :email => customer[:email], + :send_welcome_email => false # @TODO: should be true? + } + result = HTTParty.post "#{Thinkific::DOMAIN}/api/public/v1/users", + headers: Thinkific.headers, + body: body + rs = JSON.parse result.body + if rs['errors'] + begin + if rs['errors']['email'][0] == 'has already been taken' + u = Thinkific::User.where( :email => customer[:email] ) + return u + end + end + else + return rs + end + end + # works def self.all result = HTTParty.get "#{Thinkific::DOMAIN}/api/public/v1/users", :headers => Thinkific.headers, :query => Thinkific.query rs = JSON.parse result.body