supersaas-api-client 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/actions.yaml +21 -0
  3. data/.gitignore +3 -1
  4. data/.rubocop.yml +1 -0
  5. data/.rubocop_todo.yml +296 -0
  6. data/Gemfile +5 -3
  7. data/Gemfile.lock +31 -4
  8. data/README.md +108 -54
  9. data/Rakefile +8 -6
  10. data/bin/console +4 -3
  11. data/examples/appointments.rb +70 -42
  12. data/examples/forms.rb +20 -22
  13. data/examples/groups.rb +20 -0
  14. data/examples/promotions.rb +32 -0
  15. data/examples/schedules.rb +23 -11
  16. data/examples/users.rb +31 -23
  17. data/lib/supersaas-api-client/api/appointments.rb +37 -25
  18. data/lib/supersaas-api-client/api/base_api.rb +69 -23
  19. data/lib/supersaas-api-client/api/forms.rb +16 -9
  20. data/lib/supersaas-api-client/api/groups.rb +12 -0
  21. data/lib/supersaas-api-client/api/promotions.rb +29 -0
  22. data/lib/supersaas-api-client/api/schedules.rb +14 -4
  23. data/lib/supersaas-api-client/api/users.rb +28 -15
  24. data/lib/supersaas-api-client/client.rb +101 -35
  25. data/lib/supersaas-api-client/exception.rb +3 -1
  26. data/lib/supersaas-api-client/models/appointment.rb +9 -12
  27. data/lib/supersaas-api-client/models/base_model.rb +4 -1
  28. data/lib/supersaas-api-client/models/field_list.rb +12 -0
  29. data/lib/supersaas-api-client/models/form.rb +5 -2
  30. data/lib/supersaas-api-client/models/group.rb +7 -0
  31. data/lib/supersaas-api-client/models/promotion.rb +7 -0
  32. data/lib/supersaas-api-client/models/resource.rb +3 -1
  33. data/lib/supersaas-api-client/models/schedule.rb +3 -1
  34. data/lib/supersaas-api-client/models/slot.rb +4 -6
  35. data/lib/supersaas-api-client/models/super_form.rb +7 -0
  36. data/lib/supersaas-api-client/models/user.rb +5 -8
  37. data/lib/supersaas-api-client/version.rb +4 -2
  38. data/lib/supersaas-api-client.rb +3 -1
  39. data/lib/supersaas.rb +23 -15
  40. data/supersaas-api-client.gemspec +19 -18
  41. metadata +40 -26
  42. data/test/appointments_test.rb +0 -99
  43. data/test/client_test.rb +0 -46
  44. data/test/forms_test.rb +0 -22
  45. data/test/schedules_test.rb +0 -19
  46. data/test/test_helper.rb +0 -23
  47. data/test/users_test.rb +0 -68
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
3
5
 
4
6
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
8
10
  end
9
11
 
10
- task :default => :test
12
+ task default: :test
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "supersaas-api-client"
4
+ require 'bundler/setup'
5
+ require 'supersaas-api-client'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "supersaas-api-client"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,19 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "date"
4
- require "pp"
5
- require "supersaas-api-client"
4
+ require 'date'
5
+ require 'supersaas-api-client'
6
6
 
7
- puts "\n\r# SuperSaaS Appointments Example\n\r"
7
+ puts "# SuperSaaS Appointments Example"
8
8
 
9
9
  unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
10
- puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g.\n\r"
11
- puts " SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<api_key> ./examples/appointments.rb\n\r"
10
+ puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g."
11
+ puts "SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<api_key> ./examples/appointments.rb"
12
12
  return
13
13
  end
14
14
 
15
15
  puts "## Account: #{Supersaas::Client.instance.account_name}"
16
- puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}\n\r"
16
+ puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}"
17
17
 
18
18
  Supersaas::Client.instance.verbose = true
19
19
 
@@ -21,64 +21,92 @@ if ENV['SSS_API_SCHEDULE']
21
21
  schedule_id = ENV['SSS_API_SCHEDULE']
22
22
  show_slot = ENV['SSS_API_SLOT'] ? true : false
23
23
  else
