Birst_Command 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/Birst_Command.gemspec +4 -3
- data/CHANGELOG.md +23 -0
- data/Gemfile +7 -3
- data/Gemfile.lock +65 -0
- data/README.md +34 -23
- data/Rakefile +0 -13
- data/bin/birstcl +5 -12
- data/lib/birst_command.rb +3 -1
- data/lib/birst_command/core_additions.rb +8 -0
- data/lib/birst_command/session.rb +110 -47
- data/lib/birst_command/settings.rb +26 -0
- data/lib/birst_command/version.rb +1 -1
- data/spec/bc_spec_fixtures.rb +70 -0
- data/spec/birst_command_spec.rb +13 -0
- data/spec/cookie_spec.rb +74 -0
- data/spec/sample_settings.yaml +9 -0
- data/spec/session_spec.rb +101 -0
- data/spec/session_spec_helper.rb +10 -0
- data/spec/settings_spec.rb +19 -0
- metadata +37 -30
- data/config.json_template +0 -6
- data/lib/birst_command/config.rb +0 -28
- data/test/.gitignore +0 -1
- data/test/config_test.json_template +0 -8
- data/test/standard/resources/config_test.json +0 -4
- data/test/standard/test_add_user_to_space.rb +0 -49
- data/test/standard/test_command_helper.rb +0 -44
- data/test/standard/test_cookie.rb +0 -61
- data/test/standard/test_copy_space.rb +0 -55
- data/test/standard/test_list_spaces.rb +0 -24
- data/test/standard/test_login.rb +0 -23
- data/test/standard/test_password.rb +0 -21
- data/test/standard/test_read_config.rb +0 -18
- data/test/test_birst_command.rb +0 -10
@@ -0,0 +1,26 @@
|
|
1
|
+
module Birst_Command
|
2
|
+
|
3
|
+
# Public: Configatron instance used to set default options for Birst_Connect
|
4
|
+
Settings = Configatron::Store.new
|
5
|
+
|
6
|
+
def self.load_default_settings
|
7
|
+
# Default settings applied to all sessions (can be overridden in specific session)
|
8
|
+
Settings.session do |session|
|
9
|
+
session.wsdl = "https://app2101.bws.birst.com/CommandWebService.asmx?WSDL"
|
10
|
+
session.endpoint = "https://app2101.bws.birst.com/CommandWebService.asmx"
|
11
|
+
session.username = ENV['BIRST_USER'] || "BIRST_USER"
|
12
|
+
session.password = ENV['BIRST_PWD'] || "BIRST_PWD"
|
13
|
+
session.soap_log = true
|
14
|
+
session.soap_log_level = :error
|
15
|
+
session.soap_logger = Logger.new(STDOUT)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
load_default_settings
|
19
|
+
|
20
|
+
def self.load_settings_from_file(file)
|
21
|
+
parse_erb = ERB.new(IO.read(file)).result(binding)
|
22
|
+
settings = YAML.load(parse_erb).symbolize_keys
|
23
|
+
Settings.configure_from_hash(settings)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module BCSpecFixtures
|
2
|
+
class << self
|
3
|
+
|
4
|
+
def login_token
|
5
|
+
"46a87e10b37e21653186ffe0973f54ae"
|
6
|
+
end
|
7
|
+
|
8
|
+
def login
|
9
|
+
<<-EOT.unindent
|
10
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
11
|
+
<soap:Body>
|
12
|
+
<LoginResponse xmlns="http://www.birst.com/">
|
13
|
+
<LoginResult>#{login_token}</LoginResult>
|
14
|
+
</LoginResponse>
|
15
|
+
</soap:Body>
|
16
|
+
</soap:Envelope>
|
17
|
+
EOT
|
18
|
+
end
|
19
|
+
|
20
|
+
def logout
|
21
|
+
<<-EOT.unindent
|
22
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
23
|
+
<soap:Body>
|
24
|
+
<LogoutResponse xmlns="http://www.birst.com/"/>
|
25
|
+
</soap:Body>
|
26
|
+
</soap:Envelope>
|
27
|
+
EOT
|
28
|
+
end
|
29
|
+
|
30
|
+
def list_spaces
|
31
|
+
<<-EOT.unindent
|
32
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
33
|
+
<soap:Body>
|
34
|
+
<listSpacesResponse xmlns="http://www.birst.com/">
|
35
|
+
<listSpacesResult>
|
36
|
+
<UserSpace>
|
37
|
+
<name>My_First_Space</name>
|
38
|
+
<owner>user@example.com</owner>
|
39
|
+
<id>b016c5c7-00ad-413a-a058-db78edef2961</id>
|
40
|
+
</UserSpace>
|
41
|
+
<UserSpace>
|
42
|
+
<name>My_Second_Space</name>
|
43
|
+
<owner>user@example.com</owner>
|
44
|
+
<id>b7f3df39-438c-4ec7-bd29-489f41afde14</id>
|
45
|
+
</UserSpace>
|
46
|
+
</listSpacesResult>
|
47
|
+
</listSpacesResponse>
|
48
|
+
</soap:Body>
|
49
|
+
</soap:Envelope>
|
50
|
+
EOT
|
51
|
+
end
|
52
|
+
|
53
|
+
def list_users_in_space
|
54
|
+
<<-EOT.unindent
|
55
|
+
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
56
|
+
<soap:Body>
|
57
|
+
<listUsersInSpaceResponse xmlns="http://www.birst.com/">
|
58
|
+
<listUsersInSpaceResult>
|
59
|
+
<string>user@example.com</string>
|
60
|
+
<string>myname@example.com</string>
|
61
|
+
<string>coolbeans@example.com</string>
|
62
|
+
</listUsersInSpaceResult>
|
63
|
+
</listUsersInSpaceResponse>
|
64
|
+
</soap:Body>
|
65
|
+
</soap:Envelope>
|
66
|
+
EOT
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH << '../lib'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
|
6
|
+
require 'birst_command'
|
7
|
+
require 'savon/mock/spec_helper'
|
8
|
+
require 'session_spec_helper'
|
9
|
+
require_relative 'bc_spec_fixtures'
|
10
|
+
|
11
|
+
include Birst_Command
|
12
|
+
include Savon::SpecHelper
|
13
|
+
include SessionSpecHelper
|
data/spec/cookie_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Unfortunately, Savon cannot mock cookies. So we'll have to run it live.
|
2
|
+
describe "Cookie handling" do
|
3
|
+
before { Settings.session.soap_log_level = :debug }
|
4
|
+
|
5
|
+
# Create a new space
|
6
|
+
let(:session_vars) do
|
7
|
+
space_id = nil
|
8
|
+
cookie = nil
|
9
|
+
Session.new do |bc|
|
10
|
+
space_id = bc.create_new_space(
|
11
|
+
:spaceName => "Birst_Command-Spec-#{SecureRandom.hex(4)}",
|
12
|
+
:comments => "",
|
13
|
+
:automatic => "false"
|
14
|
+
)
|
15
|
+
cookie = bc.auth_cookie
|
16
|
+
end
|
17
|
+
{ :space_id => space_id, :cookie => cookie }
|
18
|
+
end
|
19
|
+
|
20
|
+
# Set the space id and cookie separately
|
21
|
+
[:space_id, :cookie].each do |var|
|
22
|
+
let(var) { session_vars[var] }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Example data chunk to upload
|
26
|
+
let(:data_chunk) do
|
27
|
+
<<-EOT.unindent
|
28
|
+
category,value
|
29
|
+
A,1
|
30
|
+
B,2
|
31
|
+
C,3
|
32
|
+
D,4
|
33
|
+
E,5
|
34
|
+
EOT
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# Cleanup created spaces
|
39
|
+
after do
|
40
|
+
Session.new do |bc|
|
41
|
+
bc.delete_space :spaceId => space_id
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# This test doesn't always fail if there is a cookie problem, so test it 5 times
|
47
|
+
1.upto(5).each do
|
48
|
+
specify "cookie should enforce login environment" do
|
49
|
+
upload_token = nil
|
50
|
+
Session.new auth_cookie: cookie do |bc|
|
51
|
+
upload_token = bc.begin_data_upload(:spaceID => space_id,
|
52
|
+
:sourceName => "MyTestData"
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
Session.new auth_cookie: cookie, soap_log_level: :error do |bc|
|
57
|
+
bc.upload_data(:dataUploadToken => upload_token,
|
58
|
+
:numBytes => data_chunk.bytesize,
|
59
|
+
:data => Base64.encode64(data_chunk)
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
Session.new auth_cookie: cookie do |bc|
|
64
|
+
bc.finish_data_upload(:dataUploadToken => upload_token)
|
65
|
+
end
|
66
|
+
|
67
|
+
Session.new auth_cookie: cookie do |bc|
|
68
|
+
upload_complete = bc.is_data_upload_complete(:dataUploadToken => upload_token)
|
69
|
+
puts "UPLOAD COMPLETE? #{upload_complete}"
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
---
|
2
|
+
|
3
|
+
session:
|
4
|
+
wsdl: "https://app2101.bws.birst.com/CommandWebService.asmx?WSDL"
|
5
|
+
endpoint: "https://app2101.bws.birst.com/CommandWebService.asmx"
|
6
|
+
username: "ThisIsntARealUsername"
|
7
|
+
password: "<%= ENV['BC_SPEC_PASSWORD'] %>"
|
8
|
+
soap_log: true
|
9
|
+
soap_log_level: :error
|
@@ -0,0 +1,101 @@
|
|
1
|
+
describe "Sessions" do
|
2
|
+
before { Settings.session.soap_log_level = :debug }
|
3
|
+
|
4
|
+
shared_examples_for "Log in and out" do
|
5
|
+
|
6
|
+
context "by calling the object methods directly" do
|
7
|
+
specify "without options" do
|
8
|
+
mysession = Session.new
|
9
|
+
expect(mysession.login).to be_successful
|
10
|
+
mysession.logout
|
11
|
+
end
|
12
|
+
|
13
|
+
specify "with options" do
|
14
|
+
mysession = Session.new :soap_log_level => :error, :soap_logger => Logger.new(STDOUT)
|
15
|
+
expect(mysession.login).to be_successful
|
16
|
+
mysession.logout
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "in a session block" do
|
21
|
+
specify "without options" do
|
22
|
+
Session.new do |bc|
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
specify "with options" do
|
27
|
+
Session.new :soap_log_level => :error, :soap_logger => Logger.new(STDOUT) do |bc|
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
shared_examples_for "list spaces" do
|
35
|
+
describe "list spaces" do
|
36
|
+
it "should list spaces" do
|
37
|
+
spaces = nil
|
38
|
+
Session.new do |bc|
|
39
|
+
spaces = bc.list_spaces
|
40
|
+
end
|
41
|
+
|
42
|
+
expect(spaces[:user_space].length).to be > 0
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
shared_examples_for "list users in space" do
|
48
|
+
describe "list users in space" do
|
49
|
+
it "should list the users in the space" do
|
50
|
+
users = nil
|
51
|
+
Session.new do |bc|
|
52
|
+
users = bc.list_users_in_space :spaceID => spaceID
|
53
|
+
end
|
54
|
+
|
55
|
+
expect(users[:string].length).to be > 0
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
context "with mock objects" do
|
63
|
+
|
64
|
+
before { savon.mock! }
|
65
|
+
after { savon.unmock! }
|
66
|
+
|
67
|
+
context "mock log in and out" do
|
68
|
+
before { mock_login_and_out }
|
69
|
+
it_behaves_like "Log in and out"
|
70
|
+
end
|
71
|
+
|
72
|
+
context "mock list spaces" do
|
73
|
+
before do
|
74
|
+
mock_login_and_out { savon.expects(:list_spaces).with(message: { :token => BCSpecFixtures.login_token }).returns(BCSpecFixtures.list_spaces) }
|
75
|
+
end
|
76
|
+
it_behaves_like "list spaces"
|
77
|
+
end
|
78
|
+
|
79
|
+
context "mock list users in spaces" do
|
80
|
+
let(:spaceID) { "b7f3df39-438c-4ec7-bd29-489f41afde14" }
|
81
|
+
before do
|
82
|
+
message = { :token => BCSpecFixtures.login_token, :spaceID => spaceID }
|
83
|
+
mock_login_and_out { savon.expects(:list_users_in_space).with(message: message).returns(BCSpecFixtures.list_users_in_space) }
|
84
|
+
end
|
85
|
+
it_behaves_like "list users in space"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "with live connection to BWS", :live => true do
|
90
|
+
it_behaves_like "Log in and out"
|
91
|
+
it_behaves_like "list spaces"
|
92
|
+
|
93
|
+
let(:spaceID) do
|
94
|
+
spaces = nil
|
95
|
+
Session.new { |bc| spaces = bc.list_spaces }
|
96
|
+
spaces[:user_space][0][:id]
|
97
|
+
end
|
98
|
+
it_behaves_like "list users in space"
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module SessionSpecHelper
|
2
|
+
def mock_login_and_out(&block)
|
3
|
+
crypt = Envcrypt::Envcrypter.new
|
4
|
+
|
5
|
+
message = { :username => Settings.session.username, :password => crypt.decrypt(Settings.session.password) }
|
6
|
+
savon.expects(:login).with(message: message).returns(BCSpecFixtures.login)
|
7
|
+
yield if block_given?
|
8
|
+
savon.expects(:logout).with(message: { :token => BCSpecFixtures.login_token }).returns(BCSpecFixtures.logout)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe "Loading settings from YAML file" do
|
2
|
+
|
3
|
+
let(:test_password) { "Habedashery==" }
|
4
|
+
|
5
|
+
before do
|
6
|
+
ENV['BC_SPEC_PASSWORD'] = test_password
|
7
|
+
|
8
|
+
file = File.join(File.dirname(__FILE__),"sample_settings.yaml")
|
9
|
+
Birst_Command.load_settings_from_file(file)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set the username from the file" do
|
13
|
+
expect(Settings.session.username).to eq "ThisIsntARealUsername"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should use ERB to set the password" do
|
17
|
+
expect(Settings.session.password).to eq test_password
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Birst_Command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sterling Paramore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.5'
|
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: '2.
|
26
|
+
version: '2.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: httpclient
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: configatron
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.2'
|
55
69
|
description: Ruby interface to Birst web API
|
56
70
|
email:
|
57
71
|
- gnilrets@gmail.com
|
@@ -62,32 +76,29 @@ extra_rdoc_files: []
|
|
62
76
|
files:
|
63
77
|
- .bundle/config
|
64
78
|
- .gitignore
|
79
|
+
- .rspec
|
65
80
|
- .ruby-version
|
66
81
|
- Birst_Command.gemspec
|
82
|
+
- CHANGELOG.md
|
67
83
|
- Gemfile
|
84
|
+
- Gemfile.lock
|
68
85
|
- LICENSE
|
69
86
|
- README.md
|
70
87
|
- Rakefile
|
71
88
|
- bin/birstcl
|
72
|
-
- config.json_template
|
73
89
|
- doc/roadmap.md
|
74
90
|
- lib/birst_command.rb
|
75
|
-
- lib/birst_command/config.rb
|
76
91
|
- lib/birst_command/core_additions.rb
|
77
92
|
- lib/birst_command/session.rb
|
93
|
+
- lib/birst_command/settings.rb
|
78
94
|
- lib/birst_command/version.rb
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
-
|
86
|
-
- test/standard/test_list_spaces.rb
|
87
|
-
- test/standard/test_login.rb
|
88
|
-
- test/standard/test_password.rb
|
89
|
-
- test/standard/test_read_config.rb
|
90
|
-
- test/test_birst_command.rb
|
95
|
+
- spec/bc_spec_fixtures.rb
|
96
|
+
- spec/birst_command_spec.rb
|
97
|
+
- spec/cookie_spec.rb
|
98
|
+
- spec/sample_settings.yaml
|
99
|
+
- spec/session_spec.rb
|
100
|
+
- spec/session_spec_helper.rb
|
101
|
+
- spec/settings_spec.rb
|
91
102
|
homepage: https://github.com/gnilrets
|
92
103
|
licenses:
|
93
104
|
- MIT
|
@@ -108,19 +119,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
119
|
version: '0'
|
109
120
|
requirements: []
|
110
121
|
rubyforge_project: Birst_Command
|
111
|
-
rubygems_version: 2.
|
122
|
+
rubygems_version: 2.3.0
|
112
123
|
signing_key:
|
113
124
|
specification_version: 4
|
114
125
|
summary: Birst Command
|
115
126
|
test_files:
|
116
|
-
-
|
117
|
-
-
|
118
|
-
-
|
119
|
-
-
|
120
|
-
-
|
121
|
-
-
|
122
|
-
-
|
123
|
-
- test/standard/test_login.rb
|
124
|
-
- test/standard/test_password.rb
|
125
|
-
- test/standard/test_read_config.rb
|
126
|
-
- test/test_birst_command.rb
|
127
|
+
- spec/bc_spec_fixtures.rb
|
128
|
+
- spec/birst_command_spec.rb
|
129
|
+
- spec/cookie_spec.rb
|
130
|
+
- spec/sample_settings.yaml
|
131
|
+
- spec/session_spec.rb
|
132
|
+
- spec/session_spec_helper.rb
|
133
|
+
- spec/settings_spec.rb
|