Skip to content

Commit

Permalink
Merge pull request #18 from jobready/timeout
Browse files Browse the repository at this point in the history
Add timeout feature
  • Loading branch information
s01ipsist authored Apr 10, 2017
2 parents 9989dce + 6238ff1 commit 5983e86
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 39 deletions.
4 changes: 2 additions & 2 deletions lib/moodle_rb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require 'moodle_rb/users'

module MoodleRb
def self.new(token, url)
Client.new(token, url)
def self.new(token, url, query_options = {})
Client.new(token, url, query_options)
end
end
13 changes: 7 additions & 6 deletions lib/moodle_rb/categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ class Categories
include HTTParty
include Utility

attr_reader :token
attr_reader :token, :query_options
ROOT_CATEGORY = 0

def initialize(token, url)
def initialize(token, url, query_options)
@token = token
@query_options = query_options
self.class.base_uri url
end

Expand All @@ -16,7 +17,7 @@ def index
'/webservice/rest/server.php',
{
:query => query_hash('core_course_get_categories', token)
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response
Expand Down Expand Up @@ -47,7 +48,7 @@ def create(params)
}
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response.first
Expand All @@ -66,7 +67,7 @@ def show(id)
}
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response.first
Expand All @@ -85,7 +86,7 @@ def destroy(id)
}
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response.nil?
Expand Down
17 changes: 9 additions & 8 deletions lib/moodle_rb/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ class Client
include HTTParty
include Utility

attr_reader :token, :url
attr_reader :token, :url, :query_options

def initialize(token, url)
def initialize(token, url, query_options)
@token = token
@url = url
@query_options = query_options
self.class.base_uri url
end

Expand All @@ -16,30 +17,30 @@ def site_info
'/webservice/rest/server.php',
{
:query => query_hash('core_webservice_get_site_info', token)
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response
end

def courses
MoodleRb::Courses.new(token, url)
MoodleRb::Courses.new(token, url, query_options)
end

def categories
MoodleRb::Categories.new(token, url)
MoodleRb::Categories.new(token, url, query_options)
end

def users
MoodleRb::Users.new(token, url)
MoodleRb::Users.new(token, url, query_options)
end

def enrolments
MoodleRb::Enrolments.new(token, url)
MoodleRb::Enrolments.new(token, url, query_options)
end

def grades
MoodleRb::Grades.new(token, url)
MoodleRb::Grades.new(token, url, query_options)
end
end
end
15 changes: 8 additions & 7 deletions lib/moodle_rb/courses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ class Courses
include HTTParty
include Utility

attr_reader :token
attr_reader :token, :query_options

def initialize(token, url)
def initialize(token, url, query_options)
@token = token
@query_options = query_options
self.class.base_uri url
end

Expand All @@ -15,7 +16,7 @@ def index
'/webservice/rest/server.php',
{
:query => query_hash('core_course_get_courses', token)
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response
Expand Down Expand Up @@ -45,7 +46,7 @@ def create(params)
}
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response.first
Expand All @@ -63,7 +64,7 @@ def show(id)
}
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response.first
Expand All @@ -79,7 +80,7 @@ def destroy(id)
'0' => id
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response
Expand All @@ -93,7 +94,7 @@ def enrolled_users(course_id)
:body => {
:courseid => course_id
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response
Expand Down
7 changes: 4 additions & 3 deletions lib/moodle_rb/enrolments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ class Enrolments
include HTTParty
include Utility

attr_reader :token
attr_reader :token, :query_options
STUDENT_ROLE_ID = 5

def initialize(token, url)
def initialize(token, url, query_options)
@token = token
@query_options = query_options
self.class.base_uri url
end

Expand All @@ -27,7 +28,7 @@ def create(params)
}
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.code == 200 && response.parsed_response.nil?
Expand Down
9 changes: 5 additions & 4 deletions lib/moodle_rb/grades.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ class Grades
include HTTParty
include Utility

attr_reader :token
attr_reader :token, :query_options

def initialize(token, url)
def initialize(token, url, query_options)
@token = token
@query_options = query_options
self.class.base_uri url
end

Expand All @@ -18,7 +19,7 @@ def by_assignment(assignment_id)
:body => {
:assignmentids => api_array(assignment_id)
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response['assignments']
Expand All @@ -33,7 +34,7 @@ def by_course(course_id, *user_ids)
:courseid => course_id,
:userids => api_array(user_ids)
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response['items']
Expand Down
17 changes: 9 additions & 8 deletions lib/moodle_rb/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ class Users
include HTTParty
include Utility

attr_reader :token
attr_reader :token, :query_options

def initialize(token, url)
def initialize(token, url, query_options)
@token = token
@query_options = query_options
self.class.base_uri url
end

Expand All @@ -25,7 +26,7 @@ def create(params)
'0' => params
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response.first
Expand All @@ -44,7 +45,7 @@ def show(id)
}
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response['users'] &&
Expand All @@ -61,7 +62,7 @@ def destroy(id)
'0' => id
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response.nil?
Expand All @@ -75,7 +76,7 @@ def enrolled_courses(user_id)
:body => {
:userid => user_id
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response
Expand All @@ -91,7 +92,7 @@ def search(params = {})
:body => {
:criteria => key_value_query_format(params)
}
}
}.merge(query_options)
)
check_for_errors(response)
response.parsed_response['users']
Expand All @@ -110,7 +111,7 @@ def update(params)
'0' => params
}
}
}
}.merge(query_options)
)
check_for_errors(response)
response.response.code == '200'
Expand Down
2 changes: 1 addition & 1 deletion lib/moodle_rb/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module MoodleRb
VERSION = '1.0.3' unless defined?(self::VERSION)
VERSION = '1.0.4' unless defined?(self::VERSION)

def self.version
VERSION
Expand Down

0 comments on commit 5983e86

Please sign in to comment.