tfso 0.11.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c02d9906c1e939ac6bbe6b0adebfd7ab8614582a36d041560fdde3d2930dd08a
4
- data.tar.gz: 5f50765e1440337a223dcb10693d7baccf806acc93c528335e639b9475ae5b75
3
+ metadata.gz: 49fddfbc2027f861bb99bcca42cbf7b345c4c491e1c04c5f76e9b3e7aa2b1dd3
4
+ data.tar.gz: ca977aff312bf6266cb7034d85c7f4b97fa4c9f2f99f244cf1ce4168c1577d03
5
5
  SHA512:
6
- metadata.gz: '07789a426e785143a03a3e5bbfe7c43df4364b06afbde3fc96eaaff29cfc6a7c4485cb710c4f25b753aa3d4b4ca7f55ebe593909ce7dc720a5895ddfa1c985ea'
7
- data.tar.gz: 57eb84fce1e27bf13b2ad7208db724e49e8915262e462e4472960fa2402048e272d2a1c4996b179c257cf19b45866f47451cf2354e744432305d77f7483d0404
6
+ metadata.gz: 507ae593e60c81909016c498f2ca7d3b64f45a64b3ea6be04cb6ccbc2f9b1ff0ab224c14c514e2b541469fdb101912c6b19b325804ec1a3364e63e349614874b
7
+ data.tar.gz: 5a76203f710eec5d3c6cc212510473c9dd7efbb428299d4663bd3bff42beac45aec6d0e2ab22f674d9dc4a9c049335ac27592708ee0017ef86c3e0e99fce94be
data/lib/tfso.rb CHANGED
@@ -1,6 +1,7 @@
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'
@@ -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
 
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 }, 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
 
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'] } }, 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,12 +36,12 @@ 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
42
43
  if result[:company][:api_exception]
43
- raise "Error when saving tfso company"
44
+ raise result[:company][:api_exception]
44
45
  else
45
46
  result[:company]
46
47
  end
@@ -109,13 +110,13 @@ module TFSO
109
110
  company.delete(:billing_address)
110
111
  end
111
112
  if company[:tfso]
112
- company[:tfso].keys.each{|k| company[k] = company[:tfso].delete(k) }
113
+ company[:tfso].keys.each{|k| company[k] = company[:tfso].delete(k)}
113
114
  company.delete(:tfso)
114
115
  end
115
116
 
116
117
  mappings = {:name => :Name, :nickname => :NickName, :gov_no => :OrganizationNumber, :country_code => :Country}
117
118
 
118
- 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]}
119
120
  company
120
121
  end
121
122
 
@@ -0,0 +1,5 @@
1
+ module TFSO
2
+ module Errors
3
+ class Authentication < StandardError; end
4
+ end
5
+ end
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,7 +42,7 @@ 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
 
@@ -92,14 +93,22 @@ module TFSO
92
93
  if items.any?
93
94
  invoiceRows = []
94
95
  items.each {|item|
95
- invoiceRows << {
96
- ProductId: item[:product_id],
97
- Name: item[:description],
98
- Price: item[:price].to_f,
99
- Quantity: item[:quantity].to_f
100
- }
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
101
110
  }
102
- invoice_info[:InvoiceRows] = { :InvoiceRow => invoiceRows }
111
+ invoice_info[:InvoiceRows] = invoiceRows
103
112
  end
104
113
  invoice_info
105
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 }, 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
 
data/lib/tfso/person.rb CHANGED
@@ -6,6 +6,7 @@ module TFSO
6
6
  URL = 'https://webservices.24sevenoffice.com/CRM/Contact/PersonService.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,7 +31,7 @@ module TFSO
30
31
  if result
31
32
  if result.class == Hash
32
33
  if result[:api_exception]
33
- raise "Error when saving tfso person"
34
+ raise result[:api_exception]
34
35
  else
35
36
  result
36
37
  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
data/lib/tfso/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TFSO
2
- VERSION = "0.11.0"
2
+ VERSION = '1.0.2'
3
3
  end
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", "~> 1.15"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "minitest"
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.11.0
4
+ version: 1.0.2
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-06-30 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon
@@ -28,44 +28,44 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.15'
33
+ version: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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,6 +99,7 @@ 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
@@ -110,7 +111,7 @@ homepage: https://github.com/espen/tfso
110
111
  licenses:
111
112
  - MIT
112
113
  metadata: {}
113
- post_install_message:
114
+ post_install_message:
114
115
  rdoc_options: []
115
116
  require_paths:
116
117
  - lib
@@ -125,8 +126,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  - !ruby/object:Gem::Version
126
127
  version: '0'
127
128
  requirements: []
128
- rubygems_version: 3.0.3
129
- signing_key:
129
+ rubygems_version: 3.2.17
130
+ signing_key:
130
131
  specification_version: 4
131
132
  summary: Ruby API Wrapper for 24SevenOffice.
132
133
  test_files: []