24
- puts "ERROR! Missing schedule id. Rerun the script with your schedule id, e.g.\n\r"
25
- puts " SSS_API_SCHEDULE=<scheduleid> ./examples/appointments.rb\n\r"
24
+ puts "ERROR! Missing schedule id. Rerun the script with your schedule id, e.g."
25
+ puts " SSS_API_SCHEDULE=<scheduleid> ./examples/appointments.rb"
26
26
  return
27
27
  end
28
28
 
29
+ # give
30
+ user_id = ENV.fetch('SSS_API_USER', nil)
31
+
32
+ unless user_id
33
+ puts "User is created and then deleted at the end"
34
+ params = { full_name: 'Example', name: 'example@example.com', email: 'example@example.com', api_key: 'example' }
35
+ user = Supersaas::Client.instance.users.create(params)
36
+ user_id = user.match(/users\/(\d+)\.json/)[1]
37
+ puts "#New user created #{user_id}"
38
+ end
39
+
40
+
29
41
  description = nil
30
- new_appointment_id = nil
31
- user = ENV['SSS_API_USER']
32
- if user
42
+ if user_id
33
43
  description = '1234567890.'
34
- params = {full_name: 'Example', description: description, name: 'example@example.com', email: 'example@example.com', mobile: '555-5555', phone: '555-5555', address: 'addr'}
44
+ params = { full_name: 'Example', description: description, name: 'example@example.com', email: 'example@example.com',
45
+ mobile: '555-5555', phone: '555-5555', address: 'addr' }
35
46
  if show_slot
36
- params[:slot_id] = ENV['SSS_API_SLOT']
47
+ params[:slot_id] = ENV.fetch('SSS_API_SLOT', nil)
37
48
  else
38
- days = 1 + rand(30)
49
+ days = rand(1..30)
39
50
  params[:start] = Time.now + (days * 24 * 60 * 60)
40
51
  params[:finish] = params[:start] + (60 * 60)
41
52
  end
42
- puts "\n\rcreating new appointment..."
43
- puts "\n\r#### Supersaas::Client.instance.appointments.create(#{schedule_id}, #{user}, {...})\n\r"
44
- Supersaas::Client.instance.appointments.create(schedule_id, user, params)
53
+ puts "creating new appointment..."
54
+ puts "#### Supersaas::Client.instance.appointments.create(#{schedule_id}, #{user_id}, {...})"
55
+ Supersaas::Client.instance.appointments.create(schedule_id, user_id, params)
45
56
  else
46
- puts "\n\rskipping create/update/delete (NO DESTRUCTIVE ACTIONS FOR SCHEDULE DATA)...\n\r"
57
+ puts "skipping create/update/delete (NO DESTRUCTIVE ACTIONS FOR SCHEDULE DATA)..."
47
58
  end
48
59
 
49
- puts "\n\rlisting appointments..."
50
- puts "\n\r#### Supersaas::Client.instance.appointments.list(#{schedule_id}, nil, nil, 25)\n\r"
60
+ puts "listing appointments..."
61
+ puts "#### Supersaas::Client.instance.appointments.list(#{schedule_id}, nil, nil, 25)"
51
62
 
52
63
  appointments = Supersaas::Client.instance.appointments.list(schedule_id, nil, nil, 25)
53
- appointments.each do |appointment|
54
- puts "#{description} == #{appointment.description}"
55
- if description == appointment.description
56
- puts "\n\rupdating appointment..."
57
- puts "\n\r#### Supersaas::Client.instance.appointments.update(#{schedule_id}, #{new_appointment_id}, {...})\n\r"
58
- Supersaas::Client.instance.appointments.update(schedule_id, new_appointment_id, {country: 'FR', address: 'Rue 1'})
59
-
60
- puts "\n\rdeleting appointment..."
61
- puts "\n\r#### Supersaas::Client.instance.appointments.delete(#{schedule_id}. #{new_appointment_id})\n\r"
62
- Supersaas::Client.instance.appointments.delete(schedule_id, new_appointment_id)
63
- break
64
- end
65
- end
66
64
 
67
- if appointments.size > 0
65
+ if appointments.size.positive?
68
66
  appointment_id = appointments.sample.id
69
- puts "\n\rgetting appointment..."
70
- puts "\n\r#### Supersaas::Client.instance.appointments.get(#{appointment_id})\n\r"
67
+ puts "getting appointment..."
68
+ puts "#### Supersaas::Client.instance.appointments.get(#{appointment_id})"
71
69
  Supersaas::Client.instance.appointments.get(schedule_id, appointment_id)
