quickbooks_web_connector 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 571ae04bbdd6cefeb9f277118239b06bf98dc292
4
+ data.tar.gz: 2a121acd4c1450fa7626b00c8fb4555a8d2c0af2
5
+ SHA512:
6
+ metadata.gz: 26b37af64bafefbcf016367e66cd13b0db7aaf9192dff2d0b6e0ab70f48e30fe15c843c4fa2503c1cfbd2dc4a94cde2ae2b72c9d29a4022a36f424655c8f58b5
7
+ data.tar.gz: 5a5045052b55c5fd906afd4a9cb4b5db28d2e54c9351d5638560bc4f6a6490b139d05add8f4ad02b61c6ef8891cb723abaebc7b868d65dffdeeb9029151ba717
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ end
21
21
  task :default => 'spec:all'
22
22
 
23
23
  namespace :spec do
24
- gemfiles = %w(rails_32 rails_40)
24
+ gemfiles = FileList['gemfiles/*.gemfile'].map { |f| File.basename(f, '.gemfile') }
25
25
 
26
26
  gemfiles.each do |gemfile|
27
27
  desc "Run tests against #{gemfile}"
@@ -2,10 +2,16 @@ module QuickbooksWebConnector
2
2
  class QwcController < QuickbooksWebConnectorController
3
3
 
4
4
  def download
5
- send_data render_to_string(:qwc),
6
- disposition: 'attachment',
7
- filename: 'qbwc.qwc',
8
- type: :xml
5
+ @user = QuickbooksWebConnector.config.users[params[:username]]
6
+
7
+ if !@user
8
+ render nothing: true, status: :not_found
9
+ else
10
+ send_data render_to_string(:qwc),
11
+ disposition: 'attachment',
12
+ filename: "#{@user.username}.qwc",
13
+ type: :xml
14
+ end
9
15
  end
10
16
 
11
17
  end
@@ -1,12 +1,12 @@
1
1
  xml.instruct!
2
2
  xml.QBWCXML do
3
- xml.AppName QuickbooksWebConnector.config.app_name
3
+ xml.AppName "#{QuickbooksWebConnector.config.app_name} (#{@user.username})"
4
4
  xml.AppID
5
5
  xml.AppURL quickbooks_web_connector.soap_url
6
6
  xml.AppDescription QuickbooksWebConnector.config.app_description
7
7
  xml.AppSupport main_app.root_url
8
- xml.UserName QuickbooksWebConnector.config.username
9
- xml.OwnerID '{d69682e6-4436-44bc-bd19-d6bfbd11778d}'
10
- xml.FileID '{916222f3-c574-4c70-8c9d-e3cec2634e49}'
8
+ xml.UserName @user.username
9
+ xml.OwnerID "{#{@user.owner_id}}"
10
+ xml.FileID "{#{@user.file_id}}"
11
11
  xml.QBType 'QBFS'
12
12
  end
data/config/routes.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  QuickbooksWebConnector::Engine.routes.draw do
2
2
 
3
- get 'qwc' => 'qwc#download', defaults: { format: :xml }
3
+ get 'qwc/:username' => 'qwc#download', as: :qwc, defaults: { format: :xml }
4
4
  post 'soap' => 'soap#endpoint'
5
5
 
6
6
  # QWC will perform a GET request to verify the SSL certificate
@@ -6,6 +6,7 @@ require 'quickbooks_web_connector/config'
6
6
  require 'quickbooks_web_connector/failure'
7
7
  require 'quickbooks_web_connector/job'
8
8
  require 'quickbooks_web_connector/json_coder'
9
+ require 'quickbooks_web_connector/user'
9
10
 
10
11
  require 'quickbooks_web_connector/soap_wrapper/default'
11
12
  require 'quickbooks_web_connector/soap_wrapper/defaultMappingRegistry'
@@ -14,32 +14,49 @@ module QuickbooksWebConnector
14
14
  @config
15
15
  end
16
16
 
17
+ def self.reset_configuration!
18
+ @config = QuickbooksWebConnector::Configuration.new
19
+ set_default_configuration
20
+ end
21
+
22
+ def self.set_default_configuration
23
+ configure do |config|
24
+ config.server_version = '1.0.0'
25
+ config.minimum_web_connector_client_version = nil
26
+
27
+ config.parent_controller = 'ApplicationController'
28
+
29
+ config.app_name = 'My QBWC App'
30
+ config.app_description = 'My QBWC App Description'
31
+ end
32
+ end
33
+
17
34
  class Configuration
