moodle 0.0.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ac635580be17fb36b6b0b1f12bffbf9592ff773
4
- data.tar.gz: ab7c1465b102719613c1499ad3a84341fea0b703
3
+ metadata.gz: 21dada7b7c2d9a6a9f1918835cba252ad73917b4
4
+ data.tar.gz: e29af8894d6d2f53d398a26b03cbf8e6c2c147a7
5
5
  SHA512:
6
- metadata.gz: 159208b1c4ca10250fd7265ff86bf43e46d177a9dd30941425aa71d99d39af3198e24f2edc474b2bbd17fb48a3869188487dce5bb2330ace753236c24c525717
7
- data.tar.gz: 812371e44861ed813083ee50062d85fc52708567a0e6afecf8c69dcb7aa6dc8a58bb05467bbe1865364b02d23b1100aa6ce5e4ce7c4bb83e2cb613a5af9311f2
6
+ metadata.gz: ffa4d6d3fa5f14360e36ca981db5eec18a469db2a7b101d54c3db6ddd365ee563154ebce9d53d6dc8a93920672c888251dc0e3bb79c79a07a59272f6e303b2a4
7
+ data.tar.gz: 42deb18c2d0de7258ab738ba89c3d3320ee31ee8d5178e6cc29d5f6c511255eff169238edbcbf2d13183cb3978e9a72ee20e4b85a4123fdbcbacec7a7102f2fc
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ gem 'mocha', :require => false, :group => :test
5
5
  gem 'rest-client'
6
6
  gem 'sanitize'
7
7
  gem 'hashie'