72
70
  end
73
71
 
74
- puts "\n\rlisting changes..."
72
+ puts "listing changes..."
75
73
  from = DateTime.now - 120
76
- puts "\n\r#### Supersaas::Client.instance.appointments.changes(#{schedule_id}, '#{from.strftime("%Y-%m-%d %H:%M:%S")}', '#{to.strftime("%Y-%m-%d %H:%M:%S")}', #{show_slot || 'false'})\n\r"
74
+ to = DateTime.now + 360_000
75
+ puts "#### Supersaas::Client.instance.appointments.changes(#{schedule_id},
76
+ '#{from.strftime('%Y-%m-%d %H:%M:%S')}', '#{to.strftime('%Y-%m-%d %H:%M:%S')}', #{show_slot || 'false'})"
77
77
 
78
78
  Supersaas::Client.instance.appointments.changes(schedule_id, from, show_slot)
79
79
 
80
- puts "\n\rlisting available..."
80
+ puts "listing available..."
81
81
  from = DateTime.now
82
- puts "\n\r#### Supersaas::Client.instance.appointments.available(#{schedule_id}, '#{from.strftime("%Y-%m-%d %H:%M:%S")}')\n\r"
82
+ puts "#### Supersaas::Client.instance.appointments.available(#{schedule_id},
83
+ '#{from.strftime('%Y-%m-%d %H:%M:%S')}')"
84
+
85
+ Supersaas::Client.instance.appointments.available(schedule_id, from)
86
+
87
+ puts "Appointments for a single user..."
88
+ user = Supersaas::Client.instance.users.list(nil, 1).first
89
+ from = DateTime.now
90
+ puts "#### Supersaas::Client.instance.appointments.agenda(#{schedule_id}, user.id,
91
+ '#{from.strftime('%Y-%m-%d %H:%M:%S')}')"
92
+ Supersaas::Client.instance.appointments.agenda(schedule_id, user.id, from.strftime('%Y-%m-%d %H:%M:%S'))
93
+
94
+ # Update and delete appointments
95
+ appointments.each do |appointment|
96
+ puts "#{description} == #{appointment.description}"
97
+ next unless description == appointment.description
98
+
99
+ puts "updating appointment..."
100
+ puts "#### Supersaas::Client.instance.appointments.update(#{schedule_id}, #{appointment.id}, {...})"
101
+ Supersaas::Client.instance.appointments.update(schedule_id, appointment.id, { country: 'FR', address: 'Rue 1' })
102
+
103
+ puts "deleting appointment..."
104
+ puts "#### Supersaas::Client.instance.appointments.delete(#{schedule_id}. #{appointment.id})"
105
+ Supersaas::Client.instance.appointments.delete(schedule_id, appointment.id)
106
+ break
107
+ end
83
108
 
84
- Supersaas::Client.instance.appointments.available(schedule_id, from)
109
+ # Puts delete user
110
+ unless ENV.fetch('SSS_API_USER', nil)
111
+ Supersaas::Client.instance.users.delete(user_id)
112
+ end
data/examples/forms.rb CHANGED
@@ -1,39 +1,37 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "pp"
4
- require "supersaas-api-client"
4
+ require 'supersaas-api-client'
5
5
 
6
- puts "\n\r# SuperSaaS Forms Example\n\r"
6
+ puts "# SuperSaaS Forms Example"
7
7
 
8
8
  unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
9
- puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g.\n\r"
10
- puts " SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/appointments.rb\n\r"
9
+ puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g."
10
+ puts " SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/appointments.rb"
11
11
  return
12
12
  end
13
13
 
14
14
  puts "## Account: #{Supersaas::Client.instance.account_name}"
15
- puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}\n\r"
15
+ puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}"
16
16
 
17
17
  Supersaas::Client.instance.verbose = true
18
18
 
