bridge_api 0.1.54 → 0.1.63
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -13
- data/README.md +17 -0
- data/bridge_api.gemspec +0 -1
- data/lib/bridge_api.rb +7 -5
- data/lib/bridge_api/api_array.rb +4 -2
- data/lib/bridge_api/client.rb +124 -56
- data/lib/bridge_api/client/account.rb +2 -1
- data/lib/bridge_api/client/affiliation.rb +13 -11
- data/lib/bridge_api/client/clone_object.rb +3 -3
- data/lib/bridge_api/client/course_template.rb +2 -0
- data/lib/bridge_api/client/custom_field.rb +2 -0
- data/lib/bridge_api/client/data_dump.rb +2 -0
- data/lib/bridge_api/client/enrollment.rb +2 -0
- data/lib/bridge_api/client/group.rb +2 -0
- data/lib/bridge_api/client/learner_item.rb +2 -0
- data/lib/bridge_api/client/live_course.rb +2 -0
- data/lib/bridge_api/client/live_course_enrollment.rb +2 -0
- data/lib/bridge_api/client/live_course_session.rb +3 -2
- data/lib/bridge_api/client/manager.rb +2 -0
- data/lib/bridge_api/client/program.rb +3 -1
- data/lib/bridge_api/client/program_enrollment.rb +6 -0
- data/lib/bridge_api/client/role.rb +2 -0
- data/lib/bridge_api/client/sub_account.rb +7 -1
- data/lib/bridge_api/client/user.rb +6 -5
- data/lib/bridge_api/version.rb +3 -1
- data/spec/bridge_api/client/account_spec.rb +6 -6
- data/spec/bridge_api/client/affiliations_spec.rb +3 -2
- data/spec/bridge_api/client/clone_object_spec.rb +8 -9
- data/spec/bridge_api/client/course_template_spec.rb +2 -0
- data/spec/bridge_api/client/custom_field_spec.rb +2 -0
- data/spec/bridge_api/client/data_dump_spec.rb +2 -0
- data/spec/bridge_api/client/enrollment_spec.rb +2 -0
- data/spec/bridge_api/client/group_spec.rb +2 -0
- data/spec/bridge_api/client/learner_items_spec.rb +2 -0
- data/spec/bridge_api/client/live_course_enrollments_spec.rb +2 -0
- data/spec/bridge_api/client/live_course_session_spec.rb +5 -3
- data/spec/bridge_api/client/live_course_spec.rb +2 -0
- data/spec/bridge_api/client/manager_spec.rb +2 -0
- data/spec/bridge_api/client/program_enrollment_spec.rb +7 -0
- data/spec/bridge_api/client/role_spec.rb +2 -0
- data/spec/bridge_api/client/sub_account_spec.rb +6 -4
- data/spec/bridge_api/client/user_spec.rb +2 -1
- data/spec/bridge_api/client_spec.rb +99 -5
- data/spec/support/fake_bridge.rb +8 -2
- data/spec/test_helper.rb +3 -1
- metadata +53 -68
@@ -1,15 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BridgeAPI
|
2
4
|
class Client
|
3
5
|
module CloneObject
|
4
|
-
|
5
6
|
def clone_objects(params = {})
|
6
7
|
post("#{API_PATH}#{ADMIN_PATH}#{CLONE_OBJECTS_PATH}", params)
|
7
8
|
end
|
8
9
|
|
9
|
-
def clone_object_status(id, params={})
|
10
|
+
def clone_object_status(id, params = {})
|
10
11
|
get("#{API_PATH}#{ADMIN_PATH}#{CLONE_OBJECTS_PATH}/#{id}", params)
|
11
12
|
end
|
12
|
-
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BridgeAPI
|
2
4
|
class Client
|
3
5
|
module LiveCourseSession
|
4
|
-
|
5
6
|
def get_live_course_sessions(live_course_id, params = {})
|
6
7
|
get("#{API_PATH}#{AUTHOR_PATH}#{LIVE_COURSES_PATH}/#{live_course_id}#{SESSIONS_PATH}", params)
|
7
8
|
end
|
@@ -35,4 +36,4 @@ module BridgeAPI
|
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
38
|
-
end
|
39
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BridgeAPI
|
2
4
|
class Client
|
3
5
|
# WARNING: the API endpoint for program enrollments is currently undocumented
|
@@ -9,6 +11,10 @@ module BridgeAPI
|
|
9
11
|
post("#{API_PATH}#{AUTHOR_PATH}#{PROGRAM_PATH}/#{program_id}#{PROGRAM_ENROLLMENT_PATH}", params)
|
10
12
|
end
|
11
13
|
|
14
|
+
def update_program_enrollment(program_id, program_enrollment_id, params = {})
|
15
|
+
put("#{API_PATH}#{AUTHOR_PATH}#{PROGRAM_PATH}/#{program_id}#{PROGRAM_ENROLLMENT_PATH}/#{program_enrollment_id}", params)
|
16
|
+
end
|
17
|
+
|
12
18
|
def delete_program_enrollment(program_id, enrollment_id, params = {})
|
13
19
|
delete("#{API_PATH}#{AUTHOR_PATH}#{PROGRAM_PATH}/#{program_id}#{PROGRAM_ENROLLMENT_PATH}/#{enrollment_id}", params)
|
14
20
|
end
|
@@ -1,8 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BridgeAPI
|
2
4
|
class Client
|
3
5
|
module SubAccount
|
4
6
|
def get_sub_accounts(params = {})
|
5
|
-
|
7
|
+
path = "#{API_PATH}#{ADMIN_PATH}#{SUB_ACCOUNT_PATH}"
|
8
|
+
RESULT_MAPPING[path] = {
|
9
|
+
meta: %w[data_dump_enabled data_dump_subaccount_enabled]
|
10
|
+
}
|
11
|
+
get(path, params)
|
6
12
|
end
|
7
13
|
|
8
14
|
def get_sub_account(subaccount_id, params = {})
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BridgeAPI
|
2
4
|
class Client
|
3
5
|
module User
|
@@ -53,15 +55,14 @@ module BridgeAPI
|
|
53
55
|
users = get_user(user_id, 'includes[]' => 'custom_fields')
|
54
56
|
payload = []
|
55
57
|
return payload if users.members.empty?
|
58
|
+
|
56
59
|
existing_values = users.linked['custom_field_values']
|
57
60
|
custom_field_values.each do |field_id, value|
|
58
61
|
field_value_id = begin
|
59
62
|
existing_values.find do |v|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
false
|
64
|
-
end
|
63
|
+
v['links']['custom_field']['id'] == field_id.to_s
|
64
|
+
rescue StandardError
|
65
|
+
false
|
65
66
|
end['id']
|
66
67
|
rescue StandardError
|
67
68
|
nil
|
data/lib/bridge_api/version.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe BridgeAPI::Client::CourseTemplate do
|
@@ -9,12 +11,10 @@ describe BridgeAPI::Client::CourseTemplate do
|
|
9
11
|
|
10
12
|
it 'should create an account' do
|
11
13
|
templates = @client.create_account(
|
12
|
-
{
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
name: 'subdomain'
|
17
|
-
}
|
14
|
+
sub_account: {
|
15
|
+
locale: 'en',
|
16
|
+
subdomain: 'subdomain',
|
17
|
+
name: 'subdomain'
|
18
18
|
}
|
19
19
|
)
|
20
20
|
expect(templates.status).to(eq(200))
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe BridgeAPI::Client::Affiliation do
|
@@ -6,7 +8,7 @@ describe BridgeAPI::Client::Affiliation do
|
|
6
8
|
end
|
7
9
|
|
8
10
|
it 'should list the affiliations' do
|
9
|
-
response = @client.list_affiliations(
|
11
|
+
response = @client.list_affiliations(item_id: 1, item_type: 'CourseTemple')
|
10
12
|
expect(response.status).to(eq(204))
|
11
13
|
end
|
12
14
|
|
@@ -14,5 +16,4 @@ describe BridgeAPI::Client::Affiliation do
|
|
14
16
|
response = @client.share_affiliations_batch
|
15
17
|
expect(response.status).to(eq(204))
|
16
18
|
end
|
17
|
-
|
18
19
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe BridgeAPI::Client::CloneObject do
|
@@ -7,14 +9,12 @@ describe BridgeAPI::Client::CloneObject do
|
|
7
9
|
|
8
10
|
it 'should clone an object' do
|
9
11
|
response = @client.clone_objects(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
]
|
17
|
-
}
|
12
|
+
clone_objects: [
|
13
|
+
{
|
14
|
+
source_type: 'CourseTemplate',
|
15
|
+
source_id: 1
|
16
|
+
}
|
17
|
+
]
|
18
18
|
).first
|
19
19
|
expect(response['destination_id']).to(eq(1))
|
20
20
|
end
|
@@ -23,5 +23,4 @@ describe BridgeAPI::Client::CloneObject do
|
|
23
23
|
response = @client.clone_object_status(1).first
|
24
24
|
expect(response['state']).to(eq('completed'))
|
25
25
|
end
|
26
|
-
|
27
26
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe BridgeAPI::Client::LiveCourseSession do
|
@@ -28,7 +30,7 @@ describe BridgeAPI::Client::LiveCourseSession do
|
|
28
30
|
end
|
29
31
|
|
30
32
|
it 'should delete a live course session in bridge' do
|
31
|
-
response = @client.delete_live_course_session(1,5)
|
33
|
+
response = @client.delete_live_course_session(1, 5)
|
32
34
|
expect(response.status).to eq(204)
|
33
35
|
end
|
34
36
|
|
@@ -45,7 +47,7 @@ describe BridgeAPI::Client::LiveCourseSession do
|
|
45
47
|
it 'should update web_conference' do
|
46
48
|
params = {
|
47
49
|
web_conference: {
|
48
|
-
provider:
|
50
|
+
provider: 'Bluejeans'
|
49
51
|
}
|
50
52
|
}
|
51
53
|
response = @client.update_web_conference(1, 5, params)
|
@@ -58,7 +60,7 @@ describe BridgeAPI::Client::LiveCourseSession do
|
|
58
60
|
end
|
59
61
|
|
60
62
|
it 'should get default web_conference config' do
|
61
|
-
response = @client.get_default_web_conference(
|
63
|
+
response = @client.get_default_web_conference(default_session: 1)
|
62
64
|
expect(response.status).to eq(200)
|
63
65
|
end
|
64
66
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe BridgeAPI::Client::ProgramEnrollment do
|
@@ -10,6 +12,11 @@ describe BridgeAPI::Client::ProgramEnrollment do
|
|
10
12
|
expect(response.status).to(eq(204))
|
11
13
|
end
|
12
14
|
|
15
|
+
it 'should udpate a program enrollment' do
|
16
|
+
response = @client.update_program_enrollment(1, 1)
|
17
|
+
expect(response.status).to(eq(200))
|
18
|
+
end
|
19
|
+
|
13
20
|
it 'should delete a program enrollment' do
|
14
21
|
response = @client.delete_program_enrollment(1, 2)
|
15
22
|
expect(response.status).to(eq(204))
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
describe BridgeAPI::Client::SubAccount do
|
@@ -35,19 +37,19 @@ describe BridgeAPI::Client::SubAccount do
|
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'should update the lti config' do
|
38
|
-
params = {lti_tool: {consumer_key:
|
40
|
+
params = { lti_tool: { consumer_key: 'YoooKey', shared_secret: SecureRandom.hex(16) } }
|
39
41
|
response = @client.update_sub_account_lti_config(2, 15, params)
|
40
42
|
expect(response.body['lti_tool']['id']).to(eq '20')
|
41
43
|
end
|
42
44
|
|
43
45
|
it 'should create new lti config' do
|
44
|
-
params = {lti_tool: {consumer_key:
|
45
|
-
response = @client.create_sub_account_lti_config(2,params)
|
46
|
+
params = { lti_tool: { consumer_key: 'SomeKey', shared_secret: SecureRandom.hex(16) } }
|
47
|
+
response = @client.create_sub_account_lti_config(2, params)
|
46
48
|
expect(response.status).to(eq 201)
|
47
49
|
end
|
48
50
|
|
49
51
|
it 'should delete a lti config' do
|
50
|
-
response = @client.delete_lti_config(2,15)
|
52
|
+
response = @client.delete_lti_config(2, 15)
|
51
53
|
expect(response.status).to(eq 204)
|
52
54
|
end
|
53
55
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
describe BridgeAPI::Client do
|
3
4
|
it 'should set the auth header to basic auth' do
|
@@ -12,20 +13,113 @@ describe BridgeAPI::Client do
|
|
12
13
|
|
13
14
|
it 'should set the meta property on client' do
|
14
15
|
client = BridgeAPI::Client.new(prefix: 'https://www.fake.com', token: 'test_token')
|
15
|
-
users
|
16
|
+
users = client.get_all_users
|
16
17
|
expect(users.meta['next']).to(eq('http://bridge.bridgeapp.com/api/author/users?after=eyJ0eXAiOiJKV1QiLCJhSDiQQ'))
|
17
18
|
end
|
18
19
|
|
19
20
|
it 'should set the linked property on client' do
|
20
21
|
client = BridgeAPI::Client.new(prefix: 'https://www.fake.com', token: 'test_token')
|
21
|
-
users
|
22
|
+
users = client.get_all_users
|
22
23
|
expect(users.linked['custom_fields'][0]['id']).to(eq('1'))
|
23
24
|
end
|
24
25
|
|
25
26
|
it 'should enforce rate limits' do
|
26
|
-
client
|
27
|
+
client = BridgeAPI::Client.new(prefix: 'https://www.fake.com', api_key: 'fake_token', api_secret: 'fake_secret')
|
27
28
|
BridgeAPI.enforce_rate_limits = true
|
28
|
-
users
|
29
|
-
users
|
29
|
+
users = client.get_all_users
|
30
|
+
users = client.get_all_users
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'initialize' do
|
34
|
+
it 'should set initial token when using a pool' do
|
35
|
+
expect_any_instance_of(BridgeAPI::Client).to receive(:initialize_from_token_pool).and_call_original
|
36
|
+
client = BridgeAPI::Client.new(prefix: 'https://www.fake.com', api_keys: { 'key1' => 'secret1', 'key2' => 'secret2' })
|
37
|
+
expect(client.config[:api_key]).to eq('key1')
|
38
|
+
expect(client.config[:api_secret]).to eq('secret1')
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should not call initialize_from_token_pool for a single token' do
|
42
|
+
expect_any_instance_of(BridgeAPI::Client).to_not receive(:initialize_from_token_pool)
|
43
|
+
BridgeAPI::Client.new(prefix: 'https://www.fake.com', api_key: 'fake_token', api_secret: 'fake_secret')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'has_token_pool?' do
|
48
|
+
it 'should return true for api keys' do
|
49
|
+
config = { prefix: 'https://www.fake.com', api_keys: { 'key1' => 'secret1', 'key2' => 'secret2' } }
|
50
|
+
client = BridgeAPI::Client.new(config)
|
51
|
+
expect(client.has_token_pool?(config)).to be_truthy
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should return true for tokens' do
|
55
|
+
config = { prefix: 'https://www.fake.com', api_tokens: %w[token1 token2] }
|
56
|
+
client = BridgeAPI::Client.new(config)
|
57
|
+
expect(client.has_token_pool?(config)).to be_truthy
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should return false for single key' do
|
61
|
+
config = { prefix: 'https://www.fake.com', api_key: 'fake_token', api_secret: 'fake_secret' }
|
62
|
+
client = BridgeAPI::Client.new(config)
|
63
|
+
expect(client.has_token_pool?(config)).to be_falsey
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'initialize_from_token_pool' do
|
68
|
+
it 'should take first from api keys' do
|
69
|
+
config = { prefix: 'https://www.fake.com', api_keys: { 'key1' => 'secret1', 'key2' => 'secret2' } }
|
70
|
+
client = BridgeAPI::Client.new(config)
|
71
|
+
new_config = client.initialize_from_token_pool(config)
|
72
|
+
expect(new_config[:api_key]).to eq('key1')
|
73
|
+
expect(new_config[:api_secret]).to eq('secret1')
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should take first from tokens' do
|
77
|
+
config = { prefix: 'https://www.fake.com', api_tokens: %w[token1 token2] }
|
78
|
+
client = BridgeAPI::Client.new(config)
|
79
|
+
new_config = client.initialize_from_token_pool(config)
|
80
|
+
expect(new_config[:token]).to eq('token1')
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'get_next_key' do
|
85
|
+
it 'should find next key' do
|
86
|
+
keys = { 'key1' => 'secret1', 'key2' => 'secret2' }
|
87
|
+
config = { prefix: 'https://www.fake.com', api_keys: keys }
|
88
|
+
client = BridgeAPI::Client.new(config)
|
89
|
+
expect(client.get_next_key(keys.keys, 'key1')).to eq('key2')
|
90
|
+
expect(client.get_next_key(keys.keys, 'key2')).to eq('key1')
|
91
|
+
expect(client.get_next_key(keys.keys, 'non-existent-key')).to eq('key1')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'rotate_token!' do
|
96
|
+
context 'with api key pool' do
|
97
|
+
it 'should rotate to the next key' do
|
98
|
+
keys = { 'key1' => 'secret1', 'key2' => 'secret2' }
|
99
|
+
config = { prefix: 'https://www.fake.com', api_keys: keys }
|
100
|
+
client = BridgeAPI::Client.new(config)
|
101
|
+
expect(client.config[:api_key]).to eq('key1')
|
102
|
+
expect(client.config[:api_secret]).to eq('secret1')
|
103
|
+
client.rotate_token!
|
104
|
+
expect(client.config[:api_key]).to eq('key2')
|
105
|
+
expect(client.config[:api_secret]).to eq('secret2')
|
106
|
+
client.rotate_token!
|
107
|
+
expect(client.config[:api_key]).to eq('key1')
|
108
|
+
expect(client.config[:api_secret]).to eq('secret1')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'with token pool' do
|
113
|
+
it 'should rotate to the next key' do
|
114
|
+
keys = %w[token1 token2]
|
115
|
+
config = { prefix: 'https://www.fake.com', api_tokens: keys }
|
116
|
+
client = BridgeAPI::Client.new(config)
|
117
|
+
expect(client.config[:token]).to eq('token1')
|
118
|
+
client.rotate_token!
|
119
|
+
expect(client.config[:token]).to eq('token2')
|
120
|
+
client.rotate_token!
|
121
|
+
expect(client.config[:token]).to eq('token1')
|
122
|
+
end
|
123
|
+
end
|
30
124
|
end
|
31
125
|
end
|