bridge_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/bridge_api.gemspec +30 -0
- data/lib/bridge_api.rb +2 -0
- data/lib/bridge_api/api_array.rb +122 -0
- data/lib/bridge_api/client.rb +30 -0
- data/lib/bridge_api/client/course_template.rb +31 -0
- data/lib/bridge_api/client/enrollment.rb +23 -0
- data/lib/bridge_api/client/user.rb +27 -0
- data/lib/bridge_api/version.rb +3 -0
- data/spec/bridge_api/client/course_template_spec.rb +44 -0
- data/spec/bridge_api/client/enrollment_spec.rb +31 -0
- data/spec/bridge_api/client/user_spec.rb +35 -0
- data/spec/fixtures/course.json +23 -0
- data/spec/fixtures/courses.json +41 -0
- data/spec/fixtures/enrollment.json +42 -0
- data/spec/fixtures/enrollments.json +58 -0
- data/spec/fixtures/programs.json +59 -0
- data/spec/fixtures/user.json +24 -0
- data/spec/fixtures/users.json +42 -0
- data/spec/support/fake_bridge.rb +90 -0
- data/spec/test_helper.rb +23 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 15c3b894f06ca9f65f91b19eb4cde98f2ef5c570
|
4
|
+
data.tar.gz: a369351fe7d85428b9a6fe90f71fc72b076bc962
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37eccbf695ba29433e660db1c93a516d1eb57ffecf41a9f0d05f89489597d04456bb2757e2709725ebbeca086f5263f6f9f328dce1c8ee44e773867b5b3e875a
|
7
|
+
data.tar.gz: b9c5fe4cf15c271badb1a3ca210fff894cb0648f7a8300835675870bd5e19c663a43abb1f3a18885648e39bf32f604af8e8b0e5385006a9e047719d79cb9ed68
|
data/.gitignore
ADDED
data/bridge_api.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'bridge_api/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.authors = ["Jay Shaffer"]
|
7
|
+
gem.email = ["jshaffer@instructure.com"]
|
8
|
+
gem.description = %q{Ruby gem for interacting with the bridge API}
|
9
|
+
gem.summary = %q{Bridge API}
|
10
|
+
gem.homepage = "https://getbridge.com"
|
11
|
+
gem.license = 'MIT'
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.files += Dir.glob("lib/**/*.rb")
|
15
|
+
gem.files += Dir.glob("spec/**/*")
|
16
|
+
gem.test_files = Dir.glob("spec/**/*")
|
17
|
+
gem.name = "bridge_api"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.version = BridgeAPI::VERSION
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rake', '~> 0'
|
22
|
+
gem.add_development_dependency 'bundler', '~> 1.0', '>= 1.0.0'
|
23
|
+
gem.add_development_dependency 'rspec', '~> 2.6'
|
24
|
+
gem.add_development_dependency 'webmock', '~> 0'
|
25
|
+
gem.add_development_dependency 'pry', '~> 0'
|
26
|
+
gem.add_development_dependency 'tilt', '>= 1.3.4', '~> 1.3'
|
27
|
+
|
28
|
+
gem.add_dependency 'footrest', '~> 0.2', '>= 0.2.2'
|
29
|
+
|
30
|
+
end
|
data/lib/bridge_api.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
|
2
|
+
module BridgeAPI
|
3
|
+
class ApiArray
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
@next_page = nil
|
7
|
+
@prev_page = nil
|
8
|
+
|
9
|
+
META_FIELDS = %w(meta linked).freeze
|
10
|
+
|
11
|
+
attr_reader :status, :headers, :members
|
12
|
+
|
13
|
+
def self.process_response(response, api_client)
|
14
|
+
ApiArray.new(response, api_client)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(response, api_client)
|
18
|
+
@api_client = api_client
|
19
|
+
case response.status
|
20
|
+
when 200..206
|
21
|
+
apply_response_metadata(response)
|
22
|
+
@members = get_response_content(response)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def length
|
27
|
+
@members.length
|
28
|
+
end
|
29
|
+
|
30
|
+
def [](i)
|
31
|
+
@members[i]
|
32
|
+
end
|
33
|
+
|
34
|
+
def last
|
35
|
+
@members.last
|
36
|
+
end
|
37
|
+
|
38
|
+
def each(&block)
|
39
|
+
@members.each { |member| block.call(member) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def pages?
|
43
|
+
!@next_page.nil?
|
44
|
+
end
|
45
|
+
|
46
|
+
def next_page
|
47
|
+
load_page(@next_page)
|
48
|
+
end
|
49
|
+
|
50
|
+
def each_page(&block)
|
51
|
+
block.call(@members)
|
52
|
+
while @next_page
|
53
|
+
response = get_page(@next_page)
|
54
|
+
apply_response_metadata(response)
|
55
|
+
block.call(@members)
|
56
|
+
end
|
57
|
+
@link_hash = {}
|
58
|
+
end
|
59
|
+
|
60
|
+
def all_pages!
|
61
|
+
if pages?
|
62
|
+
response = get_page(@next_page)
|
63
|
+
apply_response_metadata(response)
|
64
|
+
@members.concat(get_response_content(response))
|
65
|
+
while @next_page
|
66
|
+
response = get_page(@next_page)
|
67
|
+
apply_response_metadata(response)
|
68
|
+
@members.concat(get_response_content(response))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
self
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def get_page(url, params = {})
|
77
|
+
query = URI.parse(url).query
|
78
|
+
p = CGI.parse(query).merge(params)
|
79
|
+
u = url.gsub("?#{query}", '')
|
80
|
+
p.each { |k, v| p[k] = v.first if v.is_a?(Array) }
|
81
|
+
@api_client.connection.send(:get) do |r|
|
82
|
+
r.url(u, p)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def load_page(url)
|
87
|
+
response = get_page(url)
|
88
|
+
ApiArray.process_response(response, @api_client)
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_response_content(response)
|
92
|
+
if response.body.is_a?(Hash)
|
93
|
+
content = response.body.reject{|k, v| META_FIELDS.include?(k)}
|
94
|
+
if content.length > 0
|
95
|
+
return content.values[0]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
[]
|
99
|
+
end
|
100
|
+
|
101
|
+
def apply_response_metadata(response)
|
102
|
+
@status = response.status
|
103
|
+
@headers = response.headers
|
104
|
+
@method = response.env[:method]
|
105
|
+
init_pages(response)
|
106
|
+
end
|
107
|
+
|
108
|
+
def init_pages(response)
|
109
|
+
@next_page = nil
|
110
|
+
@prev_page = nil
|
111
|
+
if response.body.is_a?(Hash) && response.body.key?('meta')
|
112
|
+
if response.body['meta'].key?('next')
|
113
|
+
@next_page = response.body['meta']['next']
|
114
|
+
end
|
115
|
+
if response.body['meta'].key?('prev')
|
116
|
+
@prev_page = response.body['meta']['prev']
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'footrest/client'
|
2
|
+
|
3
|
+
module BridgeAPI
|
4
|
+
class Client < Footrest::Client
|
5
|
+
|
6
|
+
COURSE_TEMPLATE_PATH = '/course_templates'
|
7
|
+
ENROLLMENT_PATH = '/enrollments'
|
8
|
+
USER_PATH = '/users'
|
9
|
+
ADMIN_PATH = "/admin"
|
10
|
+
AUTHOR_PATH = "/author"
|
11
|
+
LEARNER_PATH = "/learner"
|
12
|
+
API_VERSION = 1
|
13
|
+
API_PATH = '/api'
|
14
|
+
|
15
|
+
require 'bridge_api/api_array'
|
16
|
+
|
17
|
+
Dir[File.dirname(__FILE__) + '/client/*.rb'].each {|file| require file }
|
18
|
+
|
19
|
+
include CourseTemplate
|
20
|
+
include Enrollment
|
21
|
+
include User
|
22
|
+
|
23
|
+
# Override Footrest request for ApiArray support
|
24
|
+
def request(method, &block)
|
25
|
+
ApiArray::process_response(connection.send(method, &block), self)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module BridgeAPI
|
2
|
+
class Client
|
3
|
+
module CourseTemplate
|
4
|
+
|
5
|
+
def get_all_course_templates(params = {})
|
6
|
+
get("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}", params)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_course_template(params = {})
|
10
|
+
post("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}", params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_course_template(course_template_id, params = {})
|
14
|
+
delete("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}/#{course_template_id}", params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def publish_course_template(course_template_id, params = {})
|
18
|
+
post("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}/#{course_template_id}/publish", params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_course_template(course_template_id, params = {})
|
22
|
+
get("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}/#{course_template_id}", params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_course_template(course_template_id, params = {})
|
26
|
+
put("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}/#{course_template_id}", params)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module BridgeAPI
|
2
|
+
class Client
|
3
|
+
module Enrollment
|
4
|
+
|
5
|
+
def add_enrollment(course_template_id, params = {})
|
6
|
+
post("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}/#{course_template_id}#{ENROLLMENT_PATH}", params)
|
7
|
+
end
|
8
|
+
|
9
|
+
def delete_enrollment(enrollment_id, params = {})
|
10
|
+
delete("#{API_PATH}#{AUTHOR_PATH}#{ENROLLMENT_PATH}/#{enrollment_id}", params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def update_enrollment(enrollment_id, params = {})
|
14
|
+
put("#{API_PATH}#{AUTHOR_PATH}#{ENROLLMENT_PATH}/#{enrollment_id}", params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_all_enrollments(course_template_id, params = {})
|
18
|
+
get("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}/#{course_template_id}#{ENROLLMENT_PATH}", params)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module BridgeAPI
|
2
|
+
class Client
|
3
|
+
module User
|
4
|
+
|
5
|
+
def add_user(params = {})
|
6
|
+
post("#{API_PATH}#{ADMIN_PATH}#{USER_PATH}", params)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_user(user_id, params = {})
|
10
|
+
get("#{API_PATH}#{AUTHOR_PATH}#{USER_PATH}/#{user_id}", params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_user(user_id, params = {})
|
14
|
+
delete("#{API_PATH}#{ADMIN_PATH}#{USER_PATH}/#{user_id}", params)
|
15
|
+
end
|
16
|
+
|
17
|
+
def update_user(user_id, params = {})
|
18
|
+
put("#{API_PATH}#{AUTHOR_PATH}#{USER_PATH}/#{user_id}", params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_all_users(params = {})
|
22
|
+
get("#{API_PATH}#{AUTHOR_PATH}#{USER_PATH}", params)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe BridgeAPI::Client::CourseTemplate do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should get all course templates' do
|
10
|
+
templates = @client.get_all_course_templates.all_pages!
|
11
|
+
expect(templates.count).to(eq(2))
|
12
|
+
expect(templates.first['title']).to(eq('My Test Course'))
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should create a course template' do
|
16
|
+
template = @client.create_course_template
|
17
|
+
expect(template.count).to(eq(1))
|
18
|
+
expect(template.first['title']).to(eq('My only course'))
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should delete a course' do
|
22
|
+
response = @client.delete_course_template(1)
|
23
|
+
expect(response.status).to(eq(204))
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should publish a course' do
|
27
|
+
template = @client.publish_course_template(1)
|
28
|
+
expect(template.count).to(eq(1))
|
29
|
+
expect(template.first['title']).to(eq('My only course'))
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should get a single course template' do
|
33
|
+
template = @client.get_course_template(1)
|
34
|
+
expect(template.count).to(eq(1))
|
35
|
+
expect(template.first['title']).to(eq('My only course'))
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should update a course template' do
|
39
|
+
template = @client.update_course_template(1)
|
40
|
+
expect(template.count).to(eq(1))
|
41
|
+
expect(template.first['title']).to(eq('My only course'))
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe BridgeAPI::Client::Enrollment do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should add an enrollment' do
|
10
|
+
response = @client.add_enrollment(1)
|
11
|
+
expect(response.status).to(eq(204))
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should delete an enrollment' do
|
15
|
+
response = @client.delete_enrollment(1)
|
16
|
+
expect(response.status).to(eq(204))
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should update an enrollment' do
|
21
|
+
enrollment = @client.update_enrollment(1)
|
22
|
+
expect(enrollment.first['id']).to(eq("3"))
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should get all enrollments' do
|
26
|
+
enrollments = @client.get_all_enrollments(1)
|
27
|
+
expect(enrollments.length).to(eq(2))
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe BridgeAPI::Client::User do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should add an user' do
|
10
|
+
response = @client.add_user
|
11
|
+
expect(response.first['id']).to(eq("10"))
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should get a user' do
|
15
|
+
response = @client.get_user(1)
|
16
|
+
expect(response.first['id']).to(eq("10"))
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should delete an user' do
|
20
|
+
response = @client.delete_user(1)
|
21
|
+
expect(response.status).to(eq(204))
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should update a user' do
|
25
|
+
response = @client.update_user(1)
|
26
|
+
expect(response.first['id']).to(eq("10"))
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should get all users' do
|
30
|
+
response = @client.get_all_users
|
31
|
+
expect(response.length).to(eq(2))
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
{
|
2
|
+
"meta": {},
|
3
|
+
"course_templates": [
|
4
|
+
{
|
5
|
+
"id": "1",
|
6
|
+
"estimated_time": 1,
|
7
|
+
"passing_threshold": 80,
|
8
|
+
"title": "My only course",
|
9
|
+
"is_published": true,
|
10
|
+
"has_unpublished_changes": false,
|
11
|
+
"default_days_until_due": 7,
|
12
|
+
"has_certificate": false,
|
13
|
+
"program_ids": ["3", "4"],
|
14
|
+
"external_status": "inapplicable",
|
15
|
+
"course_type":"bridge",
|
16
|
+
"enrollments_count": 2,
|
17
|
+
"next_section_due": "2015-07-07T23:59:59.000Z",
|
18
|
+
"links": {
|
19
|
+
"author": "1"
|
20
|
+
}
|
21
|
+
}
|
22
|
+
]
|
23
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
{
|
2
|
+
"meta": {},
|
3
|
+
"course_templates": [
|
4
|
+
{
|
5
|
+
"id": "1",
|
6
|
+
"estimated_time": 1,
|
7
|
+
"passing_threshold": 80,
|
8
|
+
"title": "My Test Course",
|
9
|
+
"is_published": true,
|
10
|
+
"has_unpublished_changes": false,
|
11
|
+
"default_days_until_due": 7,
|
12
|
+
"has_certificate": false,
|
13
|
+
"program_ids": ["3", "4"],
|
14
|
+
"external_status": "inapplicable",
|
15
|
+
"course_type":"bridge",
|
16
|
+
"enrollments_count": 2,
|
17
|
+
"next_section_due": "2015-07-07T23:59:59.000Z",
|
18
|
+
"links": {
|
19
|
+
"author": "1"
|
20
|
+
}
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"id": "2",
|
24
|
+
"estimated_time": 1,
|
25
|
+
"passing_threshold": 80,
|
26
|
+
"title": "My second test Course",
|
27
|
+
"is_published": true,
|
28
|
+
"has_unpublished_changes": false,
|
29
|
+
"default_days_until_due": 7,
|
30
|
+
"has_certificate": false,
|
31
|
+
"program_ids": ["3", "4"],
|
32
|
+
"external_status": "inapplicable",
|
33
|
+
"course_type":"bridge",
|
34
|
+
"enrollments_count": 2,
|
35
|
+
"next_section_due": "2015-07-07T23:59:59.000Z",
|
36
|
+
"links": {
|
37
|
+
"author": "1"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
]
|
41
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
{
|
2
|
+
"meta": {},
|
3
|
+
"linked": {
|
4
|
+
"course_templates": [
|
5
|
+
{
|
6
|
+
"id": "2"
|
7
|
+
}
|
8
|
+
],
|
9
|
+
"learners": [
|
10
|
+
{
|
11
|
+
"id": "15",
|
12
|
+
"name": "John Smith",
|
13
|
+
"avatar_url": null,
|
14
|
+
"deleted": false
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"id": "11",
|
18
|
+
"name": "jshaffer@instructure.com",
|
19
|
+
"avatar_url": null,
|
20
|
+
"deleted": false
|
21
|
+
}
|
22
|
+
]
|
23
|
+
},
|
24
|
+
"enrollments": [
|
25
|
+
{
|
26
|
+
"id": "3",
|
27
|
+
"course_template": "2",
|
28
|
+
"end_at": "2015-12-29T23:59:59.000-07:00",
|
29
|
+
"progress": 0,
|
30
|
+
"can_be_removed": true,
|
31
|
+
"completed_at": null,
|
32
|
+
"score": 0,
|
33
|
+
"state": "created",
|
34
|
+
"links": {
|
35
|
+
"learner": {
|
36
|
+
"type": "learners",
|
37
|
+
"id": "11"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
]
|
42
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
{
|
2
|
+
"meta": {},
|
3
|
+
"linked": {
|
4
|
+
"course_templates": [
|
5
|
+
{
|
6
|
+
"id": "2"
|
7
|
+
}
|
8
|
+
],
|
9
|
+
"learners": [
|
10
|
+
{
|
11
|
+
"id": "15",
|
12
|
+
"name": "John Smith",
|
13
|
+
"avatar_url": null,
|
14
|
+
"deleted": false
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"id": "11",
|
18
|
+
"name": "jshaffer@instructure.com",
|
19
|
+
"avatar_url": null,
|
20
|
+
"deleted": false
|
21
|
+
}
|
22
|
+
]
|
23
|
+
},
|
24
|
+
"enrollments": [
|
25
|
+
{
|
26
|
+
"id": "2",
|
27
|
+
"course_template": "2",
|
28
|
+
"end_at": "2015-12-29T23:59:59.000-07:00",
|
29
|
+
"progress": 0,
|
30
|
+
"can_be_removed": true,
|
31
|
+
"completed_at": null,
|
32
|
+
"score": 0,
|
33
|
+
"state": "created",
|
34
|
+
"links": {
|
35
|
+
"learner": {
|
36
|
+
"type": "learners",
|
37
|
+
"id": "11"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
},
|
41
|
+
{
|
42
|
+
"id": "34",
|
43
|
+
"course_template": "2",
|
44
|
+
"end_at": "2016-02-29T23:59:59.000-07:00",
|
45
|
+
"progress": 0,
|
46
|
+
"can_be_removed": true,
|
47
|
+
"completed_at": null,
|
48
|
+
"score": 0,
|
49
|
+
"state": "created",
|
50
|
+
"links": {
|
51
|
+
"learner": {
|
52
|
+
"type": "learners",
|
53
|
+
"id": "15"
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
{
|
2
|
+
"meta": {},
|
3
|
+
"programs": [
|
4
|
+
{
|
5
|
+
"id": "1",
|
6
|
+
"title": "New Program",
|
7
|
+
"course_count": 0,
|
8
|
+
"unfinished_learners_count": 0,
|
9
|
+
"next_due_at": null,
|
10
|
+
"overdue_learners_count": null,
|
11
|
+
"is_published": true,
|
12
|
+
"publishable": true,
|
13
|
+
"has_unpublished_changes": false,
|
14
|
+
"assignment_period": 0,
|
15
|
+
"sub_account": {
|
16
|
+
"id": 1,
|
17
|
+
"name": "chrisc",
|
18
|
+
"not_current": false
|
19
|
+
},
|
20
|
+
"course_templates": [
|
21
|
+
{
|
22
|
+
"id": "1",
|
23
|
+
"estimated_time": 1,
|
24
|
+
"passing_threshold": 80,
|
25
|
+
"default_days_until_due": 7,
|
26
|
+
"title": "Test Course 1",
|
27
|
+
"is_published": true
|
28
|
+
}
|
29
|
+
]
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"id": "2",
|
33
|
+
"title": "New Program 2",
|
34
|
+
"course_count": 0,
|
35
|
+
"unfinished_learners_count": 0,
|
36
|
+
"next_due_at": null,
|
37
|
+
"overdue_learners_count": null,
|
38
|
+
"is_published": true,
|
39
|
+
"publishable": true,
|
40
|
+
"has_unpublished_changes": false,
|
41
|
+
"assignment_period": 0,
|
42
|
+
"sub_account": {
|
43
|
+
"id": 1,
|
44
|
+
"name": "chrisc",
|
45
|
+
"not_current": false
|
46
|
+
},
|
47
|
+
"course_templates": [
|
48
|
+
{
|
49
|
+
"id": "2",
|
50
|
+
"estimated_time": 1,
|
51
|
+
"passing_threshold": 80,
|
52
|
+
"default_days_until_due": 7,
|
53
|
+
"title": "Test Course 1",
|
54
|
+
"is_published": true
|
55
|
+
}
|
56
|
+
]
|
57
|
+
}
|
58
|
+
]
|
59
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"meta": {},
|
3
|
+
"linked": {},
|
4
|
+
"users": [
|
5
|
+
{
|
6
|
+
"id": "10",
|
7
|
+
"uid": "testuser",
|
8
|
+
"first_name": "test",
|
9
|
+
"last_name": "mcfake",
|
10
|
+
"email": "test@test.com",
|
11
|
+
"roles": [],
|
12
|
+
"name": "Brandon Broshinsky",
|
13
|
+
"avatar_url": null,
|
14
|
+
"deleted_at": null,
|
15
|
+
"unsubscribed": null,
|
16
|
+
"welcomedAt": "2015-09-28T14:03:43.771-06:00",
|
17
|
+
"loggedInAt": null,
|
18
|
+
"links": {},
|
19
|
+
"meta": {
|
20
|
+
"can_masquerade": true
|
21
|
+
}
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
{
|
2
|
+
"meta": {},
|
3
|
+
"linked": {},
|
4
|
+
"users": [
|
5
|
+
{
|
6
|
+
"id": "9",
|
7
|
+
"uid": "brandonbr",
|
8
|
+
"first_name": "test",
|
9
|
+
"last_name": "mcfake",
|
10
|
+
"email": "test@test.com",
|
11
|
+
"roles": [],
|
12
|
+
"name": "Brandon Broshinsky",
|
13
|
+
"avatar_url": null,
|
14
|
+
"deleted_at": null,
|
15
|
+
"unsubscribed": null,
|
16
|
+
"welcomedAt": "2015-09-28T14:03:43.771-06:00",
|
17
|
+
"loggedInAt": null,
|
18
|
+
"links": {},
|
19
|
+
"meta": {
|
20
|
+
"can_masquerade": true
|
21
|
+
}
|
22
|
+
},
|
23
|
+
{
|
24
|
+
"id": "4",
|
25
|
+
"uid": "jfarnworth+bridgetest1@instructure.com",
|
26
|
+
"first_name": "Jtest",
|
27
|
+
"last_name": "Ftest",
|
28
|
+
"email": "jfarnworth+bridgetest1@instructure.com",
|
29
|
+
"roles": [],
|
30
|
+
"name": "Jtest Ftest",
|
31
|
+
"avatar_url": null,
|
32
|
+
"deleted_at": null,
|
33
|
+
"unsubscribed": null,
|
34
|
+
"welcomedAt": "2015-09-08T15:56:36.307-06:00",
|
35
|
+
"loggedInAt": "2015-07-17T00:00:00.000-06:00",
|
36
|
+
"links": {},
|
37
|
+
"meta": {
|
38
|
+
"can_masquerade": true
|
39
|
+
}
|
40
|
+
}
|
41
|
+
]
|
42
|
+
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'tilt'
|
3
|
+
|
4
|
+
class FakeBridge < Sinatra::Base
|
5
|
+
|
6
|
+
## Course Templates
|
7
|
+
|
8
|
+
get %r{/api/author/course_templates$} do
|
9
|
+
get_json_data 200, 'courses.json'
|
10
|
+
end
|
11
|
+
|
12
|
+
get %r{/api/author/course_templates/\d+$} do
|
13
|
+
get_json_data 200, 'course.json'
|
14
|
+
end
|
15
|
+
|
16
|
+
post %r{/api/author/course_templates$} do
|
17
|
+
get_json_data 200, 'course.json'
|
18
|
+
end
|
19
|
+
|
20
|
+
post %r{/api/author/course_templates/\d+/publish$} do
|
21
|
+
get_json_data 200, 'course.json'
|
22
|
+
end
|
23
|
+
|
24
|
+
put %r{/api/author/course_templates/\d+$} do
|
25
|
+
get_json_data 200, 'course.json'
|
26
|
+
end
|
27
|
+
|
28
|
+
delete %r{/api/author/course_templates/\d+$} do
|
29
|
+
get_json_data 204, nil
|
30
|
+
end
|
31
|
+
|
32
|
+
## Programs
|
33
|
+
|
34
|
+
get %r{/api/author/programs.*$} do
|
35
|
+
get_json_data 200, 'programs.json'
|
36
|
+
end
|
37
|
+
|
38
|
+
## Users
|
39
|
+
|
40
|
+
get %r{/api/author/users$} do
|
41
|
+
get_json_data 200, 'users.json'
|
42
|
+
end
|
43
|
+
|
44
|
+
get %r{/api/author/users/\d+$} do
|
45
|
+
get_json_data 200, 'user.json'
|
46
|
+
end
|
47
|
+
|
48
|
+
put %r{/api/author/users/\d+$} do
|
49
|
+
get_json_data 200, 'user.json'
|
50
|
+
end
|
51
|
+
|
52
|
+
post %r{/api/admin/users$} do
|
53
|
+
get_json_data 200, 'user.json'
|
54
|
+
end
|
55
|
+
|
56
|
+
delete %r{/api/admin/users/\d+$} do
|
57
|
+
get_json_data 204, nil
|
58
|
+
end
|
59
|
+
|
60
|
+
## Enrollments
|
61
|
+
|
62
|
+
post %r{/api/author/course_templates/\d+/enrollments$} do
|
63
|
+
get_json_data 204, nil
|
64
|
+
end
|
65
|
+
|
66
|
+
get %r{/api/author/course_templates/\d+/enrollments$} do
|
67
|
+
get_json_data 200, 'enrollments.json'
|
68
|
+
end
|
69
|
+
|
70
|
+
delete %r{/api/author/enrollments.*$} do
|
71
|
+
get_json_data 204, nil
|
72
|
+
end
|
73
|
+
|
74
|
+
put %r{/api/author/enrollments.*$} do
|
75
|
+
get_json_data 200, 'enrollment.json'
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def get_json_data(response_code, file_name)
|
81
|
+
content_type :json
|
82
|
+
status response_code
|
83
|
+
unless file_name.nil?
|
84
|
+
File.open(File.dirname(__FILE__) + '/../fixtures/' + file_name).read
|
85
|
+
else
|
86
|
+
{}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/spec/test_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'bridge_api'
|
2
|
+
require 'rspec'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'json'
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
|
9
|
+
|
10
|
+
config.before(:each) do
|
11
|
+
WebMock.disable_net_connect!
|
12
|
+
WebMock.stub_request(:any, /api\/.*/).to_rack(FakeBridge)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def fixture(*file)
|
18
|
+
File.new(File.join(File.expand_path("../fixtures", __FILE__), *file))
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bridge_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jay Shaffer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.0.0
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.6'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.6'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: webmock
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: pry
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: tilt
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: 1.3.4
|
96
|
+
- - "~>"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '1.3'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 1.3.4
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '1.3'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: footrest
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0.2'
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 0.2.2
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - "~>"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0.2'
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: 0.2.2
|
129
|
+
description: Ruby gem for interacting with the bridge API
|
130
|
+
email:
|
131
|
+
- jshaffer@instructure.com
|
132
|
+
executables: []
|
133
|
+
extensions: []
|
134
|
+
extra_rdoc_files: []
|
135
|
+
files:
|
136
|
+
- ".gitignore"
|
137
|
+
- bridge_api.gemspec
|
138
|
+
- lib/bridge_api.rb
|
139
|
+
- lib/bridge_api/api_array.rb
|
140
|
+
- lib/bridge_api/client.rb
|
141
|
+
- lib/bridge_api/client/course_template.rb
|
142
|
+
- lib/bridge_api/client/enrollment.rb
|
143
|
+
- lib/bridge_api/client/user.rb
|
144
|
+
- lib/bridge_api/version.rb
|
145
|
+
- spec/bridge_api/client/course_template_spec.rb
|
146
|
+
- spec/bridge_api/client/enrollment_spec.rb
|
147
|
+
- spec/bridge_api/client/user_spec.rb
|
148
|
+
- spec/fixtures/course.json
|
149
|
+
- spec/fixtures/courses.json
|
150
|
+
- spec/fixtures/enrollment.json
|
151
|
+
- spec/fixtures/enrollments.json
|
152
|
+
- spec/fixtures/programs.json
|
153
|
+
- spec/fixtures/user.json
|
154
|
+
- spec/fixtures/users.json
|
155
|
+
- spec/support/fake_bridge.rb
|
156
|
+
- spec/test_helper.rb
|
157
|
+
homepage: https://getbridge.com
|
158
|
+
licenses:
|
159
|
+
- MIT
|
160
|
+
metadata: {}
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.4.3
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Bridge API
|
181
|
+
test_files:
|
182
|
+
- spec/bridge_api/client/course_template_spec.rb
|
183
|
+
- spec/bridge_api/client/enrollment_spec.rb
|
184
|
+
- spec/bridge_api/client/user_spec.rb
|
185
|
+
- spec/fixtures/course.json
|
186
|
+
- spec/fixtures/courses.json
|
187
|
+
- spec/fixtures/enrollment.json
|
188
|
+
- spec/fixtures/enrollments.json
|
189
|
+
- spec/fixtures/programs.json
|
190
|
+
- spec/fixtures/user.json
|
191
|
+
- spec/fixtures/users.json
|
192
|
+
- spec/support/fake_bridge.rb
|
193
|
+
- spec/test_helper.rb
|
194
|
+
has_rdoc:
|