bridge_api 0.1.20 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +14 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +4 -4
  5. data/bin/jenkins +17 -0
  6. data/bridge_api.gemspec +18 -19
  7. data/build.sh +5 -0
  8. data/docker-compose.yml +18 -0
  9. data/lib/bridge_api/api_array.rb +22 -30
  10. data/lib/bridge_api/client.rb +23 -22
  11. data/lib/bridge_api/client/account.rb +9 -0
  12. data/lib/bridge_api/client/course_template.rb +0 -2
  13. data/lib/bridge_api/client/custom_field.rb +0 -2
  14. data/lib/bridge_api/client/enrollment.rb +0 -2
  15. data/lib/bridge_api/client/live_course.rb +0 -2
  16. data/lib/bridge_api/client/live_course_enrollment.rb +0 -2
  17. data/lib/bridge_api/client/manager.rb +1 -3
  18. data/lib/bridge_api/client/role.rb +1 -3
  19. data/lib/bridge_api/client/sub_account.rb +4 -0
  20. data/lib/bridge_api/client/user.rb +15 -10
  21. data/lib/bridge_api/version.rb +1 -1
  22. data/spec/bridge_api/client/account_spec.rb +14 -0
  23. data/spec/bridge_api/client/course_template_spec.rb +1 -3
  24. data/spec/bridge_api/client/custom_field_spec.rb +4 -7
  25. data/spec/bridge_api/client/data_dump_spec.rb +1 -1
  26. data/spec/bridge_api/client/enrollment_spec.rb +3 -7
  27. data/spec/bridge_api/client/group_spec.rb +3 -3
  28. data/spec/bridge_api/client/live_course_enrollments_spec.rb +1 -1
  29. data/spec/bridge_api/client/live_course_spec.rb +2 -2
  30. data/spec/bridge_api/client/manager_spec.rb +4 -6
  31. data/spec/bridge_api/client/program_enrollment_spec.rb +1 -1
  32. data/spec/bridge_api/client/sub_account_spec.rb +2 -4
  33. data/spec/bridge_api/client/user_spec.rb +6 -9
  34. data/spec/bridge_api/client_spec.rb +7 -10
  35. data/spec/fixtures/accounts.json +129 -0
  36. data/spec/support/fake_bridge.rb +16 -9
  37. data/spec/test_helper.rb +2 -7
  38. metadata +50 -41
@@ -1,7 +1,6 @@
1
1
  module BridgeAPI
2
2
  class Client
3
3
  module Role
4
-
5
4
  def get_all_roles(params = {})
6
5
  get("#{API_PATH}#{AUTHOR_PATH}#{ROLE_PATH}", params)
7
6
  end
@@ -9,7 +8,6 @@ module BridgeAPI
9
8
  def get_role(role_id, params = {})
10
9
  get("#{API_PATH}#{AUTHOR_PATH}#{ROLE_PATH}/#{role_id}", params)
11
10
  end
12
-
13
11
  end
14
12
  end
15
- end
13
+ end
@@ -5,6 +5,10 @@ module BridgeAPI
5
5
  get("#{API_PATH}#{ADMIN_PATH}#{SUB_ACCOUNT_PATH}", params)
6
6
  end
7
7
 
8
+ def update_subaccount(subaccount_id, params = {})
9
+ put("#{API_PATH}#{ADMIN_PATH}#{SUB_ACCOUNT_PATH}/#{subaccount_id}", params)
10
+ end
11
+
8
12
  def share_course_with_subaccount(course_template_id, params = {})
9
13
  put("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}/#{course_template_id}/#{SUB_ACCOUNT_PATH}/share", params)
10
14
  end
@@ -1,7 +1,6 @@
1
1
  module BridgeAPI
2
2
  class Client
3
3
  module User
4
-
5
4
  def add_user(params = {})
6
5
  post("#{API_PATH}#{ADMIN_PATH}#{USER_PATH}", params)
7
6
  end
@@ -43,20 +42,26 @@ module BridgeAPI
43
42
  # '2': 'Another Custom Value'
44
43
  # }
