tfso 0.8.0 → 0.14.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 +5 -3
- data/lib/tfso/client.rb +2 -1
- data/lib/tfso/company.rb +10 -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
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 655776d30e65157f5da6a45cbb25ff130a8e4f4fd4eb1924b8f3b61084270c99
|
4
|
+
data.tar.gz: a547429273d8d60d1f6a771ba8a5b05518ff3eeab26324a8c9cd5dbe14638fcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 174bc898b4f0f6cb434a16c2d6ac73b2bcfbe53202cdaf41f358495f12278319f4cb530b229095ba53b87d08c50aed913d8e3597b49a899ed7880c8f26161c63
|
7
|
+
data.tar.gz: 2d738c2860fe67bf2e579c195b747109b788e41fa8b9a0e546eeb35805ff28fe384e5df5fce77f8f67a2c87bca5f05e76b0924ec963664ec2d283c88b0f91f52
|
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]
|
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] ||= []
|
@@ -70,24 +72,28 @@ module TFSO
|
|
70
72
|
:Value => company.delete(:billing_email)
|
71
73
|
}
|
72
74
|
}
|
75
|
+
company.delete(:billing_email)
|
73
76
|
end
|
74
77
|
if company[:email]
|
75
78
|
company[:EmailAddresses] << {:Work => {
|
76
79
|
:Value => company.delete(:email)
|
77
80
|
}
|
78
81
|
}
|
82
|
+
company.delete(:email)
|
79
83
|
end
|
80
84
|
if company[:phone_number]
|
81
85
|
company[:PhoneNumbers] << {:Work => {
|
82
86
|
:Value => company.delete(:phone_number)
|
83
87
|
}
|
84
88
|
}
|
89
|
+
company.delete(:phone_number)
|
85
90
|
end
|
86
91
|
if company[:mobile_phone_number]
|
87
92
|
company[:PhoneNumbers] << {:Mobile => {
|
88
93
|
:Value => company.delete(:mobile_phone_number)
|
89
94
|
}
|
90
95
|
}
|
96
|
+
company.delete(:mobile_phone_number)
|
91
97
|
end
|
92
98
|
if company[:billing_address]
|
93
99
|
address = {
|
@@ -104,13 +110,13 @@ module TFSO
|
|
104
110
|
company.delete(:billing_address)
|
105
111
|
end
|
106
112
|
if company[:tfso]
|
107
|
-
company[:tfso].keys.each{|k| company[k] = company[:tfso].delete(k)
|
113
|
+
company[:tfso].keys.each{|k| company[k] = company[:tfso].delete(k)}
|
108
114
|
company.delete(:tfso)
|
109
115
|
end
|
110
116
|
|
111
117
|
mappings = {:name => :Name, :nickname => :NickName, :gov_no => :OrganizationNumber, :country_code => :Country}
|
112
118
|
|
113
|
-
company.keys.each {
|
119
|
+
company.keys.each {|k| company[ mappings[k] ] = company.delete(k) if mappings[k]}
|
114
120
|
company
|
115
121
|
end
|
116
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
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: 0.14.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-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -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.1.3
|
130
|
+
signing_key:
|
129
131
|
specification_version: 4
|
130
132
|
summary: Ruby API Wrapper for 24SevenOffice.
|
131
133
|
test_files: []
|