18
35
  include ActiveSupport::Configurable
19
36
 
20
37
  config_accessor :server_version
21
38
  config_accessor :minimum_web_connector_client_version
22
- config_accessor :username
23
- config_accessor :password
24
- config_accessor :company_file_path
25
39
 
26
40
  config_accessor :parent_controller
27
41
 
28
42
  config_accessor :app_name
29
43
  config_accessor :app_description
30
- end
31
44
 
32
- configure do |config|
33
- config.server_version = '1.0.0'
34
- config.minimum_web_connector_client_version = nil
35
- config.username = 'web_connector'
36
- config.password = 'secret'
37
- config.company_file_path = ''
45
+ def initialize
46
+ config.users = {}
47
+ end
38
48
 
39
- config.parent_controller = 'ApplicationController'
49
+ def users
50
+ config.users
51
+ end
40
52
 
41
- config.app_name = 'My QBWC App'
42
- config.app_description = 'My QBWC App Description'
53
+ def user(username, *args)
54
+ username = username.to_s
55
+
56
+ config.users[username] = User.new(username, *args)
57
+ end
43
58
  end
44
59
 
60
+ set_default_configuration
61
+
45
62
  end
@@ -45,12 +45,15 @@ module QuickbooksWebConnector
45
45
  #
46
46
  def authenticate(parameters)
47
47
  token = SecureRandom.uuid
48
- result = if parameters.strUserName == QuickbooksWebConnector.config.username && parameters.strPassword == QuickbooksWebConnector.config.password
48
+
49
+ user = QuickbooksWebConnector.config.users[parameters.strUserName]
50
+
51
+ result = if user && user.valid_password?(parameters.strPassword)
49
52
  if QuickbooksWebConnector.size > 0
50
53
  # Store how many jobs are queued so we can track progress later
51
54
  QuickbooksWebConnector.store_job_count_for_session
52
55
 
53
- QuickbooksWebConnector.config.company_file_path
56
+ user.company_file_path
54
57
  else
55
58
  'none'
56
59
  end
@@ -0,0 +1,24 @@
1
+ module QuickbooksWebConnector
2
+ class User
3
+
4
+ attr_reader :username, :company_file_path, :owner_id, :file_id
5
+
6
+ def initialize(username, password, company_file_path, owner_id = nil, file_id = nil)
7
+ @username = username
8
+ @password = password
9
+ @company_file_path = company_file_path
10
+
11
+ @owner_id = owner_id || 'd69682e6-4436-44bc-bd19-d6bfbd11778d'
12
+ @file_id = file_id || '916222f3-c574-4c70-8c9d-e3cec2634e49'
13
+ end
14
+
15
+ def valid_password?(provided_password)
16
+ provided_password == password
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :password
22
+
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module QuickbooksWebConnector
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -1,131 +1,78 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe QuickbooksWebConnector::Configuration do
4
- subject { QuickbooksWebConnector.config }
4
+ subject(:configuration) { QuickbooksWebConnector.config }
5
5
 
6
6
  describe 'server_version' do
7
-
8
- context 'by default' do
9
- its(:server_version) { should eq '1.0.0' }
7
+ it 'returns 1.0.0 by default' do
8
+ expect(configuration.server_version).to eq('1.0.0')
10
9
  end
11
10
 
12
- context 'configured via config block' do
13
- before { QuickbooksWebConnector.configure { |c| c.server_version = '1.2.3' } }
14
-
15
- its(:server_version) { should eq '1.2.3' }
11
+ it 'allows the server_version to be configured' do
12
+ QuickbooksWebConnector.config.server_version = '1.2.3'
16
13
 
17
- after { QuickbooksWebConnector.configure { |c| c.server_version = '1.0.0' } }
14
+ expect(configuration.server_version).to eq('1.2.3')
18
15
  end
19
-
20
16
  end
21
17
 
22
18
  describe 'minimum_web_connector_client_version' do
23
-
24
- context 'by default' do
25
- its(:minimum_web_connector_client_version) { should be_nil }
19
+ it 'sets no minimum by default' do
20
+ expect(configuration.minimum_web_connector_client_version).to be_nil
26
21
  end
27
22
 
28
- context 'configured via config block' do
29
- before { QuickbooksWebConnector.configure { |c| c.minimum_web_connector_client_version = '2.1.0.30' } }
30
-
31
- its(:minimum_web_connector_client_version) { should eq '2.1.0.30' }
23
+ it 'allows the minimum_web_connector_client_version to be configured' do
24
+ QuickbooksWebConnector.config.minimum_web_connector_client_version = '2.1.0.30'
32
25
 