45
44
  def build_custom_values_payload(user_id, custom_field_values)
46
- users = self.get_user(user_id, {'includes[]' => 'custom_fields'})
45
+ users = get_user(user_id, 'includes[]' => 'custom_fields')
47
46
  payload = []
48
- return payload unless users.members.size > 0
47
+ return payload if users.members.empty?
49
48
  existing_values = users.linked['custom_field_values']
50
49
  custom_field_values.each do |field_id, value|
51
- field_value_id = existing_values.find {|v|
52
- v['links']['custom_field']['id'] == field_id.to_s rescue false
53
- }['id'] rescue nil
54
- payload << {'id' => field_value_id, 'custom_field_id' => field_id, 'value' => value}
50
+ field_value_id = begin
51
+ existing_values.find do |v|
52
+ begin
53
+ v['links']['custom_field']['id'] == field_id.to_s
54
+ rescue StandardError
55
+ false
56
+ end
57
+ end['id']
58
+ rescue StandardError
59
+ nil
60
+ end
61
+ payload << { 'id' => field_value_id, 'custom_field_id' => field_id, 'value' => value }
55
62
  end
56
63
  payload
57
64
  end
58
-
59
65
  end
60
-
61
66
  end
62
- end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module BridgeAPI
2
- VERSION = '0.1.20' unless defined?(BridgeAPI::VERSION)
2
+ VERSION = '0.1.21'.freeze unless defined?(BridgeAPI::VERSION)
3
3
  end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ describe BridgeAPI::Client::CourseTemplate do
4
+ before do
5
+ @client = BridgeAPI::Client.new(
6
+ prefix: 'http://test.bridge.com', token: 'test_token'
7
+ )
8
+ end
9
+
10
+ it 'should update an account' do
11
+ templates = @client.update_account(1)
12
+ expect(templates.status).to(eq(200))
13
+ end
14
+ end
@@ -1,9 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe BridgeAPI::Client::CourseTemplate do
4
-
5
4
  before do
6
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
7
6
  end
8
7
 
9
8
  it 'should get all course templates' do
@@ -40,5 +39,4 @@ describe BridgeAPI::Client::CourseTemplate do
40
39
  expect(template.count).to(eq(1))
41
40
  expect(template.first['title']).to(eq('My only course'))
42
41
  end
43
-
44
42
  end
@@ -1,19 +1,18 @@
1
1
  require 'test_helper'
2
2
  require 'byebug'
3
3
  describe BridgeAPI::Client::CustomField do
4
-
5
4
  before do
6
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
7
6
  end
8
7
 
9
8
  it 'should add an custom field' do
10
9
  response = @client.add_custom_field
11
- expect(response.first['id']).to(eq("30"))
10
+ expect(response.first['id']).to(eq('30'))
12
11
  end
13
12
 
14
13
  it 'should get a custom field' do
15
14
  response = @client.get_custom_field(1)
16
- expect(response.first['id']).to(eq("30"))
15
+ expect(response.first['id']).to(eq('30'))
17
16
  end
18
17
 
19
18
  it 'should delete an custom field' do
@@ -23,13 +22,11 @@ describe BridgeAPI::Client::CustomField do
23
22
 
24
23
  it 'should update a custom field' do
25
24
  response = @client.update_custom_field(1)
26
- expect(response.first['id']).to(eq("30"))
25
+ expect(response.first['id']).to(eq('30'))
27
26
  end
28
27
 
29
28
  it 'should get all custom field' do
30
29
  response = @client.get_all_custom_fields
31
30
  expect(response.length).to(eq(1))
32
31
  end
33
-
34
32
  end
35
-
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  describe BridgeAPI::Client::DataDump do
4
4
  before do
5
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
6
6
  end
7
7
 
8
8
  it 'should get all data dumps' do
@@ -1,9 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe BridgeAPI::Client::Enrollment do
4
-
5
4
  before do
6
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
7
6
  end
8
7
 
9
8
  it 'should add an enrollment' do
@@ -14,12 +13,11 @@ describe BridgeAPI::Client::Enrollment do
14
13
  it 'should delete an enrollment' do
