Skip to content

Commit 5983e86

Browse files
authored
Merge pull request #18 from jobready/timeout
Add timeout feature
2 parents 9989dce + 6238ff1 commit 5983e86

File tree

8 files changed

+45
-39
lines changed

8 files changed

+45
-39
lines changed

lib/moodle_rb.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
require 'moodle_rb/users'
1111

1212
module MoodleRb
13-
def self.new(token, url)
14-
Client.new(token, url)
13+
def self.new(token, url, query_options = {})
14+
Client.new(token, url, query_options)
1515
end
1616
end

lib/moodle_rb/categories.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ class Categories
33
include HTTParty
44
include Utility
55

6-
attr_reader :token
6+
attr_reader :token, :query_options
77
ROOT_CATEGORY = 0
88

9-
def initialize(token, url)
9+
def initialize(token, url, query_options)
1010
@token = token
11+
@query_options = query_options
1112
self.class.base_uri url
1213
end
1314

@@ -16,7 +17,7 @@ def index
1617
'/webservice/rest/server.php',
1718
{
1819
:query => query_hash('core_course_get_categories', token)
19-
}
20+
}.merge(query_options)
2021
)
2122
check_for_errors(response)
2223
response.parsed_response
@@ -47,7 +48,7 @@ def create(params)
4748
}
4849
}
4950
}
50-
}
51+
}.merge(query_options)
5152
)
5253
check_for_errors(response)
5354
response.parsed_response.first
@@ -66,7 +67,7 @@ def show(id)
6667
}
6768
}
6869
}
69-
}
70+
}.merge(query_options)
7071
)
7172
check_for_errors(response)
7273
response.parsed_response.first
@@ -85,7 +86,7 @@ def destroy(id)
8586
}
8687
}
8788
}
88-
}
89+
}.merge(query_options)
8990
)
9091
check_for_errors(response)
9192
response.parsed_response.nil?

lib/moodle_rb/client.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ class Client
33
include HTTParty
44
include Utility
55

6-
attr_reader :token, :url
6+
attr_reader :token, :url, :query_options
77

8-
def initialize(token, url)
8+
def initialize(token, url, query_options)
99
@token = token
1010
@url = url
11+
@query_options = query_options
1112
self.class.base_uri url
1213
end
1314

@@ -16,30 +17,30 @@ def site_info
1617
'/webservice/rest/server.php',
1718
{
1819
:query => query_hash('core_webservice_get_site_info', token)
19-
}
20+
}.merge(query_options)
2021
)
2122
check_for_errors(response)
2223
response.parsed_response
2324
end
2425

2526
def courses
26-
MoodleRb::Courses.new(token, url)
27+
MoodleRb::Courses.new(token, url, query_options)
2728
end
2829

2930
def categories
30-
MoodleRb::Categories.new(token, url)
31+
MoodleRb::Categories.new(token, url, query_options)
3132
end
3233

3334
def users
34-
MoodleRb::Users.new(token, url)
35+
MoodleRb::Users.new(token, url, query_options)
3536
end
3637

3738
def enrolments
38-
MoodleRb::Enrolments.new(token, url)
39+
MoodleRb::Enrolments.new(token, url, query_options)
3940
end
4041

4142
def grades
42-
MoodleRb::Grades.new(token, url)
43+
MoodleRb::Grades.new(token, url, query_options)
4344
end
4445
end
4546
end

lib/moodle_rb/courses.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ class Courses
33
include HTTParty
44
include Utility
55

6-
attr_reader :token
6+
attr_reader :token, :query_options
77

8-
def initialize(token, url)
8+
def initialize(token, url, query_options)
99
@token = token
10+
@query_options = query_options
1011
self.class.base_uri url
1112
end
1213