33
- after { QuickbooksWebConnector.configure { |c| c.minimum_web_connector_client_version = nil } }
26
+ expect(configuration.minimum_web_connector_client_version).to eq('2.1.0.30')
34
27
  end
35
-
36
28
  end
37
29
 
38
- context 'username' do
39
-
40
- context 'by default' do
41
- its(:username) { should eq 'web_connector' }
30
+ describe 'user' do
31
+ it 'defaults to no users' do
32
+ expect(configuration.users).to be_empty
42
33
  end
43
34
 
44
- context 'configured via a config block' do
45
- before { QuickbooksWebConnector.configure { |c| c.username = 'jsmith' } }
35
+ it 'adds a new user' do
36
+ configuration.user 'jane', 'secret', '/path/to/company.qbw'
46
37
 
47
- its(:username) { should eq 'jsmith' }
48
-
49
- after { QuickbooksWebConnector.configure { |c| c.username = 'web_connector' } }
50
- end
51
- end
52
-
53
- context 'password' do
54
-
55
- context 'by default' do
56
- its(:password) { should eq 'secret' }
57
- end
58
-
59
- context 'configured via a config block' do
60
- before { QuickbooksWebConnector.configure { |c| c.password = 'quickbooks' } }
61
-
62
- its(:password) { should eq 'quickbooks' }
63
-
64
- after { QuickbooksWebConnector.configure { |c| c.password = 'secret' } }
65
- end
66
- end
67
-
68
- context 'company_file_path' do
69
-
70
- context 'by default' do
71
- its(:company_file_path) { should eq '' }
72
- end
73
-
74
- context 'configured via a config block' do
75
- before { QuickbooksWebConnector.configure { |c| c.company_file_path = '/path/to/company.qbw' } }
76
-
77
- its(:company_file_path) { should eq '/path/to/company.qbw' }
78
-
79
- after { QuickbooksWebConnector.configure { |c| c.company_file_path = '' } }
38
+ expect(configuration.users.size).to eq(1)
80
39
  end
81
40
  end
82
41
 
83
42
  describe 'parent_controller' do
84
-
85
- context 'by default' do
86
- its(:parent_controller) { should eq 'ApplicationController' }
43
+ it 'uses ApplicationController by default' do
44
+ expect(configuration.parent_controller).to eq('ApplicationController')
87
45
  end
88
46
 
89
- context 'configured via config block' do
90
- before { QuickbooksWebConnector.configure { |c| c.parent_controller = 'MyController' } }
47
+ it 'allows the parent_controller to be configured' do
48
+ QuickbooksWebConnector.config.parent_controller = 'MyController'
91
49
 
92
- its(:parent_controller) { should eq 'MyController' }
93
-
94
- after { QuickbooksWebConnector.configure { |c| c.parent_controller = 'ApplicationController' } }
50
+ expect(configuration.parent_controller).to eq('MyController')
95
51
  end
96
-
97
52
  end
98
53
 
99
54
  describe 'app_name' do
100
-
101
- context 'by default' do
102
- its(:app_name) { should eq 'My QBWC App' }
55
+ it 'uses My QBWC App by default' do
56
+ expect(configuration.app_name).to eq('My QBWC App')
103
57
  end
104
58
 
105
- context 'configured via a config block' do
106
- before { QuickbooksWebConnector.configure { |c| c.app_name = 'Sample App' } }
107
-
108
- its(:app_name) { should eq 'Sample App' }
59
+ it 'allows the app_name to be configured' do
60
+ QuickbooksWebConnector.config.app_name = 'Sample App'
109
61
 
110
- after { QuickbooksWebConnector.configure { |c| c.app_name = 'My QBWC App' } }
62
+ expect(configuration.app_name).to eq('Sample App')
111
63
  end
112
-
113
64
  end
114
65
 
115
66
  describe 'app_description' do
116
-
117
- context 'by default' do
118
- its(:app_description) { should eq 'My QBWC App Description' }
67
+ it 'sets a default description' do
68
+ expect(configuration.app_description).to eq('My QBWC App Description')
119
69
  end
120
70
 
121
- context 'configured via a config block' do
122
- before { QuickbooksWebConnector.configure { |c| c.app_description = 'Sample Description' } }
71
+ it 'allows the app_description to be configured' do
72
+ QuickbooksWebConnector.config.app_description = 'Sample Description'
123
73
 