19
- if ENV['SSS_API_FORM']
20
- form_id = ENV['SSS_API_FORM']
21
- else
22
- puts "ERROR! Missing form id. Rerun the script with your form id, e.g.\n\r"
23
- puts " SSS_API_FORM=<formid> ./examples/forms.rb\n\r"
24
- return
25
- end
19
+ puts "You will need to create a form, and also attach the form to a booking, see documentation on how to do that"
20
+ puts "The below example will take a form in random, and if it is not attached to something then 404 error will be raised"
21
+
22
+ puts "listing forms..."
23
+ puts "#### Supersaas::Client.instance.forms.forms"
26
24
 
27
- puts "\n\rlisting forms..."
28
- puts "\n\r#### Supersaas::Client.instance.forms.list(#{form_id})\n\r"
25
+ template_forms = Supersaas::Client.instance.forms.forms
29
26
 
30
- forms = Supersaas::Client.instance.forms.list(form_id)
27
+ if template_forms.size.positive?
28
+ template_form_id = template_forms.sample.id
31
29
 
32
- if forms.size > 0
33
- form_id = forms.sample.id
34
- puts "\n\rgetting form..."
35
- puts "\n\r#### Supersaas::Client.instance.forms.get(#{form_id})\n\r"
36
- form = Supersaas::Client.instance.forms.get(form_id)
30
+ puts "listing forms from account"
31
+ puts "#### Supersaas::Client.instance.forms.list"
32
+ form_id = Supersaas::Client.instance.forms.list(template_form_id).sample.id
37
33
  end
38
34
 
39
- puts
35
+ puts "getting form..."
36
+ puts "#### Supersaas::Client.instance.forms.get(#{form_id})"
37
+ Supersaas::Client.instance.forms.get(form_id)
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'supersaas-api-client'
4
+
5
+ puts "# SuperSaaS Groups Example"
6
+
7
+ unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
8
+ puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g."
9
+ puts "SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/users.rb"
10
+ return
11
+ end
12
+
13
+ puts "## Account: #{Supersaas::Client.instance.account_name}"
14
+ puts "## API KEY: #{'*' * Supersaas::Client.instance.api_key.size}"
15
+
16
+ Supersaas::Client.instance.verbose = true
17
+
18
+ puts "listing groups..."
19
+ puts "#### Supersaas::Client.instance.groups.list"
20
+ Supersaas::Client.instance.groups.list
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'supersaas-api-client'
4
+
5
+ puts "# SuperSaaS Promotions Example"
6
+
7
+ unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
8
+ puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g."
9
+ puts "SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/users.rb"
10
+ return
11
+ end
12
+
13
+ puts "## Account: #{Supersaas::Client.instance.account_name}"
14
+ puts "## API KEY: #{'*' * Supersaas::Client.instance.api_key.size}"
15
+
16
+ Supersaas::Client.instance.verbose = true
17
+
18
+ puts "listing promotions..."
19
+ puts "#### Supersaas::Client.instance.promotions.list"
20
+ promotions = Supersaas::Client.instance.promotions.list
21
+
22
+ [10, promotions.size].min&.times do |i|
23
+ puts "A promotion"
24
+ puts "#### Supersaas::Client.instance.promotion(#{promotions[i].id})"
25
+ Supersaas::Client.instance.promotions.promotion(promotions[i].code)
26
+ end
27
+
28
+ # Uncomment to try out duplicating a promotional code
29
+ # puts "duplicate promotional code"
30
+ # puts "#### Supersaas::Client.instance.promotions.duplicate_promotion_code('new_id', 'id_to_duplicate')"
31
+ # Supersaas::Client.instance.promotions.duplicate_promotion_code("pcode#{SecureRandom.hex(4)}", promotions.first.code)
32
+ # puts
@@ -1,27 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "supersaas-api-client"
4
+ require 'supersaas-api-client'
4
5
 
5
- puts "\n\r# SuperSaaS Schedules Example\n\r"
6
+ puts "# SuperSaaS Schedules Example"
6
7
 
7
8
  unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
8
- puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g.\n\r"
9
- puts " SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/users.rb\n\r"
9
+ puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g."
10
+ puts "SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/users.rb"
10
11
  return
11
12
  end
12
13
 
13
14
  puts "## Account: #{Supersaas::Client.instance.account_name}"
14
- puts "## API KEY: #{'*' * Supersaas::Client.instance.api_key.size}\n\r"
15
+ puts "## API KEY: #{'*' * Supersaas::Client.instance.api_key.size}"
15
16
 
