tfso 0.11.0 → 0.12.0

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: e603bcd974bed56f5faefb73570f88731d6df5ae77e22a341d38d2abf770a43f
4
+ data.tar.gz: 4c180d23ef43cae4788c7f2c364a23ca1929c7c231732fbb9b15d8836d5594bc
5
5
  SHA512:
6
- metadata.gz: '07789a426e785143a03a3e5bbfe7c43df4364b06afbde3fc96eaaff29cfc6a7c4485cb710c4f25b753aa3d4b4ca7f55ebe593909ce7dc720a5895ddfa1c985ea'
7
- data.tar.gz: 57eb84fce1e27bf13b2ad7208db724e49e8915262e462e4472960fa2402048e272d2a1c4996b179c257cf19b45866f47451cf2354e744432305d77f7483d0404
6
+ metadata.gz: e2da1a63d8ae2f602b64ad678f9ca0351a8fd072fce2c1d7ba6ff8fc8fc2f452c55c12baa4858c10c2e182f3df5a3da65b7f74bd11429a074d2c88b9afbac93f
7
+ data.tar.gz: c6f1a4f5165bd3dfde6f7e64b1ba211c608f852e31d5a201a82c0f8a47bfeeda13feb58ae4e16bcc682c384a5dddc2bd05562e4b54ff57fe7f040163da30c598
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]
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,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
@@ -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
 
@@ -99,7 +100,7 @@ module TFSO
99
100
  Quantity: item[:quantity].to_f
100
101
  }
101
102
  }
102
- invoice_info[:InvoiceRows] = { :InvoiceRow => invoiceRows }
103
+ invoice_info[:InvoiceRows] = {:InvoiceRow => invoiceRows}
103
104
  end
104
105
  invoice_info
105
106
  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
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 = '0.12.0'
3
3
  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: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Espen Antonsen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-30 00:00:00.000000000 Z
11
+ date: 2019-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: savon
@@ -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
@@ -125,7 +126,7 @@ 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
+ rubygems_version: 3.0.6
129
130
  signing_key:
130
131
  specification_version: 4
131
132
  summary: Ruby API Wrapper for 24SevenOffice.