8
+ gem 'rake'
8
9
  gem 'json'
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Moodle
2
- Ruby gem to interact with the Moodle via web services.
2
+ [![Build Status](https://travis-ci.org/robertboloc/moodle.png)](https://travis-ci.org/robertboloc/moodle)
3
+ [![Code Climate](https://codeclimate.com/github/robertboloc/moodle.png)](https://codeclimate.com/github/robertboloc/moodle)
4
+ [![Gem Version](https://badge.fury.io/rb/moodle.png)](http://badge.fury.io/rb/moodle)
5
+
6
+ Ruby gem to interact with Moodle via web services.
3
7
 
4
8
  ## Table of contents
5
9
  - [Installation](#installation)
@@ -79,7 +83,9 @@ Moodle implements 4 protocols: AMF, REST, SOAP, XML-RPC. Currently this gem only
79
83
  ## Functions
80
84
  These are the currently implemented web services functions:
81
85
 
82
- ### core_user_get_users_by_field
86
+ ### Users
87
+
88
+ #### core_user_get_users_by_field
83
89
  Retrieve users information for a specified unique field
84
90
  ```ruby
85
91
  user = client.core_user_get_users_by_field('id', [2])
@@ -93,4 +99,90 @@ user.firstaccess # => 139240932,
93
99
  user.lastaccess # => 1392471263
94
100
  user.profileimageurlsmall # => http://mydomain/moodle/pluginfile.php/5/user/icon/f2
95
101
  user.profileimageurl # => http://mydomain/moodle/pluginfile.php/5/user/icon/f1
102
+ ```
103
+
104
+ #### core_user_get_users
105
+ Search for users matching the criteria
106
+ ```ruby
107
+ users = client.core_user_get_users({:email => 'suchemail@test.com'})
108
+
109
+ users.each do |user|
110
+ user.id # => 2,
111
+ user.firstname # => Test
112
+ user.lastname # => User
113
+ user.fullname # => Test User
114
+ user.email # => suchemail@test.com
115
+ user.firstaccess # => 139240932,
116
+ user.lastaccess # => 1392471263
117
+ user.profileimageurlsmall # => http://mydomain/moodle/pluginfile.php/5/user/icon/f2
118
+ user.profileimageurl # => http://mydomain/moodle/pluginfile.php/5/user/icon/f1
119
+ end
120
+ ```
121
+
122
+ ### Courses
123
+
124
+ #### core_course_get_courses
125
+ Retrieve courses details by ids
126
+ ```ruby
127
+ courses = client.core_course_get_courses([2, 3])
128
+
129
+ courses.each do |course|
130
+ course.id # => 2
131
+ course.shortname # => T
132
+ course.categoryid # => 1
133
+ course.categorysortorder # => 10002
134
+ course.fullname # => Test
135
+ course.idnumber # => TX
136
+ course.summary # => test
137
+ course.summaryformat # => 1
138
+ course.format # => weeks
139
+ course.showgrades # => 1
140
+ course.newsitems # => 5
141
+ course.startdate # => 1393718400
142
+ course.numsections # => 10
143
+ course.maxbytes # => 0
144
+ course.showreports # => 0
145
+ course.visible # => 1
146
+ course.hiddensections # => 0
147
+ course.groupmode # => 0
148
+ course.groupmodeforce # => 0
149
+ course.defaultgroupingid # => 0
150
+ course.timecreated # => 1393693092
151
+ course.timemodified # => 1393693092
152
+ course.enablecompletion # => 0
153
+ course.completionnotify # => 0
154
+ course.lang # => en
155
+ course.forcetheme # => test
156
+ course.courseformatoptions.each do |format|
157
+ format.name # => numsections
158
+ value # => 10
159
+ end
160
+ end
161
+ ```
162
+
163
+ ### Webservices
164
+
165
+ #### core_webservice_get_site_info
166
+ Return some site info / user info / list web service functions
167
+ ```ruby
168
+ info = client.core_webservice_get_site_info
169
+
170
+ info.sitename # => Webservice test
171
+ info.username # => test
172
+ info.firstname # => Test
173
+ info.lastname # => Webservice
174
+ info.fullname # => Test Webservice
175
+ info.lang # => en
176
+ info.userid # => 3
177
+ info.siteurl # => http://mydomain/moodle
178
+ info.userpictureurl # => http://mydomain/moodle/pluginfile.php/15/user/icon/f1
179
+ info.functions.each do |f|
180
+ f.name # => core_user_get_users_by_field
181
+ f.version # => 2013111800.09
182
+ end
183
+ info.downloadfiles # => 0
184
+ info.uploadfiles # => 0
185
+ info.release # => 2.6+ (Build: 20140110)
186
+ info.version # => 2013111800.09
187
+ info.mobilecssurl # => ""
96
188
  ```
@@ -1,11 +1,15 @@
1
1
  require 'moodle/protocols/rest'
2
2
  require 'moodle/services/user'
3
+ require 'moodle/services/course'
4
+ require 'moodle/services/webservice'
3
5
  require 'hashie'
4
6
  require 'json'
5
7
 
6
8
  module Moodle
7
9
  class Client
8
10
  include Moodle::Service::User
11
+ include Moodle::Service::Course
12
+ include Moodle::Service::Webservice
9
13
 
10
14
  attr_reader :username, :password, :domain, :protocol, :service, :format, :token
11
15
 
@@ -45,8 +49,9 @@ module Moodle
45
49
  :password => @password,
46
50
  :service => @service
47
51
  })
48
- # @TODO: deal with error response
49
- response.token
52
+
53
+ parsed = JSON.parse(response)
54
+ parsed['token']
50
55
  end
51
56
 
52
57
  # Make a request using the desired protocol and format
@@ -57,9 +62,8 @@ module Moodle
57
62
  :wsfunction => caller[0][/`.*'/][1..-2]
58
63
  )
59
64
  response = client.request(@domain + '/webservice/' + @protocol + '/server.php', params)
60
- array_response = JSON.parse response
61
- hash_response = Hash[*array_response]
62
- Hashie::Mash.new hash_response
65
+
66
+ JSON.parse(response)
63
67
  end
64
68
  end
65
69
  end
@@ -0,0 +1,11 @@
1
+ require 'hashie'
2
+ require 'json'
3
+
4
+ module Moodle
5
+ class Helper
6
+
7
+ def to_object(json)
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ module Moodle
2
+ module Service
3
+ module Course
4
+ # Return course details
5
+ def core_course_get_courses(options)
6
+ params = {}
7
+
8
+ counter = 0
9
+ options.each do |id|
10
+ params['options[ids][' + counter.to_s + ']'] = id
11
+ counter = counter + 1
12
+ end
13
+
14
+ response = request(params)
15
+
16
+ if response.any?
17
+ courses = response.map { |course| Hashie::Mash.new(course) }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -14,7 +14,26 @@ module Moodle
14
14
  counter = counter + 1
15
15
  end
16
16
 
17
- request(params)
17
+ response = request(params)
18
+ Hashie::Mash.new *response
19
+ end
20
+
21
+ # Search for users matching the criteria
22
+ def core_user_get_users(criteria)
23
+ params = {}
24
+
25
+ counter = 0
26
+ criteria.each do |key,value|
27
+ params['criteria[' + counter.to_s + '][key]'] = key.to_s
28
+ params['criteria[' + counter.to_s + '][value]'] = value
29
+ counter = counter + 1
30
+ end
31
+
32
+ response = request(params)
33
+
34
+ if response['users']
35
+ users = response['users'].map { |user| Hashie::Mash.new(user) }
36
+ end
18
37
  end
19
38
  end
20
39
  end
@@ -0,0 +1,10 @@
1
+ module Moodle
2
+ module Service
3
+ module Webservice
4
+ # Return some site info / user info / list web service functions
5
+ def core_webservice_get_site_info
6
+ Hashie::Mash.new request
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'moodle'
3
- spec.version = '0.0.1'
4
- spec.date = '2014-02-14'
3
+ spec.version = '0.1.0'
4
+ spec.date = '2014-03-01'
5
5
  spec.summary = "Moodle web services from ruby"
6
6
  spec.description = "Interact with Moodle from ruby"
7
7
  spec.authors = ["Robert Boloc"]
@@ -10,4 +10,4 @@ Gem::Specification.new do |spec|
10
10
  spec.homepage =
11
11
  'http://robertboloc.github.com/moodle'
12
12
  spec.license = 'MIT'
13
- end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moodle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Boloc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-14 00:00:00.000000000 Z
11
+ date: 2014-03-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Interact with Moodle from ruby
14
14
  email: robertboloc@gmail.com
@@ -17,14 +17,18 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - .gitignore
20
+ - .travis.yml
20
21
  - Gemfile
21
22
  - LICENSE.md
22
23
  - README.md
23
24
  - Rakefile
24
25
  - lib/moodle.rb
25
26
  - lib/moodle/client.rb
27
+ - lib/moodle/helper.rb
26
28
  - lib/moodle/protocols/rest.rb
29
+ - lib/moodle/services/course.rb
27
30
  - lib/moodle/services/user.rb
31
+ - lib/moodle/services/webservice.rb
28
32
  - moodle.gemspec
29
33
  - test/fixtures/config.yml
30
34
  - test/test_client.rb