16
17
  Supersaas::Client.instance.verbose = true
17
18
 
18
- puts "\n\rlisting schedules..."
19
- puts "\n\r#### Supersaas::Client.instance.schedules.list\n\r"
19
+ puts "listing schedules..."
20
+ puts "#### Supersaas::Client.instance.schedules.list"
20
21
  schedules = Supersaas::Client.instance.schedules.list
21
22
 
22
- puts "\n\rlisting schedule resources..."
23
- [10, schedules.size].min.times do |i|
24
- puts "\n\r#### Supersaas::Client.instance.schedules.resources(#{schedules[i].id})\n\r"
23
+ puts "listing schedule resources..."
24
+ [10, schedules.size].min&.times do |i|
25
+ puts "#### Supersaas::Client.instance.schedules.resources(#{schedules[i].id})"
26
+ # Capacity schedules bomb
27
+ begin
25
28
  Supersaas::Client.instance.schedules.resources(schedules[i].id)
29
+ rescue
30
+ next
31
+ end
26
32
  end
27
- puts
33
+
34
+ puts "puts listing fields..."
35
+ [10, schedules.size].min&.times do |i|
36
+ puts "#### Supersaas::Client.instance.schedules.field_list(#{schedules[i].id})"
37
+ Supersaas::Client.instance.schedules.field_list(schedules[i].id)
38
+ end
39
+ puts
data/examples/users.rb CHANGED
@@ -1,51 +1,59 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "supersaas-api-client"
4
+ require 'supersaas-api-client'
4
5
 
5
- puts "\n\r# SuperSaaS Users Example\n\r"
6
+ puts "# SuperSaaS Users Example"
6
7
 
7
8
  unless Supersaas::Client.instance.account_name && Supersaas::Client.instance.api_key
8
- puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g.\n\r"
9
- puts " SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/users.rb\n\r"
9
+ puts "ERROR! Missing account credentials. Rerun the script with your credentials, e.g."
10
+ puts "SSS_API_ACCOUNT_NAME=<myaccountname> SSS_API_KEY=<xxxxxxxxxxxxxxxxxxxxxx> ./examples/users.rb"
10
11
  return
11
12
  end
12
13
 
13
14
  puts "## Account: #{Supersaas::Client.instance.account_name}"
14
- puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}\n\r"
15
+ puts "## API Key: #{'*' * Supersaas::Client.instance.api_key.size}"
15
16
 
16
17
  Supersaas::Client.instance.verbose = true
17
18
 
18
- puts "creating new user..."
19
- puts "\n\r#### Supersaas::Client.instance.users.create({...})\n\r"
20
- params = {full_name: 'Example', name: 'example@example.com', email: 'example@example.com', api_key: 'example'}
19
+ puts 'creating new user...'
20
+ puts "#### Supersaas::Client.instance.users.create({...})"
21
+ params = { full_name: 'Example', name: 'example@example.com', email: 'example@example.com', api_key: 'example' }
21
22
  Supersaas::Client.instance.users.create(params)
22
23
  new_user_id = nil
23
24
 
24
- puts "\n\rlisting users..."
25
- puts "\n\r#### Supersaas::Client.instance.users.list(nil, 50)\n\r"
25
+ puts "listing users..."
26
+ puts "#### Supersaas::Client.instance.users.list(nil, 50)"
26
27
 
27
28
  users = Supersaas::Client.instance.users.list(nil, 50)
28
29
  users.each do |user|
29
- new_user_id = user.id if user.name == params[:email] || user.email == params[:email]
30
+ new_user_id = user.id if user.name == params[:email]
30
31
  end
31
32
 
32
33
  if new_user_id
33
- puts "\n\rgetting user..."
34
- puts "\n\r#### Supersaas::Client.instance.users.get(#{new_user_id})\n\r"
34
+ puts "getting user..."
35
+ puts "#### Supersaas::Client.instance.users.get(#{new_user_id})"
35
36
  user = Supersaas::Client.instance.users.get(new_user_id)
36
37
 
