twelvedata_ruby 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bca739fd82cc17f890fa3793d8125fcb31e1c553f6c2303d056f4a1a64ac6610
4
- data.tar.gz: 54813515e1e086fe341ffeb4a08502843e1c0ae0f4239dd890e55570381c9fd2
3
+ metadata.gz: 75436c91668d0327b3e24c99e7a58ae6f72443a6abc8343a793d773d262f1482
4
+ data.tar.gz: 334e4569575e5dc0b29b5fd7aea48ee329bff7e9c84710d463555cc1f42f49dd
5
5
  SHA512:
6
- metadata.gz: a3e77b8dafd422258e5dee1ddf68f8c48595ead5758bf3b6e084b125bf14f2b5c54091c7464b9b6a152aec4696bf1f48199e7ffb72318e67784693b469446d41
7
- data.tar.gz: 06c8fe4b17c366881fc4555d697ac276e9dc8e3956dfd6dabe5aea473e91d58a1044f5af51773586fbe3900baca8ac08fdb1436c1e9fb075768becfb9d95be3e
6
+ metadata.gz: 8cbc0aaaee0e37bf52f629963fa2e52caace90e80026fa132a442c03ea339b86817463a19d2be5f9b727600a5146ed60ae233b9815f6a798100e09c0a6b6a73d
7
+ data.tar.gz: 1c2e491b14f442dd65c65ad169a4c2555041cca20e6b2de3f820dd905d81b554a07cc08e2ca5580f1d2d98814245dc36985404d7856a36168e773a64df0b969c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,5 @@
1
- ## [Unreleased]
2
-
1
+ ## [0.2.1] - 2021-07-17
2
+ - copies http response body to a temp file first if byte size is greater than 16K before parsing it from the persisted temp file
3
3
  ## [0.1.0] - 2021-07-05
4
4
 
5
5
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twelvedata_ruby (0.2.0)
4
+ twelvedata_ruby (0.2.1)
5
5
  httpx (~> 0.14.5)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # TwelvedataRuby
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/twelvedata_ruby.svg)](https://badge.fury.io/rb/twelvedata_ruby)
3
4
 
4
5
  TwelvedataRuby is a Ruby library that exposes some convenient ways to access Twelve Data API to get information on stock, forex, crypto, and other financial market data. In order to do so, a free API key is required which can be easily requested [here](https://twelvedata.com/pricing). Visit their [API's full documentation](https://twelvedata.com/doc)
5
6
 
@@ -12,7 +12,7 @@ require_relative "twelvedata_ruby/client"
12
12
  module TwelvedataRuby
13
13
  # Holds the current version
14
14
  # @return [String] version number
15
- VERSION = "0.2.0"
15
+ VERSION = "0.2.1"
16
16
 
17
17
  # A convenient and clearer way of getting and overriding default attribute values of the singleton `Client.instance`
18
18
  #
@@ -4,6 +4,7 @@ require "csv"
4
4
  module TwelvedataRuby
5
5
  class Response
6
6
  CSV_COL_SEP = ";"
7
+ BODY_MAX_BYTESIZE = 16_000
7
8
  HTTP_STATUSES = {http_error: (400..600), success: (200..299)}.freeze
8
9
  CONTENT_TYPE_HANDLERS = {
9
10
  json: {parser: :json_parser, dumper: :json_dumper},
@@ -56,17 +57,12 @@ module TwelvedataRuby
56
57
  @content_type ||= headers["content-type"].match(%r{^.+/([a-z]+).*$})&.send(:[], 1)&.to_sym
57
58
  end
58
59
 
59
- def csv_parser
60
- chunk_parsed = nil
61
- opts = {col_sep: CSV_COL_SEP}
62
- body.each do |chk|
63
- chunk_parsed = chunk_parsed&.send(:push, CSV.parse(chk, **opts)) || CSV.parse(chk, **opts.merge(headers: true))
64
- end
65
- chunk_parsed
60
+ def csv_parser(io_str=nil)
61
+ CSV.parse(io_str || body.to_s, headers: true, col_sep: CSV_COL_SEP)
66
62
  end
67
63
 
68
64
  def csv_dumper
69
- parsed_body.is_a?(CSV::Table) ? parsed_body.to_csv : nil
65
+ parsed_body.is_a?(CSV::Table) ? parsed_body.to_csv(col_sep: CSV_COL_SEP) : nil
70
66
  end
71
67
 
72
68
  def dumped_parsed_body
@@ -89,12 +85,27 @@ module TwelvedataRuby
89
85
  parsed_body.is_a?(Hash) ? JSON.dump(parsed_body) : nil
90
86
  end
91
87
 
92
- def json_parser
93
- JSON.parse(body, symbolize_names: true)
88
+ def json_parser(io_obj=nil)
89
+ JSON.parse(io_obj || body.to_s, symbolize_names: true)
94
90
  end
95
91
 
96
92
  def parsed_body
97
- @parsed_body ||= send(body_parser)
93
+ return @parsed_body if @parsed_body
94
+ if body.bytesize < BODY_MAX_BYTESIZE
95
+ @parsed_body = send(body_parser)
96
+ else
97
+ tmp_file = Tempfile.new
98
+ begin
99
+ body.copy_to(tmp_file)
100
+ tmp_file.close
101
+ @parsed_body = send(body_parser, IO.read(tmp_file.path))
102
+ ensure
103
+ body.close
104
+ tmp_file.close
105
+ tmp_file.unlink
106
+ end
107
+ end
108
+ @parsed_body
98
109
  end
99
110
 
100
111
  def parsed_body_dumper
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twelvedata_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kendo Camajalan, KCD