twelvedata_ruby 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -2
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/twelvedata_ruby.rb +1 -1
- data/lib/twelvedata_ruby/response.rb +22 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75436c91668d0327b3e24c99e7a58ae6f72443a6abc8343a793d773d262f1482
|
4
|
+
data.tar.gz: 334e4569575e5dc0b29b5fd7aea48ee329bff7e9c84710d463555cc1f42f49dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cbc0aaaee0e37bf52f629963fa2e52caace90e80026fa132a442c03ea339b86817463a19d2be5f9b727600a5146ed60ae233b9815f6a798100e09c0a6b6a73d
|
7
|
+
data.tar.gz: 1c2e491b14f442dd65c65ad169a4c2555041cca20e6b2de3f820dd905d81b554a07cc08e2ca5580f1d2d98814245dc36985404d7856a36168e773a64df0b969c
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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
|
|
data/lib/twelvedata_ruby.rb
CHANGED
@@ -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.
|
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
|
-
|
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
|
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
|