corepro_eg 1.0.2

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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.idea/.name +1 -0
  4. data/.idea/.rakeTasks +7 -0
  5. data/.idea/codeStyleSettings.xml +14 -0
  6. data/.idea/corepro-sdk-ruby.iml +27 -0
  7. data/.idea/encodings.xml +5 -0
  8. data/.idea/misc.xml +5 -0
  9. data/.idea/modules.xml +8 -0
  10. data/.idea/scopes/scope_settings.xml +5 -0
  11. data/.idea/vcs.xml +7 -0
  12. data/Gemfile +15 -0
  13. data/LICENSE +21 -0
  14. data/README.md +47 -0
  15. data/Rakefile +2 -0
  16. data/config-sample.yml +5 -0
  17. data/corepro_eg.gemspec +25 -0
  18. data/lib/corepro/account.rb +109 -0
  19. data/lib/corepro/account_close.rb +21 -0
  20. data/lib/corepro/bank_document.rb +42 -0
  21. data/lib/corepro/card.rb +90 -0
  22. data/lib/corepro/connection.rb +86 -0
  23. data/lib/corepro/core_pro_api_exception.rb +26 -0
  24. data/lib/corepro/customer.rb +139 -0
  25. data/lib/corepro/customer_beneficiary.rb +42 -0
  26. data/lib/corepro/customer_document.rb +22 -0
  27. data/lib/corepro/external_account.rb +84 -0
  28. data/lib/corepro/external_account_document.rb +34 -0
  29. data/lib/corepro/models/account_access.rb +25 -0
  30. data/lib/corepro/models/account_id_only.rb +9 -0
  31. data/lib/corepro/models/api_error.rb +14 -0
  32. data/lib/corepro/models/customer_address.rb +17 -0
  33. data/lib/corepro/models/customer_answer.rb +9 -0
  34. data/lib/corepro/models/customer_beneficiary_id_only.rb +8 -0
  35. data/lib/corepro/models/customer_id_only.rb +8 -0
  36. data/lib/corepro/models/customer_message.rb +10 -0
  37. data/lib/corepro/models/customer_phone.rb +11 -0
  38. data/lib/corepro/models/customer_question.rb +22 -0
  39. data/lib/corepro/models/customer_response.rb +28 -0
  40. data/lib/corepro/models/customer_verify_request.rb +28 -0
  41. data/lib/corepro/models/envelope.rb +37 -0
  42. data/lib/corepro/models/external_account_id_only.rb +8 -0
  43. data/lib/corepro/models/external_account_verify.rb +13 -0
  44. data/lib/corepro/models/file_content.rb +10 -0
  45. data/lib/corepro/models/json_base.rb +93 -0
  46. data/lib/corepro/models/model_base.rb +26 -0
  47. data/lib/corepro/models/program_account.rb +20 -0
  48. data/lib/corepro/models/program_checking.rb +38 -0
  49. data/lib/corepro/models/program_e_code.rb +31 -0
  50. data/lib/corepro/models/program_external_account.rb +21 -0
  51. data/lib/corepro/models/program_interest_rate.rb +18 -0
  52. data/lib/corepro/models/program_limit.rb +12 -0
  53. data/lib/corepro/models/program_prepaid.rb +37 -0
  54. data/lib/corepro/models/program_savings.rb +36 -0
  55. data/lib/corepro/program.rb +74 -0
  56. data/lib/corepro/statement.rb +25 -0
  57. data/lib/corepro/transaction.rb +53 -0
  58. data/lib/corepro/transfer.rb +40 -0
  59. data/lib/corepro/utils/logger.rb +9 -0
  60. data/lib/corepro/utils/requestor.rb +120 -0
  61. data/lib/corepro/version.rb +4 -0
  62. data/lib/corepro.rb +15 -0
  63. data/q2labs_public.pem +9 -0
  64. data/test/a_program_test.rb +12 -0
  65. data/test/aa_customer_test.rb +78 -0
  66. data/test/ab_account_test.rb +45 -0
  67. data/test/ac_external_account_test.rb +39 -0
  68. data/test/ad_customer_beneficiary_test.rb +43 -0
  69. data/test/ae_customer_document_test.rb +16 -0
  70. data/test/af_bankdocument_test.rb +20 -0
  71. data/test/ag_external_account_document_test.rb +18 -0
  72. data/test/ai_statement_test.rb +23 -0
  73. data/test/aj_transfer_test.rb +53 -0
  74. data/test/ak_transaction_test.rb +19 -0
  75. data/test/al_card_test.rb +51 -0
  76. data/test/core_pro_test_base.rb +30 -0
  77. data/test.pdf +0 -0
  78. metadata +175 -0