37
- puts "\n\rupdating user..."
38
- puts "\n\r#### Supersaas::Client.instance.users.update(#{new_user_id})\n\r"
39
- Supersaas::Client.instance.users.update(new_user_id, {country: 'FR', address: 'Rue 1'})
38
+ puts "updating user..."
39
+ puts "#### Supersaas::Client.instance.users.update(#{new_user_id})"
40
+ Supersaas::Client.instance.users.update(new_user_id, { country: 'FR', address: 'Rue 1' })
40
41
 
41
- puts "\n\rdeleting user..."
42
- puts "\n\r#### Supersaas::Client.instance.users.delete(#{user.id})\n\r"
42
+ puts "deleting user..."
43
+ puts "#### Supersaas::Client.instance.users.delete(#{user.id})"
43
44
  Supersaas::Client.instance.users.delete(user.id)
44
45
  else
45
- puts "\n\r... did not find user in list"
46
+ puts "... did not find user in list"
46
47
  end
47
48
 
48
- puts "\n\rcreating user with errors..."
49
- puts "\n\r#### Supersaas::Client.instance.users.create\n\r"
50
- Supersaas::Client.instance.users.create({name: 'error'})
51
- puts
49
+ puts "creating user with errors..."
50
+ puts "#### Supersaas::Client.instance.users.create"
51
+ begin
52
+ Supersaas::Client.instance.users.create({ name: 'error' })
53
+ rescue Supersaas::Exception => e
54
+ puts "This raises an error #{e.message}"
55
+ end
56
+
57
+ puts "#### Supersaas::Client.instance.users.field_list"
58
+ Supersaas::Client.instance.users.field_list
59
+ puts
@@ -1,17 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Supersaas
2
4
  # REF: https://www.supersaas.com/info/dev/appointment_api
3
5
  class Appointments < BaseApi
4
- def agenda(schedule_id, user_id, from_time=nil)
6
+ def agenda(schedule_id, user_id, from_time = nil, slot = false)
5
7
  path = "/agenda/#{validate_id(schedule_id)}"
6
8
  params = {
7
9
  user: validate_present(user_id),
8
10
  from: from_time && validate_datetime(from_time)
9
11
  }
12
+ params.merge!(slot: true) if slot
10
13
  res = client.get(path, params)
11
14
  map_slots_or_bookings(res)
12
15
  end
13
16
 
14
- def agenda_slots(schedule_id, user_id, from_time=nil)
17
+ def agenda_slots(schedule_id, user_id, from_time = nil)
15
18
  path = "/agenda/#{validate_id(schedule_id)}"
