Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various changes #1

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/step_definitions/client_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
end

Given /^(?:When )?I request students for an org with id ([a-f0-9]{24}) and a school with id ([a-f0-9]{24})$/ do |org_id, school_id|
@page = @client.students(org_id, school_id)
@page = @client.students(org_id, :school_id => school_id)
end

Given /^(?:When )?I request students for that school$/ do
Expand Down
8 changes: 4 additions & 4 deletions lib/learnsprout/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Address
:zip

def initialize(attrs={})
@city = attrs["city"]
@state = attrs["state"]
@street = attrs["street"]
@zip = attrs["zip"]
@city = attrs["city"]
@state = attrs["state"]
@street = attrs["street"]
@zip = attrs["zip"]
end
end
end
22 changes: 12 additions & 10 deletions lib/learnsprout/course.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
module LearnSprout
class Course

attr_accessor :course_id,
attr_accessor :id, :course_id,
:school_id,
:name,
:number,
:time_updated
:time_updated,
:updated_at

def initialize(attrs={})
@client = attrs["client"]
@org_id = attrs["org_id"]
@course_id = attrs["id"]
@name = attrs["name"]
@number = attrs["number"]
@time_updated = attrs["time_updated"]
@school_id = attrs["school"]["id"]
@client = attrs["client"]
@org_id = attrs["org_id"]
self.id = @course_id = attrs["id"]
@name = attrs["name"]
@number = attrs["number"]
@time_updated = attrs["time_updated"]
@updated_at = Time.at(@time_updated) if @time_updated
@school_id = attrs["school"]["id"]
end

def school
@client.school(@org_id, @school_id)
@client.school(@org_id, @school_id)
end
end
end
4 changes: 2 additions & 2 deletions lib/learnsprout/nces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class Nces
:school_id

def initialize(attrs={})
@district_id = attrs["district_id"]
@school_id = attrs["school_id"]
@district_id = attrs["district_id"]
@school_id = attrs["school_id"]
end
end
end
4 changes: 2 additions & 2 deletions lib/learnsprout/org.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module LearnSprout
class Org

attr_accessor :org_id,
attr_accessor :id, :org_id,
:name

def initialize(attrs={})
@client = attrs["client"]
@org_id = attrs["id"]
self.id = @org_id = attrs["id"]
@name = attrs["name"]
end

Expand Down
71 changes: 43 additions & 28 deletions lib/learnsprout/page.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
module LearnSprout
class Page
include LearnSprout::Connection

attr_accessor :items

def initialize(url, type, extras = {})
@items = []
@type = type
@extras = extras
data = get(url)

@nextUrl = data["next"].to_s
# Remove base URL if it's included
prefix = LearnSprout.endpoint.to_s
if @nextUrl[0, prefix.length] == prefix
@nextUrl = @nextUrl[prefix.length, @nextUrl.length - prefix.length]
end

#TODO handle non-page URL?
data["data"].each do |item|
extras.each do |key, value|
item[key] = value
end
@items << type.new(item)
end
end
class Page
include LearnSprout::Connection

attr_accessor :items

def initialize(url, type, extras = {})
return false if url.nil? || url == ""
@items = []
@type = type
@extras = extras
data = get(url)

def next
return Page.new(@nextUrl, @type, @extras)
@nextUrl = data["next"].to_s
# Remove base URL if it's included
prefix = LearnSprout.endpoint.to_s
if @nextUrl[0, prefix.length] == prefix
@nextUrl = @nextUrl[prefix.length, @nextUrl.length - prefix.length]
end

#TODO handle non-page URL?
if data['data']
data['data'].each do |item|
@items << type.new(item.merge(extras))
end
end
end


# page = api_client.schools(org_id)
# while page.any? do
# ...
# end
def any?
@items && @items.any?
end

def each(&block)
return unless self.any?
self.items.map(&block)
return self.next.each(&block)
end

def next
return Page.new(@nextUrl, @type, @extras)
end
end
end
6 changes: 3 additions & 3 deletions lib/learnsprout/phone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class Phone
:home

def initialize(attrs={})
@fax = attrs["fax"]
@main = attrs["main"]
@home = attrs["home"]
@fax = attrs["fax"]
@main = attrs["main"]
@home = attrs["home"]
end
end
end
34 changes: 18 additions & 16 deletions lib/learnsprout/school.rb
Original file line number Diff line number Diff line change
@@ -1,54 +1,56 @@
module LearnSprout
class School

