pandarus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/lib/pandarus.rb +1 -0
  2. data/lib/pandarus/api_base.rb +114 -0
  3. data/lib/pandarus/model_base.rb +54 -0
  4. data/lib/pandarus/models.rb +43 -0
  5. data/lib/pandarus/models/account_authorization_config.rb +34 -0
  6. data/lib/pandarus/models/admin.rb +19 -0
  7. data/lib/pandarus/models/assignment.rb +57 -0
  8. data/lib/pandarus/models/assignment_group.rb +22 -0
  9. data/lib/pandarus/models/assignment_override.rb +27 -0
  10. data/lib/pandarus/models/collaborator.rb +19 -0
  11. data/lib/pandarus/models/collection.rb +22 -0
  12. data/lib/pandarus/models/collection_item.rb +33 -0
  13. data/lib/pandarus/models/comm_message.rb +26 -0
  14. data/lib/pandarus/models/communication_channel.rb +22 -0
  15. data/lib/pandarus/models/content_migration.rb +27 -0
  16. data/lib/pandarus/models/course.rb +46 -0
  17. data/lib/pandarus/models/day.rb +18 -0
  18. data/lib/pandarus/models/discovery_url.rb +17 -0
  19. data/lib/pandarus/models/external_feed.rb +22 -0
  20. data/lib/pandarus/models/favorite.rb +18 -0
  21. data/lib/pandarus/models/file.rb +32 -0
  22. data/lib/pandarus/models/folder.rb +35 -0
  23. data/lib/pandarus/models/grader.rb +19 -0
  24. data/lib/pandarus/models/group.rb +30 -0
  25. data/lib/pandarus/models/group_category.rb +24 -0
  26. data/lib/pandarus/models/group_membership.rb +21 -0
  27. data/lib/pandarus/models/migration_issue.rb +26 -0
  28. data/lib/pandarus/models/migrator.rb +20 -0
  29. data/lib/pandarus/models/module.rb +28 -0
  30. data/lib/pandarus/models/module_item.rb +30 -0
  31. data/lib/pandarus/models/module_item_sequence.rb +18 -0
  32. data/lib/pandarus/models/outcome.rb +27 -0
  33. data/lib/pandarus/models/outcome_group.rb +28 -0
  34. data/lib/pandarus/models/outcome_link.rb +21 -0
  35. data/lib/pandarus/models/page.rb +29 -0
  36. data/lib/pandarus/models/page_revision.rb +22 -0
  37. data/lib/pandarus/models/progress.rb +27 -0
  38. data/lib/pandarus/models/quiz.rb +42 -0
  39. data/lib/pandarus/models/quiz_report.rb +25 -0
  40. data/lib/pandarus/models/report.rb +22 -0
  41. data/lib/pandarus/models/role.rb +21 -0
  42. data/lib/pandarus/models/section.rb +23 -0
  43. data/lib/pandarus/models/submission_history.rb +18 -0
  44. data/lib/pandarus/models/submission_version.rb +39 -0
  45. data/lib/pandarus/models/user.rb +29 -0
  46. data/lib/pandarus/v1_api.rb +10021 -0
  47. data/lib/pandarus/version.rb +3 -0
  48. data/pandarus.gemspec +30 -0
  49. data/spec/api_base_spec.rb +25 -0
  50. data/spec/spec_helper.rb +1 -0
  51. metadata +211 -0
