mode 0.0.7 → 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
2
  SHA1:
3
- metadata.gz: 916fc74b44c1c5b65091492b449464196a27067c
4
- data.tar.gz: 41bdef70c556a8b1807e5e9f8fb71bfce3a39ded
3
+ metadata.gz: 03a5f9840967c0b0a7b461ff7ebbef1ceee872f6
4
+ data.tar.gz: d207b4e636caaf13e1c43ae76aa86e556aba7825
5
5
  SHA512:
6
- metadata.gz: aba504acfea6ea6cd6052666abd9f826c44e1241ba738b523089bedd8e4e700f4d40e78ba1c5df9adf8d6dfcf0f03003564114cf29a79bc597d98fca31ecbf4e
7
- data.tar.gz: 0fc687a9b19413e7c47339aaa6ddd215145a374f1cbb5d068b37c2c5b134891553c3ff69d1a8891c805f3c97f4594bedac2778374986e632b487db28d3666858
6
+ metadata.gz: da0837b3b8b33c55de80fba1d1ecfc2b16dc47831658f5fee2da7387bff8fba4ea6022a3732b30b020fe8379a66624a8bfd9b53e31d006850eba8a17a3301fda
7
+ data.tar.gz: 2aff0e732ef9fa57dfec9702e41b14c3377a6a8fe3eded36e05c17c0d7e4a0ae82102b8cab4778878a0b6f8bfaee7d724987ec7f045e92a8cb7a789a70a81243
@@ -63,6 +63,12 @@ module Mode
63
63
  end
64
64
  elsif resource.status == 401
65
65
  raise "Login failed, credentials invalid"
66
+ elsif resource.status == 404
67
+ raise "Login failed, access tokens not found"
68
+ elsif resource.status == 500
69
+ raise "Login failed, internal server error"
70
+ else
71
+ raise "Login failed, unknown error"
66
72
  end
67
73
  end
68
74
 
@@ -80,7 +86,9 @@ module Mode
80
86
  def choose_access_token
81
87
  access_tokens = fetch_access_tokens
82
88
 
83
- if access_tokens.length == 1
89
+ if access_tokens.nil?
90
+ raise "Couldn't retrieve access tokens"
91
+ elsif access_tokens.length == 1
84
92
  access_tokens.first
85
93
  else
86
94
  chosen = prompt_access_tokens(access_tokens)
@@ -30,34 +30,58 @@ module Mode
30
30
  props['host']
31
31
  end
32
32
 
33
+ def port
34
+ props['port']
35
+ end
36
+
33
37
  def database
34
38
  props['database']
35
39
  end
36
40
 
41
+ def ssl_mode
42
+ props['sslmode'] || 'prefer'
43
+ end
44
+
37
45
  def select(query, &block)
38
46
  connection_dataset(query).each(&block)
39
47
  end
40
48
 
41
49
  def connection
42
- if redshift?
43
- @connection ||= Sequel.connect(connection_url,
44
- :client_min_messages => '',
45
- :force_standard_strings => false
46
- )
47
- else
48
- @connection ||= Sequel.connect(connection_url)
49
- end
50
+ @connection ||= Sequel.connect(connection_url, adapter_opts)
50
51
  end
51
52
 
52
53
  def redshift?
53
54
  adapter == 'redshift'
54
55
  end
55
56
 
57
+ def postgres?
58
+ adapter == 'postgres'
59
+ end
60
+
56
61
  private
57
62
 
63
+ def adapter_opts
64
+ opts = {}
65
+
66
+ if redshift?
67
+ opts.merge!({
68
+ :sslmode => ssl_mode,
69
+ :client_min_messages => '',
70
+ :force_standard_strings => false
71
+ })
72
+ elsif postgres?
73
+ opts.merge!({
74
+ :sslmode => ssl_mode
75
+ })
76
+ end
77
+
78
+ opts
79
+ end
80
+
58
81
  def connection_url
82
+ port_segment = port.nil? ? nil : ":#{port}"
59
83
  password_segment = password.nil? ? nil : ":#{password}"
60
- "#{adapter}://#{username}#{password_segment}@#{host}/#{database}"
84
+ "#{adapter}://#{username}#{password_segment}@#{host}#{port_segment}/#{database}"
61
85
  end
62
86
 
63
87
  def connection_dataset(query)
data/lib/mode/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mode
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -54,9 +54,12 @@ describe Mode::Connector::DataSource do
54
54
  it 'has a connection dataset' do
55
55
  source = Mode::Connector::DataSource.new('dev', props)
56
56
 
57
+ dataset = double(:dataset, :with_sql => :dataset)
58
+ connection = double(:connection, :dataset => dataset)
59
+ Sequel.should_receive(:connect).and_return(connection)
57
60
  dataset = source.send(:connection_dataset, "SELECT * FROM fake")
58
61
 
59
- dataset.should_not == nil
62
+ dataset.should == :dataset
60
63
  end
61
64
 
62
65
  it "fetches results from dataset" do
@@ -25,6 +25,8 @@ describe Mode::Connector::Scheduler do
25
25
  rufus.should_receive(:join).and_return(true)
26
26
  rufus.should_receive(:stop).and_return(true)
27
27
 
28
+ Sequel.should_receive(:connect).and_return(:connect)
29
+
28
30
  scheduler = Mode::Connector::Scheduler.new(data_sources)
29
31
 
30
32
  scheduler.start!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mode Analytics