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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bce329056305672b1df2fcdc6c87a60bdbc73202
4
- data.tar.gz: f7c19e775975de6873784c6fe6ad283bc2004285
3
+ metadata.gz: 23e484eca3a30379d5ea34f5cad98d315a1ddb74
4
+ data.tar.gz: bbd7dc872d31056ee05dc05c3f3c3642b27a260d
5
5
  SHA512:
6
- metadata.gz: 1198ac3d96bb9dfc31eb30fddd422561f64af2fce5a4d9a92a800f99b105100d57dba1400a902fe213aaadd9cacf013b958f6948cacb299c10493fe290a6f76f
7
- data.tar.gz: 9724c5b3ea3f44ce435f35f9797f9fb63b64110fb0ceb0efbd22a446161d4e960703818ab2c5f588eb56c7d58c78fe48d2ddae0d122ccc2e193793c8a0489842
6
+ metadata.gz: c3c1314b45b45f6c01d1b41ce790b9b11dc2feef7e192e759ff0a8352f7080328aee978cf388e729f1c1db2fa3543523ca8f3090f7d06a732217fa44e4a25f30
7
+ data.tar.gz: 598319ec388b85afb5acbd47fb4790d6c659c3129c23706dd47e7a9fdd73f92d3d5326fa614a6da7ad68ce04e78789e29f25d53aee3ea21ff67c72bcd51d001d
@@ -0,0 +1,14 @@
1
+ FROM ruby:2.5.0
2
+
3
+ RUN apt-get update
4
+
5
+ RUN mkdir -p /usr/src/app
6
+ COPY Gemfile /usr/src/app/
7
+ COPY Gemfile.lock /usr/src/app/
8
+ COPY bridge_api.gemspec /usr/src/app/
9
+ COPY /lib/bridge_api/version.rb /usr/src/app/lib/bridge_api/
10
+
11
+ WORKDIR /usr/src/app
12
+ RUN bundle install --system
13
+
14
+ COPY . /usr/src/app/
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
1
  source 'https://rubygems.org'
2
- gemspec
2
+ gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bridge_api (0.1.19)
4
+ bridge_api (0.1.20)
5
5
  faraday (~> 0.9.0)
6
6
  faraday_middleware (~> 0.9.0)
7
7
  footrest (>= 0.5.1)
@@ -9,9 +9,9 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (5.1.5)
12
+ activesupport (5.2.0)
13
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
- i18n (~> 0.7)
14
+ i18n (>= 0.7, < 2)
15
15
  minitest (~> 5.1)
16
16
  tzinfo (~> 1.1)
17
17
  addressable (2.5.1)
@@ -31,7 +31,7 @@ GEM
31
31
  faraday (~> 0.9.0)
32
32
  link_header (>= 0.0.7)
33
33
  hashdiff (0.3.2)
34
- i18n (0.9.5)
34
+ i18n (1.0.1)
35
35
  concurrent-ruby (~> 1.0)
36
36
  link_header (0.0.8)
37
37
  method_source (0.8.2)
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set +e
4
+ EXIT_CODES=0
5
+
6
+ #Skip this for now until we can fix all the cop issues
7
+
8
+ #echo "Analyzing ruby code with rubocop"
9
+ #bundle exec gergich capture rubocop "bundle exec rubocop --fail-level autocorrect"
10
+ #EXIT_CODES=$(($EXIT_CODES + $?))
11
+
12
+ echo 'Running ruby specs'
13
+ bundle exec rspec
14
+ EXIT_CODES=$(($EXIT_CODES + $?))
15
+
16
+ bundle exec gergich publish
17
+ exit $EXIT_CODES
@@ -1,34 +1,33 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+
2
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
3
3
  require 'bridge_api/version'
4
4
 