@@ -0,0 +1 @@
1
+ require "pandarus/v1_api"
@@ -0,0 +1,114 @@
1
+ require "uri"
2
+ require "footrest"
3
+
4
+ module Pandarus
5
+ class APIBase < Footrest::Client
6
+ attr_reader :response
7
+
8
+ def initialize(*args)
9
+ @pagination_params = {}
10
+ super
11
+ end
12
+
13
+ # Swagger allows for each param to be a query param or a form param, which
14
+ # is a bit unusual because in the 99% case, all params will be of one type
15
+ # or the other for a single Canvas request. In order to accommodate the 1%
16
+ # case, however, we allow for mixed requests in general.
17
+ def mixed_request(method, path, query_params, form_params, headers)
18
+ @response = connection.send(method) do |r|
19
+ if query_params.empty?
20
+ r.path = fullpath(path)
21
+ else
22
+ r.url(fullpath(path), query_params)
23
+ end
24
+ r.body = form_params unless form_params.empty?
25
+ r.headers = headers if headers
26
+ end
27
+ @response.body
28
+ end
29
+
30
+ def remember_key(method, path)
31
+ "#{method}:#{path}"
32
+ end
33
+
34
+ def page_params_store(method, path, url=@response.env[:next_page])
35
+ uri = URI.parse(url)
36
+ params = Hash[URI.decode_www_form(uri.query)]
37
+ @pagination_params[remember_key(method, path)] = params
38
+ rescue URI::InvalidURIError
39
+ nil
40
+ end
41
+
42
+ def page_params_load(method, path)
43
+ @pagination_params[remember_key(method, path)]
44
+ end
45
+
46
+
47
+ def underscored_merge_opts(opts, base)
48
+ base.merge(opts).merge(underscored_flatten_hash(opts))
49
+ end
50
+
51
+ protected
52
+
53
+ # Take a hash such as { :user => { :name => "me" } } and return a flattened
54
+ # hash such as { :user__name__ => "me" }. We do this as a workaround to
55
+ # swagger's disdain for rails-style square bracket parameters in the url.
56
+ def underscored_flatten_hash(hash)
57
+ Hash[
58
+ dot_flatten_hash(hash).map do |key, value|
59
+ count = 0
60
+ newkey = key.to_s.gsub(".") {|x| count += 1; count == 1 ? '__' : '____' }
61
+ newkey += '__' if count > 0
62
+ [newkey.to_sym, value]
63
+ end
64
+ ]
65
+ end
66
+
67
+ def dot_flatten_hash(hash)
68
+ Hash[*dot_flatten_recur(hash).flatten]
69
+ end
70
+
71
+ def dot_flatten_recur(hash)
72
+ hash.map do |k1, v1|
73
+ if v1.is_a?(Hash)
74
+ dot_flatten_recur(v1).map do |k2, v2|
75
+ ["#{k1}.#{k2}", v2]
76
+ end.flatten
77
+ else
78
+ [k1, v1]
79
+ end
80
+ end
81
+ end
82
+
83
+ def escape_string(string)
84
+ URI.encode(string.to_s)
85
+ end
86
+
87
+ # Convert something like user__name__ to user[name]
88
+ def underscores_to_square_brackets(key)
89
+ key.to_s.gsub(/(__.+?__)/) do |x|
90
+ x.sub('__', '[').sub('__', ']')
91
+ end.to_sym
92
+ end
93
+
94
+ # pull querystring keys from options, and convert double underscores
95
+ # back to square brackets
96
+ def select_params(params, param_keys)
97
+ Hash[
98
+ params.select do |key, value|
99
+ param_keys.include? key
100
+ end.map do |key, value|
101
+ [underscores_to_square_brackets(key), value]
102
+ end
103
+ ]
104
+ end
105
+
106
+ def path_replace(path, args={})
107
+ rpath = path.dup
108
+ args.each_pair do |key, value|
109
+ rpath.sub!("{#{key}}", escape_string(value))
110
+ end
111
+ rpath
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,54 @@
1
+ require 'active_support'
2
+
3
+ module Pandarus
4
+ class ModelBase
5
+ def initialize(attributes = {})
6
+ return if attributes.empty?
7
+ attributes.each_pair do |name, value|
8
+ if has_attr? name.to_sym
9
+ assign(name, value)
10
+ else
11
+ raise ArgumentError, "#{name} is not an attribute of #{self.class}"
12
+ end
13
+ end
14
+ end
15
+
16
+ def attr(name)
17
+ self.class.attribute_map[name.to_sym]
18
+ end
19
+
20
+ def has_attr?(name)
21
+ self.class.attribute_map.has_key? name.to_sym
22
+ end
23
+
24
+ def inspect
25
+ Hash[
26
+ self.class.attribute_map.keys.map do |key|
27
+ [key, instance_variable_get("@#{key}")]
28
+ end
29
+ ].inspect.sub(/^\{/,"<#{self.class} ").sub(/\}$/,'>')
30
+ end
31
+
32
+ def assign(attr_name, value)
33
+ props = attr(attr_name)
34
+ if props[:type]
35
+ if props[:container]
36
+ value = value.map{ |v| props[:type].constantize.new(v) }
37
+ else
38
+ value = props[:type].constantize.new(v)
39
+ end
40
+ end
41
+ instance_variable_set("@#{attr_name}", value)
42
+ end
43
+
44
+ def to_body
45
+ body = {}
46
+ self.class.attribute_map.each_pair do |key, props|
47
+ unless (value = self.send(key).nil?)
48
+ body[props[:external]] = value
49
+ end
50
+ end
51
+ body
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,43 @@
1
+ # This is an autogenerated file. See readme.md.
2
+ require 'pandarus/models/admin'
3
+ require 'pandarus/models/account_authorization_config'
4
+ require 'pandarus/models/role'
5
+ require 'pandarus/models/assignment_group'
6
+ require 'pandarus/models/group_category'
7
+ require 'pandarus/models/content_migration'
8
+ require 'pandarus/models/folder'
9
+ require 'pandarus/models/collection'
10
+ require 'pandarus/models/discovery_url'
11
+ require 'pandarus/models/collaborator'
12
+ require 'pandarus/models/module_item_sequence'
13
+ require 'pandarus/models/quiz'
14
+ require 'pandarus/models/comm_message'
15
+ require 'pandarus/models/collection_item'
16
+ require 'pandarus/models/assignment_override'
17
+ require 'pandarus/models/migrator'
18
+ require 'pandarus/models/outcome_group'
19
+ require 'pandarus/models/section'
20
+ require 'pandarus/models/day'
21
+ require 'pandarus/models/file'
22
+ require 'pandarus/models/page'
23
+ require 'pandarus/models/submission_version'
24
+ require 'pandarus/models/group'
25
+ require 'pandarus/models/submission_history'
26
+ require 'pandarus/models/course'
27
+ require 'pandarus/models/migration_issue'
28
+ require 'pandarus/models/grader'
29
+ require 'pandarus/models/favorite'
30
+ require 'pandarus/models/user'
31
+ require 'pandarus/models/outcome_link'
32
+ require 'pandarus/models/report'
33
+ require 'pandarus/models/assignment'
34
+ require 'pandarus/models/module_item'
35
+ require 'pandarus/models/outcome'
36
+ require 'pandarus/models/external_feed'
37
+ require 'pandarus/models/communication_channel'
38
+ require 'pandarus/models/progress'
39
+ require 'pandarus/models/module'
40
+ require 'pandarus/models/page_revision'
41
+ require 'pandarus/models/group_membership'
42
+ require 'pandarus/models/quiz_report'
43
+
@@ -0,0 +1,34 @@
1
+ require "pandarus/model_base"
2
+
3
+ # This is an autogenerated file. See readme.md.
4
+ module Pandarus
5
+ class AccountAuthorizationConfig < ModelBase
6
+ attr_accessor :login_handle_name, :identifier_format, :auth_type, :id, :log_out_url, :log_in_url, :certificate_fingerprint, :change_password_url, :requested_authn_context, :position, :idp_entity_id, :login_attribute, :auth_host, :auth_filter, :auth_over_tls, :auth_base, :auth_username, :auth_port
7
+
8
+
9
+ def self.attribute_map
10
+ {
11
+ :login_handle_name => {:external => "login_handle_name", :container => false, :type => nil},
12
+ :identifier_format => {:external => "identifier_format", :container => false, :type => nil},
13
+ :auth_type => {:external => "auth_type", :container => false, :type => nil},
14
+ :id => {:external => "id", :container => false, :type => nil},
15
+ :log_out_url => {:external => "log_out_url", :container => false, :type => nil},
16
+ :log_in_url => {:external => "log_in_url", :container => false, :type => nil},
17
+ :certificate_fingerprint => {:external => "certificate_fingerprint", :container => false, :type => nil},
18
+ :change_password_url => {:external => "change_password_url", :container => false, :type => nil},
19
+ :requested_authn_context => {:external => "requested_authn_context", :container => false, :type => nil},
20
+ :position => {:external => "position", :container => false, :type => nil},
21
+ :idp_entity_id => {:external => "idp_entity_id", :container => false, :type => nil},
22
+ :login_attribute => {:external => "login_attribute", :container => false, :type => nil},
23
+ :auth_host => {:external => "auth_host", :container => false, :type => nil},
24
+ :auth_filter => {:external => "auth_filter", :container => false, :type => nil},
25
+ :auth_over_tls => {:external => "auth_over_tls", :container => false, :type => nil},
26
+ :auth_base => {:external => "auth_base", :container => false, :type => nil},
27
+ :auth_username => {:external => "auth_username", :container => false, :type => nil},
28
+ :auth_port => {:external => "auth_port", :container => false, :type => nil}
29
+
30
+ }
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,19 @@
1
+ require "pandarus/model_base"
2
+
3
+ # This is an autogenerated file. See readme.md.
4
+ module Pandarus
5
+ class Admin < ModelBase
6
+ attr_accessor :id, :role, :user
7
+
8
+
9
+ def self.attribute_map
10
+ {
11
+ :id => {:external => "id", :container => false, :type => nil},
12
+ :role => {:external => "role", :container => false, :type => nil},
13
+ :user => {:external => "user", :container => false, :type => nil}
14
+
15
+ }
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,57 @@
1
+ require "pandarus/model_base"
2
+
3
+ # This is an autogenerated file. See readme.md.
4
+ module Pandarus
5
+ class Assignment < ModelBase
6
+ attr_accessor :id, :name, :description, :due_at, :lock_at, :unlock_at, :all_dates, :course_id, :html_url, :assignment_group_id, :allowed_extensions, :turnitin_enabled, :turnitin_settings, :grade_group_students_individually, :external_tool_tag_attributes, :peer_reviews, :automatic_peer_reviews, :peer_review_count, :peer_reviews_assign_at, :group_category_id, :needs_grading_count, :position, :muted, :points_possible, :submission_types, :grading_type, :grading_standard_id, :published, :locked_for_user, :lock_info, :lock_explanation, :quiz_id, :anonymous_submissions, :discussion_topic, :freeze_on_copy, :frozen, :frozen_attributes, :submission, :use_rubric_for_grading, :rubric_settings, :rubric
7
+
8
+
9
+ def self.attribute_map
10
+ {
11
+ :id => {:external => "id", :container => false, :type => nil},
12
+ :name => {:external => "name", :container => false, :type => nil},
13
+ :description => {:external => "description", :container => false, :type => nil},
14
+ :due_at => {:external => "due_at", :container => false, :type => nil},
15
+ :lock_at => {:external => "lock_at", :container => false, :type => nil},
16
+ :unlock_at => {:external => "unlock_at", :container => false, :type => nil},
17
+ :all_dates => {:external => "all_dates", :container => false, :type => nil},
18
+ :course_id => {:external => "course_id", :container => false, :type => nil},
19
+ :html_url => {:external => "html_url", :container => false, :type => nil},
20
+ :assignment_group_id => {:external => "assignment_group_id", :container => false, :type => nil},
21
+ :allowed_extensions => {:external => "allowed_extensions", :container => false, :type => nil},
22
+ :turnitin_enabled => {:external => "turnitin_enabled", :container => false, :type => nil},
23
+ :turnitin_settings => {:external => "turnitin_settings", :container => false, :type => nil},
24
+ :grade_group_students_individually => {:external => "grade_group_students_individually", :container => false, :type => nil},
25
+ :external_tool_tag_attributes => {:external => "external_tool_tag_attributes", :container => false, :type => nil},
26
+ :peer_reviews => {:external => "peer_reviews", :container => false, :type => nil},
27
+ :automatic_peer_reviews => {:external => "automatic_peer_reviews", :container => false, :type => nil},
28
+ :peer_review_count => {:external => "peer_review_count", :container => false, :type => nil},
29
+ :peer_reviews_assign_at => {:external => "peer_reviews_assign_at", :container => false, :type => nil},
30
+ :group_category_id => {:external => "group_category_id", :container => false, :type => nil},
31
+ :needs_grading_count => {:external => "needs_grading_count", :container => false, :type => nil},
32
+ :position => {:external => "position", :container => false, :type => nil},
33
+ :muted => {:external => "muted", :container => false, :type => nil},
34
+ :points_possible => {:external => "points_possible", :container => false, :type => nil},
35
+ :submission_types => {:external => "submission_types", :container => false, :type => nil},
36
+ :grading_type => {:external => "grading_type", :container => false, :type => nil},
37
+ :grading_standard_id => {:external => "grading_standard_id", :container => false, :type => nil},
38
+ :published => {:external => "published", :container => false, :type => nil},
39
+ :locked_for_user => {:external => "locked_for_user", :container => false, :type => nil},
40
+ :lock_info => {:external => "lock_info", :container => false, :type => nil},
41
+ :lock_explanation => {:external => "lock_explanation", :container => false, :type => nil},
42
+ :quiz_id => {:external => "quiz_id", :container => false, :type => nil},
43
+ :anonymous_submissions => {:external => "anonymous_submissions", :container => false, :type => nil},
44
+ :discussion_topic => {:external => "discussion_topic", :container => false, :type => nil},
45
+ :freeze_on_copy => {:external => "freeze_on_copy", :container => false, :type => nil},
46
+ :frozen => {:external => "frozen", :container => false, :type => nil},
47
+ :frozen_attributes => {:external => "frozen_attributes", :container => false, :type => nil},
48
+ :submission => {:external => "submission", :container => false, :type => nil},
49
+ :use_rubric_for_grading => {:external => "use_rubric_for_grading", :container => false, :type => nil},
50
+ :rubric_settings => {:external => "rubric_settings", :container => false, :type => nil},
51
+ :rubric => {:external => "rubric", :container => false, :type => nil}
52
+
53
+ }
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,22 @@
1
+ require "pandarus/model_base"
2
+
3
+ # This is an autogenerated file. See readme.md.
4
+ module Pandarus
5
+ class AssignmentGroup < ModelBase
6
+ attr_accessor :id, :name, :position, :group_weight, :assignments, :rules
7
+
8
+
9
+ def self.attribute_map
10
+ {
11
+ :id => {:external => "id", :container => false, :type => nil},
12
+ :name => {:external => "name", :container => false, :type => nil},
13
+ :position => {:external => "position", :container => false, :type => nil},
14
+ :group_weight => {:external => "group_weight", :container => false, :type => nil},
15
+ :assignments => {:external => "assignments", :container => false, :type => nil},
16
+ :rules => {:external => "rules", :container => false, :type => nil}
17
+
18
+ }
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,27 @@
1
+ require "pandarus/model_base"
2
+
3
+ # This is an autogenerated file. See readme.md.
4
+ module Pandarus
5
+ class AssignmentOverride < ModelBase
6
+ attr_accessor :id, :assignment_id, :student_ids, :group_id, :course_section_id, :title, :due_at, :all_day, :all_day_date, :unlock_at, :lock_at
7
+
8
+
9
+ def self.attribute_map
10
+ {
11
+ :id => {:external => "id", :container => false, :type => nil},
12
+ :assignment_id => {:external => "assignment_id", :container => false, :type => nil},
13
+ :student_ids => {:external => "student_ids", :container => false, :type => nil},
14
+ :group_id => {:external => "group_id", :container => false, :type => nil},
15
+ :course_section_id => {:external => "course_section_id", :container => false, :type => nil},
16
+ :title => {:external => "title", :container => false, :type => nil},
17
+ :due_at => {:external => "due_at", :container => false, :type => nil},
18
+ :all_day => {:external => "all_day", :container => false, :type => nil},
19
+ :all_day_date => {:external => "all_day_date", :container => false, :type => "Date"},
20
+ :unlock_at => {:external => "unlock_at", :container => false, :type => nil},
21
+ :lock_at => {:external => "lock_at", :container => false, :type => nil}
22
+
23
+ }
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,19 @@
1
+ require "pandarus/model_base"
2
+
3
+ # This is an autogenerated file. See readme.md.
4
+ module Pandarus
5
+ class Collaborator < ModelBase
6
+ attr_accessor :id, :type, :name
7
+
8
+
9
+ def self.attribute_map
10
+ {
11
+ :id => {:external => "id", :container => false, :type => nil},
12
+ :type => {:external => "type", :container => false, :type => nil},
13
+ :name => {:external => "name", :container => false, :type => nil}
14
+
15
+ }
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,22 @@
1
+ require "pandarus/model_base"
2
+
3
+ # This is an autogenerated file. See readme.md.
4
+ module Pandarus
5
+ class Collection < ModelBase
6
+ attr_accessor :id, :name, :visibility, :followed_by_user, :followers_count, :items_count
7
+
8
+
9
+ def self.attribute_map
10
+ {
11
+ :id => {:external => "id", :container => false, :type => nil},
12
+ :name => {:external => "name", :container => false, :type => nil},
13
+ :visibility => {:external => "visibility", :container => false, :type => nil},
14
+ :followed_by_user => {:external => "followed_by_user", :container => false, :type => nil},
15
+ :followers_count => {:external => "followers_count", :container => false, :type => nil},
16
+ :items_count => {:external => "items_count", :container => false, :type => nil}
17
+
18
+ }
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,33 @@
1
+ require "pandarus/model_base"
2
+
3
+ # This is an autogenerated file. See readme.md.
4
+ module Pandarus
5
+ class CollectionItem < ModelBase
6
+ attr_accessor :id, :collection_id, :item_type, :link_url, :post_count, :upvote_count, :upvoted_by_user, :root_item_id, :image_url, :image_pending, :title, :description, :user_comment, :html_preview, :url, :created_at, :user
7
+
8
+
9
+ def self.attribute_map
10
+ {
11
+ :id => {:external => "id", :container => false, :type => nil},
12
+ :collection_id => {:external => "collection_id", :container => false, :type => nil},
13
+ :item_type => {:external => "item_type", :container => false, :type => nil},
14
+ :link_url => {:external => "link_url", :container => false, :type => nil},
15
+ :post_count => {:external => "post_count", :container => false, :type => nil},
16
+ :upvote_count => {:external => "upvote_count", :container => false, :type => nil},
17
+ :upvoted_by_user => {:external => "upvoted_by_user", :container => false, :type => nil},
18
+ :root_item_id => {:external => "root_item_id", :container => false, :type => nil},
19
+ :image_url => {:external => "image_url", :container => false, :type => nil},
20
+ :image_pending => {:external => "image_pending", :container => false, :type => nil},
21
+ :title => {:external => "title", :container => false, :type => nil},
22
+ :description => {:external => "description", :container => false, :type => nil},
23
+ :user_comment => {:external => "user_comment", :container => false, :type => nil},
24
+ :html_preview => {:external => "html_preview", :container => false, :type => nil},
25
+ :url => {:external => "url", :container => false, :type => nil},
26
+ :created_at => {:external => "created_at", :container => false, :type => "Date"},
27
+ :user => {:external => "user", :container => false, :type => nil}
28
+
29
+ }
30
+ end
31
+ end
32
+ end
33
+