provet-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/brakeman.yml +29 -0
  3. data/.github/workflows/rspec.yml +29 -0
  4. data/.github/workflows/rubocop.yml +36 -0
  5. data/.rspec +3 -0
  6. data/.rubocop.yml +34 -0
  7. data/CHANGELOG.md +53 -0
  8. data/CODE_OF_CONDUCT.md +84 -0
  9. data/Gemfile +15 -0
  10. data/Gemfile.lock +88 -0
  11. data/LICENSE.txt +21 -0
  12. data/README.md +184 -0
  13. data/Rakefile +8 -0
  14. data/bin/console +15 -0
  15. data/bin/setup +8 -0
  16. data/lib/provet.rb +83 -0
  17. data/lib/provet/appointment.rb +23 -0
  18. data/lib/provet/availability.rb +13 -0
  19. data/lib/provet/base.rb +135 -0
  20. data/lib/provet/client.rb +15 -0
  21. data/lib/provet/consultation.rb +23 -0
  22. data/lib/provet/consultation_discharge_instruction.rb +19 -0
  23. data/lib/provet/consultation_item.rb +23 -0
  24. data/lib/provet/consultation_item_template.rb +23 -0
  25. data/lib/provet/department.rb +23 -0
  26. data/lib/provet/invoice.rb +19 -0
  27. data/lib/provet/invoice_row.rb +23 -0
  28. data/lib/provet/item.rb +19 -0
  29. data/lib/provet/item_list.rb +23 -0
  30. data/lib/provet/item_template.rb +11 -0
  31. data/lib/provet/item_template_item.rb +15 -0
  32. data/lib/provet/laboratory_analysis_group.rb +11 -0
  33. data/lib/provet/patient.rb +15 -0
  34. data/lib/provet/phone_number.rb +11 -0
  35. data/lib/provet/reason.rb +15 -0
  36. data/lib/provet/reason_group.rb +11 -0
  37. data/lib/provet/reminder.rb +11 -0
  38. data/lib/provet/reminder_template.rb +11 -0
  39. data/lib/provet/shift.rb +11 -0
  40. data/lib/provet/shift_type.rb +23 -0
  41. data/lib/provet/user.rb +27 -0
  42. data/lib/provet/user_details.rb +11 -0
  43. data/lib/provet/user_group.rb +23 -0
  44. data/lib/provet/vat_group.rb +23 -0
  45. data/lib/provet/version.rb +5 -0
  46. data/provet-client.gemspec +27 -0
  47. metadata +105 -0
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rubocop/rake_task'
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'provet'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/provet.rb ADDED
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'provet/base'
4
+ require 'provet/appointment'
5
+ require 'provet/availability'
6
+ require 'provet/client'
7
+ require 'provet/consultation_discharge_instruction'
8
+ require 'provet/consultation_item_template'
9
+ require 'provet/consultation_item'
10
+ require 'provet/consultation'
11
+ require 'provet/department'
12
+ require 'provet/invoice_row'
13
+ require 'provet/invoice'
14
+ require 'provet/item_list'
15
+ require 'provet/item_template_item'
16
+ require 'provet/item_template'
17
+ require 'provet/item'
18
+ require 'provet/laboratory_analysis_group'
19
+ require 'provet/patient'
20
+ require 'provet/phone_number'
21
+ require 'provet/reason_group'
22
+ require 'provet/reason'
23
+ require 'provet/reminder_template'
24
+ require 'provet/reminder'
25
+ require 'provet/shift_type'
26
+ require 'provet/shift'
27
+ require 'provet/user_details'
28
+ require 'provet/user_group'
29
+ require 'provet/user'
30
+ require 'provet/vat_group'
31
+
32
+ module Provet
33
+ class Error < StandardError; end
34
+ class MethodNotAllowedError < Error; end
35
+
36
+ @@host = 'https://us.provetcloud.com'
37
+ @@instance = nil
38
+ @@api_version = '0.1'
39
+ @@token = nil
40
+
41
+ def self.host
42
+ @@host
43
+ end
44
+
45
+ def self.host=(value)
46
+ @@host = value
47
+ set_base_uri
48
+ end
49
+
50
+ def self.instance
51
+ @@instance
52
+ end
53
+
54
+ def self.instance=(value)
55
+ @@instance = value
56
+ set_base_uri
57
+ end
58
+
59
+ def self.api_version
60
+ @@api_version
61
+ end
62
+
63
+ def self.api_version=(value)
64
+ @@api_version = value
65
+ set_base_uri
66
+ end
67
+
68
+ def self.token
69
+ @@token
70
+ end
71
+
72
+ def self.token=(value)
73
+ @@token = value
74
+ end
75
+
76
+ def self.set_base_uri
77
+ Provet::Base.base_uri("#{host}/#{instance}/api/#{api_version}")
78
+ end
79
+
80
+ def self.root
81
+ File.dirname __dir__
82
+ end
83
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Provet
4
+ class Appointment < Provet::Base
5
+ private
6
+
7
+ def endpoint_name
8
+ 'appointment'
9
+ end
10
+
11
+ def soft_deletable?
12
+ true
13
+ end
14
+
15
+ def archive_payload
16
+ { active: 0 }.to_json
17
+ end
18
+
19
+ def restore_payload
20
+ { active: 1 }.to_json
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Provet
4
+ class Availability < Provet::Base
5
+ private
6
+
7
+ def endpoint_name
8
+ # should be 'availability', not 'availibility'
9
+ # but that's how the endpoint is implemented
10
+ 'veterinarians_availibility'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+
5
+ module Provet
6
+ class Base
7
+ include HTTParty
8
+
9
+ def list(query = {})
10
+ get(collection_path, query: query)
11
+ end
12
+
13
+ def all(query = {})
14
+ data = list(page: 1, **query)
15
+
16
+ return [] unless data['results'].is_a?(Array) && data['results'].any? && data['num_pages'].is_a?(Integer)
17
+
18
+ num_pages = data['num_pages']
19
+ return data['results'] if num_pages <= 1
20
+
21
+ results = data['results']
22
+ (2..num_pages).each do |page_index|
23
+ data = list(page: page_index, **query)
24
+ results += data['results']
25
+ end
26
+ results
27
+ end
28
+
29
+ def find(id)
30
+ get(resource_path(id))
31
+ end
32
+
33
+ def create(body)
34
+ post(collection_path, body)
35
+ end
36
+
37
+ def update(id, body, verb: :put)
38
+ send(verb, resource_path(id), body)
39
+ end
40
+
41
+ def destroy(id, hard: !soft_deletable?)
42
+ if hard
43
+ delete(resource_path(id))
44
+ else
45
+ patch(resource_path(id), archive_payload)
46
+ end
47
+ end
48
+
49
+ def really_destroy!(id)
50
+ raise MethodNotAllowedError unless soft_deletable?
51
+
52
+ destroy(id, hard: true)
53
+ end
54
+
55
+ def restore(id)
56
+ raise MethodNotAllowedError unless soft_deletable?
57
+
58
+ patch(resource_path(id), restore_payload)
59
+ end
60
+
61
+ def collection_url
62
+ File.join(self.class.base_uri, collection_path)
63
+ end
64
+
65
+ def collection_path
66
+ File.join('/', endpoint_name, '/')
67
+ end
68
+
69
+ def resource_url(id)
70
+ File.join(self.class.base_uri, resource_path(id))
71
+ end
72
+
73
+ def resource_path(id)
74
+ File.join(collection_path, id.to_s, '/')
75
+ end
76
+
77
+ protected
78
+
79
+ def soft_deletable?
80
+ false
81
+ end
82
+
83
+ def archive_payload
84
+ { archived: 1 }.to_json
85
+ end
86
+
87
+ def restore_payload
88
+ { archived: 0 }.to_json
89
+ end
90
+
91
+ def get(path, query: {})
92
+ options = default_options
93
+ options[:query] ||= default_query
94
+ options[:query].merge!(query) if query.any?
95
+
96
+ self.class.get(path, options)
97
+ end
98
+
99
+ def post(path, body)
100
+ self.class.post(path, default_options.merge(body: body))
101
+ end
102
+
103
+ def put(path, body)
104
+ self.class.put(path, default_options.merge(body: body))
105
+ end
106
+
107
+ def patch(path, body)
108
+ self.class.patch(path, default_options.merge(body: body))
109
+ end
110
+
111
+ def delete(path)
112
+ self.class.delete(path, default_options)
113
+ end
114
+
115
+ def default_options
116
+ { headers: headers }
117
+ end
118
+
119
+ def default_query
120
+ {}
121
+ end
122
+
123
+ def headers
124
+ {
125
+ 'Content-Type' => 'application/json',
126
+ 'Accept' => 'application/json',
127
+ 'Authorization' => "Token #{Provet.token}"
128
+ }
129
+ end
130
+
131
+ def endpoint_name
132
+ raise 'Must be overriden by subclass'
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Provet
4
+ class Client < Provet::Base
5
+ private
6
+
7
+ def soft_deletable?
8
+ true
9
+ end
10
+
11
+ def endpoint_name
12
+ 'client'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Provet
4
+ class Consultation < Provet::Base
5
+ def create(_body)
6
+ raise MethodNotAllowedError
7
+ end
8
+
9
+ def update(*_args)
10
+ raise MethodNotAllowedError
11
+ end
12
+
13
+ def destroy(_id)
14
+ raise MethodNotAllowedError
15
+ end
16
+
17
+ private
18
+
19
+ def endpoint_name
20
+ 'consultation'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Provet
4
+ class ConsultationDischargeInstruction < Provet::Base
5
+ def initialize(consultation_id:)
6
+ @consultation_id = consultation_id
7
+ end
8
+
9
+ def destroy(*_args)
10
+ raise MethodNotAllowedError
11
+ end
12
+
13
+ private
14
+
15
+ def endpoint_name
16
+ "consultation/#{@consultation_id}/consultationdischargeinstruction"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Provet
4
+ class ConsultationItem < Provet::Base
5
+ def create(_body)
6
+ raise MethodNotAllowedError
7
+ end
8
+
9
+ def update(*_args)
10
+ raise MethodNotAllowedError
11
+ end
12
+
13
+ def destroy(_id)
14
+ raise MethodNotAllowedError
15
+ end
16
+
17
+ private
18
+
19
+ def endpoint_name
20
+ 'consultationitem'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Provet
4
+ class ConsultationItemTemplate < Provet::Base
5
+ def create(_body)
6
+ raise MethodNotAllowedError
7
+ end
8
+
9
+ def update(*_args)
10
+ raise MethodNotAllowedError
11
+ end
12
+
13
+ def destroy(_id)
14
+ raise MethodNotAllowedError
15
+ end
16
+
17
+ private
18
+
19
+ def endpoint_name
20
+ 'consultationitemtemplate'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Provet
4
+ class Department < Provet::Base
5
+ def create(_body)
6
+ raise MethodNotAllowedError
7
+ end
8
+
9
+ def update(*_args)
10
+ raise MethodNotAllowedError
11
+ end
12
+
13
+ def destroy(_id)
14
+ raise MethodNotAllowedError
15
+ end
16
+
17
+ private
18
+
19
+ def endpoint_name
20
+ 'department'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Provet
4
+ class Invoice < Provet::Base
5
+ def create(_body)
6
+ raise MethodNotAllowedError
7
+ end
8
+
9
+ def destroy(_id)
10
+ raise MethodNotAllowedError
11
+ end
12
+
13
+ private
14
+
15
+ def endpoint_name
16
+ 'invoice'
17
+ end
18
+ end
19
+ end