5
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"
6
+ gem.authors = ['Jay Shaffer']
7
+ gem.email = ['jshaffer@instructure.com']
8
+ gem.description = 'Ruby gem for interacting with the bridge API'
9
+ gem.summary = 'Bridge API'
10
+ gem.homepage = 'https://getbridge.com'
11
11
  gem.license = 'MIT'
12
12
 
13
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"]
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
19
  gem.version = BridgeAPI::VERSION
20
20
 
21
- gem.add_development_dependency 'rake', '~> 0'
22
21
  gem.add_development_dependency 'bundler', '~> 1.0', '>= 1.0.0'
23
- gem.add_development_dependency 'rspec', '~> 2.6'
24
- gem.add_development_dependency 'webmock', '~>1.22.6'
22
+ gem.add_development_dependency 'byebug', '~> 8.2.2'
25
23
  gem.add_development_dependency 'pry', '~> 0'
26
- gem.add_development_dependency 'tilt', '>= 1.3.4', '~> 1.3'
24
+ gem.add_development_dependency 'rake', '~> 0'
25
+ gem.add_development_dependency 'rspec', '~> 2.6'
27
26
  gem.add_development_dependency 'sinatra', '~> 1.0'
28
- gem.add_development_dependency 'byebug', '~> 8.2.2'
27
+ gem.add_development_dependency 'tilt', '>= 1.3.4', '~> 1.3'
28
+ gem.add_development_dependency 'webmock', '~>1.22.6'
29
29
 
30
- gem.add_dependency 'footrest', '>= 0.5.1'
31
30
  gem.add_dependency 'faraday', '~> 0.9.0'
32
31
  gem.add_dependency 'faraday_middleware', '~> 0.9.0'
33
-
32
+ gem.add_dependency 'footrest', '>= 0.5.1'
34
33
  end
@@ -0,0 +1,5 @@
1
+ set -e
2
+
3
+ docker-compose build
4
+ docker-compose up -d
5
+ docker-compose run -T web bin/jenkins
@@ -0,0 +1,18 @@
1
+ version: '2'
2
+
3
+ services:
4
+ web:
5
+ build:
6
+ context: .
7
+ dockerfile: ./Dockerfile
8
+ environment:
9
+ APP_DOMAIN: web
10
+ GERGICH_KEY: "${GERGICH_KEY}"
11
+ GERRIT_PROJECT: "${GERRIT_PROJECT}"
12
+ GERRIT_HOST: "${GERRIT_HOST}"
13
+ GERRIT_BRANCH: "${GERRIT_BRANCH}"
14
+ volumes:
15
+ - "coverage:/usr/src/app/coverage"
16
+
17
+ volumes:
18
+ coverage: {}
@@ -6,14 +6,14 @@ module BridgeAPI
6
6
  @next_page = nil
7
7
  @prev_page = nil
8
8
 
9
- attr_reader :status, :headers, :members, :body, :errors
9
+ attr_reader :status, :headers, :members, :body, :errors, :meta, :linked
10
10
 
11
11
  def self.process_response(response, api_client, result_mapping)
12
12
  ApiArray.new(response, api_client, result_mapping)
13
13
  end
14
14
 
15
15
  def initialize(response, api_client, result_mapping)
16
- @meta_fields = %w(meta linked)
16
+ @meta_fields = %w[meta linked]
17
17
  @api_client = api_client
18
18
  @linked = {}
19
19
  @meta = {}
@@ -26,13 +26,11 @@ module BridgeAPI
26
26
  mapping_exists = result_mapping.key?(matches[1])
27
27
  mapping = result_mapping[matches[1]] if mapping_exists
28
28
  end
29
- unless mapping.nil?
30
- @extra_meta_fields.concat(mapping[:meta])
31
- end
29
+ @extra_meta_fields.concat(mapping[:meta]) unless mapping.nil?
32
30
  case response.status
33
- when *((200..206).to_a + [302])
34
- apply_response_metadata(response)
35
- @members = get_response_content(response)
31
+ when *((200..206).to_a + [302])
32
+ apply_response_metadata(response)
33
+ @members = get_response_content(response)
36
34
  else
