desmos 0.1.2
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.
- data/.rvmrc +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +45 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/autotest/discover.rb +3 -0
- data/desmos.gemspec +91 -0
- data/lib/desmos.rb +19 -0
- data/lib/desmos/configuration.rb +66 -0
- data/lib/desmos/debug_mode.rb +9 -0
- data/lib/desmos/errors.rb +10 -0
- data/lib/desmos/request_support.rb +44 -0
- data/lib/desmos/student.rb +10 -0
- data/lib/desmos/tutor.rb +10 -0
- data/lib/desmos/user.rb +34 -0
- data/lib/desmos/utils.rb +64 -0
- data/lib/desmos/whiteboard.rb +96 -0
- data/spec/desmos/configuration_spec.rb +105 -0
- data/spec/desmos/request_support_spec.rb +99 -0
- data/spec/desmos/student_spec.rb +38 -0
- data/spec/desmos/tutor_spec.rb +38 -0
- data/spec/desmos/user_spec.rb +38 -0
- data/spec/desmos/utils_spec.rb +20 -0
- data/spec/desmos/whiteboard_spec.rb +203 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/configure.rb +9 -0
- metadata +226 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ree-1.8.7-2010.02@desmos
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.6.2)
|
5
|
+
activesupport (3.1.0)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
addressable (2.2.6)
|
8
|
+
autotest (4.4.6)
|
9
|
+
ZenTest (>= 4.4.1)
|
10
|
+
awesome_print (0.4.0)
|
11
|
+
crack (0.1.8)
|
12
|
+
diff-lcs (1.1.3)
|
13
|
+
git (1.2.5)
|
14
|
+
jeweler (1.6.0)
|
15
|
+
bundler (~> 1.0.0)
|
16
|
+
git (>= 1.2.5)
|
17
|
+
rake
|
18
|
+
multi_json (1.0.3)
|
19
|
+
oauth (0.4.5)
|
20
|
+
rake (0.9.2)
|
21
|
+
rspec (2.6.0)
|
22
|
+
rspec-core (~> 2.6.0)
|
23
|
+
rspec-expectations (~> 2.6.0)
|
24
|
+
rspec-mocks (~> 2.6.0)
|
25
|
+
rspec-core (2.6.4)
|
26
|
+
rspec-expectations (2.6.0)
|
27
|
+
diff-lcs (~> 1.1.2)
|
28
|
+
rspec-mocks (2.6.0)
|
29
|
+
webmock (1.7.5)
|
30
|
+
addressable (~> 2.2, > 2.2.5)
|
31
|
+
crack (>= 0.1.7)
|
32
|
+
yajl-ruby (0.8.3)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
activesupport (~> 3.0)
|
39
|
+
autotest
|
40
|
+
awesome_print
|
41
|
+
jeweler
|
42
|
+
oauth (~> 0.4.5)
|
43
|
+
rspec
|
44
|
+
webmock
|
45
|
+
yajl-ruby (~> 0.8.2)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Moran
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= desmos
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Ryan Moran. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
begin
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
gem.name = "desmos"
|
16
|
+
gem.summary = %Q{Desmos API Wrapper}
|
17
|
+
gem.description = %Q{Desmos API Wrapper}
|
18
|
+
gem.email = "ryan.moran@gmail.com"
|
19
|
+
gem.homepage = "http://github.com/RevolutionPrep/desmos"
|
20
|
+
gem.authors = ["Ryan Moran"]
|
21
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
22
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
23
|
+
end
|
24
|
+
Jeweler::GemcutterTasks.new
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov_opts = "--exclude osx\/objc,gems\/,spec\/"
|
38
|
+
spec.rcov = true
|
39
|
+
end
|
40
|
+
|
41
|
+
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/desmos.gemspec
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{desmos}
|
8
|
+
s.version = "0.1.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Ryan Moran}]
|
12
|
+
s.date = %q{2011-09-08}
|
13
|
+
s.description = %q{Desmos API Wrapper}
|
14
|
+
s.email = %q{ryan.moran@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".rvmrc",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"autotest/discover.rb",
|
28
|
+
"desmos.gemspec",
|
29
|
+
"lib/desmos.rb",
|
30
|
+
"lib/desmos/configuration.rb",
|
31
|
+
"lib/desmos/debug_mode.rb",
|
32
|
+
"lib/desmos/errors.rb",
|
33
|
+
"lib/desmos/request_support.rb",
|
34
|
+
"lib/desmos/student.rb",
|
35
|
+
"lib/desmos/tutor.rb",
|
36
|
+
"lib/desmos/user.rb",
|
37
|
+
"lib/desmos/utils.rb",
|
38
|
+
"lib/desmos/whiteboard.rb",
|
39
|
+
"spec/desmos/configuration_spec.rb",
|
40
|
+
"spec/desmos/request_support_spec.rb",
|
41
|
+
"spec/desmos/student_spec.rb",
|
42
|
+
"spec/desmos/tutor_spec.rb",
|
43
|
+
"spec/desmos/user_spec.rb",
|
44
|
+
"spec/desmos/utils_spec.rb",
|
45
|
+
"spec/desmos/whiteboard_spec.rb",
|
46
|
+
"spec/spec.opts",
|
47
|
+
"spec/spec_helper.rb",
|
48
|
+
"spec/support/configure.rb"
|
49
|
+
]
|
50
|
+
s.homepage = %q{http://github.com/RevolutionPrep/desmos}
|
51
|
+
s.require_paths = [%q{lib}]
|
52
|
+
s.rubygems_version = %q{1.8.6}
|
53
|
+
s.summary = %q{Desmos API Wrapper}
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_runtime_dependency(%q<yajl-ruby>, ["~> 0.8.2"])
|
60
|
+
s.add_runtime_dependency(%q<oauth>, ["~> 0.4.5"])
|
61
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
|
62
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<autotest>, [">= 0"])
|
65
|
+
s.add_development_dependency(%q<awesome_print>, [">= 0"])
|
66
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
67
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<yajl-ruby>, ["~> 0.8.2"])
|
70
|
+
s.add_dependency(%q<oauth>, ["~> 0.4.5"])
|
71
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0"])
|
72
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
73
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
74
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
75
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
76
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
77
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
78
|
+
end
|
79
|
+
else
|
80
|
+
s.add_dependency(%q<yajl-ruby>, ["~> 0.8.2"])
|
81
|
+
s.add_dependency(%q<oauth>, ["~> 0.4.5"])
|
82
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0"])
|
83
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
84
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
85
|
+
s.add_dependency(%q<autotest>, [">= 0"])
|
86
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
87
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
88
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
data/lib/desmos.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_support/core_ext/hash/keys'
|
2
|
+
require 'oauth'
|
3
|
+
require 'yajl'
|
4
|
+
|
5
|
+
module Desmos
|
6
|
+
autoload :Configuration, 'desmos/configuration'
|
7
|
+
autoload :DebugMode, 'desmos/debug_mode'
|
8
|
+
autoload :RequestSupport, 'desmos/request_support'
|
9
|
+
autoload :Student, 'desmos/student'
|
10
|
+
autoload :Tutor, 'desmos/tutor'
|
11
|
+
autoload :User, 'desmos/user'
|
12
|
+
autoload :Utils, 'desmos/utils'
|
13
|
+
autoload :Whiteboard, 'desmos/whiteboard'
|
14
|
+
|
15
|
+
# ERROR CLASSES
|
16
|
+
autoload :ConfigurationError, 'desmos/errors'
|
17
|
+
autoload :RequestError, 'desmos/errors'
|
18
|
+
autoload :WhiteboardNotFound, 'desmos/errors'
|
19
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Desmos
|
2
|
+
module Configuration
|
3
|
+
|
4
|
+
def domain=(domain)
|
5
|
+
@domain = case domain
|
6
|
+
when String
|
7
|
+
domain.match(/https?\:\/\//) ? ('https://' + domain.split('://')[1]) : 'https://' + domain
|
8
|
+
else
|
9
|
+
domain
|
10
|
+
end
|
11
|
+
end
|
12
|
+
module_function :domain=
|
13
|
+
|
14
|
+
def domain
|
15
|
+
@domain || raise(ConfigurationError, 'Desmos::Configuration.domain is a required configuration value.')
|
16
|
+
end
|
17
|
+
module_function :domain
|
18
|
+
|
19
|
+
def version=(version)
|
20
|
+
@version = case version
|
21
|
+
when String, Numeric
|
22
|
+
version = version.to_s
|
23
|
+
version.match(/api_v\d+/) ? version : 'api_v' + version.match(/\d+/)[0]
|
24
|
+
else
|
25
|
+
version
|
26
|
+
end
|
27
|
+
end
|
28
|
+
module_function :version=
|
29
|
+
|
30
|
+
def version
|
31
|
+
@version || raise(ConfigurationError, 'Desmos::Configuration.version is a required configuration value.')
|
32
|
+
end
|
33
|
+
module_function :version
|
34
|
+
|
35
|
+
def key=(key)
|
36
|
+
@key = key.nil? ? key : key.to_s
|
37
|
+
end
|
38
|
+
module_function :key=
|
39
|
+
|
40
|
+
def key
|
41
|
+
@key || raise(ConfigurationError, 'Desmos::Configuration.key is a required configuration value.')
|
42
|
+
end
|
43
|
+
module_function :key
|
44
|
+
|
45
|
+
def secret=(secret)
|
46
|
+
@secret = secret
|
47
|
+
end
|
48
|
+
module_function :secret=
|
49
|
+
|
50
|
+
def secret
|
51
|
+
@secret || raise(ConfigurationError, 'Desmos::Configuration.secret is a required configuration value.')
|
52
|
+
end
|
53
|
+
module_function :secret
|
54
|
+
|
55
|
+
def debug_mode=(debug_mode)
|
56
|
+
@debug_mode = debug_mode
|
57
|
+
end
|
58
|
+
module_function :debug_mode=
|
59
|
+
|
60
|
+
def debug_mode
|
61
|
+
@debug_mode || false
|
62
|
+
end
|
63
|
+
module_function :debug_mode
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Desmos
|
2
|
+
module RequestSupport
|
3
|
+
include DebugMode
|
4
|
+
|
5
|
+
def request!(object, method, options = {})
|
6
|
+
debug "\n[RequestSupport.request!] (#{object.inspect}, #{method.inspect}, #{options.inspect})"
|
7
|
+
response = make_request(object, method, options)
|
8
|
+
parse_response(response)
|
9
|
+
end
|
10
|
+
|
11
|
+
def make_request(object, method, options = {})
|
12
|
+
debug "\n[RequestSupport.make_request] (#{object.inspect}, #{method.inspect}, #{options.inspect})"
|
13
|
+
uri = build_uri(object, method, options)
|
14
|
+
consumer = OAuth::Consumer.new(Configuration.key, Configuration.secret, :site => Configuration.domain)
|
15
|
+
http = build_http(uri)
|
16
|
+
request = consumer.create_signed_request(:get, "#{Configuration.domain}#{uri.path}?#{uri.query}", nil, options.merge(:scheme => 'query_string'))
|
17
|
+
debug "request:\n#{request.path}"
|
18
|
+
http.request(request)
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_uri(object, method, options = {})
|
22
|
+
debug "\n[RequestSupport.build_uri]: (#{object.inspect}, #{method.inspect}, #{options.inspect})"
|
23
|
+
query_string = Desmos::Utils.traversal_to_param_string(Desmos::Utils.traverse_params_hash(options))
|
24
|
+
uri = URI.parse("#{Configuration.domain}/#{Configuration.version}/#{object}/#{method}?#{query_string}")
|
25
|
+
debug "uri = #{uri.to_s}"
|
26
|
+
uri
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_http(uri)
|
30
|
+
debug "\n[RequestSupport.build_http] (#{uri.inspect})"
|
31
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
32
|
+
http.use_ssl = true
|
33
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
34
|
+
http
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_response(response)
|
38
|
+
debug "\n[RequestSupport.parse_response] (#{response.inspect})"
|
39
|
+
debug "response.body:\n#{response.body}"
|
40
|
+
parsed_response = Yajl::Parser.parse(response.body).symbolize_keys
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/desmos/tutor.rb
ADDED
data/lib/desmos/user.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Desmos
|
2
|
+
class User
|
3
|
+
attr_accessor :id, :hash, :type, :name
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
options.symbolize_keys!
|
7
|
+
@type = 'user'
|
8
|
+
@hash = options[:hash]
|
9
|
+
|
10
|
+
raise ArgumentError, ':id is a required attribute' unless options[:id]
|
11
|
+
@id = options[:id]
|
12
|
+
|
13
|
+
raise ArgumentError, ':name is a required attribute' unless options[:name]
|
14
|
+
@name = options[:name]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.build_from_hash(options = {})
|
18
|
+
options.symbolize_keys!
|
19
|
+
return if options[:id].blank?
|
20
|
+
return if options[:name].blank?
|
21
|
+
new(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def request_options
|
25
|
+
options = {}
|
26
|
+
options.merge!(:user_id => id)
|
27
|
+
options.merge!(:user_name => name)
|
28
|
+
options.merge!(:user_type => type)
|
29
|
+
options.merge!(:user_hash => hash) if hash
|
30
|
+
options
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|