16
19
  params = {
17
20
  user: validate_present(user_id),
@@ -22,7 +25,7 @@ module Supersaas
22
25
  map_slots_or_bookings(res, true)
23
26
  end
24
27
 
25
- def available(schedule_id, from_time, length_minutes=nil, resource=nil, full=nil, limit=nil)
28
+ def available(schedule_id, from_time, length_minutes = nil, resource = nil, full = nil, limit = nil)
26
29
  path = "/free/#{validate_id(schedule_id)}"
27
30
  params = {
28
31
  length: length_minutes && validate_number(length_minutes),
@@ -35,27 +38,27 @@ module Supersaas
35
38
  map_slots_or_bookings(res)
36
39
  end
37
40
 
38
- def list(schedule_id, form=nil, start_time=nil, limit=nil)
39
- path = "/bookings"
41
+ def list(schedule_id, form = nil, start_time = nil, limit = nil)
42
+ path = '/bookings'
40
43
  params = {
41
- schedule_id: validate_id(schedule_id),
42
- form: form ? true : nil,
43
- start: start_time ? validate_datetime(start_time) : nil,
44
- limit: limit && validate_number(limit)
44
+ schedule_id: validate_id(schedule_id),
45
+ form: form ? true : nil,
46
+ start: start_time ? validate_datetime(start_time) : nil,
47
+ limit: limit && validate_number(limit)
45
48
  }
46
49
  res = client.get(path, params)
47
50
  map_slots_or_bookings(res)
48
51
  end
49
52
 
50
53
  def get(schedule_id, appointment_id)
51
- params = {schedule_id: validate_id(schedule_id)}
54
+ params = { schedule_id: validate_id(schedule_id) }
52
55
  path = "/bookings/#{validate_id(appointment_id)}"
53
56
  res = client.get(path, params)
54
57
  Supersaas::Appointment.new(res)
55
58
  end
56
59
 
57
- def create(schedule_id, user_id, attributes, form=nil, webhook=nil)
58
- path = "/bookings"
60
+ def create(schedule_id, user_id, attributes, form = nil, webhook = nil)
61
+ path = '/bookings'
59
62
  params = {
60
63
  schedule_id: schedule_id,
61
64
  webhook: webhook,
@@ -83,16 +86,14 @@ module Supersaas
83
86
  client.post(path, params)
84
87
  end
85
88
 
86
- def update(schedule_id, appointment_id, attributes, form=nil, webhook=nil)
89
+ def update(schedule_id, appointment_id, attributes, form = nil, webhook = nil)
87
90
  path = "/bookings/#{validate_id(appointment_id)}"
88
91
  params = {
89
92
  schedule_id: schedule_id,
90
- webhook: webhook,
91
- form: form,
92
93
  booking: {
93
94
  start: attributes[:start],
94
95
  finish: attributes[:finish],
95
- name: validate_present(attributes[:name]),
96
+ name: attributes[:name],
96
97
  email: attributes[:email],
97
98
  full_name: attributes[:full_name],
98
99
  address: attributes[:address],
@@ -108,33 +109,39 @@ module Supersaas
108
109
  slot_id: attributes[:slot_id]
109
110
  }
110
111
  }
112
+
113
+ params.merge!(form: form) if form
114
+ params.merge!(webhook: webhook) if webhook
115
+ params[:booking].compact!
111
116
  client.put(path, params)
112
117
  end
113
118
 
114
119
  def delete(schedule_id, appointment_id)
115
120
  path = "/bookings/#{validate_id(appointment_id)}"
116
- params = {schedule_id: validate_id(schedule_id)}
121
+ params = { schedule_id: validate_id(schedule_id) }
117
122
  client.delete(path, nil, params)
118
123
  end
119
124
 
120
- def changes(schedule_id, from_time=nil, to=nil, slot=false)
125
+ def changes(schedule_id, from_time = nil, to = nil, slot = false, user = nil, limit = nil, offset = nil)
121
126
  path = "/changes/#{validate_id(schedule_id)}"
122
- params = build_param({}, from_time, to, slot)
127
+ params = build_param({}, from_time, to, slot, user, limit, offset)
123
128
  res = client.get(path, params)
124
129
  map_slots_or_bookings(res)
125
130
  end
126
131
 
127
- def range(schedule_id, today=false, from_time=nil, to=nil, slot=false)
132
+ def range(schedule_id, today = false, from_time = nil, to = nil, slot = false, user = nil, resource_id = nil, service_id = nil,
133
+ limit = nil, offset = nil)
128
134
  path = "/range/#{validate_id(schedule_id)}"
129
- params = {}; params.merge!(today: true) if today
130
- params = build_param(params, from_time, to, slot)
135
+ params = {}
136
+ params.merge!(today: true) if today
137
+ params = build_param(params, from_time, to, slot, user, limit, offset, resource_id, service_id)
131
138
  res = client.get(path, params)
132
139
  map_slots_or_bookings(res)
133
140
  end
134
141
 
135
142
  private
136
143
 
137
- def map_slots_or_bookings(obj, slot=false)
144
+ def map_slots_or_bookings(obj, slot = false)
138
145
  if obj.is_a?(Array) && slot
139
146
  obj.map { |attributes| Supersaas::Slot.new(attributes) }
140
147
  elsif obj.is_a?(Array)
@@ -148,11 +155,16 @@ module Supersaas
148
155
  end
149
156
  end
150
157
 
151
- def build_param(params, from_time, to, slot)
158
+ def build_param(params, from_time, to, slot, user, limit, offset, resource_id = nil, service_id = nil)
152
159
  params.merge!(from: validate_datetime(from_time)) if from_time
153
160
  params.merge!(to: validate_datetime(to)) if to
154
161
  params.merge!(slot: true) if slot
162
+ params.merge!(user: validate_user(user)) if user
163
+ params.merge!(limit: validate_number(limit)) if limit
164
+ params.merge!(offset: validate_number(offset)) if offset
165
+ params.merge!(resource_id: validate_id(resource_id)) if resource_id
166
+ params.merge!(service_id: validate_id(service_id)) if service_id
155
167
  params
156
168
  end
157
169
  end
158
- end
170
+ end