bridge_blueprint 0.0.03 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 314da5f541b119ccdb38da750580e3f26fb3e6d1
4
- data.tar.gz: f0b3a8c9094c8fee3246f10c76851f6930817faa
2
+ SHA256:
3
+ metadata.gz: 7e440e81516ef2932ea241fc35b0a5ee0744638ad859b2f56289a88ba61e9152
4
+ data.tar.gz: 39530b8322f62933ce815fe6e954c7000342c886d0249a6fec378e69e0c910b4
5
5
  SHA512:
6
- metadata.gz: 6a6c91eea14345a3a32c6092080b6b31cd5b01d71de83c71c23d961ab70e9d9fa469a16add295f122130408dc793c1a2e9d9cf9654169c6c549f6003ee60efe4
7
- data.tar.gz: 481dce12ae4952ee9f7dd79f3d40738027ba738fc7f12c75fd5f1b9d2d8a0c080c5ab261e1651119be86206851fef8b2b095d823df2705bab198cd150167546d
6
+ metadata.gz: 1ac0f6bf8aa8c8089d543a383349d24e5b3e3c33fb90a2790e21a51d31b13540d59176ad1aa23a39cd6eac1548e3019788dcc0814cae9143c927c509ee0c4972
7
+ data.tar.gz: a26c94d1f6c5c0288751543c1f0a45a65f09229ba292a9ecb16403b432868e59b909622553555c19b975d1c8a94ff1ef64f31de6ff7379ccb66da1b3f05144be
data/.gitignore CHANGED
@@ -1,6 +1,50 @@
1
- /.*.iml
2
- .idea/
3
- bridge_api.iml
4
- .byebug.*
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
5
12
 
6
- .*.gem
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'bin/**/*'
4
+ - 'node_modules/**/*'
5
+ - 'vendor/**/*'
6
+ Metrics/ClassLength:
7
+ Max: 150
8
+ Metrics/LineLength:
9
+ Max: 120
10
+ Style/Documentation:
11
+ Enabled: false
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - 'bridge_blueprint.gemspec'
15
+ - 'spec/**/*'
16
+ Style/FrozenStringLiteralComment:
17
+ Enabled: false
18
+ Style/SymbolArray:
19
+ Enabled: false
20
+ Metrics/MethodLength:
21
+ Exclude:
22
+ - spec/**/*
23
+ Naming/AccessorMethodName:
24
+ Enabled: false
data/.simplecov ADDED
@@ -0,0 +1,7 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ SimpleCov.minimum_coverage 80
3
+ SimpleCov.minimum_coverage_by_file 80
4
+ SimpleCov.start do
5
+ add_group 'lib', 'lib'
6
+ add_filter 'spec'
7
+ end
data/Dockerfile ADDED
@@ -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_blueprint.gemspec /usr/src/app/
9
+ COPY /lib/bridge_blueprint/version.rb /usr/src/app/lib/bridge_blueprint/
10
+
11
+ WORKDIR /usr/src/app
12
+ RUN bundle install --system
13
+
14
+ COPY . /usr/src/app/
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
- gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,22 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bridge_blueprint (0.0.02)
5
- bridge_api (~> 0.1.0)
4
+ bridge_blueprint (0.0.7)
5
+ bridge_api (~> 0.1.16)
6
6
  open_uri_redirections (~> 0.2.1)
7
7
  rubyzip (~> 1.2.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (5.1.2)
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)
18
18
  public_suffix (~> 2.0, >= 2.0.2)
19
- bridge_api (0.1.14)
19
+ ast (2.4.0)
20
+ bridge_api (0.1.19)
20
21
  faraday (~> 0.9.0)
21
22
  faraday_middleware (~> 0.9.0)
22
23
  footrest (>= 0.5.1)
@@ -26,6 +27,7 @@ GEM
26
27
  crack (0.4.3)
27
28
  safe_yaml (~> 1.0.0)
28
29
  diff-lcs (1.3)