37
35
  set_response_vars(response)
38
36
  end
@@ -40,9 +38,13 @@ module BridgeAPI
40
38
 
41
39
  def set_response_vars(response)
42
40
  @headers = response.headers
43
- @status= response.status
44
- @body= response.body
45
- @errors = response.body['errors'] rescue []
41
+ @status = response.status
42
+ @body = response.body
43
+ @errors = begin
44
+ response.body['errors']
45
+ rescue StandardError
46
+ []
47
+ end
46
48
  end
47
49
 
48
50
  def length
@@ -57,33 +59,26 @@ module BridgeAPI
57
59
  @members.last
58
60
  end
59
61
 
60
- def each(&block)
61
- @members.each { |member| block.call(member) }
62
+ def each
63
+ @members.each { |member| yield(member) }
62
64
  end
63
65
 
64
66
  def pages?
65
67
  !@next_page.nil?
66
68
  end
67
69
 
68
- def meta
69
- @meta
70
- end
71
-
72
- def linked
73
- @linked
74
- end
75
70
 
76
71
  def next_page
77
72
  load_page(@next_page)
78
73
  end
79
74
 
80
- def each_page(&block)
81
- block.call(@members, @linked, @meta)
75
+ def each_page
76
+ yield(@members, @linked, @meta)
82
77
  while @next_page
83
78
  response = get_page(@next_page)
84
79
  apply_response_metadata(response, false)
85
80
  @members = get_response_content(response)
86
- block.call(@members, @linked, @meta)
81
+ yield(@members, @linked, @meta)
87
82
  end
88
83
  @link_hash = {}
89
84
  end
@@ -121,10 +116,8 @@ module BridgeAPI
121
116
 
122
117
  def get_response_content(response)
123
118
  return [] unless response.body.is_a?(Hash)
124
- content = response.body.reject{|k, v| @meta_fields.include?(k) || @extra_meta_fields.include?(k)}
125
- if content.length > 0
126
- return content.values[0]
127
- end
119
+ content = response.body.reject { |k, _v| @meta_fields.include?(k) || @extra_meta_fields.include?(k) }
120
+ return content.values[0] unless content.empty?
128
121
  []
129
122
  end
130
123
 
@@ -142,13 +135,13 @@ module BridgeAPI
142
135
 
143
136
  def init_linked(response)
144
137
  if response.body.is_a?(Hash) && response.body.key?('linked')
145
- @linked = @linked.merge(response.body['linked']){|key,oldval,newval| [*oldval].to_a + [*newval].to_a }
138
+ @linked = @linked.merge(response.body['linked']) { |_key, oldval, newval| [*oldval].to_a + [*newval].to_a }
146
139
  end
147
140
  end
148
141
 
149
142
  def init_meta(response)
150
143
  if response.body.is_a?(Hash) && response.body.key?('meta')
151
- @meta = @meta.merge(response.body['meta']){|key,oldval,newval| [*oldval].to_a + [*newval].to_a }
144
+ @meta = @meta.merge(response.body['meta']) { |_key, oldval, newval| [*oldval].to_a + [*newval].to_a }
152
145
  @extra_meta_fields.each do |field|
153
146
  @meta[field] = response.body[field]
154
147
  end
@@ -167,6 +160,5 @@ module BridgeAPI
167
160
  end
168
161
  end
169
162
  end
170
-
171
163
  end
172
164
  end
@@ -9,36 +9,37 @@ require 'base64'
9
9
 
10
10
  module BridgeAPI
11
11
  class Client < Footrest::Client