@@ -15,7 +16,7 @@ def index
1516
'/webservice/rest/server.php',
1617
{
1718
:query => query_hash('core_course_get_courses', token)
18-
}
19+
}.merge(query_options)
1920
)
2021
check_for_errors(response)
2122
response.parsed_response
@@ -45,7 +46,7 @@ def create(params)
4546
}
4647
}
4748
}
48-
}
49+
}.merge(query_options)
4950
)
5051
check_for_errors(response)
5152
response.parsed_response.first
@@ -63,7 +64,7 @@ def show(id)
6364
}
6465
}
6566
}
66-
}
67+
}.merge(query_options)
6768
)
6869
check_for_errors(response)
6970
response.parsed_response.first
@@ -79,7 +80,7 @@ def destroy(id)
7980
'0' => id
8081
}
8182
}
82-
}
83+
}.merge(query_options)
8384
)
8485
check_for_errors(response)
8586
response.parsed_response
@@ -93,7 +94,7 @@ def enrolled_users(course_id)
9394
:body => {
9495
:courseid => course_id
9596
}
96-
}
97+
}.merge(query_options)
9798
)
9899
check_for_errors(response)
99100
response.parsed_response

lib/moodle_rb/enrolments.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ class Enrolments
33
include HTTParty
44
include Utility
55

6-
attr_reader :token
6+
attr_reader :token, :query_options
77
STUDENT_ROLE_ID = 5
88

9-
def initialize(token, url)
9+
def initialize(token, url, query_options)
1010
@token = token
11+
@query_options = query_options
1112
self.class.base_uri url
1213
end
1314

@@ -27,7 +28,7 @@ def create(params)
2728
}
2829
}
2930
}
30-
}
31+
}.merge(query_options)
3132
)
3233
check_for_errors(response)
3334
response.code == 200 && response.parsed_response.nil?

lib/moodle_rb/grades.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ class Grades
33
include HTTParty
44
include Utility
55

6-
attr_reader :token
6+
attr_reader :token, :query_options
77

8-
def initialize(token, url)
8+
def initialize(token, url, query_options)
99
@token = token
10+
@query_options = query_options
1011
self.class.base_uri url
1112
end
1213

@@ -18,7 +19,7 @@ def by_assignment(assignment_id)
1819
:body => {
1920
:assignmentids => api_array(assignment_id)
2021
}
21-
}
22+
}.merge(query_options)
2223
)
2324
check_for_errors(response)
2425
response.parsed_response['assignments']
@@ -33,7 +34,7 @@ def by_course(course_id, *user_ids)
3334
:courseid => course_id,
3435
:userids => api_array(user_ids)
3536
}
36-
}
37+
}.merge(query_options)
3738
)
3839
check_for_errors(response)
3940
response.parsed_response['items']

lib/moodle_rb/users.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ class Users
33
include HTTParty
44
include Utility
55

6-
attr_reader :token
6+
attr_reader :token, :query_options
77

8-
def initialize(token, url)
8+
def initialize(token, url, query_options)
99
@token = token
10+
@query_options = query_options
1011
self.class.base_uri url
1112
end
1213

@@ -25,7 +26,7 @@ def create(params)
2526
'0' => params
2627
}
2728
}
28-
}
29+
}.merge(query_options)
2930
)
3031
check_for_errors(response)
3132
response.parsed_response.first
@@ -44,7 +45,7 @@ def show(id)
4445
}
4546
}
4647
}
47-
}
48+
}.merge(query_options)
4849
)
4950
check_for_errors(response)
5051
response.parsed_response['users'] &&
@@ -61,7 +62,7 @@ def destroy(id)
6162
'0' => id
6263
}
6364
}
64-
}
65+
}.merge(query_options)
6566
)
6667
check_for_errors(response)
6768
response.parsed_response.nil?
@@ -75,7 +76,7 @@ def enrolled_courses(user_id)
7576
:body => {
7677
:userid => user_id
7778
}
78-
}
79+
}.merge(query_options)
7980
)
8081
check_for_errors(response)
8182
response.parsed_response
@@ -91,7 +92,7 @@ def search(params = {})
9192
:body => {
9293
:criteria => key_value_query_format(params)
9394
}
94-
}
95+
}.merge(query_options)
9596
)
9697
check_for_errors(response)
9798
response.parsed_response['users']
@@ -110,7 +111,7 @@ def update(params)
110111
'0' => params
111112
}
112113
}
113-
}
114+
}.merge(query_options)
114115
)
115116
check_for_errors(response)
116117
response.response.code == '200'

lib/moodle_rb/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module MoodleRb
2-
VERSION = '1.0.3' unless defined?(self::VERSION)
2+
VERSION = '1.0.4' unless defined?(self::VERSION)
33

44
def self.version
55
VERSION

0 commit comments

Comments
 (0)