30
+ docile (1.3.0)
29
31
  faraday (0.9.2)
30
32
  multipart-post (>= 1.2, < 3)
31
33
  faraday_middleware (0.9.2)
@@ -35,12 +37,18 @@ GEM
35
37
  faraday (~> 0.9.0)
36
38
  link_header (>= 0.0.7)
37
39
  hashdiff (0.3.4)
38
- i18n (0.8.6)
40
+ i18n (1.0.0)
41
+ concurrent-ruby (~> 1.0)
42
+ json (2.1.0)
39
43
  link_header (0.0.8)
40
44
  method_source (0.8.2)
41
- minitest (5.10.3)
45
+ minitest (5.11.3)
42
46
  multipart-post (2.0.0)
43
47
  open_uri_redirections (0.2.1)
48
+ parallel (1.12.1)
49
+ parser (2.5.1.0)
50
+ ast (~> 2.4.0)
51
+ powerpack (0.1.1)
44
52
  pry (0.10.4)
45
53
  coderay (~> 1.1.0)
46
54
  method_source (~> 0.8.1)
@@ -49,6 +57,7 @@ GEM
49
57
  rack (1.6.5)
50
58
  rack-protection (1.5.3)
51
59
  rack
60
+ rainbow (3.0.0)
52
61
  rake (0.9.6)
53
62
  rspec (2.99.0)
54
63
  rspec-core (~> 2.99.0)
@@ -58,8 +67,21 @@ GEM
58
67
  rspec-expectations (2.99.2)
59
68
  diff-lcs (>= 1.1.3, < 2.0)
60
69
  rspec-mocks (2.99.4)
70
+ rubocop (0.54.0)
71
+ parallel (~> 1.10)
72
+ parser (>= 2.5)
73
+ powerpack (~> 0.1)
74
+ rainbow (>= 2.2.2, < 4.0)
75
+ ruby-progressbar (~> 1.7)
76
+ unicode-display_width (~> 1.0, >= 1.0.1)
77
+ ruby-progressbar (1.9.0)
61
78
  rubyzip (1.2.1)
62
79
  safe_yaml (1.0.4)
80
+ simplecov (0.16.1)
81
+ docile (~> 1.1)
82
+ json (>= 1.8, < 3)
83
+ simplecov-html (~> 0.10.0)
84
+ simplecov-html (0.10.2)
63
85
  sinatra (1.4.8)
64
86
  rack (~> 1.5)
65
87
  rack-protection (~> 1.4)
@@ -67,8 +89,9 @@ GEM
67
89
  slop (3.6.0)
68
90
  thread_safe (0.3.6)
69
91
  tilt (1.4.1)
70
- tzinfo (1.2.3)
92
+ tzinfo (1.2.5)
71
93
  thread_safe (~> 0.1)
94
+ unicode-display_width (1.3.2)
72
95
  webmock (2.3.2)
73
96
  addressable (>= 2.3.6)
74
97
  crack (>= 0.3.2)
@@ -84,9 +107,11 @@ DEPENDENCIES
84
107
  pry (~> 0)
85
108
  rake (~> 0)
86
109
  rspec (~> 2.6)
110
+ rubocop (~> 0.54.0)
111
+ simplecov (~> 0.16.1)
87
112
  sinatra (~> 1.0)
88
113
  tilt (~> 1.3, >= 1.3.4)
89
114
  webmock (~> 2.3.1)
90
115
 
91
116
  BUNDLED WITH
92
- 1.14.6
117
+ 1.16.1
data/bin/jenkins ADDED
@@ -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,33 +1,37 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
3
5
  require 'bridge_blueprint/version'
4
6
 
5
7
  Gem::Specification.new do |gem|
