salesflip-jobboersen_integration 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -16,15 +16,15 @@ module AccountExtras
|
|
16
16
|
response = connection.post(
|
17
17
|
"/administration/accounts.xml?auth_token=#{self.user.tjb_auth_token}",
|
18
18
|
self.to_xml(:only => [:name]))
|
19
|
-
|
20
|
-
self.update_attributes :tjb_id =>
|
19
|
+
attributes = Hash.from_xml(response.body)['account']
|
20
|
+
self.update_attributes :tjb_id => attributes['_id'],
|
21
21
|
:do_not_update => true
|
22
22
|
rescue
|
23
23
|
nil
|
24
24
|
end
|
25
25
|
|
26
26
|
def update_in_tjb
|
27
|
-
connection.put("/administration/accounts/#{self.
|
27
|
+
connection.put("/administration/accounts/#{self.tjb_id}.xml?auth_token=#{self.user.tjb_auth_token}",
|
28
28
|
self.to_xml(:only => [:name]))
|
29
29
|
end
|
30
30
|
|
@@ -16,15 +16,15 @@ module ContactExtras
|
|
16
16
|
def create_in_tjb
|
17
17
|
response = connection.post(
|
18
18
|
"/administration/contacts.xml?auth_token=#{self.user.tjb_auth_token}", tjb_xml)
|
19
|
-
|
20
|
-
self.update_attributes :tjb_id =>
|
19
|
+
attributes = Hash.from_xml(response.body)['user']
|
20
|
+
self.update_attributes :tjb_id => attributes['_id'], :do_not_update => true
|
21
21
|
rescue
|
22
22
|
nil
|
23
23
|
end
|
24
24
|
|
25
25
|
def update_in_tjb
|
26
|
-
|
27
|
-
"/administration/contacts/#{self.
|
26
|
+
connection.put(
|
27
|
+
"/administration/contacts/#{self.tjb_id}.xml?auth_token=#{self.user.tjb_auth_token}", tjb_xml)
|
28
28
|
rescue
|
29
29
|
nil
|
30
30
|
end
|
data/lib/app/lib/user_extras.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'rexml/document'
|
2
|
-
|
3
1
|
module UserExtras
|
4
2
|
def self.included( base )
|
5
3
|
base.class_eval do
|
@@ -20,9 +18,9 @@ module UserExtras
|
|
20
18
|
response = connection.post('/administration/administrators.xml',
|
21
19
|
self.to_xml(:only => :email))
|
22
20
|
if response.code == '200'
|
23
|
-
|
24
|
-
self.update_attributes :tjb_id =>
|
25
|
-
:tjb_auth_token =>
|
21
|
+
attributes = Hash.from_xml(response.body)['administrator']
|
22
|
+
self.update_attributes :tjb_id => attributes['_id'],
|
23
|
+
:tjb_auth_token => attributes['authentication_token'],
|
26
24
|
:do_not_update => true
|
27
25
|
end
|
28
26
|
rescue
|
@@ -30,14 +28,15 @@ module UserExtras
|
|
30
28
|
end
|
31
29
|
|
32
30
|
def update_in_tjb
|
33
|
-
connection.put(
|
31
|
+
connection.put(
|
32
|
+
"/administration/administrators/#{self.tjb_id}.xml?auth_token=#{self.tjb_auth_token}",
|
34
33
|
self.to_xml(:only => :email))
|
35
34
|
rescue
|
36
35
|
nil
|
37
36
|
end
|
38
37
|
|
39
38
|
def connection
|
40
|
-
|
39
|
+
ActiveResource::Connection.new(JobboersenIntegration.jobboersen_uri)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
data/test/unit/user_test.rb
CHANGED
@@ -17,17 +17,19 @@ class UserTest < ActiveSupport::TestCase
|
|
17
17
|
should 'have tjb_auth_token field' do
|
18
18
|
assert User.fields.map(&:first).include?('tjb_auth_token')
|
19
19
|
end
|
20
|
-
|
21
|
-
context 'when the user does not exist in 1000jobboersen' do
|
22
|
-
setup do
|
23
|
-
FakeWeb.register_uri(:post, 'http://1000jobboersen.de/administration/administrators.xml',
|
24
|
-
:body => File.read('test/support/administrator_create_success.xml'))
|
25
|
-
end
|
26
20
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
should 'update the tjb_id when the administrator account has been created in 1000jobboersen' do
|
22
|
+
FakeWeb.register_uri(:post, 'http://1000jobboersen.de/administration/administrators.xml',
|
23
|
+
:body => File.read('test/support/administrator_create_success.xml'))
|
24
|
+
user = User.create! :email => 'test@test.com'
|
25
|
+
assert_equal '4bcdbfea24d8f22230000011', user.tjb_id
|
26
|
+
assert_equal 'La9Hbm8SnPJN-F-zUhlp', user.tjb_auth_token
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'not blow up when an error response is returned' do
|
30
|
+
FakeWeb.register_uri(:post, 'http://1000jobboersen.de/administration/administrators.xml',
|
31
|
+
:status => '500')
|
32
|
+
user = User.create! :email => 'test@test.com'
|
33
|
+
assert !user.new_record?
|
32
34
|
end
|
33
35
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salesflip-jobboersen_integration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors: []
|
13
13
|
|