jemquarie 0.0.4 → 0.0.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +8 -3
- data/lib/jemquarie/account_details.rb +36 -0
- data/lib/jemquarie/balance.rb +36 -0
- data/lib/jemquarie/base.rb +28 -0
- data/lib/jemquarie/expiry.rb +29 -0
- data/lib/jemquarie/importer.rb +6 -23
- data/lib/jemquarie/parser/account_details.rb +46 -0
- data/lib/jemquarie/parser/balance.rb +34 -0
- data/lib/jemquarie/parser/cash_transactions.rb +2 -5
- data/lib/jemquarie/parser/expiry.rb +14 -0
- data/lib/jemquarie/parser/generic.rb +16 -0
- data/lib/jemquarie/version.rb +1 -1
- data/lib/jemquarie.rb +10 -3
- data/spec/files/account_details/details.xml +3261 -0
- data/spec/files/balance/balances.xml +662 -0
- data/spec/files/balance/error_e0009.xml +19 -0
- data/spec/files/expiry/expiry.xml +20 -0
- data/spec/lib/accont_details_spec.rb +42 -0
- data/spec/lib/balance_spec.rb +44 -0
- data/spec/lib/expiry_spec.rb +25 -0
- data/spec/lib/importer_spec.rb +6 -6
- metadata +36 -14
- /data/spec/files/{no_data.xml → transactions/no_data.xml} +0 -0
- /data/spec/files/{non_authenticated.xml → transactions/non_authenticated.xml} +0 -0
- /data/spec/files/{single_transaction.xml → transactions/single_transaction.xml} +0 -0
- /data/spec/files/{transactions.xml → transactions/transactions.xml} +0 -0
- /data/spec/files/{wrong_account_number.xml → transactions/wrong_account_number.xml} +0 -0
- /data/spec/files/{wrong_authentication.xml → transactions/wrong_authentication.xml} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a28a851bb5b04394d353f9f93be6ab95415f29e
|
4
|
+
data.tar.gz: 3bce6fa5363daaea2e6b2aacc2fd60eb95df1327
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9988e37be3a4de4168b64c06f455e0f96855188863bc9c6a96db95cf504e0f94753d350e090efd82edd781d48486a19a27562cf3ffe5ed25d1fe5181d8a9352a
|
7
|
+
data.tar.gz: d2e7ccaf4614d8749bdb386da54c924c1430896c519a5b4720d7f2c5443194f3b83fda6c18ee59866464689681f21932f26726798660d59de57b74cc699ef4f9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -41,12 +41,10 @@ The auth code and password need to be the unhashed values.
|
|
41
41
|
Jemquarie::Importer.new(username, password).cash_transactions(10.years.ago.to_date, Date.today, account_number)
|
42
42
|
```
|
43
43
|
|
44
|
-
### Results
|
45
|
-
|
46
44
|
## Success with data
|
47
45
|
|
48
46
|
The gem should return an array with formatted data. Here an example:
|
49
|
-
```
|
47
|
+
```ruby
|
50
48
|
[
|
51
49
|
{
|
52
50
|
:foreign_identifier => "123456",
|
@@ -71,6 +69,13 @@ It just returns an empty Array
|
|
71
69
|
It returns an Hash {:error => "Invalid credentials"} .
|
72
70
|
|
73
71
|
|
72
|
+
### Other available calls are:
|
73
|
+
|
74
|
+
- client balances
|
75
|
+
- account details
|
76
|
+
- expiry of credentials
|
77
|
+
|
78
|
+
|
74
79
|
## Authors ##
|
75
80
|
|
76
81
|
* [Claudio Contin](http://github.com/clod81)
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Jemquarie
|
2
|
+
|
3
|
+
class AccountDetails < Base
|
4
|
+
|
5
|
+
include Parser::AccountDetails
|
6
|
+
|
7
|
+
def details(date_from = (Date.today - 1.day), date_to = Date.today, account_number = '', include_closed = 'Y')
|
8
|
+
response = @client.call(:generate_xml_extract, :message => create_message(date_from, date_to, account_number, include_closed))
|
9
|
+
return parse_account_details(response) if response.success?
|
10
|
+
{:error => "An error has occured, please try again later"}
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create_message(date_from, date_to, account_number, include_closed)
|
16
|
+
{
|
17
|
+
:string => hash_key(Jemquarie.api_key), # base64 encoded of the sha1 hashed api key
|
18
|
+
:string0 => Jemquarie.app_key,
|
19
|
+
:string1 => hash_key(@username),
|
20
|
+
:string2 => hash_key(@password),
|
21
|
+
:string3 => 'your.clients Account Details',
|
22
|
+
:string4 => 'V1.3',
|
23
|
+
:strings => [
|
24
|
+
{
|
25
|
+
:item0 => account_number, # Account Number
|
26
|
+
:item1 => date_from.strftime("%Y-%m-%dT%H:%M:%S"), # START DATE
|
27
|
+
:item2 => date_to.strftime("%Y-%m-%dT%H:%M:%S"), # TO DATE
|
28
|
+
:item3 => include_closed # Include closed accounts flag
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Jemquarie
|
2
|
+
|
3
|
+
class Balance < Base
|
4
|
+
|
5
|
+
include Parser::Balance
|
6
|
+
|
7
|
+
def balance(account_number = '')
|
8
|
+
response = @client.call(:generate_xml_extract, :message => create_message(account_number))
|
9
|
+
return parse_balance_response(response) if response.success?
|
10
|
+
{:error => "An error has occured, please try again later"}
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create_message(account_number)
|
16
|
+
{
|
17
|
+
:string => hash_key(Jemquarie.api_key), # base64 encoded of the sha1 hashed api key
|
18
|
+
:string0 => Jemquarie.app_key,
|
19
|
+
:string1 => hash_key(@username),
|
20
|
+
:string2 => hash_key(@password),
|
21
|
+
:string3 => 'your.clients Balances',
|
22
|
+
:string4 => 'V1.3',
|
23
|
+
:strings => [
|
24
|
+
{
|
25
|
+
:item0 => account_number, # Account Number
|
26
|
+
:item1 => '',
|
27
|
+
:item2 => '',
|
28
|
+
:item3 => ''
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module Jemquarie
|
5
|
+
|
6
|
+
class Base
|
7
|
+
|
8
|
+
include Parser::Generic
|
9
|
+
|
10
|
+
def initialize(username, password)
|
11
|
+
@username = username
|
12
|
+
@password = password
|
13
|
+
@client = ::Savon.client do
|
14
|
+
endpoint Jemquarie::BASE_URI
|
15
|
+
wsdl File.expand_path("../extract.wsdl", __FILE__)
|
16
|
+
pretty_print_xml true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def hash_key(key)
|
23
|
+
Base64.strict_encode64(OpenSSL::Digest::SHA1.digest(key))
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Jemquarie
|
2
|
+
|
3
|
+
class Expiry < Base
|
4
|
+
|
5
|
+
include Parser::Expiry
|
6
|
+
|
7
|
+
def credentials_expiry
|
8
|
+
response = @client.call(:generate_xml_extract, :message => create_message)
|
9
|
+
return parse_expiry_response(response) if response.success?
|
10
|
+
{:error => "An error has occured, please try again later"}
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create_message
|
16
|
+
{
|
17
|
+
:string => hash_key(Jemquarie.api_key), # base64 encoded of the sha1 hashed api key
|
18
|
+
:string0 => Jemquarie.app_key,
|
19
|
+
:string1 => hash_key(@username),
|
20
|
+
:string2 => hash_key(@password),
|
21
|
+
:string3 => 'Authentication Expiry',
|
22
|
+
:string4 => 'V1.0',
|
23
|
+
:strings => ''
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
data/lib/jemquarie/importer.rb
CHANGED
@@ -1,34 +1,21 @@
|
|
1
|
-
require 'openssl'
|
2
|
-
require 'base64'
|
3
|
-
|
4
1
|
module Jemquarie
|
5
2
|
|
6
|
-
class Importer
|
7
|
-
|
8
|
-
include Jemquarie::Parser::CashTransactions
|
3
|
+
class Importer < Base
|
9
4
|
|
10
|
-
|
11
|
-
@username = username
|
12
|
-
@password = password
|
13
|
-
@client = ::Savon.client do
|
14
|
-
endpoint Jemquarie::BASE_URI
|
15
|
-
wsdl File.expand_path("../extract.wsdl", __FILE__)
|
16
|
-
pretty_print_xml true
|
17
|
-
end
|
18
|
-
end
|
5
|
+
include Parser::CashTransactions
|
19
6
|
|
20
|
-
def cash_transactions(date_from = (Date.today - 1.day), date_to = Date.today, account_number = '')
|
7
|
+
def cash_transactions(date_from = (Date.today - 1.day), date_to = Date.today, account_number = '', include_closed = 'Y')
|
21
8
|
if account_number.blank? && ((date_to - date_from).days > 2.days) # if no account specified, ESI api doesn't allow to ask more than 2 days of transactions
|
22
9
|
return {:error => "Cannot request more than 2 days of transactions if not account is specified"}
|
23
10
|
end
|
24
|
-
response = @client.call(:generate_xml_extract, :message => create_message(date_from, date_to, account_number))
|
11
|
+
response = @client.call(:generate_xml_extract, :message => create_message(date_from, date_to, account_number, include_closed))
|
25
12
|
return parse_cash_transactions_response(response) if response.success?
|
26
13
|
{:error => "An error has occured, please try again later"}
|
27
14
|
end
|
28
15
|
|
29
16
|
private
|
30
17
|
|
31
|
-
def create_message(date_from, date_to, account_number)
|
18
|
+
def create_message(date_from, date_to, account_number, include_closed)
|
32
19
|
{
|
33
20
|
:string => hash_key(Jemquarie.api_key), # base64 encoded of the sha1 hashed api key
|
34
21
|
:string0 => Jemquarie.app_key,
|
@@ -41,16 +28,12 @@ private
|
|
41
28
|
:item0 => account_number, # Account Number
|
42
29
|
:item1 => date_from.strftime("%Y-%m-%dT%H:%M:%S"), # START DATE
|
43
30
|
:item2 => date_to.strftime("%Y-%m-%dT%H:%M:%S"), # TO DATE
|
44
|
-
:item3 =>
|
31
|
+
:item3 => include_closed # Include closed accounts flag
|
45
32
|
}
|
46
33
|
]
|
47
34
|
}
|
48
35
|
end
|
49
36
|
|
50
|
-
def hash_key(key)
|
51
|
-
Base64.strict_encode64(OpenSSL::Digest::SHA1.digest(key))
|
52
|
-
end
|
53
|
-
|
54
37
|
end
|
55
38
|
|
56
39
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Jemquarie
|
2
|
+
module Parser
|
3
|
+
module AccountDetails
|
4
|
+
|
5
|
+
def parse_account_details(response)
|
6
|
+
result = generic_request_response(response)
|
7
|
+
return result if result[:error]
|
8
|
+
details = []
|
9
|
+
return details unless result["XMLExtract"]["yourclientsAccountDetails"] && result["XMLExtract"]["yourclientsAccountDetails"]["yourclientsAccountDetail"]
|
10
|
+
xml_details = if result["XMLExtract"]["yourclientsAccountDetails"]["yourclientsAccountDetail"].is_a?(Hash)
|
11
|
+
[result["XMLExtract"]["yourclientsAccountDetails"]["yourclientsAccountDetail"]]
|
12
|
+
else
|
13
|
+
result["XMLExtract"]["yourclientsAccountDetails"]["yourclientsAccountDetail"]
|
14
|
+
end
|
15
|
+
xml_details.each do |detail|
|
16
|
+
details << parse_single_detail(detail)
|
17
|
+
end
|
18
|
+
details
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def parse_single_detail(detail)
|
24
|
+
{
|
25
|
+
:account_number => detail["AccountNumber"],
|
26
|
+
:account_name => detail["AccountName"],
|
27
|
+
:account_short_name => detail["AccountShortName"],
|
28
|
+
:product => detail["Product"],
|
29
|
+
:product_name => detail["ProductName"],
|
30
|
+
:address_line_1 => detail["AddressLine1"],
|
31
|
+
:address_line_4 => detail["AddressLine4"],
|
32
|
+
:address_line_5 => detail["AddressLine5"],
|
33
|
+
:address_line_6 => detail["AddressLine6"],
|
34
|
+
:dealer_code => detail["DealerCode"],
|
35
|
+
:adviser_code => detail["AdviserCode"],
|
36
|
+
:account_status => detail["AccountStatus"],
|
37
|
+
:date_modified => Time.parse(detail["DateModified"] + " UTC"),
|
38
|
+
:bsb => detail["Bsb"],
|
39
|
+
:primary_broker_name => detail["PrimaryBrokerName"],
|
40
|
+
:primary_adviser_name => detail["PrimaryAdviserName"]
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Jemquarie
|
2
|
+
module Parser
|
3
|
+
module Balance
|
4
|
+
|
5
|
+
def parse_balance_response(response)
|
6
|
+
result = generic_request_response(response)
|
7
|
+
return result if result[:error]
|
8
|
+
balances = []
|
9
|
+
return balances unless result["XMLExtract"] && result["XMLExtract"]["yourclientsBalances"] && result["XMLExtract"]["yourclientsBalances"]["yourclientsBalance"]
|
10
|
+
xml_balances = if result["XMLExtract"]["yourclientsBalances"]["yourclientsBalance"].is_a?(Hash)
|
11
|
+
[result["XMLExtract"]["yourclientsBalances"]["yourclientsBalance"]]
|
12
|
+
else
|
13
|
+
result["XMLExtract"]["yourclientsBalances"]["yourclientsBalance"]
|
14
|
+
end
|
15
|
+
xml_balances.each do |balance|
|
16
|
+
balances << parse_single_balance(balance)
|
17
|
+
end
|
18
|
+
balances
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def parse_single_balance(balance)
|
24
|
+
{
|
25
|
+
:account_number => balance["AccountNumber"],
|
26
|
+
:ledger_balance => balance["LedgerBalance"],
|
27
|
+
:available_balance => balance["AvailableBalance"],
|
28
|
+
:as_at_date => Time.parse(balance["AsAtDate"] + " UTC")
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -3,11 +3,8 @@ module Jemquarie
|
|
3
3
|
module CashTransactions
|
4
4
|
|
5
5
|
def parse_cash_transactions_response(response)
|
6
|
-
|
7
|
-
return
|
8
|
-
body[:generate_xml_extract_response] && body[:generate_xml_extract_response][:result] && body[:generate_xml_extract_response][:result].is_a?(String)
|
9
|
-
result = Hash.from_xml(Nokogiri::XML.fragment(body[:generate_xml_extract_response][:result]).to_s)
|
10
|
-
return {error: result["XMLExtract"]["RequestDetails"]["RequestErrorDetails"]} if result["XMLExtract"]["RequestDetails"]["RequestStatus"] == "Failure"
|
6
|
+
result = generic_request_response(response)
|
7
|
+
return result if result[:error]
|
11
8
|
transactions = []
|
12
9
|
return transactions unless result["XMLExtract"] && result["XMLExtract"]["yourclientsTransactions"] && result["XMLExtract"]["yourclientsTransactions"]["yourclientsTransaction"]
|
13
10
|
xml_transactions = if result["XMLExtract"]["yourclientsTransactions"]["yourclientsTransaction"].is_a?(Hash)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Jemquarie
|
2
|
+
module Parser
|
3
|
+
module Expiry
|
4
|
+
|
5
|
+
def parse_expiry_response(response)
|
6
|
+
result = generic_request_response(response)
|
7
|
+
return result if result[:error]
|
8
|
+
result["XMLExtract"]["ExpiryDate"]
|
9
|
+
Time.parse(result["XMLExtract"]["ExpiryDate"] + " UTC")
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Jemquarie
|
2
|
+
module Parser
|
3
|
+
module Generic
|
4
|
+
|
5
|
+
def generic_request_response(response)
|
6
|
+
body = response.body
|
7
|
+
return {:error => "Invalid Authentication Code or Authentication Password"} unless
|
8
|
+
body[:generate_xml_extract_response] && body[:generate_xml_extract_response][:result] && body[:generate_xml_extract_response][:result].is_a?(String)
|
9
|
+
result = Hash.from_xml(Nokogiri::XML.fragment(body[:generate_xml_extract_response][:result]).to_s)
|
10
|
+
return {error: result["XMLExtract"]["RequestDetails"]["RequestErrorDetails"]} if result["XMLExtract"]["RequestDetails"]["RequestStatus"] == "Failure"
|
11
|
+
result
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/jemquarie/version.rb
CHANGED
data/lib/jemquarie.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
require 'savon'
|
2
2
|
require 'active_support/core_ext/hash'
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
require 'jemquarie/parser/generic'
|
4
|
+
require 'jemquarie/parser/cash_transactions'
|
5
|
+
require 'jemquarie/parser/expiry'
|
6
|
+
require 'jemquarie/parser/account_details'
|
7
|
+
require 'jemquarie/parser/balance'
|
8
|
+
require 'jemquarie/base'
|
9
|
+
require 'jemquarie/importer'
|
10
|
+
require 'jemquarie/expiry'
|
11
|
+
require 'jemquarie/account_details'
|
12
|
+
require 'jemquarie/balance'
|
6
13
|
|
7
14
|
module Jemquarie
|
8
15
|
|