124
- its(:app_description) { should eq 'Sample Description' }
125
-
126
- after { QuickbooksWebConnector.configure { |c| c.app_description = 'My QBWC App Description' } }
74
+ expect(configuration.app_description).to eq('Sample Description')
127
75
  end
128
-
129
76
  end
130
77
 
131
78
  end
@@ -1,28 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe QuickbooksWebConnector::QwcController do
3
+ RSpec.describe QuickbooksWebConnector::QwcController, type: :controller do
4
4
 
5
5
  describe 'GET :download' do
6
- before { get :download, format: :xml, use_route: 'quickbooks_web_connector' }
6
+ it 'renders the QWC file' do
7
+ QuickbooksWebConnector.config.user 'jane', 'password', '/path/to/company.qbw'
7
8
 
8
- it 'responds with success' do
9
- expect(response).to be_success
10
- end
9
+ get :download, username: 'jane', format: :xml, use_route: 'quickbooks_web_connector'
11
10
 
12
- it 'responds as XML' do
11
+ expect(response).to be_success
13
12
  expect(response.header['Content-Type']).to match(/application\/xml/)
14
- end
15
-
16
- it 'sends the file as an attachment' do
17
13
  expect(response.header['Content-Disposition']).to match(/attachment/)
14
+ expect(response.header['Content-Disposition']).to match(/jane\.qwc/)
15
+ expect(response).to render_template(:qwc)
16
+ expect(assigns(:user).username).to eq('jane')
18
17
  end
19
18
 
20
- it 'names the file' do
21
- expect(response.header['Content-Disposition']).to match(/qbwc\.qwc/)
22
- end
19
+ it 'returns a 404 when no user matches the given username' do
20
+ get :download, username: 'jane', format: :xml, use_route: 'quickbooks_web_connector'
23
21
 
24
- it 'renders the qwc template' do
25
- assert_template :qwc
22
+ expect(response.code).to eq('404')
23
+ expect(response).to_not render_template(:qwc)
26
24
  end
27
25
  end
28
26
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe QuickbooksWebConnector::SoapController do
3
+ RSpec.describe QuickbooksWebConnector::SoapController, type: :controller do
4
4
 
5
5
  # QWC will perform a GET to check the certificate, so we gotta respond
6
6
  describe 'GET :endpoint' do
@@ -47,7 +47,7 @@ describe QuickbooksWebConnector::SoapController do
47
47
  # </env:Envelope>
48
48
 
49
49
  before do
50
- QuickbooksWebConnector.configure { |c| c.server_version = '1.2.3' }
50
+ QuickbooksWebConnector.config.server_version = '1.2.3'
51
51
 
52
52
  post :endpoint, { use_route: 'quickbooks_web_connector' }
53
53
  end
@@ -135,19 +135,7 @@ describe QuickbooksWebConnector::SoapController do
135
135
  # </env:Envelope>
136
136
 
137
137
  before do
138
- QuickbooksWebConnector.configure do |c|
139
- c.username = 'foo'
140
- c.password = 'bar'
141
- c.company_file_path = "C:\\path\\to\\company.qbw"
142
- end
143
- end
144
-
145
- after do
146
- QuickbooksWebConnector.configure do |c|
147
- c.username = 'web_connector'
148
- c.password = 'secret'
149
- c.company_file_path = nil
150
- end
138
+ QuickbooksWebConnector.config.user 'foo', 'bar', "C:\\path\\to\\company.qbw"
151
139
  end
152
140
 
153
141
  it 'responds that theres no jobs to work when authenticated without jobs' do
@@ -159,7 +147,7 @@ describe QuickbooksWebConnector::SoapController do
159
147
  end
160
148
 
161
149
  it 'returns the company_file_path when theres data to send' do
162
- SomeBuilder.stub(:perform).with(1).and_return('<some><xml></xml></some>')
150
+ allow(SomeBuilder).to receive(:perform).with(1).and_return('<some><xml></xml></some>')
163
151
  QuickbooksWebConnector.enqueue SomeBuilder, SomeHandler, 1
164
152
 
165
153
  do_post
@@ -202,7 +190,7 @@ describe QuickbooksWebConnector::SoapController do
202
190
  # </env:Envelope>
203
191
 
204
192
  before do
205
- SomeBuilder.stub(:perform).with(1).and_return('<some><xml></xml></some>')
193
+ allow(SomeBuilder).to receive(:perform).with(1).and_return('<some><xml></xml></some>')
206
194
  QuickbooksWebConnector.enqueue SomeBuilder, SomeHandler, 1
207
195
 
208
196
  do_post