6
- gem.authors = ["Jay Shaffer"]
7
- gem.email = ["jshaffer@instructure.com"]
8
- gem.description = %q{Tools for consuming bridge data dumps}
9
- gem.summary = %q{Bridge Blueprint}
10
- gem.homepage = "https://getbridge.com"
8
+ gem.authors = ['Jay Shaffer']
9
+ gem.email = ['jshaffer@instructure.com']
10
+ gem.description = 'Tools for consuming bridge data dumps'
11
+ gem.summary = 'Bridge Blueprint'
12
+ gem.homepage = 'https://getbridge.com'
11
13
  gem.license = 'MIT'
12
14
 
13
15
  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_blueprint"
18
- gem.require_paths = ["lib"]
16
+ gem.files += Dir.glob('lib/**/*.rb')
17
+ gem.files += Dir.glob('spec/**/*')
18
+ gem.test_files = Dir.glob('spec/**/*')
19
+ gem.name = 'bridge_blueprint'
20
+ gem.require_paths = ['lib']
19
21
  gem.version = BridgeBlueprint::VERSION
20
22
 
21
- gem.add_runtime_dependency 'bridge_api', '~> 0.1.0'
23
+ gem.add_runtime_dependency 'bridge_api', '~> 0.1.16'
22
24
  gem.add_runtime_dependency 'open_uri_redirections', '~> 0.2.1'
23
25
  gem.add_runtime_dependency 'rubyzip', '~> 1.2.1'
24
26
 
25
- gem.add_development_dependency 'rake', '~> 0'
26
27
  gem.add_development_dependency 'bundler', '~> 1.0', '>= 1.0.0'
27
- gem.add_development_dependency 'rspec', '~> 2.6'
28
- gem.add_development_dependency 'webmock', '~>2.3.1'
28
+ gem.add_development_dependency 'byebug', '~> 8.2.2'
29
29
  gem.add_development_dependency 'pry', '~> 0'
30
- gem.add_development_dependency 'tilt', '>= 1.3.4', '~> 1.3'
30
+ gem.add_development_dependency 'rake', '~> 0'
31
+ gem.add_development_dependency 'rspec', '~> 2.6'
32
+ gem.add_development_dependency 'rubocop', '~> 0.54.0'
33
+ gem.add_development_dependency 'simplecov', '~> 0.16.1'
31
34
  gem.add_development_dependency 'sinatra', '~> 1.0'
32
- gem.add_development_dependency 'byebug', '~> 8.2.2'
35
+ gem.add_development_dependency 'tilt', '>= 1.3.4', '~> 1.3'
36
+ gem.add_development_dependency 'webmock', '~>2.3.1'
33
37
  end
data/build.sh ADDED
@@ -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: {}
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bridge_blueprint/version'
2
4
  require 'bridge_blueprint/data_dump'
3
5
  require 'bridge_blueprint/constants'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BridgeBlueprint
2
4
  class Constants
3
5
  STATUS_FAILED = 'failed'
@@ -1,16 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'csv'
2
4
  require 'zip'
3
5
 
4
6
  module BridgeBlueprint
5
7
  class DataDump
6
-
7
8
  @path = nil
8
9
 
9
10
  def initialize(path)
10
11
  @path = path
11
- unless File.exists?(path)
12
- raise "File not found #{path}"
13
- end
12
+ raise "File not found #{path}" unless File.exist?(path)
14
13
  end
15
14
 
16
15
  def each_row(name)
@@ -26,15 +25,18 @@ module BridgeBlueprint
26
25
  def extract_from_zip(name)
27
26
  Dir.mktmpdir do |dir|
28
27
  path = nil
28
+ file = nil
29
29
  Zip::File.open(@path) do |zip_file|
30
30
  zip_file.each do |entry|
31
- if "#{name.to_s}" == entry.name
32
- path = "#{dir}/#{entry.name}"
33
- file = entry.extract(path)
34
- yield "#{dir}/#{name}" if block_given?
35
- return
36
- end
31
+ next unless name.to_s == entry.name
32
+ path = "#{dir}/#{entry.name}"
33
+ file = entry.extract(path)
34
+ break
37
35
  end
