Class: Thinkific::User

Inherits:
Object
  • Object
show all
Defined in:
lib/thinkific/user.rb

Class Method Summary collapse

Class Method Details

.allObject

works



47
48
49
50
51
52
53
# 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 = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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) ⇒ Object



5
6
7
8
# File 'lib/thinkific/user.rb', line 5

def self.get id
  puts "+++ get one user"
  raise 'not implemented'
end

.where(delta = {}) ⇒ Object

find by email



11
12
13
14
15
16
17
18
19
20
21
# 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