@@ -0,0 +1,93 @@
1
+ require 'json'
2
+
3
+ module CorePro
4
+ module Models
5
+ class JsonBase
6
+ def is_hash?
7
+ false
8
+ end
9
+
10
+ def to_hash
11
+ hash = {}
12
+ self.instance_variables.each do |var|
13
+ val = self.instance_variable_get var
14
+ if val != nil
15
+ if val.instance_of?(Array)
16
+ arr = []
17
+ val.each do |x|
18
+ arr.push(x.to_hash)
19
+ end
20
+ hash[var.to_s.delete('@')] = arr
21
+ else
22
+ hash[var.to_s.delete('@')] = val
23
+ end
24
+ end
25
+ end
26
+
27
+ hash
28
+ end
29
+
30
+ def to_json
31
+ hash = {}
32
+ self.instance_variables.each do |var|
33
+ val = self.instance_variable_get var
34
+ if val != nil
35
+ if val.instance_of?(String)
36
+ hash[var.to_s.delete('@')] = val
37
+ elsif val.instance_of?(Array)
38
+ # do not serialize empty arrays. no point.
39
+ if val.length > 0
40
+ arr = []
41
+ val.each do |x|
42
+ h = x.to_hash
43
+ arr.push h
44
+ end
45
+ hash[var.to_s.delete('@')] = arr
46
+ end
47
+ else
48
+ hash[var.to_s.delete('@')] = val.to_json
49
+ end
50
+ end
51
+ end
52
+ hash.to_json
53
+ end
54
+
55
+
56
+
57
+ def from_json! json, classDefs = nil
58
+ classDefs = classDefs || {}
59
+ json.each do |var, val|
60
+ # if self.instance_variable_defined?("@#{var}")
61
+ cd = nil
62
+ cd = classDefs[var] if classDefs.has_key? var
63
+ if cd == nil
64
+ self.instance_variable_set "@#{var}", val
65
+ else
66
+ if val.kind_of?(Array)
67
+ arr = []
68
+ val.each do |x|
69
+ item = cd.new
70
+ item.from_json! x, nil
71
+ arr.push item
72
+ end
73
+ self.instance_variable_set "@#{var}", arr
74
+ elsif cd.new.is_hash?
75
+ # elsif val.kind_of?(Hash)
76
+ hash = {}
77
+ val.each do |key, itemJson|
78
+ item = cd.new
79
+ item.from_json! itemJson, nil
80
+ hash[key] = item
81
+ end
82
+ self.instance_variable_set "@#{var}", hash
83
+ else
84
+ item = cd.new
85
+ item.from_json! val, nil
86
+ self.instance_variable_set "@#{var}", item
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'json_base'
2
+ require 'uri'
3
+
4
+ module CorePro
5
+ module Models
6
+ class ModelBase < JsonBase
7
+ attr_accessor :requestId
8
+
9
+ def self.escape(val)
10
+ if val.to_s.empty?
11
+ ''
12
+ else
13
+ URI::escape(val)
14
+ end
15
+ end
16
+
17
+ def to_s
18
+ vars = self.instance_variables.map{|v|
19
+ "#{v}=#{instance_variable_get(v).inspect}"
20
+ }.join(", ")
21
+ "<#{self.class}: #{vars}>"
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'json_base'
2
+ module CorePro
3
+ module Models
4
+ class ProgramAccount < JsonBase
5
+
6
+ def is_hash?
7
+ true
8
+ end
9
+
10
+ attr_accessor :programAccountId
11
+ attr_accessor :type
12
+ attr_accessor :accountNumber
13
+ attr_accessor :accountNumberMasked
14
+ attr_accessor :description
15
+ attr_accessor :accountBalance
16
+ attr_accessor :isActive
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'json_base'
2
+ require_relative 'program_interest_rate'
3
+ require_relative 'program_limit'
4
+ module CorePro
5
+ module Models
6
+ class ProgramChecking < JsonBase
7
+
8
+ def is_hash?
9
+ true
10
+ end
11
+ attr_accessor :category
12
+ attr_accessor :type
13
+ attr_accessor :productId
14
+ attr_accessor :balanceLimit
15
+ attr_accessor :interestRates
16
+ attr_accessor :isExternalWithdrawEnabled
17
+ attr_accessor :isInterestEnabled
18
+ attr_accessor :isRecurringContributionEnabled
19
+ attr_accessor :perTransactionDepositLimit
20
+ attr_accessor :perTransactionWithdrawLimit
21
+
22
+ def initialize
23
+ super
24
+ @interestRates = []
25
+ end
26
+
27
+ def from_json! json, classDefs
28
+ classDefs = classDefs || {}
29
+ classDefs['balanceLimit'] = CorePro::Models::ProgramLimit
30
+ classDefs['interestRates'] = CorePro::Models::ProgramInterestRate
31
+ classDefs['perTransactionDepositLimit'] = CorePro::Models::ProgramLimit
32
+ classDefs['perTransactionWithdrawLimit'] = CorePro::Models::ProgramLimit
33
+
34
+ super json, classDefs
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'json_base'
2
+ module CorePro
3
+ module Models
4
+ class ProgramECode < JsonBase
5
+
6
+ def is_hash?
7
+ true
8
+ end
9
+
10
+ attr_accessor :category
11
+ attr_accessor :type
12
+ attr_accessor :programECodeId
13
+ attr_accessor :productCode
14
+ attr_accessor :minimumAmount
15
+ attr_accessor :maximumAmount
16
+ attr_accessor :name
17
+ attr_accessor :imageUrl
18
+ attr_accessor :isReissueSupported
19
+
20
+ def initialize
21
+ super
22
+ end
23
+
24
+ def from_json! json, classDefs
25
+ classDefs = classDefs || {}
26
+
27
+ super json, classDefs
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'json_base'
2
+ module CorePro
3
+ module Models
4
+ class ProgramExternalAccount < JsonBase
5
+
6
+ def is_hash?
7
+ true
8
+ end
9
+
10
+ attr_accessor :programExternalAccountId
11
+ attr_accessor :type
12
+ attr_accessor :routingNumber
13
+ attr_accessor :accountNumber
14
+ attr_accessor :accountNumberMasked
15
+ attr_accessor :description
16
+ attr_accessor :nachaName
17
+ attr_accessor :isActive
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'json_base'
2
+ module CorePro
3
+ module Models
4
+ class ProgramInterestRate < JsonBase
5
+ attr_accessor :tier
6
+ attr_accessor :apy
7
+ attr_accessor :apr
8
+ attr_accessor :minimumAmount
9
+ attr_accessor :maximumAmount
10
+ attr_accessor :effectiveDate
11
+ attr_accessor :expireDate
12
+ attr_accessor :rateEffectiveDate
13
+ attr_accessor :rateExpireDate
14
+ attr_accessor :description
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ require_relative 'json_base'
2
+ module CorePro
3
+ module Models
4
+ class ProgramLimit < JsonBase
5
+ attr_accessor :minimumAmount
6
+ attr_accessor :maximumAmount
7
+ def to_s
8
+ return "min: #{@minimumAmount}, max: #{@maximumAmount}"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'json_base'
2
+ require_relative 'program_interest_rate'
3
+ require_relative 'program_limit'
4
+ module CorePro
5
+ module Models
6
+ class ProgramPrepaid < JsonBase
7
+ def is_hash?
8
+ true
9
+ end
10
+ attr_accessor :category
11
+ attr_accessor :type
12
+ attr_accessor :balanceLimit
13
+ attr_accessor :interestRates
14
+ attr_accessor :isImmediateLoadFromLinkedAccountEnabled
15
+ attr_accessor :isExternalWithdrawEnabled
16
+ attr_accessor :isInterestEnabled
17
+ attr_accessor :isRecurringContributionEnabled
18
+ attr_accessor :perTransactionDepositLimit
19
+ attr_accessor :perTransactionWithdrawLimit
20
+
21
+ def initialize
22
+ super
23
+ @interestRates = []
24
+ end
25
+
26
+ def from_json! json, classDefs
27
+ classDefs = classDefs || {}
28
+ classDefs['balanceLimit'] = CorePro::Models::ProgramLimit
29
+ classDefs['interestRates'] = CorePro::Models::ProgramInterestRate
30
+ classDefs['perTransactionDepositLimit'] = CorePro::Models::ProgramLimit
31
+ classDefs['perTransactionWithdrawLimit'] = CorePro::Models::ProgramLimit
32
+
33
+ super json, classDefs
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'json_base'
2
+ require_relative 'program_interest_rate'
3
+ require_relative 'program_limit'
4
+ module CorePro
5
+ module Models
6
+ class ProgramSavings < JsonBase
7
+ def is_hash?
8
+ true
9
+ end
10
+ attr_accessor :category
11
+ attr_accessor :type
12
+ attr_accessor :balanceLimit
13
+ attr_accessor :interestRates
14
+ attr_accessor :isExternalWithdrawEnabled
15
+ attr_accessor :isInterestEnabled
16
+ attr_accessor :isRecurringContributionEnabled
17
+ attr_accessor :perTransactionDepositLimit
18
+ attr_accessor :perTransactionWithdrawLimit
19
+
20
+ def initialize
21
+ @interestRates = []
22
+ super
23
+ end
24
+
25
+ def from_json! json, classDefs
26
+ classDefs = classDefs || {}
27
+ classDefs['balanceLimit'] = CorePro::Models::ProgramLimit
28
+ classDefs['interestRates'] = CorePro::Models::ProgramInterestRate
29
+ classDefs['perTransactionDepositLimit'] = CorePro::Models::ProgramLimit
30
+ classDefs['perTransactionWithdrawLimit'] = CorePro::Models::ProgramLimit
31
+
32
+ super json, classDefs
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,74 @@
1
+ require_relative 'models/model_base'
2
+ require_relative 'utils/requestor'
3
+ require_relative 'models/program_account'
4
+ require_relative 'models/program_checking'
5
+ require_relative 'models/program_e_code'
6
+ require_relative 'models/program_external_account'
7
+ require_relative 'models/program_interest_rate'
8
+ require_relative 'models/program_savings'
9
+ require_relative 'models/program_prepaid'
10
+ require_relative 'models/program_limit'
11
+
12
+ module CorePro
13
+ class Program < Models::ModelBase
14
+
15
+ attr_accessor :name
16
+ attr_accessor :verificationType
17
+ attr_accessor :timeZone
18
+ attr_accessor :perUserDailyWithdrawLimit
19
+ attr_accessor :perUserMonthlyWithdrawLimit
20
+ attr_accessor :perProgramDailyWithdrawLimit
21
+ attr_accessor :perUserDailyDepositLimit
22
+ attr_accessor :perUserMonthlyDepositLimit
23
+ attr_accessor :perProgramDailyDepositLimit
24
+ attr_accessor :website
25
+ attr_accessor :isInternalToInternalTransferEnabled
26
+ attr_accessor :decimalCount
27
+ attr_accessor :validAccountTypes
28
+ attr_accessor :filledDate
29
+ attr_accessor :externalAccountCountMax
30
+ attr_accessor :accountCountMax
31
+ attr_accessor :checkingProducts
32
+ attr_accessor :eCodeProducts
33
+ attr_accessor :savingsProducts
34
+ attr_accessor :prepaidProducts
35
+ attr_accessor :accounts
36
+ attr_accessor :externalAccounts
37
+
38
+ def initialize
39
+ super
40
+ @checkingProducts = {}
41
+ @eCodeProducts = {}
42
+ @savingsProducts = {}
43
+ @prepaidProducts = {}
44
+ @accounts = {}
45
+ @externalAccounts = {}
46
+ end
47
+
48
+ def from_json! json, classDefs
49
+ classDefs = classDefs || {}
50
+ classDefs['perUserDailyWithdrawLimit'] = CorePro::Models::ProgramLimit
51
+ classDefs['perUserMonthlyWithdrawLimit'] = CorePro::Models::ProgramLimit
52
+ classDefs['perProgramDailyWithdrawLimit'] = CorePro::Models::ProgramLimit
53
+
54
+ classDefs['perUserDailyDepositLimit'] = CorePro::Models::ProgramLimit
55
+ classDefs['perUserMonthlyDepositLimit'] = CorePro::Models::ProgramLimit
56
+ classDefs['perProgramDailyDepositLimit'] = CorePro::Models::ProgramLimit
57
+
58
+ classDefs['checkingProducts'] = CorePro::Models::ProgramChecking
59
+ classDefs['eCodeProducts'] = CorePro::Models::ProgramECode
60
+ classDefs['savingsProducts'] = CorePro::Models::ProgramSavings
61
+ classDefs['prepaidProducts'] = CorePro::Models::ProgramPrepaid
62
+
63
+ classDefs['accounts'] = CorePro::Models::ProgramAccount
64
+ classDefs['externalAccounts'] = CorePro::Models::ProgramExternalAccount
65
+
66
+ super json, classDefs
67
+ end
68
+
69
+ def self.get(connection = nil, loggingObject = nil)
70
+ CorePro::Utils::Requestor.get("/program/get", Program, connection, loggingObject)
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'models/model_base'
2
+ require_relative 'utils/requestor'
3
+ require_relative 'models/file_content'
4
+
5
+ module CorePro
6
+ class Statement < Models::ModelBase
7
+ attr_accessor :statementId
8
+ attr_accessor :customerId
9
+ attr_accessor :type
10
+ attr_accessor :month
11
+ attr_accessor :year
12
+
13
+ def self.list(customerId, connection = nil, loggingObject = nil)
14
+ CorePro::Utils::Requestor.get("/statement/list/#{customerId}", Statement, connection, loggingObject)
15
+ end
16
+
17
+ def self.get(customerId, statementId, connection = nil, loggingObject = nil)
18
+ CorePro::Utils::Requestor.get("/statement/get/#{customerId}/#{statementId}", Statement, connection, loggingObject)
19
+ end
20
+
21
+ def self.download(customerId, statementId, connection = nil, loggingObject = nil)
22
+ CorePro::Utils::Requestor.get("/statement/download/#{customerId}/#{statementId}", CorePro::Models::FileContent, connection, loggingObject)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,53 @@
1
+ require_relative 'models/model_base'
2
+ require_relative 'utils/requestor'
3
+
4
+ require 'date'
5
+ module CorePro
6
+ class Transaction < Models::ModelBase
7
+ attr_accessor :transactionCount
8
+ attr_accessor :customerId
9
+ attr_accessor :transactionId
10
+ attr_accessor :tag
11
+ attr_accessor :createdDate
12
+ attr_accessor :type
13
+ attr_accessor :typeCode
14
+ attr_accessor :status
15
+ attr_accessor :amount
16
+ attr_accessor :settledDate
17
+ attr_accessor :voidedDate
18
+ attr_accessor :nachaDescription
19
+ attr_accessor :friendlyDescription
20
+ attr_accessor :availableDate
21
+ attr_accessor :returnCode
22
+ attr_accessor :isCredit
23
+
24
+ def self.list(customerId, accountId, status = nil, beginDate = nil, endDate = nil, pageNumber = 0, pageSize = 200, connection = nil, loggingObject = nil)
25
+ t = Transaction.new
26
+ t.customerId = customerId
27
+ t.list accountId, status, beginDate, endDate, pageNumber, pageSize, connection, loggingObject
28
+ end
29
+
30
+ def list(accountId = nil, status = nil, beginDate = nil, endDate =nil, pageNumber =0, pageSize = 200, connection = nil, loggingObject = nil)
31
+ start = beginDate.kind_of?(Date) ? beginDate.strftime('%Y-%m-%d') : (beginDate.kind_of?(String) ? beginDate[0..9] : nil)
32
+ finish = endDate.kind_of?(Date) ? endDate.strftime('%Y-%m-%d') : (endDate.kind_of?(String) ? endDate[0..9] : nil)
33
+
34
+ start ||= ''
35
+ finish ||= ''
36
+
37
+ if finish != '' && start == ''
38
+ start = '1900-01-01'
39
+ end
40
+
41
+ CorePro::Utils::Requestor.get("/transaction/list/#{self.customerId}/#{accountId}/#{Transaction.escape(status)}/#{start}/#{finish}?pageNumber=#{pageNumber}&pageSize=#{pageSize}", Transaction, connection, loggingObject)
42
+ end
43
+
44
+ def self.get(customerId, transactionId, connection = nil, loggingObject = nil)
45
+ CorePro::Utils::Requestor.get("/transaction/get/#{customerId}/#{transactionId}", Transaction, connection, loggingObject)
46
+ end
47
+
48
+ def self.getByTag(customerId, tag, connection = nil, loggingObject = nil)
49
+ CorePro::Utils::Requestor.get("/transaction/getByTag/#{customerId}/#{Transaction.escape(tag)}", Transaction, connection, loggingObject)
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,40 @@
1
+ require_relative 'models/model_base'
2
+ require_relative 'utils/requestor'
3
+
4
+ module CorePro
5
+ class Transfer < Models::ModelBase
6
+
7
+ attr_accessor :customerId
8
+ attr_accessor :fromId
9
+ attr_accessor :toId
10
+ attr_accessor :amount
11
+ attr_accessor :tag
12
+ attr_accessor :transactionId
13
+
14
+ def self.create(customerId, fromId, toId, amount, tag, connection = nil, loggingObject = nil)
15
+ t = Transfer.new
16
+ t.customerId = customerId
17
+ t.fromId = fromId
18
+ t.toId = toId
19
+ t.amount = amount
20
+ t.tag = tag
21
+ t.create connection, loggingObject
22
+ end
23
+
24
+ def create(connection = nil, loggingObject = nil)
25
+ CorePro::Utils::Requestor.post('/transfer/create', Transfer, self, connection, loggingObject)
26
+ end
27
+
28
+ def self.void(customerId, transactionId, tag, connection = nil, loggingObject = nil)
29
+ t = Transfer.new
30
+ t.customerId = customerId
31
+ t.transactionId = transactionId
32
+ t.tag = tag
33
+ t.void connection, loggingObject
34
+ end
35
+
36
+ def void(connection = nil, loggingObject = nil)
37
+ CorePro::Utils::Requestor.post('/transfer/void', Transfer, self, connection, loggingObject)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ module CorePro
2
+ module Utils
3
+ class Logger
4
+ def write(body, loggingObject)
5
+ # TODO: write to log file / registered callback class
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,120 @@
1
+ require_relative '../version'
2
+ require_relative 'logger'
3
+ require_relative '../models/envelope'
4
+ require_relative '../core_pro_api_exception'
5
+ require_relative '../connection'
6
+
7
+ require 'openssl'
8
+ require 'base64'
9
+ require 'net/https'
10
+ require 'uri'
11
+ require 'json'
12
+
13
+ module CorePro
14
+ module Utils
15
+ class Requestor
16
+
17
+ SDK_USER_AGENT = "CorePro Ruby SDK v #{CorePro::VERSION}"
18
+
19
+ @@config = begin
20
+ if File.exists?('config.yml')
21
+ YAML.load(File.open('config.yml'))
22
+ else
23
+ {}
24
+ end
25
+ rescue ArgumentError => e
26
+ puts "Could not parse YAML: #{e.message}"
27
+ end
28
+
29
+
30
+ def self.get(relativeUrl, classDef, connection, loggingObject)
31
+ connection ||= Connection.createFromConfig()
32
+ if connection.headerValue.to_s.empty? || connection.domainName.to_s.empty?
33
+ raise ArgumentError, 'A valid connection with apiKey, apiSecret, and domainName must be specified.'
34
+ end
35
+ uri = URI.parse("https://#{connection.domainName}#{relativeUrl}")
36
+ if connection.proxyServerName != nil && connection.proxyPort != nil
37
+ proxy = Net::HTTP::Proxy(connection.proxyServerName, connection.proxyPort)
38
+ http = proxy.new(uri.host, uri.port)
39
+ else
40
+ http = Net::HTTP.new(uri.host, uri.port)
41
+ end
42
+ http.use_ssl = true
43
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
44
+ headers = { 'User-Agent' => SDK_USER_AGENT,
45
+ 'Content-Type' => 'application/json; charset=utf-8',
46
+ 'Accept' => 'application/json; charset=utf-8',
47
+ 'Authorization' => connection.headerValue,
48
+ 'Host' => connection.domainName}
49
+ request = Net::HTTP::Get.new(uri.request_uri, headers)
50
+
51
+ response = http.request(request)
52
+
53
+ #Logger.write("hi mom", loggingObject)
54
+ parseResponse(request, response, classDef, connection, loggingObject)
55
+
56
+ end
57
+
58
+ def self.post(relativeUrl, classDef, toPost, connection, loggingObject)
59
+ connection ||= Connection.createFromConfig()
60
+ if connection.headerValue.to_s.empty? || connection.domainName.to_s.empty?
61
+ raise ArgumentError, 'A valid connection with apiKey, apiSecret, and domainName must be specified.'
62
+ end
63
+
64
+ uri = URI.parse("https://#{connection.domainName}#{relativeUrl}")
65
+ if connection.proxyServerName != nil && connection.proxyPort != nil
66
+ proxy = Net::HTTP::Proxy(connection.proxyServerName, connection.proxyPort)
67
+ http = proxy.new(uri.host, uri.port)
68
+ else
69
+ http = Net::HTTP.new(uri.host, uri.port)
70
+ end
71
+ http.use_ssl = true
72
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
73
+ headers = { 'User-Agent' => SDK_USER_AGENT,
74
+ 'Content-Type' => 'application/json; charset=utf-8',
75
+ 'Accept' => 'application/json; charset=utf-8',
76
+ 'Authorization' => connection.headerValue,
77
+ 'Host' => connection.domainName}
78
+ request = Net::HTTP::Post.new(uri.request_uri, headers)
79
+ request.body = toPost.to_json
80
+ response = http.request(request)
81
+
82
+ #Logger.write("hi mom", loggingObject)
83
+ parseResponse(request, response, classDef, connection, loggingObject)
84
+
85
+ end
86
+
87
+ def self.parseResponse(req, resp, classDef, conn, loggingObject)
88
+ case resp.code
89
+ when '501'
90
+ raise 501
91
+ when '502'
92
+ raise 502
93
+ when '503'
94
+ raise 503
95
+ when '504'
96
+ raise 504
97
+ when '505'
98
+ raise 505
99
+ else
100
+ envelope = CorePro::Models::Envelope.new
101
+ envelope.rawRequestBody = req.body
102
+ envelope.rawResponseBody = resp.body
103
+ parsedJson = JSON.parse(resp.body)
104
+ envelope.from_json! parsedJson, { 'data' => classDef }
105
+ if envelope.errors.length > 0
106
+ raise CorePro::CoreProApiException.new(envelope.errors)
107
+ else
108
+ if classDef == nil
109
+ # no class definition given, return raw envelope
110
+ envelope
111
+ else
112
+ # class definition given, return just that data
113
+ envelope.data
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/ruby -w
2
+ module CorePro
3
+ VERSION = '1.0.2'
4
+ end