36
+ end
37
+ if file
38
+ yield "#{dir}/#{name}" if block_given?
39
+ else
38
40
  raise "File #{name} not found in zip archive #{@path}"
39
41
  end
40
42
  end
@@ -1,59 +1,73 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'open-uri'
2
4
  require 'open_uri_redirections'
3
5
  require 'net/http'
4
6
  require 'uri'
5
7
  require 'base64'
6
- require "bridge_api"
8
+ require 'bridge_api'
7
9
 
8
10
  module BridgeBlueprint
9
-
10
11
  class RemoteData
11
-
12
12
  USERS_CSV_NAME = 'users.csv'
13
13
  CUSTOM_FIELD_CSV_NAME = 'custom_fields.csv'
14
14
  GRANTS_CSV_NAME = 'grants.csv'
15
15
 
16
+ attr_accessor :client
17
+
16
18
  @base_url = nil
17
19
  @auth_header = nil
18
20
  @file_url = nil
19
21
  @file_path = nil
20
22
  @is_complete = false
21
23
  @client = nil
24
+ @models = nil
22
25
 
23
- def initialize(base_url, key, secret)
26
+ def initialize(base_url, key, secret, models = nil)
24
27
  @base_url = base_url
25
- @auth_header = 'Basic ' + Base64.strict_encode64("#{key}:#{secret}")
28
+ @auth_header = 'Basic ' + Base64.strict_encode64("#{key}:#{secret}")
26
29
  @client = BridgeAPI::Client.new(prefix: base_url, api_key: key, api_secret: secret)
30
+ @models = models
27
31
  end
28
32
 
29
33
  def start_data_report
30
- @client.create_data_dump
34
+ raw_dumps = get_dumps
35
+ dumps = raw_dumps.members
36
+ unless dumps.empty?
37
+ dump = dumps.first
38
+ case dump['status']
39
+ when 'pending'
40
+ return
41
+ when 'complete'
42
+ return if Time.parse(dump['date']) > Time.now - 300
43
+ end
44
+ end
45
+ @models.present? ? @client.create_data_dump({only: @models}) : @client.create_data_dump
31
46
  end
32
47
 
33
48
  def status
34
49
  dumps = get_dumps
35
- if dumps.members.size > 0
36
- return get_dumps.first['status']
37
- else
38
- return BridgeBlueprint::Constants::STATUS_NOT_FOUND
39
- end
50
+ return get_dumps.first['status'] unless dumps.members.empty?
51
+ BridgeBlueprint::Constants::STATUS_NOT_FOUND
40
52
  end
41
53
 
42
- def store_file(path)
43
- @file_path = path
54
+ def remote_url
44
55
  uri = URI.parse(@base_url)
45
56
  http = Net::HTTP.new(uri.host, uri.port)
46
57
  http.read_timeout = 300
47
- http.use_ssl = (uri.scheme == "https")
58
+ http.use_ssl = (uri.scheme == 'https')
48
59
  req = Net::HTTP::Get.new("#{@base_url}/api/admin/data_dumps/download")
49
- req.add_field("Authorization", @auth_header)
60
+ req.add_field('Authorization', @auth_header)
50
61
  res = http.request(req)
51
- redirect_url = res['location']
52
- open(redirect_url,
53
- ) do |remote_file|
54
- File.open(@file_path, 'wb') do |file|
55
- file.write(remote_file.read)
56
- end
62
+ res['location']
63
+ end
64
+
65
+ def store_file(path)
66
+ @file_path = path
67
+ url = remote_url
68
+ raise 'Missing location url from bridge data dump response' if url.blank?
69
+ File.open(@file_path, 'w') do |_file|
70
+ IO.copy_stream(open(url), @file_path)
57
71
  end
58
72
  end
59
73
 
@@ -65,11 +79,10 @@ module BridgeBlueprint
65
79
 
66
80
  def get_headers