15
14
  response = @client.delete_enrollment(1)
16
15
  expect(response.status).to(eq(204))
17
-
18
16
  end
19
17
 
20
18
  it 'should update an enrollment' do
21
19
  enrollment = @client.update_enrollment(1)
22
- expect(enrollment.first['id']).to(eq("3"))
20
+ expect(enrollment.first['id']).to(eq('3'))
23
21
  end
24
22
 
25
23
  it 'should get all enrollments' do
@@ -28,10 +26,8 @@ describe BridgeAPI::Client::Enrollment do
28
26
  end
29
27
 
30
28
  it 'should update due date for enrollments' do
31
- enrollment = [{end_at: nil}]
29
+ enrollment = [{ end_at: nil }]
32
30
  response = @client.update_enrollment_due_date(1, enrollment)
33
31
  expect(response.status).to(eq 200)
34
32
  end
35
-
36
33
  end
37
-
@@ -2,10 +2,10 @@ require 'test_helper'
2
2
 
3
3
  describe BridgeAPI::Client::Group do
4
4
  before do
5
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
6
6
  end
7
7
 
8
- let(:params) {{ name: 'Test Group', smart: true }}
8
+ let(:params) { { name: 'Test Group', smart: true } }
9
9
 
10
10
  it 'should create a group' do
11
11
  response = @client.add_group(groups: params)
@@ -22,4 +22,4 @@ describe BridgeAPI::Client::Group do
22
22
  expect(response.members.first['id']).to eq('6')
23
23
  expect(response.members.first['type']).to eq('smart')
24
24
  end
25
- end
25
+ end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  describe BridgeAPI::Client::LiveCourseEnrollment do
4
4
  before do
5
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
6
6
  end
7
7
 
8
8
  it 'should get a list of live course enrollments' do
@@ -2,11 +2,11 @@ require 'test_helper'
2
2
 
3
3
  describe BridgeAPI::Client::LiveCourse do
4
4
  before do
5
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
6
6
  end
7
7
 
8
8
  it 'should get a list of live courses' do
9
- response = @client.get_all_live_courses()
9
+ response = @client.get_all_live_courses
10
10
  expect(response.status).to eq(200)
11
11
  expect(response.members.count).to eq(2)
12
12
  expect(response.members.first['id']).to eq('1')
@@ -1,22 +1,20 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe BridgeAPI::Client::User do
4
-
5
4
  before do
6
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
7
6
  end
8
7
 
9
8
  it 'should get all managers' do
10
9
  response = @client.get_all_managers
11
- expect(response.first['id']).to(eq("17"))
10
+ expect(response.first['id']).to(eq('17'))
12
11
  end
13
12
 
14
13
  it 'should get all the people who report to a manager' do
15
14
  response = @client.get_manager_direct_reports(17)
16
15
  expect(response.members.count).to(eq(2))
17
- expect(response.members.first['id']).to(eq("3"))
16
+ expect(response.members.first['id']).to(eq('3'))
18
17
  expect(response.meta['direct_reports_count']).to(eq(2))
19
- expect(response.meta['manager_id']).to(eq("17"))
18
+ expect(response.meta['manager_id']).to(eq('17'))
20
19
  end
21
-
22
20
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  describe BridgeAPI::Client::ProgramEnrollment do
4
4
  before do
5
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
6
6
  end
7
7
 
8
8
  it 'should add a program enrollment' do
@@ -1,14 +1,12 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe BridgeAPI::Client::SubAccount do
4
-
5
4
  before do
6
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
7
6
  end
8
7
 
9
8
  it 'should get all subaccounts' do
10
9
  response = @client.get_sub_accounts
11
- expect(response.first['id']).to(eq("141"))
10
+ expect(response.first['id']).to(eq('141'))
12
11
  end
13
-
14
12
  end
@@ -1,19 +1,18 @@
1
1
  require 'test_helper'
2
2
 
3
3
  describe BridgeAPI::Client::User do
4
-
5
4
  before do