12
-
13
- DATA_DUMP_DOWNLOAD_PATH = '/data_dumps/download'
14
- DATA_DUMP_PATH = '/data_dumps'
15
- COURSE_TEMPLATE_PATH = '/course_templates'
16
- ENROLLMENT_PATH = '/enrollments'
17
- PROGRAM_PATH = '/programs'
18
- PROGRAM_ENROLLMENT_PATH = '/learners'
19
- USER_PATH = '/users'
20
- GROUPS_PATH = '/groups'
21
- MANAGER_PATH = '/managers'
22
- ADMIN_PATH = "/admin"
23
- AUTHOR_PATH = "/author"
24
- LEARNER_PATH = "/learner"
25
- CUSTOM_FIELD_PATH = "/custom_fields"
26
- SUB_ACCOUNT_PATH = '/sub_accounts'
12
+ DATA_DUMP_DOWNLOAD_PATH = '/data_dumps/download'.freeze
13
+ DATA_DUMP_PATH = '/data_dumps'.freeze
14
+ COURSE_TEMPLATE_PATH = '/course_templates'.freeze
15
+ ENROLLMENT_PATH = '/enrollments'.freeze
16
+ PROGRAM_PATH = '/programs'.freeze
17
+ PROGRAM_ENROLLMENT_PATH = '/learners'.freeze
18
+ USER_PATH = '/users'.freeze
19
+ GROUPS_PATH = '/groups'.freeze
20
+ MANAGER_PATH = '/managers'.freeze
21
+ ADMIN_PATH = '/admin'.freeze
22
+ AUTHOR_PATH = '/author'.freeze
23
+ LEARNER_PATH = '/learner'.freeze
24
+ CUSTOM_FIELD_PATH = '/custom_fields'.freeze
25
+ SUB_ACCOUNT_PATH = '/sub_accounts'.freeze
26
+ SUPPORT_PATH = '/support'.freeze
27
+ ACCOUNT_PATH = '/accounts'.freeze
27
28
  API_VERSION = 1
28
- API_PATH = '/api'
29
- ROLE_PATH = '/roles'
29
+ API_PATH = '/api'.freeze
30
+ ROLE_PATH = '/roles'.freeze
30
31
  RESULT_MAPPING = {}
31
32
 
32
33
  require 'bridge_api/api_array'
33
34
 
34
35
  Dir[File.dirname(__FILE__) + '/client/*.rb'].each do |file|
35
36
  require file
36
- include self.const_get("#{File.basename(file).gsub('.rb','').split("_").map{|ea| ea.capitalize}.join('')}")
37
+ include const_get(File.basename(file).gsub('.rb', '').split('_').map(&:capitalize).join('').to_s)
37
38
  end
38
39
 
39
40
  # Override Footrest request for ApiArray support
40
41
  def request(method, &block)
41
- ApiArray::process_response(connection.send(method, &block), self, RESULT_MAPPING)
42
+ ApiArray.process_response(connection.send(method, &block), self, RESULT_MAPPING)
42
43
  end
43
44
 
44
45
  def set_connection(config)
@@ -53,12 +54,12 @@ module BridgeAPI
53
54
  end
54
55
  faraday.use Footrest::FollowRedirects, limit: 5 unless config[:follow_redirects] == false
55
56
  faraday.adapter Faraday.default_adapter
56
- faraday.use Footrest::ParseJson, :content_type => /\bjson$/
57
+ faraday.use Footrest::ParseJson, content_type: /\bjson$/
57
58
  faraday.use Footrest::RaiseFootrestErrors
58
59
  faraday.use Footrest::Pagination
59
- faraday.headers[:accept] = "application/json"
60
+ faraday.headers[:accept] = 'application/json'
60
61
  faraday.headers[:authorization] = "Bearer #{config[:token]}" if config[:token]
61
- faraday.headers[:user_agent] = "Footrest"
62
+ faraday.headers[:user_agent] = 'Footrest'
62
63
  if config[:api_key] && config[:api_secret]
63
64
  faraday.headers[:authorization] = 'Basic ' + Base64.strict_encode64("#{config[:api_key]}:#{config[:api_secret]}")
