ps_utilities 0.2.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 637da17d1d419b00baea629e618529517c09fa7e16f71dd358a850b0978fc599
4
- data.tar.gz: a1ec6ced4f33ac5ff849dd48c0f216133e7fe291b1224c8dc082d42c16a66876
3
+ metadata.gz: d12612f8c4d8b6ce0ee6a52c4d30748c5ca12b1f8414478d0f2164f8aa79295e
4
+ data.tar.gz: 5e0cbd4742dd42f98679cdea0356f1714e0ae23b878adba319cc1e33c7c901f4
5
5
  SHA512:
6
- metadata.gz: 062a02dd9e855ad0533da5eb6c735021a0607ea6a4db59d33f063b223d0c3918e99071760bb456b9316f81b58e5daf1e06b977c92fbe02b0aa035a81d2841244
7
- data.tar.gz: cca916c4339884397ebf5cc40fd6dcd1f8f0ff6d6a17b3cafdf61f30fccf0584ecab4f6bec7b58c7dc3d476b6168810155780dd3a61832861f9958519f2b3690
6
+ metadata.gz: eb7bca650ace01f55b015bd52db6385c0b5d9fc1bdd99eac873bc6f9f4aebde2b05d51eb65226f9eab43f379d280daf8e423d03d461660810d7ecead03ed1322
7
+ data.tar.gz: 44d0548cea631ab20b45d21667c96611321eac42f7f5ef11c21239abde10984ec1f25d013ada635a2c66fede989c11e20927b0be3ed3516dc59bc8a2344ae8e7
@@ -51,8 +51,18 @@ module PsUtilities
51
51
  case command
52
52
  when nil, :authenticate
53
53
  # authenticate unless token_valid?
54
+ # when :get
55
+ # api(:get, api_path, options) unless api_path.empty?
56
+ # when :put
57
+ # send(:api, :put, api_path, options) unless api_path.empty?
58
+ # when :post
59
+ # api(, api_path, options) unless api_path.empty?
54
60
  when :get, :put, :post
55
- send(command, api_path, options) unless api_path.empty?
61
+ api(command, api_path, options) unless api_path.empty?
62
+ # when :get, :put, :post
63
+ # send(command, api_path, options) unless api_path.empty?
64
+ # when :get, :put, :post
65
+ # send(:api, command, api_path, options) unless api_path.empty?
56
66
  else
57
67
  send(command, params)
58
68
  end
@@ -60,6 +70,24 @@ module PsUtilities
60
70
 
61
71
  private
62
72
 
73
+ # options = {query: {}}
74
+ def api(verb, api_path, options={})
75
+ count = 0
76
+ retries = 3
77
+ ps_url = base_uri + api_path
78
+ options = options.merge(headers)
79
+ begin
80
+ HTTParty.send(verb, ps_url, options)
81
+ rescue Net::ReadTimeout, Net::OpenTimeout
82
+ if count < retries
83
+ count += 1
84
+ retry
85
+ else
86
+ { error: "no response (timeout) from URL: #{url}" }
87
+ end
88
+ end
89
+ end
90
+
63
91
  # options = {query: {}}
64
92
  def get(api_path, options={})
65
93
  count = 0
@@ -3,32 +3,29 @@ module PsUtilities
3
3
  module PreBuiltGet
4
4
 
5
5
  def get_active_students_count(params={})
6
- # url = "/ws/v1/district/student/count?q=school_enrollment.enroll_status_code==0"
7
- url = "/ws/v1/district/student/count"
8
- options = { query: {"q" => "school_enrollment.enroll_status_code==0"} }
9
- get(url, options)
6
+ # api_path = "/ws/v1/district/student/count?q=school_enrollment.enroll_status_code==0"
7
+ api_path = "/ws/v1/district/student/count"
8
+ options = { query: {"q" => "school_enrollment.enroll_status_code==0"} }
9
+ get(api_path, options)
10
10
  end
11
11
 
12
12
  def get_active_students_info(params={})
13
- # url = "/ws/v1/district/student?q=school_enrollment.enroll_status==a&pagesize=500"
14
- url = "/ws/v1/district/student"
13
+ # api_path = "/ws/v1/district/student?q=school_enrollment.enroll_status==a&pagesize=500"
14
+ api_path = "/ws/v1/district/student"
15
15
  options = { query:
16
16
  {"q" => "school_enrollment.enroll_status_code==0",
17
- "pagesize" => "500"}
18
- }
19
- get(url, options)
17
+ "pagesize" => "500"} }
18
+ get(api_path, options)
20
19
  end
21
20
 
22
- # las-test.powerschool.com/ws/v1/district/student?expansions=school_enrollment&q=student_username==xxxxx237
23
21
  # params = {username: "xxxxxxx"}
24
22
  def get_one_student_record(params)
25
- # url = "/ws/v1/district/student?expansions=school_enrollment,contact&q=student_username==xxxxxx237"
26
- url = "/ws/v1/district/student"
27
- options = { query:
28
- {"q" => "student_username==#{params[:username]}",
29
- "expansions" => "school_enrollment,contact,contact_info"}
30
- }
31
- get(url, options)
23
+ # api_path = "/ws/v1/district/student?expansions=school_enrollment,contact&q=student_username==xxxxxx237"
24
+ api_path = "/ws/v1/district/student"
25
+ options = { query:
26
+ { "q" => "student_username==#{params[:username]}",
27
+ "expansions" => "school_enrollment,contact,contact_info"} }
28
+ get(api_path, options)
32
29
  end
33
30
 
34
31
  end
@@ -1,5 +1,5 @@
1
1
  module PsUtilities
2
2
  module Version
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ps_utilities
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Weisbecker