meducation_sdk 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 +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +5 -0
- data/CONTRIBUTING.md +30 -0
- data/Gemfile +4 -0
- data/LICENCE.md +617 -0
- data/README.md +73 -0
- data/Rakefile +8 -0
- data/lib/meducation_sdk/configuration.rb +35 -0
- data/lib/meducation_sdk/mocker.rb +56 -0
- data/lib/meducation_sdk/resources/item_comment.rb +20 -0
- data/lib/meducation_sdk/resources/media_file.rb +23 -0
- data/lib/meducation_sdk/resources/mesh_heading.rb +20 -0
- data/lib/meducation_sdk/resources/mnemonic.rb +15 -0
- data/lib/meducation_sdk/resources/notification.rb +25 -0
- data/lib/meducation_sdk/resources/partner.rb +15 -0
- data/lib/meducation_sdk/resources/premium_tutorial.rb +14 -0
- data/lib/meducation_sdk/resources/syllabus_item.rb +15 -0
- data/lib/meducation_sdk/resources/user.rb +14 -0
- data/lib/meducation_sdk/version.rb +3 -0
- data/lib/meducation_sdk.rb +60 -0
- data/meducation_sdk.gemspec +30 -0
- data/test/mocker_test.rb +34 -0
- data/test/resource_test.rb +21 -0
- data/test/resources/item_comment_test.rb +15 -0
- data/test/resources/media_file_test.rb +14 -0
- data/test/resources/user_test.rb +10 -0
- data/test/test_helper.rb +28 -0
- metadata +190 -0
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Meducation SDK
|
2
|
+
|
3
|
+
[](https://travis-ci.org/meducation/meducation_sdk)
|
4
|
+
[](https://gemnasium.com/meducation/meducation_sdk)
|
5
|
+
[](https://codeclimate.com/github/meducation/meducation_sdk)
|
6
|
+
|
7
|
+
A wrapper for Meducation's SDK.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'meducation_sdk'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Resources accept the following methods:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
MeducationSDK::MediaFile.find(id)
|
27
|
+
MeducationSDK::MediaFile.find_each #=> do ... end
|
28
|
+
MeducationSDK::MediaFile.where(foo: 'bar') #=> do ... end
|
29
|
+
MeducationSDK::MediaFile.create(foo: 'bar')
|
30
|
+
```
|
31
|
+
|
32
|
+
The following objects are currently supported:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
MediaFile
|
36
|
+
User
|
37
|
+
ItemComment
|
38
|
+
```
|
39
|
+
|
40
|
+
### Is it any good?
|
41
|
+
|
42
|
+
[Yes.](http://news.ycombinator.com/item?id=3067434)
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
Firstly, thank you!! :heart::sparkling_heart::heart:
|
47
|
+
|
48
|
+
We'd love to have you involved. Please read our [contributing guide](https://github.com/meducation/propono/tree/master/CONTRIBUTING.md) for information on how to get stuck in.
|
49
|
+
|
50
|
+
### Contributors
|
51
|
+
|
52
|
+
This project is managed by the [Meducation team](http://company.meducation.net/about#team).
|
53
|
+
|
54
|
+
These individuals have come up with the ideas and written the code that made this possible:
|
55
|
+
|
56
|
+
- [Jeremy Walker](http://github.com/iHID)
|
57
|
+
|
58
|
+
## Licence
|
59
|
+
|
60
|
+
Copyright (C) 2013 New Media Education Ltd
|
61
|
+
|
62
|
+
This program is free software: you can redistribute it and/or modify
|
63
|
+
it under the terms of the GNU Affero General Public License as published by
|
64
|
+
the Free Software Foundation, either version 3 of the License, or
|
65
|
+
(at your option) any later version.
|
66
|
+
|
67
|
+
This program is distributed in the hope that it will be useful,
|
68
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
69
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
70
|
+
GNU Affero General Public License for more details.
|
71
|
+
|
72
|
+
A copy of the GNU Affero General Public License is available in [Licence.md](https://github.com/meducation/propono/blob/master/LICENCE.md)
|
73
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module MeducationSDK
|
2
|
+
class MeducationSDKError < StandardError
|
3
|
+
end
|
4
|
+
class MeducationSDKConfigurationError < MeducationSDKError
|
5
|
+
end
|
6
|
+
|
7
|
+
class Configuration
|
8
|
+
|
9
|
+
SETTINGS = [
|
10
|
+
:logger, :access_id, :secret_key, :endpoint
|
11
|
+
]
|
12
|
+
|
13
|
+
attr_writer *SETTINGS
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
Filum.config do |config|
|
17
|
+
config.logfile = "./log/loquor.log"
|
18
|
+
end
|
19
|
+
logger = Filum.logger
|
20
|
+
end
|
21
|
+
|
22
|
+
SETTINGS.each do |setting|
|
23
|
+
define_method setting do
|
24
|
+
get_or_raise(setting)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def get_or_raise(setting)
|
31
|
+
instance_variable_get("@#{setting.to_s}") ||
|
32
|
+
raise(MeducationSDKConfigurationError.new("Configuration for #{setting} is not set"))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module MeducationSDK
|
2
|
+
class Mocker
|
3
|
+
def self.mock!
|
4
|
+
RESOURCES.each do |resource|
|
5
|
+
new(resource).mock!
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.unmock!
|
10
|
+
RESOURCES.each do |resource|
|
11
|
+
new(resource).unmock!
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(resource_name)
|
16
|
+
@resource_name = resource_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def mock!
|
20
|
+
return if MeducationSDK.const_defined?(original_klass)
|
21
|
+
|
22
|
+
resource = "MeducationSDK::#{resource_klass}".constantize
|
23
|
+
mock = "MeducationSDK::#{mock_klass}".constantize
|
24
|
+
|
25
|
+
MeducationSDK.const_set(original_klass, resource)
|
26
|
+
MeducationSDK.send(:remove_const, resource_klass)
|
27
|
+
MeducationSDK.const_set(resource_klass, mock)
|
28
|
+
MeducationSDK.send(:remove_const, mock_klass)
|
29
|
+
end
|
30
|
+
|
31
|
+
def unmock!
|
32
|
+
return unless MeducationSDK.const_defined?(original_klass)
|
33
|
+
|
34
|
+
original = "MeducationSDK::#{original_klass}".constantize
|
35
|
+
resource = "MeducationSDK::#{resource_klass}".constantize
|
36
|
+
|
37
|
+
MeducationSDK.const_set(mock_klass, resource)
|
38
|
+
MeducationSDK.send(:remove_const, resource_klass)
|
39
|
+
MeducationSDK.const_set(resource_klass, original)
|
40
|
+
MeducationSDK.send(:remove_const, original_klass)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def resource_klass
|
45
|
+
@resource_name.classify
|
46
|
+
end
|
47
|
+
|
48
|
+
def mock_klass
|
49
|
+
"#{@resource_name}_mock".classify
|
50
|
+
end
|
51
|
+
|
52
|
+
def original_klass
|
53
|
+
"#{@resource_name}_original".classify
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MeducationSDK
|
2
|
+
class ItemComment < Loquor::Resource
|
3
|
+
self.path = "/item_comments"
|
4
|
+
|
5
|
+
def item
|
6
|
+
@item ||= "MeducationSDK::#{item_type}".constantize.find(item_id)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class ItemCommentMock < ItemComment
|
11
|
+
extend Loquor::ResourceMock
|
12
|
+
|
13
|
+
self.attributes = {
|
14
|
+
id: 1,
|
15
|
+
user_id: 8,
|
16
|
+
item_id: 5, item_type: "MediaFile",
|
17
|
+
parsed_content: "Foobar"
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MeducationSDK
|
2
|
+
class MediaFile < Loquor::Resource
|
3
|
+
self.path = "/media_files"
|
4
|
+
|
5
|
+
def user
|
6
|
+
@user ||= User.find(user_id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def comments
|
10
|
+
@comments ||= ItemComment.where(item_id: id, item_type: "MediaFile")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class MediaFileMock < MediaFile
|
15
|
+
extend Loquor::ResourceMock
|
16
|
+
|
17
|
+
self.attributes = {
|
18
|
+
id: 1,
|
19
|
+
user_id: 1,
|
20
|
+
title: "Abdominal Ultrasound Tutorial"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module MeducationSDK
|
2
|
+
class MeshHeading < Loquor::Resource
|
3
|
+
self.path = "/partners"
|
4
|
+
|
5
|
+
def parents
|
6
|
+
MeshHeading.where(id: parent_ids)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class MeshHeadingMock < MeshHeading
|
11
|
+
extend Loquor::ResourceMock
|
12
|
+
|
13
|
+
self.attributes = {
|
14
|
+
id: 1,
|
15
|
+
name: "Some Mesh Heading",
|
16
|
+
parent_ids: [2,3,4]
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MeducationSDK
|
2
|
+
class Mnemonic < Loquor::Resource
|
3
|
+
self.path = "/partners"
|
4
|
+
end
|
5
|
+
|
6
|
+
class MnemonicMock < Mnemonic
|
7
|
+
extend Loquor::ResourceMock
|
8
|
+
|
9
|
+
self.attributes = {
|
10
|
+
id: 1,
|
11
|
+
subject: "Some interesting topic",
|
12
|
+
mnemonic_string: "SIT"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module MeducationSDK
|
2
|
+
class Notification < Loquor::Resource
|
3
|
+
self.path = "/notifications"
|
4
|
+
|
5
|
+
def item
|
6
|
+
@item ||= "MeducationSDK::#{item_type}".constantize.find(item_id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def user
|
10
|
+
@user ||= User.find(user_id)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class NotificationMock < ItemComment
|
15
|
+
extend Loquor::ResourceMock
|
16
|
+
|
17
|
+
self.attributes = {
|
18
|
+
id: 1,
|
19
|
+
notification: "foobar",
|
20
|
+
user_id: 5,
|
21
|
+
item_id: 3,
|
22
|
+
item_type: "Comment"
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MeducationSDK
|
2
|
+
class Partner < Loquor::Resource
|
3
|
+
self.path = "/partners"
|
4
|
+
end
|
5
|
+
|
6
|
+
class PartnerMock < Partner
|
7
|
+
extend Loquor::ResourceMock
|
8
|
+
|
9
|
+
self.attributes = {
|
10
|
+
id: 1,
|
11
|
+
name: "Medical Protection Society",
|
12
|
+
abbreviated_name: "Medical Protection Society"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module MeducationSDK
|
2
|
+
class PremiumTutorial < Loquor::Resource
|
3
|
+
self.path = "/premium_tutorials"
|
4
|
+
end
|
5
|
+
|
6
|
+
class PremiumTutorialMock < PremiumTutorial
|
7
|
+
extend Loquor::ResourceMock
|
8
|
+
|
9
|
+
self.attributes = {
|
10
|
+
id: 1,
|
11
|
+
title: "Al's Medicine Tutorial",
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
require 'loquor'
|
3
|
+
|
4
|
+
require "meducation_sdk/version"
|
5
|
+
require "meducation_sdk/configuration"
|
6
|
+
require "meducation_sdk/mocker"
|
7
|
+
|
8
|
+
RESOURCES = %w{
|
9
|
+
item_comment
|
10
|
+
media_file
|
11
|
+
mesh_heading
|
12
|
+
mnemonic
|
13
|
+
notification
|
14
|
+
partner
|
15
|
+
premium_tutorial
|
16
|
+
syllabus_item
|
17
|
+
user
|
18
|
+
}
|
19
|
+
RESOURCES.each do |resource|
|
20
|
+
require "meducation_sdk/resources/#{resource}"
|
21
|
+
end
|
22
|
+
|
23
|
+
module MeducationSDK
|
24
|
+
def self.config
|
25
|
+
@config ||= Configuration.new
|
26
|
+
if block_given?
|
27
|
+
yield @config
|
28
|
+
else
|
29
|
+
@config
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.mock!
|
34
|
+
MeducationSDK::Mocker.mock!
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
=begin
|
39
|
+
Interactors = {
|
40
|
+
"Group::Discussion" => "/group_discussions",
|
41
|
+
"Group::DiscussionPost" => "/group_discussion_posts",
|
42
|
+
"Item::Comment" => "/item_comments",
|
43
|
+
"MediaFile" => "/media_files",
|
44
|
+
"MeshHeading" => "/mesh_headings",
|
45
|
+
"Mnemonic" => "/mnemonics",
|
46
|
+
"Premium::Tutorial" => "/premium_tutorials",
|
47
|
+
"Partner" => "/partners",
|
48
|
+
"SyllabusItem" => "/syllabus_items",
|
49
|
+
"User" => "/users"
|
50
|
+
#
|
51
|
+
#ExamRoom::Practice::Exam::Challenge
|
52
|
+
#Friendship
|
53
|
+
#Ecommerce::Subscription
|
54
|
+
#Message.find
|
55
|
+
#Group::Membership
|
56
|
+
#Group::Invite
|
57
|
+
#KnowledgeBank::Answer
|
58
|
+
#User::Friendship
|
59
|
+
}
|
60
|
+
=end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'meducation_sdk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "meducation_sdk"
|
8
|
+
spec.version = MeducationSDK::VERSION
|
9
|
+
spec.authors = ["Jeremy Walker"]
|
10
|
+
spec.email = ["jez.walker@gmail.com"]
|
11
|
+
spec.description = "Meducation's SDK"
|
12
|
+
spec.summary = "The SDK for Meducation"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport", '~> 3.2.15'
|
22
|
+
spec.add_dependency "loquor", '~> 0.3.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "minitest", '~> 5.0.8'
|
28
|
+
spec.add_development_dependency "mocha"
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
end
|
data/test/mocker_test.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module MeducationSDK
|
4
|
+
class MockerTest < Minitest::Test
|
5
|
+
|
6
|
+
def test_mock_switches_classes
|
7
|
+
MeducationSDK.mock!
|
8
|
+
assert MeducationSDK.const_defined?(:MediaFileOriginal)
|
9
|
+
assert MeducationSDK.const_defined?(:MediaFile)
|
10
|
+
refute MeducationSDK.const_defined?(:MediaFileMock)
|
11
|
+
ensure
|
12
|
+
MeducationSDK::Mocker.unmock!
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_mock_substitutes_in_mock_classes
|
16
|
+
MeducationSDK.mock!
|
17
|
+
|
18
|
+
id = 5
|
19
|
+
Loquor::HttpAction::Get.expects(:get).never
|
20
|
+
assert id, MediaFile.find('id').id
|
21
|
+
ensure
|
22
|
+
MeducationSDK::Mocker.unmock!
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_mock_sample_returns_media_file_with_attributes
|
26
|
+
MeducationSDK.mock!
|
27
|
+
|
28
|
+
media_file = MediaFile.sample
|
29
|
+
media_file.title.should == "Abdominal Ultrasound Tutorial"
|
30
|
+
ensure
|
31
|
+
MeducationSDK::Mocker.unmock!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
module MeducationSDK
|
3
|
+
class ResourceTest < Minitest::Test
|
4
|
+
def self.test_resource(klass, url)
|
5
|
+
define_method :klass do klass end
|
6
|
+
define_method :url do url end
|
7
|
+
|
8
|
+
class_eval do
|
9
|
+
def test_path
|
10
|
+
assert_equal url, klass.path
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_generates_find_url
|
14
|
+
id = 7
|
15
|
+
Loquor::HttpAction::Get.expects(:get).with("#{url}/#{id}", anything())
|
16
|
+
klass.find(id)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require File.expand_path('../../resource_test', __FILE__)
|
3
|
+
|
4
|
+
module MeducationSDK
|
5
|
+
class ItemCommentTest < ResourceTest
|
6
|
+
test_resource(ItemComment, '/item_comments')
|
7
|
+
|
8
|
+
def test_item_calls_sdk
|
9
|
+
comment = ItemComment.new(item_id: 2, item_type: "MediaFile")
|
10
|
+
MeducationSDK::MediaFile.expects(:find).with(2)
|
11
|
+
comment.item
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
require File.expand_path('../../resource_test', __FILE__)
|
3
|
+
|
4
|
+
module MeducationSDK
|
5
|
+
class MediaFileTest < ResourceTest
|
6
|
+
test_resource(MediaFile, '/media_files')
|
7
|
+
|
8
|
+
def test_user_calls_sdk
|
9
|
+
media_file = MediaFile.new(user_id: 3)
|
10
|
+
MeducationSDK::User.expects(:find).with(3)
|
11
|
+
media_file.user
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
gem "minitest"
|
2
|
+
require "minitest/autorun"
|
3
|
+
require "minitest/pride"
|
4
|
+
require "minitest/mock"
|
5
|
+
require "mocha/setup"
|
6
|
+
|
7
|
+
lib = File.expand_path('../../lib', __FILE__)
|
8
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
9
|
+
|
10
|
+
require "meducation_sdk"
|
11
|
+
|
12
|
+
class Minitest::Test
|
13
|
+
def setup
|
14
|
+
MeducationSDK.config do |config|
|
15
|
+
config.logger = mock()
|
16
|
+
config.logger.stubs(:debug)
|
17
|
+
config.logger.stubs(:info)
|
18
|
+
config.logger.stubs(:error)
|
19
|
+
end
|
20
|
+
Loquor.config do |config|
|
21
|
+
config.logger = MeducationSDK.config.logger
|
22
|
+
config.access_id = "Sermo"
|
23
|
+
config.secret_key = "foobar"
|
24
|
+
config.endpoint = "http://localhost:3000"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|