tfso 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tfso.rb +4 -2
- data/lib/tfso/authentication.rb +6 -4
- data/lib/tfso/client.rb +2 -1
- data/lib/tfso/company.rb +6 -4
- data/lib/tfso/errors.rb +5 -0
- data/lib/tfso/helpers.rb +6 -1
- data/lib/tfso/invoice.rb +19 -8
- data/lib/tfso/payment.rb +2 -1
- data/lib/tfso/person.rb +47 -0
- data/lib/tfso/product.rb +1 -1
- data/lib/tfso/version.rb +1 -1
- data/tfso.gemspec +3 -3
- metadata +15 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a00d935fda27bd1614682ca5b89da473d26ddd7df4ee77c5e00e94ecef5d3a3
|
4
|
+
data.tar.gz: 6d4208e29b1f762d5d463a57dfcd9641e6339a7d62741e9b5bda8502c48e4c1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3de71d9a717c6d4522b39888459dba549e7027686b250935789f433f84284a61df9c0d00b67d3269eb7d933bfd1f16b47675228fbacf1f4766fe401df5e1f8b0
|
7
|
+
data.tar.gz: 665930704f8077f64f3d8baff2594ef695fa60f67340b872f5ec26decd2d38fd6838b6683431fa947eb645e7ab7718d64cc4aff6d1eca8b28ec194906ba9bbe5
|
data/lib/tfso.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'savon'
|
2
|
-
require
|
2
|
+
require 'tfso/version'
|
3
3
|
require 'tfso/helpers'
|
4
|
+
require 'tfso/errors'
|
4
5
|
require 'tfso/authentication'
|
5
6
|
require 'tfso/client'
|
6
7
|
require 'tfso/company'
|
7
8
|
require 'tfso/invoice'
|
8
9
|
require 'tfso/payment'
|
9
|
-
require 'tfso/product'
|
10
|
+
require 'tfso/product'
|
11
|
+
require 'tfso/person'
|
data/lib/tfso/authentication.rb
CHANGED
@@ -14,17 +14,19 @@ module TFSO
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def authenticated?
|
17
|
-
response = savon_client.call(:has_session, cookies: @cookies
|
17
|
+
response = savon_client.call(:has_session, cookies: @cookies)
|
18
|
+
raise Errors::Authentication, 'Not authenticated' if !response.body[:has_session_response][:has_session_result]
|
18
19
|
response.body[:has_session_response][:has_session_result]
|
19
20
|
end
|
20
21
|
|
21
22
|
def authenticate(username, password, identity_id = nil)
|
22
|
-
response = savon_client.call(:login, message: { credential: {Username: username, Password: password, IdentityId: identity_id, ApplicationId: application_id}
|
23
|
+
response = savon_client.call(:login, message: { credential: {Username: username, Password: password, IdentityId: identity_id, ApplicationId: application_id}})
|
24
|
+
raise Errors::Authentication, 'Incorrect credentials' if response.body[:login_response][:login_result].blank?
|
23
25
|
self.session_id = response.body[:login_response][:login_result]
|
24
26
|
end
|
25
27
|
|
26
28
|
def identities
|
27
|
-
response = savon_client.call(:get_identities, cookies: @cookies
|
29
|
+
response = savon_client.call(:get_identities, cookies: @cookies)
|
28
30
|
list = response.body[:get_identities_response][:get_identities_result][:identity]
|
29
31
|
if list.is_a?(Hash)
|
30
32
|
[list]
|
@@ -39,7 +41,7 @@ module TFSO
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def identity_id=(identity_id)
|
42
|
-
|
44
|
+
savon_client.call(:set_identity_by_id, message: {identityId: identity_id}, cookies: @cookies)
|
43
45
|
@identity_id = identity_id
|
44
46
|
end
|
45
47
|
|
data/lib/tfso/client.rb
CHANGED
@@ -6,12 +6,13 @@ module TFSO
|
|
6
6
|
URL = 'https://api.24sevenoffice.com/Client/V001/ClientService.asmx?WSDL'
|
7
7
|
|
8
8
|
def initialize(auth)
|
9
|
+
ensure_authenticated(auth)
|
9
10
|
self.session_id = auth.session_id
|
10
11
|
intialize_savon_client
|
11
12
|
end
|
12
13
|
|
13
14
|
def type_groups(module_type)
|
14
|
-
response = savon_client.call(:get_type_group_list, message: {module_type: module_type
|
15
|
+
response = savon_client.call(:get_type_group_list, message: {module_type: module_type}, cookies: @cookies)
|
15
16
|
response.body[:get_type_group_list_response][:get_type_group_list_result]
|
16
17
|
end
|
17
18
|
|
data/lib/tfso/company.rb
CHANGED
@@ -6,12 +6,13 @@ module TFSO
|
|
6
6
|
URL = 'https://api.24sevenoffice.com/CRM/Company/V001/CompanyService.asmx?wsdl'
|
7
7
|
|
8
8
|
def initialize(auth)
|
9
|
+
ensure_authenticated(auth)
|
9
10
|
self.session_id = auth.session_id
|
10
11
|
intialize_savon_client
|
11
12
|
end
|
12
13
|
|
13
14
|
def find(search_params)
|
14
|
-
response = savon_client.call(:get_companies, message: {searchParams: search_params, returnProperties: {string: ['Id', 'OrganizationNumber', 'NickName', 'Country', 'Addresses', 'EmailAddresses', 'PhoneNumbers', 'InvoiceLanguage', 'TypeGroup', 'DistributionMethod', 'Currency']
|
15
|
+
response = savon_client.call(:get_companies, message: {searchParams: search_params, returnProperties: {string: ['Id', 'OrganizationNumber', 'NickName', 'Country', 'Addresses', 'EmailAddresses', 'PhoneNumbers', 'InvoiceLanguage', 'TypeGroup', 'DistributionMethod', 'Currency']}}, cookies: @cookies)
|
15
16
|
result = response.body[:get_companies_response][:get_companies_result]
|
16
17
|
if result
|
17
18
|
if result[:company].class == Hash
|
@@ -35,7 +36,7 @@ module TFSO
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def create(company_info)
|
38
|
-
response = savon_client.call(:save_companies, message: {companies: [{Company: company_info}]
|
39
|
+
response = savon_client.call(:save_companies, message: {companies: [{Company: company_info}]}, cookies: @cookies)
|
39
40
|
result = response.body[:save_companies_response][:save_companies_result]
|
40
41
|
if result
|
41
42
|
if result[:company].class == Hash
|
@@ -53,6 +54,7 @@ module TFSO
|
|
53
54
|
end
|
54
55
|
|
55
56
|
def transform_attributes(company)
|
57
|
+
company.compact!
|
56
58
|
company[:EmailAddresses] ||= []
|
57
59
|
company[:PhoneNumbers] ||= []
|
58
60
|
company[:Addresses] ||= []
|
@@ -108,13 +110,13 @@ module TFSO
|
|
108
110
|
company.delete(:billing_address)
|
109
111
|
end
|
110
112
|
if company[:tfso]
|
111
|
-
company[:tfso].keys.each{|k| company[k] = company[:tfso].delete(k)
|
113
|
+
company[:tfso].keys.each{|k| company[k] = company[:tfso].delete(k)}
|
112
114
|
company.delete(:tfso)
|
113
115
|
end
|
114
116
|
|
115
117
|
mappings = {:name => :Name, :nickname => :NickName, :gov_no => :OrganizationNumber, :country_code => :Country}
|
116
118
|
|
117
|
-
company.keys.each {
|
119
|
+
company.keys.each {|k| company[ mappings[k] ] = company.delete(k) if mappings[k]}
|
118
120
|
company
|
119
121
|
end
|
120
122
|
|
data/lib/tfso/errors.rb
ADDED
data/lib/tfso/helpers.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
1
|
module TFSO
|
2
2
|
|
3
3
|
module Helpers
|
4
|
+
|
4
5
|
def intialize_savon_client
|
5
6
|
@savon_client = Savon.client(wsdl: self.class::URL, convert_request_keys_to: :none)
|
6
|
-
if defined?(Rails) && Rails.env.development?
|
7
|
+
if ENV['RACK_ENV'] == 'test' || defined?(Rails) && Rails.env.development?
|
7
8
|
@savon_client.globals.proxy('http://localhost:8080')
|
8
9
|
@savon_client.globals.ssl_verify_mode(:none)
|
9
10
|
end
|
10
11
|
@savon_client.globals.unwrap(true)
|
11
12
|
end
|
12
13
|
|
14
|
+
def ensure_authenticated(auth)
|
15
|
+
auth.authenticated?
|
16
|
+
end
|
17
|
+
|
13
18
|
def savon_client
|
14
19
|
@savon_client
|
15
20
|
end
|
data/lib/tfso/invoice.rb
CHANGED
@@ -6,6 +6,7 @@ module TFSO
|
|
6
6
|
URL = 'https://api.24sevenoffice.com/Economy/InvoiceOrder/V001/InvoiceService.asmx?wsdl'
|
7
7
|
|
8
8
|
def initialize(auth)
|
9
|
+
ensure_authenticated(auth)
|
9
10
|
self.session_id = auth.session_id
|
10
11
|
intialize_savon_client
|
11
12
|
end
|
@@ -41,11 +42,13 @@ module TFSO
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def create(order_attributes)
|
44
|
-
response = savon_client.call(:save_invoices, message: {invoices: [{InvoiceOrder: order_attributes
|
45
|
+
response = savon_client.call(:save_invoices, message: {invoices: [{InvoiceOrder: order_attributes}] }, cookies: @cookies)
|
45
46
|
response.body[:save_invoices_response][:save_invoices_result][:invoice_order]
|
46
47
|
end
|
47
48
|
|
48
49
|
def transform_attributes(invoice, items)
|
50
|
+
invoice.compact!
|
51
|
+
items.compact!
|
49
52
|
state = case invoice[:state]
|
50
53
|
when :invoice
|
51
54
|
'Invoiced'
|
@@ -90,14 +93,22 @@ module TFSO
|
|
90
93
|
if items.any?
|
91
94
|
invoiceRows = []
|
92
95
|
items.each {|item|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
96
|
+
if item[:type] == :text
|
97
|
+
invoiceRows << {:InvoiceRow => {
|
98
|
+
Type: 'Text',
|
99
|
+
Name: item[:name]
|
100
|
+
}}
|
101
|
+
else
|
102
|
+
invoiceRows << {:InvoiceRow => {
|
103
|
+
Type: 'Normal',
|
104
|
+
ProductId: item[:product_id],
|
105
|
+
Name: item[:name],
|
106
|
+
Price: item[:price].to_f,
|
107
|
+
Quantity: item[:quantity].to_f
|
108
|
+
}}
|
109
|
+
end
|
99
110
|
}
|
100
|
-
invoice_info[:InvoiceRows] =
|
111
|
+
invoice_info[:InvoiceRows] = invoiceRows
|
101
112
|
end
|
102
113
|
invoice_info
|
103
114
|
end
|
data/lib/tfso/payment.rb
CHANGED
@@ -6,12 +6,13 @@ module TFSO
|
|
6
6
|
URL = 'https://api.24sevenoffice.com/Economy/InvoiceOrder/V001/PaymentService.asmx?WSDL'
|
7
7
|
|
8
8
|
def initialize(auth)
|
9
|
+
ensure_authenticated(auth)
|
9
10
|
self.session_id = auth.session_id
|
10
11
|
intialize_savon_client
|
11
12
|
end
|
12
13
|
|
13
14
|
def create(payment_info)
|
14
|
-
response = savon_client.call(:register_invoice_payment, message: {payment: payment_info
|
15
|
+
response = savon_client.call(:register_invoice_payment, message: {payment: payment_info}, cookies: @cookies)
|
15
16
|
response.body[:register_invoice_payment_response][:register_invoice_payment_result]
|
16
17
|
end
|
17
18
|
|
data/lib/tfso/person.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module TFSO
|
2
|
+
class Person
|
3
|
+
|
4
|
+
include TFSO::Helpers
|
5
|
+
|
6
|
+
URL = 'https://webservices.24sevenoffice.com/CRM/Contact/PersonService.asmx?WSDL'
|
7
|
+
|
8
|
+
def initialize(auth)
|
9
|
+
ensure_authenticated(auth)
|
10
|
+
self.session_id = auth.session_id
|
11
|
+
intialize_savon_client
|
12
|
+
end
|
13
|
+
|
14
|
+
def find(search_params={})
|
15
|
+
response = savon_client.call(:get_persons, message: {personSearch: search_params}, cookies: @cookies)
|
16
|
+
result = response.body[:get_persons_response][:get_persons_result]
|
17
|
+
if result
|
18
|
+
if result[:person_item].class == Hash
|
19
|
+
[result[:person_item]]
|
20
|
+
else
|
21
|
+
result[:person_item]
|
22
|
+
end
|
23
|
+
else
|
24
|
+
[]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create(person_info)
|
29
|
+
response = savon_client.call(:save_person, message: {personItem: person_info}, cookies: @cookies)
|
30
|
+
result = response.body[:save_person_response][:save_person_result]
|
31
|
+
if result
|
32
|
+
if result.class == Hash
|
33
|
+
if result[:api_exception]
|
34
|
+
raise "Error when saving tfso person"
|
35
|
+
else
|
36
|
+
result
|
37
|
+
end
|
38
|
+
else
|
39
|
+
result
|
40
|
+
end
|
41
|
+
else
|
42
|
+
false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/tfso/product.rb
CHANGED
@@ -6,6 +6,7 @@ module TFSO
|
|
6
6
|
URL = 'https://api.24sevenoffice.com/Logistics/Product/V001/ProductService.asmx?WSDL'
|
7
7
|
|
8
8
|
def initialize(auth)
|
9
|
+
ensure_authenticated(auth)
|
9
10
|
self.session_id = auth.session_id
|
10
11
|
intialize_savon_client
|
11
12
|
end
|
@@ -30,6 +31,5 @@ module TFSO
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
34
|
end
|
35
35
|
end
|
data/lib/tfso/version.rb
CHANGED
data/tfso.gemspec
CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_dependency "savon"
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
-
spec.add_development_dependency "rake", "~>
|
27
|
-
spec.add_development_dependency "minitest", "~> 5
|
25
|
+
spec.add_development_dependency "bundler", "~> 2"
|
26
|
+
spec.add_development_dependency "rake", "~> 13"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5"
|
28
28
|
spec.add_development_dependency "dotenv"
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tfso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Espen Antonsen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -30,42 +30,42 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '5
|
61
|
+
version: '5'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '5
|
68
|
+
version: '5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: dotenv
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email:
|
85
85
|
- espen@inspired.no
|
86
86
|
executables: []
|
@@ -99,9 +99,11 @@ files:
|
|
99
99
|
- lib/tfso/authentication.rb
|
100
100
|
- lib/tfso/client.rb
|
101
101
|
- lib/tfso/company.rb
|
102
|
+
- lib/tfso/errors.rb
|
102
103
|
- lib/tfso/helpers.rb
|
103
104
|
- lib/tfso/invoice.rb
|
104
105
|
- lib/tfso/payment.rb
|
106
|
+
- lib/tfso/person.rb
|
105
107
|
- lib/tfso/product.rb
|
106
108
|
- lib/tfso/version.rb
|
107
109
|
- tfso.gemspec
|
@@ -109,7 +111,7 @@ homepage: https://github.com/espen/tfso
|
|
109
111
|
licenses:
|
110
112
|
- MIT
|
111
113
|
metadata: {}
|
112
|
-
post_install_message:
|
114
|
+
post_install_message:
|
113
115
|
rdoc_options: []
|
114
116
|
require_paths:
|
115
117
|
- lib
|
@@ -124,8 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
126
|
- !ruby/object:Gem::Version
|
125
127
|
version: '0'
|
126
128
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
128
|
-
signing_key:
|
129
|
+
rubygems_version: 3.2.3
|
130
|
+
signing_key:
|
129
131
|
specification_version: 4
|
130
132
|
summary: Ruby API Wrapper for 24SevenOffice.
|
131
133
|
test_files: []
|