tfso 0.9.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8becbb11eee5960cc843067527e7d5f77550af9634f4f01076ca4e676309fd7d
4
- data.tar.gz: 5202aafad2e06b645b08d22a2d34a9e5264a45635fdad574eeb4aaa507eedaf9
3
+ metadata.gz: 7a00d935fda27bd1614682ca5b89da473d26ddd7df4ee77c5e00e94ecef5d3a3
4
+ data.tar.gz: 6d4208e29b1f762d5d463a57dfcd9641e6339a7d62741e9b5bda8502c48e4c1d
5
5
  SHA512:
6
- metadata.gz: 86184c1e31a5f3f93db046eafa6a6827c296a411b24c5b056b4a7a08a3612fd4f7ef503088c1338106ff318d804fe37e11d76c2083a3e45c63f372c324e23103
7
- data.tar.gz: 563de3971780131b025e2ad4d4ceb68238b0d7d03cbaf1ae89e8edcaa84cf6ae7d1ef664198e194da2f7959a56aecafab3753d1ae057d852f87f8945302a7657
6
+ metadata.gz: 3de71d9a717c6d4522b39888459dba549e7027686b250935789f433f84284a61df9c0d00b67d3269eb7d933bfd1f16b47675228fbacf1f4766fe401df5e1f8b0
7
+ data.tar.gz: 665930704f8077f64f3d8baff2594ef695fa60f67340b872f5ec26decd2d38fd6838b6683431fa947eb645e7ab7718d64cc4aff6d1eca8b28ec194906ba9bbe5
@@ -1,9 +1,11 @@
1
1
  require 'savon'
2
- require "tfso/version"
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'
@@ -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
- response = savon_client.call(:set_identity_by_id, message: {identityId: identity_id}, cookies: @cookies)
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
 
@@ -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 }, cookies: @cookies)
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
 
@@ -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'] } }, cookies: @cookies)
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}] }, cookies: @cookies)
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 { |k| company[ mappings[k] ] = company.delete(k) if mappings[k] }
119
+ company.keys.each {|k| company[ mappings[k] ] = company.delete(k) if mappings[k]}
118
120
  company
119
121
  end
120
122
 
@@ -0,0 +1,5 @@
1
+ module TFSO
2
+ module Errors
3
+ class Authentication < StandardError; end
4
+ end
5
+ end
@@ -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
@@ -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 }] }, cookies: @cookies)
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
- invoiceRows << {
94
- ProductId: item[:product_id],
95
- Name: item[:description],
96
- Price: item[:price].to_f,
97
- Quantity: item[:quantity].to_f
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] = { :InvoiceRow => invoiceRows }
111
+ invoice_info[:InvoiceRows] = invoiceRows
101
112
  end
102
113
  invoice_info
103
114
  end
@@ -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 }, cookies: @cookies)
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
 
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module TFSO
2
- VERSION = "0.9.0"
2
+ VERSION = '1.0.0'
3
3
  end
@@ -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", "~> 1.15"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "minitest", "~> 5.0"
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.9.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: 2019-05-22 00:00:00.000000000 Z
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: '1.15'
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: '1.15'
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: '10.0'
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: '10.0'
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.0'
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.0'
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.0.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: []