attr_accessor :school_id,
attr_accessor :id, :school_id,
:name,
:number,
:nces,
:phone,
:address,
:time_updated
:time_updated,
:updated_at

def initialize(attrs={})
@client = attrs["client"]
@org_id = attrs["org_id"]
@school_id = attrs["id"]
@name = attrs["name"]
@number = attrs["number"]
@nces = Nces.new(attrs["nces"])
@phone = Phone.new(attrs["phone"])
@address = Address.new(attrs["address"])
@time_updated = attrs["time_updated"]
@client = attrs["client"]
@org_id = attrs["org_id"]
self.id = @school_id = attrs["id"]
@name = attrs["name"]
@number = attrs["number"]
@nces = Nces.new(attrs["nces"])
@phone = Phone.new(attrs["phone"]) if attrs["phone"]
@address = Address.new(attrs["address"])
@time_updated = attrs["time_updated"]
@updated_at = Time.at(@time_updated) if @time_updated
end

#TODO Add org method?

def student(student_id)
@client.student(@org_id, student_id)
@client.student(@org_id, student_id)
end

def students
@client.students(@org_id, :school_id => @school_id)
end

def section(section_id)
@client.section(@org_id, section_id)
@client.section(@org_id, section_id)
end

def sections
@client.sections(@org_id, :school_id => @school_id)
end

def teacher(teacher_id)
@client.teacher(@org_id, teacher_id)
@client.teacher(@org_id, teacher_id)
end

def teachers
@client.teachers(@org_id, :school_id => @school_id)
end

def term(term_id)
@client.term(@org_id, term_id)
@client.term(@org_id, term_id)
end

def terms
Expand All @@ -60,7 +62,7 @@ def current_term
end

def course(course_id)
@client.course(@org_id, course_id)
@client.course(@org_id, course_id)
end

def courses
Expand Down
54 changes: 30 additions & 24 deletions lib/learnsprout/section.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,62 @@
module LearnSprout
class Section

attr_accessor :term_id,
attr_accessor :id, :term_id,
:section_id,
:number,
:room,
:time_updated,
:teacher_id,
:school_id,
:course_id
:course_id,
:student_ids

def initialize(attrs={})
@client = attrs["client"]
@org_id = attrs["org_id"]
@section_id = attrs["id"]
@number = attrs["number"]
@room = attrs["room"]
@term_id = attrs["term"] && attrs["term"]["id"]
@teacher_id = attrs["teacher"] && attrs["teacher"]["id"]
@school_id = attrs["school"] && attrs["school"]["id"]
@course_id = attrs["course"] && attrs["course"]["id"]
@time_updated = attrs["time_updated"]
@student_ids = []
if attrs["students"]
attrs["students"].each do |student|
@student_ids.push student["id"]
end
@client = attrs["client"]
@org_id = attrs["org_id"]
self.id = @section_id = attrs["id"]
@number = attrs["number"]
@room = attrs["room"]
@term_id = attrs["term"] && attrs["term"]["id"]
@teacher_id = attrs["teacher"] && attrs["teacher"]["id"]
@school_id = attrs["school"] && attrs["school"]["id"]
@course_id = attrs["course"] && attrs["course"]["id"]
@time_updated = attrs["time_updated"]
@updated_at = Time.at(@time_updated) if @time_updated
@student_ids = []
if attrs["students"]
attrs["students"].each do |student|
if student.is_a?(Hash)
@student_ids.push student["id"]
else
@student_ids.push student
end
end
end
end

def term
@term_id && @client.term(@org_id, @term_id)
@term_id && @client.term(@org_id, @term_id)
end

def teacher
@teacher_id && @client.teacher(@org_id, @teacher_id)
@teacher_id && @client.teacher(@org_id, @teacher_id)
end

def school
@school_id && @client.school(@org_id, @school_id)
@school_id && @client.school(@org_id, @school_id)
end

def course
@course_id && @client.course(@org_id, @course_id)
@course_id && @client.course(@org_id, @course_id)
end

def students
temp_students = []
if @student_ids.count > 0
@student_ids.each do |student_id|
temp_students.push @client.student(@org_id, student_id)
end
@student_ids.each do |student_id|
temp_students.push @client.student(@org_id, student_id)
end
end
return temp_students
end
Expand Down
Loading