64
65
  elsif config[:token]
@@ -0,0 +1,9 @@
1
+ module BridgeAPI
2
+ class Client
3
+ module Account
4
+ def update_account(account_id, params = {})
5
+ put("#{API_PATH}#{SUPPORT_PATH}#{ACCOUNT_PATH}/#{account_id}", params)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,7 +1,6 @@
1
1
  module BridgeAPI
2
2
  class Client
3
3
  module CourseTemplate
4
-
5
4
  def get_all_course_templates(params = {})
6
5
  get("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}", params)
7
6
  end
@@ -25,7 +24,6 @@ module BridgeAPI
25
24
  def update_course_template(course_template_id, params = {})
26
25
  put("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}/#{course_template_id}", params)
27
26
  end
28
-
29
27
  end
30
28
  end
31
29
  end
@@ -1,7 +1,6 @@
1
1
  module BridgeAPI
2
2
  class Client
3
3
  module CustomField
4
-
5
4
  def add_custom_field(params = {})
6
5
  post("#{API_PATH}#{AUTHOR_PATH}#{CUSTOM_FIELD_PATH}", params)
7
6
  end
@@ -21,7 +20,6 @@ module BridgeAPI
21
20
  def get_all_custom_fields(params = {})
22
21
  get("#{API_PATH}#{AUTHOR_PATH}#{CUSTOM_FIELD_PATH}", params)
23
22
  end
24
-
25
23
  end
26
24
  end
27
25
  end
@@ -1,7 +1,6 @@
1
1
  module BridgeAPI
2
2
  class Client
3
3
  module Enrollment
4
-
5
4
  def add_enrollment(course_template_id, params = {})
6
5
  post("#{API_PATH}#{AUTHOR_PATH}#{COURSE_TEMPLATE_PATH}/#{course_template_id}#{ENROLLMENT_PATH}", params)
7
6
  end
@@ -21,7 +20,6 @@ module BridgeAPI
21
20
  def update_enrollment_due_date(enrollment_id, params = {})
22
21
  post("#{API_PATH}#{AUTHOR_PATH}#{ENROLLMENT_PATH}/#{enrollment_id}/due_date", params)
23
22
  end
24
-
25
23
  end
26
24
  end
27
25
  end
@@ -1,11 +1,9 @@
1
1
  module BridgeAPI
2
2
  class Client
3
3
  module LiveCourse
4
-
5
4
  def get_all_live_courses(params = {})
6
5
  get("#{API_PATH}#{AUTHOR_PATH}/live_courses", params)
7
6
  end
8
-
9
7
  end
10
8
  end
11
9
  end
@@ -1,11 +1,9 @@
1
1
  module BridgeAPI
2
2
  class Client
3
3
  module LiveCourseEnrollment
4
-
5
4
  def get_all_live_course_enrollments(live_course, params = {})
6
5
  get("#{API_PATH}#{AUTHOR_PATH}/live_courses/#{live_course}/learners", params)
7
6
  end
8
-
9
7
  end
10
8
  end
11
9
  end
@@ -1,7 +1,6 @@
1
1
  module BridgeAPI
2
2
  class Client
3
3
  module Manager
4
-
5
4
  def get_all_managers(params = {})
6
5
  get("#{API_PATH}#{AUTHOR_PATH}#{MANAGER_PATH}", params)
7
6
  end
@@ -10,11 +9,10 @@ module BridgeAPI
10
9
  path = "#{API_PATH}#{AUTHOR_PATH}#{MANAGER_PATH}/#{manager_id}/direct_reports"
11
10
  RESULT_MAPPING[path] = {
12
11
  primary: 'direct_reports',
13
- meta: ['manager_id', 'direct_reports_count']
12
+ meta: %w[manager_id direct_reports_count]
14
13
  }
15
14
  get(path, params)
16
15
  end
17
-
18
16
  end
19
17
  end
20
18
  end