class Thinkific::User

Public Class Methods

all() click to toggle source

works

# File lib/thinkific/user.rb, line 47
def self.all
      result = HTTParty.get "#{Thinkific::DOMAIN}/api/public/v1/users", 
    :headers => Thinkific.headers, 
    :query => Thinkific.query
  rs = JSON.parse result.body
  return rs['items']
end
create(customer={}) click to toggle source
# File lib/thinkific/user.rb, line 23
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
get(id) click to toggle source
# File lib/thinkific/user.rb, line 5
def self.get id
  puts "+++ get one user"
  raise 'not implemented'
end
where(delta={}) click to toggle source

find by email

# File lib/thinkific/user.rb, line 11
def self.where delta={}
      if delta[:email]
              result = HTTParty.get "#{Thinkific::DOMAIN}/api/public/v1/users", 
      :headers => Thinkific.headers, 
      :query => Thinkific.query.merge( :query => delta )
    rs = JSON.parse result.body
    return rs['items'][0]
      else
              raise 'not implemented? Expecting email.'
      end
end