6
- @client = BridgeAPI::Client.new(prefix: "http://test.bridge.com", token: "test_token")
5
+ @client = BridgeAPI::Client.new(prefix: 'http://test.bridge.com', token: 'test_token')
7
6
  end
8
7
 
9
8
  it 'should add an user' do
10
9
  response = @client.add_user
11
- expect(response.first['id']).to(eq("10"))
10
+ expect(response.first['id']).to(eq('10'))
12
11
  end
13
12
 
14
13
  it 'should get a user' do
15
14
  response = @client.get_user(1)
16
- expect(response.first['id']).to(eq("10"))
15
+ expect(response.first['id']).to(eq('10'))
17
16
  end
18
17
 
19
18
  it 'should delete an user' do
@@ -23,16 +22,14 @@ describe BridgeAPI::Client::User do
23
22
 
24
23
  it 'should update a user' do
25
24
  response = @client.update_user(1)
26
- expect(response.first['id']).to(eq("10"))
25
+ expect(response.first['id']).to(eq('10'))
27
26
 
28
- response = @client.update_user_with_custom_values(1, {'1' => 'test'})
29
- expect(response.first['id']).to(eq("10"))
27
+ response = @client.update_user_with_custom_values(1, '1' => 'test')
28
+ expect(response.first['id']).to(eq('10'))
30
29
  end
31
30
 
32
31
  it 'should get all users' do
33
32
  response = @client.get_all_users
34
33
  expect(response.length).to(eq(2))
35
34
  end
36
-
37
35
  end
38
-
@@ -1,27 +1,24 @@
1
1
 
2
2
  describe BridgeAPI::Client do
3
-
4
3
  it 'should set the auth header to basic auth' do
5
- client = BridgeAPI::Client.new(prefix: "https://www.fake.com", api_key: "fake_token", api_secret: "fake_secret")
6
- expect(client.connection.headers['Authorization']).to(eq("Basic ZmFrZV90b2tlbjpmYWtlX3NlY3JldA=="))
4
+ client = BridgeAPI::Client.new(prefix: 'https://www.fake.com', api_key: 'fake_token', api_secret: 'fake_secret')
5
+ expect(client.connection.headers['Authorization']).to(eq('Basic ZmFrZV90b2tlbjpmYWtlX3NlY3JldA=='))
7
6
  end
8
7
 
9
8
  it 'should set the auth header to bearer auth' do
10
- client = BridgeAPI::Client.new(prefix: "https://www.fake.com", token: "test_token")
11
- expect(client.connection.headers['Authorization']).to(eq("Bearer test_token"))
9
+ client = BridgeAPI::Client.new(prefix: 'https://www.fake.com', token: 'test_token')
10
+ expect(client.connection.headers['Authorization']).to(eq('Bearer test_token'))
12
11
  end
13
12
 
14
13
  it 'should set the meta property on client' do
15
- client = BridgeAPI::Client.new(prefix: "https://www.fake.com", token: "test_token")
14
+ client = BridgeAPI::Client.new(prefix: 'https://www.fake.com', token: 'test_token')
16
15
  users = client.get_all_users
17
16
  expect(users.meta['next']).to(eq('http://bridge.bridgeapp.com/api/author/users?after=eyJ0eXAiOiJKV1QiLCJhSDiQQ'))
18
17
  end
19
18
 
20
19
  it 'should set the linked property on client' do
21
- client = BridgeAPI::Client.new(prefix: "https://www.fake.com", token: "test_token")
20
+ client = BridgeAPI::Client.new(prefix: 'https://www.fake.com', token: 'test_token')
22
21
  users = client.get_all_users
23
22
  expect(users.linked['custom_fields'][0]['id']).to(eq('1'))
24
23
  end