67
81
  {
68
- 'Authorization'=> @auth_header,
69
- 'Content-Type'=> 'application/json',
70
- 'Accept'=> 'application/json'
82
+ 'Authorization' => @auth_header,
83
+ 'Content-Type' => 'application/json',
84
+ 'Accept' => 'application/json'
71
85
  }
72
86
  end
73
87
  end
74
-
75
88
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BridgeBlueprint
2
- VERSION = '0.0.03' unless defined?(BridgeBlueprint::VERSION)
4
+ VERSION = '0.0.8' unless defined?(BridgeBlueprint::VERSION)
3
5
  end
@@ -1,15 +1,16 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
2
4
  require 'zip'
3
5
 
4
6
  describe BridgeBlueprint::DataDump do
5
-
6
7
  before(:each) do
7
8
  dir = Dir.mktmpdir
8
9
  zip_folder_path = "#{File.dirname(__FILE__)}/../fixtures/bridge_zip"
9
10
  input_filenames = [
10
- 'users.csv',
11
- 'custom_fields.csv'
12
- ]
11
+ 'users.csv',
12
+ 'custom_fields.csv'
13
+ ]
13
14
 
14
15
  @zipfile_name = "#{dir}/dump.zip"
15
16
 
@@ -24,11 +25,11 @@ describe BridgeBlueprint::DataDump do
24
25
  it 'should parse a bridge data dump file' do
25
26
  file = BridgeBlueprint::DataDump.new(@zipfile_name)
26
27
  user_count = 0
27
- file.each_row('users') do |user|
28
+ file.each_row('users') do |_user|
28
29
  user_count += 1
29
30
  end
30
31
  custom_field_count = 0
31
- file.each_row('custom_fields') do |custom_field|
32
+ file.each_row('custom_fields') do |_custom_field|
32
33
  custom_field_count += 1
33
34
  end
34
35
  expect(user_count).to(eq(2))
@@ -1,15 +1,16 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
2
4
  require 'zip'
3
5
 
4
6
  describe BridgeBlueprint::RemoteData do
5
-
6
7
  before(:each) do
7
8
  @dir = Dir.mktmpdir
8
9
  zip_folder_path = "#{File.dirname(__FILE__)}/../fixtures/bridge_zip"
9
10
  input_filenames = [
10
- 'users.csv',
11
- 'custom_fields.csv'
12
- ]
11
+ 'users.csv',
12
+ 'custom_fields.csv'
13
+ ]
13
14
 
14
15
  @zipfile_name = "#{@dir}/dump.zip"
15
16
 
@@ -19,14 +20,35 @@ describe BridgeBlueprint::RemoteData do
19
20
  end
20
21
  end
21
22
 
