aadyandana-latest_stock_price 1.1.0 → 2.0.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 +10 -1
- data/lib/aadyandana/latest_stock_price/version.rb +1 -1
- data/lib/aadyandana/latest_stock_price.rb +41 -16
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d03e86f7d366b3333ea39f34938d3cfb5ce295bf6077405572a6c9d3ec9b31ef
|
4
|
+
data.tar.gz: ea948f46612499bb2712a45a4dcf6bd9e7683d9615ade101dfe6efff4eda662b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07cad6f8a683b78d2a347b4a6becbcbe7aa6f3c4e7eeaebeb2dd71ad56389f6c42989e4daebbb4beb5656d1021a867874e048ca6ec4d8c47bd67b32efd025770
|
7
|
+
data.tar.gz: bdfb6b593973277cfd852473d29bad34e89dfd006ac9792e595fe465bbeb5e519fd3f67a7015038302a431b7c9dcd8142c9a2ba42eb0b0be0a6b2d69533c0ecb
|
data/CHANGELOG.md
CHANGED
@@ -27,6 +27,10 @@ module Aadyandana
|
|
27
27
|
def initialize(api_key, params = {})
|
28
28
|
@api_key = api_key
|
29
29
|
@params = params
|
30
|
+
|
31
|
+
@datetime_attrs = %w[lastUpdateTime]
|
32
|
+
@string_meta_attrs = %w[companyName industry isin]
|
33
|
+
@string_attrs = %w[identifier symbol] + @string_meta_attrs
|
30
34
|
end
|
31
35
|
|
32
36
|
def price
|
@@ -42,16 +46,21 @@ module Aadyandana
|
|
42
46
|
def prices
|
43
47
|
page = (@params[:page] || 1).to_i
|
44
48
|
limit = (@params[:limit] || 10).to_i
|
45
|
-
|
49
|
+
|
46
50
|
stocks = get
|
47
51
|
stocks = filter(stocks)
|
52
|
+
stocks = sort(stocks, @params[:sort]) if @params[:sort]
|
48
53
|
stocks = paginate(stocks, page, limit)
|
49
54
|
|
50
55
|
stocks || []
|
51
56
|
end
|
52
57
|
|
53
58
|
def price_all
|
54
|
-
get
|
59
|
+
stocks = get
|
60
|
+
|
61
|
+
stocks = sort(stocks, @params[:sort]) if @params[:sort]
|
62
|
+
|
63
|
+
stocks
|
55
64
|
end
|
56
65
|
|
57
66
|
private
|
@@ -64,12 +73,7 @@ module Aadyandana
|
|
64
73
|
end
|
65
74
|
|
66
75
|
def get
|
67
|
-
response = self.class.get(
|
68
|
-
"/any",
|
69
|
-
{
|
70
|
-
headers: headers
|
71
|
-
}
|
72
|
-
)
|
76
|
+
response = self.class.get("/any", { headers: headers })
|
73
77
|
|
74
78
|
raise Error, "Error fetching data: #{response.message}" unless response.success?
|
75
79
|
|
@@ -84,16 +88,37 @@ module Aadyandana
|
|
84
88
|
end
|
85
89
|
|
86
90
|
def filter(stocks)
|
87
|
-
stocks = stocks.select { |stock| stock[
|
88
|
-
stocks = stocks.select { |stock| stock[
|
89
|
-
if @params[:company_name]
|
90
|
-
|
91
|
-
|
91
|
+
stocks = stocks.select { |stock| stock["identifier"] == @params[:identifier] } if @params[:identifier]
|
92
|
+
stocks = stocks.select { |stock| stock["symbol"] == @params[:symbol] } if @params[:symbol]
|
93
|
+
stocks = stocks.select { |stock| stock["meta"]["companyName"] == @params[:company_name] } if @params[:company_name]
|
94
|
+
stocks = stocks.select { |stock| stock["meta"]["industry"] == @params[:industry] } if @params[:industry]
|
95
|
+
stocks = stocks.select { |stock| stock["meta"]["isin"] == @params[:isin] } if @params[:isin]
|
96
|
+
|
97
|
+
stocks
|
98
|
+
end
|
99
|
+
|
100
|
+
def sort(stocks, sort)
|
101
|
+
field, type = sort.split(".")
|
102
|
+
|
103
|
+
stocks = stocks.sort_by do |stock|
|
104
|
+
value = stock[field]
|
105
|
+
|
106
|
+
if @datetime_attrs.include? field
|
107
|
+
value = DateTime.parse(value).to_time.to_i
|
108
|
+
value *= -1 if type == "desc"
|
109
|
+
elsif @string_attrs.include? field
|
110
|
+
value = stock["meta"][field] if @string_meta_attrs.include? field
|
111
|
+
value = value.present? ? value.downcase : "zzz"
|
112
|
+
else
|
113
|
+
value = value == "-" ? Float::INFINITY : value.to_f
|
114
|
+
value *= -1 if value != Float::INFINITY && type == "desc"
|
92
115
|
end
|
116
|
+
|
117
|
+
value
|
93
118
|
end
|
94
|
-
|
95
|
-
stocks
|
96
|
-
|
119
|
+
|
120
|
+
stocks.reverse! if (@string_attrs.include? field) && type == "desc"
|
121
|
+
|
97
122
|
stocks
|
98
123
|
end
|
99
124
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aadyandana-latest_stock_price
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- agus.adyandana
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.22.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.22.0
|
27
27
|
description: Fetches the latest stock prices from RapidAPI.
|
28
28
|
email:
|
29
29
|
- agus.adyandana@bigio.id
|