blackstack-core 1.2.2 → 1.2.4

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/blackstack-core.rb +1 -0
  3. data/lib/functions.rb +16 -21
  4. metadata +22 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f33aeb0755dce25238071e8ac61c7c6a4f8670ac167adf1d1fbe48e6d873071
4
- data.tar.gz: eb5d340b23eccae12fb9acb502d353486f6d86bac4517c01fe00f2d6a8e7c6c9
3
+ metadata.gz: c8344c762d3fc997d89a57ddcd77676814c455723f26bfe8d22e95c099cdc288
4
+ data.tar.gz: 63a99bb07b29dc75226b246495c3f101ca052786c0c3aa22cc4d1b2c15690ece
5
5
  SHA512:
6
- metadata.gz: 79f24f759399bbbe9928cf1dd6adf6861c4e8b0eb34c2d9a2f6f8ff06f9fa708ed18a658c4a552276c4eb50c3aedac235e1eebe212c6f00b84abf222c2038363
7
- data.tar.gz: f4bf1b22cbc9023c572ced8863356c37b9a2805f3cfe326a059f560a69ba2850a3b661d99e0e10c0c390a8fb66eda82c97c9642bb7af80e6502459c2ddbbaf4f
6
+ metadata.gz: 97e7775f584296c46873f921177452f9e27d94237d370e83df9f951f5436ac6a066917ce627b4ad8f106e532b090413dd126f801d37c914ae5d7394c8a61a8b3
7
+ data.tar.gz: 4f353651ad7da375523ea5c5758f9e30b1d7ca2f98bb282672cb39a3169fb5e56ce370ec8fc464572d69a9e2a027c49da3aec2c208948de4e1a98ba5f47e0b82
@@ -5,6 +5,7 @@ require 'json'
5
5
  require 'net/http'
6
6
  require 'openssl'
7
7
  require 'time'
8
+ require 'faraday'
8
9
  =begin
9
10
  require 'html_to_plain_text'
10
11
  require "RedCloth"
data/lib/functions.rb CHANGED
@@ -560,7 +560,7 @@ module BlackStack
560
560
  res = http.request req
561
561
  case res
562
562
  when Net::HTTPSuccess then res
563
- when Net::HTTPRedirection then BlackStack::Netting::call_get(URI(res['location']), params, false) if support_redirections
563
+ when Net::HTTPRedirection then BlackStack::Netting::call_get(URI(res['location']), params, ssl_verify_mode, false) if support_redirections
564
564
  else
565
565
  res.error!
566
566
  end
@@ -573,13 +573,13 @@ module BlackStack
573
573
  # For more information about support for complex data structures, reference to: https://github.com/leandrosardi/mysaas/issues/59
574
574
  #
575
575
  # url: valid internet address
576
- # params: hash of params to attach in the call
576
+ # body: hash of body to attach in the call
577
577
  # ssl_verify_mode: you can disabele SSL verification here.
578
578
  # max_channels: this method use lockfiles to prevent an excesive number of API calls from each datacenter. There is not allowed more simultaneous calls than max_channels.
579
579
  #
580
580
  # TODO: parameter support_redirections has been deprecated.
581
581
  #
582
- def self.call_post(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, support_redirections=true)
582
+ def self.call_post(url, body = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, support_redirections=true)
583
583
  # issue: https://github.com/leandrosardi/mysaas/issues/59
584
584
  #
585
585
  # when ruby pushes hash of hashes (or hash of arrays), all values are converted into strings.
@@ -587,31 +587,26 @@ module BlackStack
587
587
  #
588
588
  # the solution is to convert each element of the hash into a string using `.to_json` method.
589
589
  #
590
- # reference: https://stackoverflow.com/questions/1667630/how-do-i-convert-a-string-object-into-a-hash-object
590
+ # references:
591
+ # - https://stackoverflow.com/questions/1667630/how-do-i-convert-a-string-object-into-a-hash-object
592
+ # - https://stackoverflow.com/questions/67572866/how-to-build-complex-json-to-post-to-a-web-service-with-rails-5-2-and-faraday-ge
591
593
  #
592
594
  # iterate the keys of the hash
593
595
  #
594
- params.each { |key, value| params[key] = value.to_json }
596
+ params = {} # not needed for post calls to access points
597
+ path = URI::parse(url).path
598
+ domain = url.gsub(/#{Regexp.escape(path)}/, '')
595
599
 
596
- # do the call
597
- uri = URI(url)
598
- ret = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => ssl_verify_mode) do |http|
599
- req = Net::HTTP::Post.new(uri)
600
- req['Content-Type'] = 'application/json'
601
- req.set_form_data(params)
602
- res = http.request req
603
- case res
604
- when Net::HTTPSuccess then res
605
- #when Net::HTTPRedirection then BlackStack::Netting::call_post(URI(res['location']), params, BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, false) if support_redirections
606
- else
607
- res.error!
608
- end
609
- end
610
- # return
600
+ conn = Faraday.new(domain, :ssl=>{:verify=>ssl_verify_mode!=OpenSSL::SSL::VERIFY_NONE})
601
+ ret = conn.post(path, params) do |req|
602
+ req.body = body.to_json
603
+ req.headers['Content-Type'] = 'application/json'
604
+ req.headers['Accept'] = 'application/json'
605
+ end
611
606
  ret
612
607
  end
613
608
 
614
- #
609
+ # TODO: deprecated
615
610
  def self.api_call(url, params={}, method=BlackStack::Netting::CALL_METHOD_POST, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, max_retries=5)
616
611
  nTries = 0
617
612
  bSuccess = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackstack-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-27 00:00:00.000000000 Z
11
+ date: 2023-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: content_spinning
@@ -70,6 +70,26 @@ dependencies:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 0.14.1
73
+ - !ruby/object:Gem::Dependency
74
+ name: faraday
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 2.3.0
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.0
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.3.0
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.3.0
73
93
  description: 'THIS GEM IS STILL IN DEVELOPMENT STAGE. Find documentation here: https://github.com/leandrosardi/blackstack-core.'
74
94
  email: leandro.sardi@expandedventure.com
75
95
  executables: []