22
- stub_request(:get, "https://example.com/fake-file-url").
23
- with(:headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
24
- to_return(:status => 200, :body => lambda{|request| File.open(@zipfile_name)}, :headers => {})
23
+ stub_request(:get, 'https://example.com/fake-file-url')
24
+ .with(headers: { 'Accept' => '*/*', 'User-Agent' => 'Ruby' })
25
+ .to_return(status: 200, body: ->(_request) { File.open(@zipfile_name) }, headers: {})
25
26
  end
26
27
 
27
28
  describe 'completed' do
28
29
  it 'should start a data dump' do
29
30
  data = BridgeBlueprint::RemoteData.new('https://example.com', 'key', 'secret')
31
+ expect(data.client).to receive(:create_data_dump)
32
+ data.start_data_report
33
+ end
34
+ end
35
+
36
+ describe 'completed' do
37
+ it 'should not start a data dump if already pending' do
38
+ data = BridgeBlueprint::RemoteData.new('https://pending.com', 'key', 'secret')
39
+ expect(data.client).not_to receive(:create_data_dump)
40
+ data.start_data_report
41
+ end
42
+
43
+ it 'should not start a data dump if one has already completed in the past 5 minutes' do
44
+ data = BridgeBlueprint::RemoteData.new('https://recent.com', 'key', 'secret')
45
+ expect(data.client).not_to receive(:create_data_dump)
46
+ data.start_data_report
47
+ end
48
+
49
+ it 'should start a data dump if one hasnt already completed in the past 5 minutes' do
50
+ data = BridgeBlueprint::RemoteData.new('https://notrecent.com', 'key', 'secret')
51
+ expect(data.client).to receive(:create_data_dump)
30
52
  data.start_data_report
31
53
  end
32
54
  end
@@ -43,8 +65,7 @@ describe BridgeBlueprint::RemoteData do
43
65
  data = BridgeBlueprint::RemoteData.new('https://example.com', 'key', 'secret')
44
66
  dir = Dir.mktmpdir
45
67
  data.store_file("#{@dir}/data_dump.csv")
46
- expect(File.exists?("#{@dir}/data_dump.csv")).to(eq(true))
68
+ expect(File.exist?("#{@dir}/data_dump.csv")).to(eq(true))
47
69
  end
48
70
  end
49
-
50
71
  end
@@ -0,0 +1,9 @@
1
+ {
2
+ "meta": {},
3
+ "data_dumps": [
4
+ {
5
+ "status": "pending",
6
+ "date": "2015-11-12T19:03:37Z"
7
+ }
8
+ ]
9
+ }
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/base'
2
4
  require 'tilt'
3
5
 
4
6
  class FakeBridge < Sinatra::Base
5
-
6
7
  ## Course Templates
7
8
 
8
9
  get %r{/api/author/course_templates$} do
@@ -84,7 +85,7 @@ class FakeBridge < Sinatra::Base
84
85
  get_json_data 200, 'enrollment.json'
85
86
  end
86
87
 
87
- #Custom Fields
88
+ # Custom Fields
88
89
 
89
90
  get %r{/api/author/custom_fields} do
90
91
  get_json_data 200, 'custom_fields.json'
@@ -109,7 +110,20 @@ class FakeBridge < Sinatra::Base
109
110
  # Data Dumps
110
111
 
111
112
  get %r{/api/admin/data_dumps$} do
112
- get_json_data 200, 'data_dumps.json'
113
+ host = URI.parse(url).host
114
+ if host == 'pending.com'
115
+ get_json_data 200, 'data_dumps_pending.json'
116
+ elsif host == 'notrecent.com'
117
+ data = JSON.parse(fixture('data_dumps.json').read)
118
+ data['data_dumps'][0]['date'] = (Time.now - 310).to_s
119
+ custom_response(data.to_json)
120
+ elsif host == 'recent.com'
121
+ data = JSON.parse(fixture('data_dumps.json').read)
122
+ data['data_dumps'][0]['date'] = (Time.now - 290).to_s
123
+ custom_response(data.to_json)
124
+ else
125
+ get_json_data 200, 'data_dumps.json'
126
+ end
113
127
  end
114
128
 
115
129
  post %r{/api/admin/data_dumps$} do
@@ -119,19 +133,24 @@ class FakeBridge < Sinatra::Base
119
133
  get %r{/api/admin/data_dumps/download.*} do
120
134
  content_type :json
121
135
  status 200
122
- headers[:location] = "https://example.com/fake-file-url"
136
+ headers[:location] = 'https://example.com/fake-file-url'
123
137
  end
124
138
 
125
139
  private
126
140
 
141
+ def custom_response(data)
142
+ content_type :json
143
+ status 200
144
+ data
145
+ end
146
+
127
147
  def get_json_data(response_code, file_name)
128
148
  content_type :json
129
149
  status response_code
130
- unless file_name.nil?
131
- File.open(File.dirname(__FILE__) + '/../fixtures/' + file_name).read
132
- else
150
+ if file_name.nil?
133
151
  {}
152
+ else
153
+ File.open(File.dirname(__FILE__) + '/../fixtures/' + file_name).read
134
154
  end
135
155
  end
136
-
137
156
  end
data/spec/test_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
1
4
  require 'bridge_blueprint'
2
5
  require 'rspec'
3
6
  require 'webmock/rspec'
@@ -5,7 +8,7 @@ require 'json'
5
8
  require 'pry'
6
9
 
7
10
  RSpec.configure do |config|
8
- Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
11
+ Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
9
12
 
10
13
  config.before(:each) do
11
14
  WebMock.disable_net_connect!
@@ -13,7 +16,6 @@ RSpec.configure do |config|
13
16
  end
14
17
  end
15
18
 
16
-
17
19
  def fixture(*file)
18
- File.new(File.join(File.expand_path("../fixtures", __FILE__), *file))
20
+ File.new(File.join(File.expand_path('fixtures', __dir__), *file))
19
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridge_blueprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.03
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Shaffer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-25 00:00:00.000000000 Z
11
+ date: 2021-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bridge_api
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.1.16
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0
26
+ version: 0.1.16
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: open_uri_redirections
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,39 +53,67 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.2.1
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
59
62
  - - "~>"
60
63
  - !ruby/object:Gem::Version
61
- version: '0'
64
+ version: '1.0'
62
65
  type: :development
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 1.0.0
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '0'
74
+ version: '1.0'
69
75
  - !ruby/object:Gem::Dependency
70
- name: bundler
76
+ name: byebug
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '1.0'
76
- - - ">="
81
+ version: 8.2.2
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
77
87
  - !ruby/object:Gem::Version
78
- version: 1.0.0
88
+ version: 8.2.2
89
+ - !ruby/object:Gem::Dependency
90
+ name: pry
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
79
96
  type: :development
80
97
  prerelease: false
81
98
  version_requirements: !ruby/object:Gem::Requirement
82
99
  requirements:
83
100
  - - "~>"
84
101
  - !ruby/object:Gem::Version
85
- version: '1.0'
86
- - - ">="
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
87
108
  - !ruby/object:Gem::Version
88
- version: 1.0.0
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
89
117
  - !ruby/object:Gem::Dependency
90
118
  name: rspec
91
119
  requirement: !ruby/object:Gem::Requirement
@@ -101,81 +129,81 @@ dependencies:
101
129
  - !ruby/object:Gem::Version
102
130
  version: '2.6'
103
131
  - !ruby/object:Gem::Dependency
104
- name: webmock
132
+ name: rubocop
105
133
  requirement: !ruby/object:Gem::Requirement
106
134
  requirements:
107
135
  - - "~>"
108
136
  - !ruby/object:Gem::Version
109
- version: 2.3.1
137
+ version: 0.54.0
110
138
  type: :development
111
139
  prerelease: false
112
140
  version_requirements: !ruby/object:Gem::Requirement
113
141
  requirements:
114
142
  - - "~>"
115
143
  - !ruby/object:Gem::Version
116
- version: 2.3.1
144
+ version: 0.54.0
117
145
  - !ruby/object:Gem::Dependency
118
- name: pry
146
+ name: simplecov
119
147
  requirement: !ruby/object:Gem::Requirement
120
148
  requirements:
121
149
  - - "~>"
122
150
  - !ruby/object:Gem::Version
123
- version: '0'
151
+ version: 0.16.1
124
152
  type: :development
125
153
  prerelease: false
126
154
  version_requirements: !ruby/object:Gem::Requirement
127
155
  requirements:
128
156
  - - "~>"
129
157
  - !ruby/object:Gem::Version
130
- version: '0'
158
+ version: 0.16.1
131
159
  - !ruby/object:Gem::Dependency
132
- name: tilt
160
+ name: sinatra
133
161
  requirement: !ruby/object:Gem::Requirement
134
162
  requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- version: 1.3.4
138
163
  - - "~>"
139
164
  - !ruby/object:Gem::Version
140
- version: '1.3'
165
+ version: '1.0'
141
166
  type: :development
142
167
  prerelease: false
143
168
  version_requirements: !ruby/object:Gem::Requirement
144
169
  requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- version: 1.3.4
148
170
  - - "~>"
149
171
  - !ruby/object:Gem::Version
150
- version: '1.3'
172
+ version: '1.0'
151
173
  - !ruby/object:Gem::Dependency
152
- name: sinatra
174
+ name: tilt
153
175
  requirement: !ruby/object:Gem::Requirement
154
176
  requirements:
155
177
  - - "~>"
156
178
  - !ruby/object:Gem::Version
157
- version: '1.0'
179
+ version: '1.3'
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 1.3.4
158
183
  type: :development
159
184
  prerelease: false
160
185
  version_requirements: !ruby/object:Gem::Requirement
161
186
  requirements:
162
187
  - - "~>"
163
188
  - !ruby/object:Gem::Version
164
- version: '1.0'
189
+ version: '1.3'
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: 1.3.4
165
193
  - !ruby/object:Gem::Dependency
166
- name: byebug
194
+ name: webmock
167
195
  requirement: !ruby/object:Gem::Requirement
168
196
  requirements:
169
197
  - - "~>"
170
198
  - !ruby/object:Gem::Version
171
- version: 8.2.2
199
+ version: 2.3.1
172
200
  type: :development
173
201
  prerelease: false
174
202
  version_requirements: !ruby/object:Gem::Requirement
175
203
  requirements:
176
204
  - - "~>"
177
205
  - !ruby/object:Gem::Version
178
- version: 8.2.2
206
+ version: 2.3.1
179
207
  description: Tools for consuming bridge data dumps
180
208
  email:
181
209
  - jshaffer@instructure.com
@@ -184,11 +212,17 @@ extensions: []
184
212
  extra_rdoc_files: []
185
213
  files:
186
214
  - ".gitignore"
215
+ - ".rubocop.yml"
187
216
  - ".ruby-version"
217
+ - ".simplecov"
218
+ - Dockerfile
188
219
  - Gemfile
189
220
  - Gemfile.lock
190
221
  - README.rdoc
222
+ - bin/jenkins
191
223
  - bridge_blueprint.gemspec
224
+ - build.sh
225
+ - docker-compose.yml
192
226
  - lib/bridge_blueprint.rb
193
227
  - lib/bridge_blueprint/constants.rb
194
228
  - lib/bridge_blueprint/data_dump.rb
@@ -199,13 +233,14 @@ files:
199
233
  - spec/fixtures/bridge_zip/custom_fields.csv
200
234
  - spec/fixtures/bridge_zip/users.csv
201
235
  - spec/fixtures/data_dumps.json
236
+ - spec/fixtures/data_dumps_pending.json
202
237
  - spec/support/fake_bridge.rb
203
238
  - spec/test_helper.rb
204
239
  homepage: https://getbridge.com
205
240
  licenses:
206
241
  - MIT
207
242
  metadata: {}
208
- post_install_message:
243
+ post_install_message:
209
244
  rdoc_options: []
210
245
  require_paths:
211
246
  - lib
@@ -220,16 +255,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
255
  - !ruby/object:Gem::Version
221
256
  version: '0'
222
257
  requirements: []
223
- rubyforge_project:
224
- rubygems_version: 2.6.11
225
- signing_key:
258
+ rubygems_version: 3.0.3
259
+ signing_key:
226
260
  specification_version: 4
227
261
  summary: Bridge Blueprint
228
262
  test_files:
229
263
  - spec/bridge_blueprint/data_dump_spec.rb
230
264
  - spec/bridge_blueprint/remote_data_spec.rb
265
+ - spec/support/fake_bridge.rb
231
266
  - spec/fixtures/bridge_zip/custom_fields.csv
232
267
  - spec/fixtures/bridge_zip/users.csv
233
268
  - spec/fixtures/data_dumps.json
234
- - spec/support/fake_bridge.rb
269
+ - spec/fixtures/data_dumps_pending.json
235
270
  - spec/test_helper.rb