25
-
26
-
27
- end
24
+ end
@@ -0,0 +1,129 @@
1
+ {
2
+ "meta": {},
3
+ "accounts": [
4
+ {
5
+ "id": "968",
6
+ "active": false,
7
+ "created_at": "2018-05-10T09:41:41.707-06:00",
8
+ "name": "psengtest",
9
+ "host": {
10
+ "subdomain": "psengtest",
11
+ "vanity_domain": null,
12
+ "vanity_domain_state": "vanity_domain_inactive"
13
+ },
14
+ "account_type": "paid",
15
+ "cluster": "cluster2",
16
+ "support_account": false,
17
+ "config": {
18
+ "contact_name": null,
19
+ "contact_email": null,
20
+ "contact_phone": null,
21
+ "import_passwords": false,
22
+ "support_level": "adminsOnly",
23
+ "show_custom_support_info": false,
24
+ "support_name": null,
25
+ "support_phone": null,
26
+ "support_email": null,
27
+ "use_custom_support": false,
28
+ "custom_support_chat_url": "https://lc.chat/now/8288951/2",
29
+ "custom_support_ticket_url": "https://bridgeapp.zendesk.com/hc/en-us/requests/new?ticket_form_id=794528",
30
+ "custom_support_phone_number": "855-383-4550",
31
+ "custom_back_to_my_learning_label": null,
32
+ "custom_back_to_my_learning_href": null,
33
+ "session_timeout_redirect_url": null,
34
+ "lynda_org_id": null,
35
+ "locale": "en",
36
+ "time_zone": "America/Denver",
37
+ "auto_csv": false,
38
+ "scorm_sftp": false,
39
+ "limited_authoring": false,
40
+ "limited_managers": false,
41
+ "bridge_retain": true,
42
+ "password_reset_allowed": true,
43
+ "create_user_from_auth_hash": true,
44
+ "salesforce_id": null,
45
+ "progressive_finance_customization": false,
46
+ "data_dump_enabled": false,
47
+ "data_dump_subaccount_enabled": false,
48
+ "cloneable": false,
49
+ "learner_library_enabled": true,
50
+ "learner_calendar_enabled": true,
51
+ "iframe_host": null,
52
+ "session_reissue_seconds": 1800,
53
+ "session_expire_seconds": 86400,
54
+ "user_limit": 0,
55
+ "expiration_date": "2018-06-09",
56
+ "used_free_trial_extension": false,
57
+ "lynda_library_enabled": false,
58
+ "external_course_id_enabled": false,
59
+ "learner_library_images_disabled": false,
60
+ "elastic_search_enabled": false,
61
+ "products": [
62
+ {
63
+ "product_name": "learn",
64
+ "subscription_type": "paid"
65
+ }
66
+ ],
67
+ "webhooks_enabled": false,
68
+ "calendar": {
69
+ "office365": null
70
+ },
71
+ "auth": {
72
+ "provider": "Basic",
73
+ "model": "User"
74
+ }
75
+ },
76
+ "import_profile": {
77
+ "csv_days": [
78
+ false,
79
+ false,
80
+ false,
81
+ false,
82
+ false,
83
+ false,
84
+ false
85
+ ],
86
+ "csv_password": null,
87
+ "csv_time": null,
88
+ "csv_url": null,
89
+ "csv_user": null,
90
+ "csv_public_key": null,
91
+ "try_key_based_auth": null
92
+ },
93
+ "import_scorm_profile": {
94
+ "sftp_days": [
95
+ false,
96
+ false,
97
+ false,
98
+ false,
99
+ false,
100
+ false,
101
+ false
102
+ ],
103
+ "sftp_time": null,
104
+ "sftp_url": null,
105
+ "sftp_user": null,
106
+ "sftp_password": null,
107
+ "sftp_public_key": null,
108
+ "registration_instancing_option": "never",
109
+ "sco_launch_type": "1",
110
+ "score_rollup_mode": "1",
111
+ "publish_on_upload": true,
112
+ "add_to_learner_library": null,
113
+ "default_days_until_due": null,
114
+ "email": null,
115
+ "try_key_based_auth": null
116
+ },
117
+ "domain": {
118
+ "tac_type": "domestic",
119
+ "tac_custom_body": null
120
+ },
121
+ "notification_profile": {
122
+ "notifications": false,
123
+ "chat_notifications": false,
124
+ "from_label": null,
125
+ "reply_to": null
126
+ }
127
+ }
128
+ ]
129
+ }