fugle 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/lib/fugle/http/client.rb +15 -2
- data/lib/fugle/http/error.rb +88 -0
- data/lib/fugle/information.rb +28 -1
- data/lib/fugle/intraday/chart.rb +38 -0
- data/lib/fugle/intraday/meta.rb +60 -0
- data/lib/fugle/intraday/quote.rb +75 -1
- data/lib/fugle/intraday/trades.rb +10 -0
- data/lib/fugle/response.rb +24 -0
- data/lib/fugle/trade.rb +29 -2
- data/lib/fugle/version.rb +1 -1
- metadata +3 -3
- data/Gemfile.lock +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38224ead4ecd1869213f6e2cf2cd00d6a5e33d7f584e30249460190444c27ae6
|
4
|
+
data.tar.gz: c05472cac52a28462a822d53f3e15469b1c915ef166da87fea4706a3516f2a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc789caddaf605f7b7b3a54920506a84524ee15c4b9195b10ea6f5dfd0ce7c2fc3a2ec49295000e90ce6c7295205e52de844253b671ec89502f48a3cb9cd7044
|
7
|
+
data.tar.gz: d38c4b97870f958eb70845f62a6a0b0d97f6b0e6c70f97dcdc00c2ba028aee9b63d27ddc243e34a4542cd1180dc1c977264d832e404c0e5865b1d17658499d21
|
data/.gitignore
CHANGED
data/lib/fugle/http/client.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'net/http'
|
4
4
|
require 'json'
|
5
|
+
require 'fugle/http/error'
|
5
6
|
|
6
7
|
module Fugle
|
7
8
|
module HTTP
|
@@ -29,14 +30,26 @@ module Fugle
|
|
29
30
|
return super if @api.nil?
|
30
31
|
return self unless @api.is_a?(Class)
|
31
32
|
|
32
|
-
|
33
|
-
res = Response.new(@api, JSON.parse(Net::HTTP.get(uri)))
|
33
|
+
res = fetch(@api.uri(*args))
|
34
34
|
yield res.body if block_given?
|
35
35
|
res
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
39
39
|
|
40
|
+
# @since 0.1.0
|
41
|
+
# @api private
|
42
|
+
def fetch(uri)
|
43
|
+
use_ssl = uri.scheme == 'https'
|
44
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl) do |http|
|
45
|
+
http.request Net::HTTP::Get.new(uri)
|
46
|
+
end
|
47
|
+
body = JSON.parse(res.body)
|
48
|
+
return Response.new(@api, body) if res.is_a?(Net::HTTPSuccess)
|
49
|
+
|
50
|
+
Error.new(@api, body)
|
51
|
+
end
|
52
|
+
|
40
53
|
# @since 0.1.0
|
41
54
|
# @api private
|
42
55
|
def find(name)
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Fugle
|
6
|
+
module HTTP
|
7
|
+
# @since 0.1.0
|
8
|
+
# @api private
|
9
|
+
class Error
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
delegate %i[code message] => :body
|
13
|
+
|
14
|
+
# @since 0.1.0
|
15
|
+
# @api private
|
16
|
+
attr_reader :info, :body
|
17
|
+
|
18
|
+
# @since 0.1.0
|
19
|
+
# @api private
|
20
|
+
def initialize(api, body)
|
21
|
+
@api = api
|
22
|
+
@version = body['apiVersion']
|
23
|
+
@body = Body.new(body['error'])
|
24
|
+
end
|
25
|
+
|
26
|
+
# Convert to Hash
|
27
|
+
#
|
28
|
+
# @return [Hash] the response as hash
|
29
|
+
#
|
30
|
+
# @since 0.1.0
|
31
|
+
# @api private
|
32
|
+
def to_h
|
33
|
+
{
|
34
|
+
version: @version,
|
35
|
+
body: @body
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# Convert to JSON
|
40
|
+
#
|
41
|
+
# @return [String] the json string
|
42
|
+
#
|
43
|
+
# @since 0.1.0
|
44
|
+
# @api private
|
45
|
+
def to_json(*args)
|
46
|
+
to_h.to_json(*args)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @since 0.1.0
|
50
|
+
# @api private
|
51
|
+
class Body
|
52
|
+
# @since 0.1.0
|
53
|
+
# @api private
|
54
|
+
attr_reader :code, :message
|
55
|
+
|
56
|
+
# @since 0.1.0
|
57
|
+
# @api private
|
58
|
+
def initialize(error)
|
59
|
+
@code = error['code']
|
60
|
+
@message = error['message']
|
61
|
+
end
|
62
|
+
|
63
|
+
# Convert to Hash
|
64
|
+
#
|
65
|
+
# @return [Hash] the response as hash
|
66
|
+
#
|
67
|
+
# @since 0.1.0
|
68
|
+
# @api private
|
69
|
+
def to_h
|
70
|
+
{
|
71
|
+
code: @code,
|
72
|
+
message: @message
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
# Convert to JSON
|
77
|
+
#
|
78
|
+
# @return [String] the json string
|
79
|
+
#
|
80
|
+
# @since 0.1.0
|
81
|
+
# @api private
|
82
|
+
def to_json(*args)
|
83
|
+
to_h.to_json(*args)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/fugle/information.rb
CHANGED
@@ -19,8 +19,35 @@ module Fugle
|
|
19
19
|
@mode = attributes['mode']
|
20
20
|
@timezone = attributes['timeZone']
|
21
21
|
@country_code = attributes['countryCode']
|
22
|
-
@
|
22
|
+
@updated_at = DateTime.parse(attributes['lastUpdatedAt'])
|
23
23
|
@date = Date.parse(attributes['date'])
|
24
24
|
end
|
25
|
+
|
26
|
+
# Convert to Hash
|
27
|
+
#
|
28
|
+
# @return [Hash] the response as hash
|
29
|
+
#
|
30
|
+
# @since 0.1.0
|
31
|
+
# @api private
|
32
|
+
def to_h
|
33
|
+
{
|
34
|
+
symbol: @symbol,
|
35
|
+
mode: @mode,
|
36
|
+
timezone: @timezone,
|
37
|
+
country_code: @country_code,
|
38
|
+
date: @date,
|
39
|
+
updated_at: @updated_at
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
# Convert to JSON
|
44
|
+
#
|
45
|
+
# @return [String] the json string
|
46
|
+
#
|
47
|
+
# @since 0.1.0
|
48
|
+
# @api private
|
49
|
+
def to_json(*args)
|
50
|
+
to_h.to_json(*args)
|
51
|
+
end
|
25
52
|
end
|
26
53
|
end
|
data/lib/fugle/intraday/chart.rb
CHANGED
@@ -29,6 +29,16 @@ module Fugle
|
|
29
29
|
@items.each(&block)
|
30
30
|
end
|
31
31
|
|
32
|
+
# Convert to JSON
|
33
|
+
#
|
34
|
+
# @return [String] the json string
|
35
|
+
#
|
36
|
+
# @since 0.1.0
|
37
|
+
# @api private
|
38
|
+
def to_json(*args)
|
39
|
+
to_a.to_json(*args)
|
40
|
+
end
|
41
|
+
|
32
42
|
# @since 0.1.0
|
33
43
|
# @api private
|
34
44
|
class Item
|
@@ -44,6 +54,34 @@ module Fugle
|
|
44
54
|
instance_variable_set("@#{name}", value)
|
45
55
|
end
|
46
56
|
end
|
57
|
+
|
58
|
+
# Convert to Hash
|
59
|
+
#
|
60
|
+
# @return [Hash] the response as hash
|
61
|
+
#
|
62
|
+
# @since 0.1.0
|
63
|
+
# @api private
|
64
|
+
def to_h
|
65
|
+
{
|
66
|
+
open: @open,
|
67
|
+
high: @high,
|
68
|
+
low: @low,
|
69
|
+
close: @close,
|
70
|
+
unit: @unit,
|
71
|
+
volume: @volume,
|
72
|
+
time: @time
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
# Convert to JSON
|
77
|
+
#
|
78
|
+
# @return [String] the json string
|
79
|
+
#
|
80
|
+
# @since 0.1.0
|
81
|
+
# @api private
|
82
|
+
def to_json(*args)
|
83
|
+
to_h.to_json(*args)
|
84
|
+
end
|
47
85
|
end
|
48
86
|
end
|
49
87
|
end
|
data/lib/fugle/intraday/meta.rb
CHANGED
@@ -51,6 +51,41 @@ module Fugle
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
# Convert to Hash
|
55
|
+
#
|
56
|
+
# @return [Hash] the response as hash
|
57
|
+
#
|
58
|
+
# @since 0.1.0
|
59
|
+
# @api private
|
60
|
+
# rubocop:disable Metrics/MethodLength
|
61
|
+
def to_h
|
62
|
+
{
|
63
|
+
name: @name,
|
64
|
+
industry: @industry,
|
65
|
+
type: @type,
|
66
|
+
price: @price,
|
67
|
+
is_index: index?,
|
68
|
+
is_terminated: terminated?,
|
69
|
+
is_suspended: suspended?,
|
70
|
+
is_warrant: warrant?,
|
71
|
+
can_day_buy_sell: day_buy_sell?,
|
72
|
+
can_day_sell_buy: day_sell_buy?,
|
73
|
+
can_short_margin: short_margin?,
|
74
|
+
can_short_lend: short_lend?
|
75
|
+
}
|
76
|
+
end
|
77
|
+
# rubocop:enable Metrics/MethodLength
|
78
|
+
|
79
|
+
# Convert to JSON
|
80
|
+
#
|
81
|
+
# @return [String] the json string
|
82
|
+
#
|
83
|
+
# @since 0.1.0
|
84
|
+
# @api private
|
85
|
+
def to_json(*args)
|
86
|
+
to_h.to_json(*args)
|
87
|
+
end
|
88
|
+
|
54
89
|
# @since 0.1.0
|
55
90
|
# @api private
|
56
91
|
class Price
|
@@ -66,6 +101,31 @@ module Fugle
|
|
66
101
|
@low_limit = data['priceLowLimit']
|
67
102
|
@currency = data['currency']
|
68
103
|
end
|
104
|
+
|
105
|
+
# Convert to Hash
|
106
|
+
#
|
107
|
+
# @return [Hash] the response as hash
|
108
|
+
#
|
109
|
+
# @since 0.1.0
|
110
|
+
# @api private
|
111
|
+
def to_h
|
112
|
+
{
|
113
|
+
reference: @reference,
|
114
|
+
high_limit: @high_limit,
|
115
|
+
low_limit: @low_limit,
|
116
|
+
currency: @currency
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
# Convert to JSON
|
121
|
+
#
|
122
|
+
# @return [String] the json string
|
123
|
+
#
|
124
|
+
# @since 0.1.0
|
125
|
+
# @api private
|
126
|
+
def to_json(*args)
|
127
|
+
to_h.to_json(*args)
|
128
|
+
end
|
69
129
|
end
|
70
130
|
end
|
71
131
|
end
|
data/lib/fugle/intraday/quote.rb
CHANGED
@@ -45,6 +45,32 @@ module Fugle
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
# Convert to Hash
|
49
|
+
#
|
50
|
+
# @return [Hash] the response as hash
|
51
|
+
#
|
52
|
+
# @since 0.1.0
|
53
|
+
# @api private
|
54
|
+
def to_h
|
55
|
+
{
|
56
|
+
total: @total,
|
57
|
+
trial: @trial,
|
58
|
+
trade: @trade,
|
59
|
+
price: @price,
|
60
|
+
order: @order
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
# Convert to JSON
|
65
|
+
#
|
66
|
+
# @return [String] the json string
|
67
|
+
#
|
68
|
+
# @since 0.1.0
|
69
|
+
# @api private
|
70
|
+
def to_json(*args)
|
71
|
+
to_h.to_json(*args)
|
72
|
+
end
|
73
|
+
|
48
74
|
# @since 0.1.0
|
49
75
|
# @api private
|
50
76
|
class Price
|
@@ -59,6 +85,30 @@ module Fugle
|
|
59
85
|
@low = Trade.new(data['priceLow'])
|
60
86
|
@open = Trade.new(data['priceOpen'])
|
61
87
|
end
|
88
|
+
|
89
|
+
# Convert to Hash
|
90
|
+
#
|
91
|
+
# @return [Hash] the response as hash
|
92
|
+
#
|
93
|
+
# @since 0.1.0
|
94
|
+
# @api private
|
95
|
+
def to_h
|
96
|
+
{
|
97
|
+
high: @high,
|
98
|
+
low: @low,
|
99
|
+
open: @open
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
# Convert to JSON
|
104
|
+
#
|
105
|
+
# @return [String] the json string
|
106
|
+
#
|
107
|
+
# @since 0.1.0
|
108
|
+
# @api private
|
109
|
+
def to_json(*args)
|
110
|
+
to_h.to_json(*args)
|
111
|
+
end
|
62
112
|
end
|
63
113
|
|
64
114
|
# @since 0.1.0
|
@@ -71,10 +121,34 @@ module Fugle
|
|
71
121
|
# @since 0.1.0
|
72
122
|
# @api private
|
73
123
|
def initialize(data)
|
74
|
-
@
|
124
|
+
@updated_at = DateTime.parse(data['at'])
|
75
125
|
@best_bids = data['bestBids'].map { |item| Trade.new(item) }
|
76
126
|
@best_asks = data['bestAsks'].map { |item| Trade.new(item) }
|
77
127
|
end
|
128
|
+
|
129
|
+
# Convert to Hash
|
130
|
+
#
|
131
|
+
# @return [Hash] the response as hash
|
132
|
+
#
|
133
|
+
# @since 0.1.0
|
134
|
+
# @api private
|
135
|
+
def to_h
|
136
|
+
{
|
137
|
+
updated_at: @updated_at,
|
138
|
+
best_bids: @best_bids,
|
139
|
+
best_asks: @best_asks
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
# Convert to JSON
|
144
|
+
#
|
145
|
+
# @return [String] the json string
|
146
|
+
#
|
147
|
+
# @since 0.1.0
|
148
|
+
# @api private
|
149
|
+
def to_json(*args)
|
150
|
+
to_h.to_json(*args)
|
151
|
+
end
|
78
152
|
end
|
79
153
|
end
|
80
154
|
end
|
@@ -26,6 +26,16 @@ module Fugle
|
|
26
26
|
def each(&block)
|
27
27
|
@items.each(&block)
|
28
28
|
end
|
29
|
+
|
30
|
+
# Convert to JSON
|
31
|
+
#
|
32
|
+
# @return [String] the json string
|
33
|
+
#
|
34
|
+
# @since 0.1.0
|
35
|
+
# @api private
|
36
|
+
def to_json(*args)
|
37
|
+
to_a.to_json(*args)
|
38
|
+
end
|
29
39
|
end
|
30
40
|
end
|
31
41
|
end
|
data/lib/fugle/response.rb
CHANGED
@@ -21,5 +21,29 @@ module Fugle
|
|
21
21
|
@info = Information.new(attributes.dig('data', 'info'))
|
22
22
|
@body = body.new(attributes.dig('data', body.data_name))
|
23
23
|
end
|
24
|
+
|
25
|
+
# Convert to Hash
|
26
|
+
#
|
27
|
+
# @return [Hash] the response as hash
|
28
|
+
#
|
29
|
+
# @since 0.1.0
|
30
|
+
# @api private
|
31
|
+
def to_h
|
32
|
+
{
|
33
|
+
version: @version,
|
34
|
+
info: @info,
|
35
|
+
body: @body
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# Convert to JSON
|
40
|
+
#
|
41
|
+
# @return [String] the json string
|
42
|
+
#
|
43
|
+
# @since 0.1.0
|
44
|
+
# @api private
|
45
|
+
def to_json(*args)
|
46
|
+
to_h.to_json(*args)
|
47
|
+
end
|
24
48
|
end
|
25
49
|
end
|
data/lib/fugle/trade.rb
CHANGED
@@ -8,7 +8,7 @@ module Fugle
|
|
8
8
|
class Trade
|
9
9
|
# @since 0.1.0
|
10
10
|
# @api private
|
11
|
-
attr_reader :price, :unit, :order, :volume, :serial
|
11
|
+
attr_reader :price, :unit, :order, :volume, :serial, :updated_at
|
12
12
|
|
13
13
|
# @since 0.1.0
|
14
14
|
# @api private
|
@@ -18,7 +18,34 @@ module Fugle
|
|
18
18
|
@order = item['order']
|
19
19
|
@volume = item['volume']
|
20
20
|
@serial = item['serial']
|
21
|
-
@
|
21
|
+
@updated_at = DateTime.parse(item['at']) if item['at']
|
22
|
+
end
|
23
|
+
|
24
|
+
# Convert to Hash
|
25
|
+
#
|
26
|
+
# @return [Hash] the response as hash
|
27
|
+
#
|
28
|
+
# @since 0.1.0
|
29
|
+
# @api private
|
30
|
+
def to_h
|
31
|
+
{
|
32
|
+
price: @price,
|
33
|
+
unit: @uint,
|
34
|
+
volume: @volume,
|
35
|
+
order: @order,
|
36
|
+
serial: @serial,
|
37
|
+
updated_at: @updated_at
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
# Convert to JSON
|
42
|
+
#
|
43
|
+
# @return [String] the json string
|
44
|
+
#
|
45
|
+
# @since 0.1.0
|
46
|
+
# @api private
|
47
|
+
def to_json(*args)
|
48
|
+
to_h.to_json(*args)
|
22
49
|
end
|
23
50
|
end
|
24
51
|
end
|
data/lib/fugle/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fugle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 蒼時弦也
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,7 +107,6 @@ files:
|
|
107
107
|
- ".travis.yml"
|
108
108
|
- CODE_OF_CONDUCT.md
|
109
109
|
- Gemfile
|
110
|
-
- Gemfile.lock
|
111
110
|
- README.md
|
112
111
|
- Rakefile
|
113
112
|
- bin/console
|
@@ -118,6 +117,7 @@ files:
|
|
118
117
|
- lib/fugle/http.rb
|
119
118
|
- lib/fugle/http/api.rb
|
120
119
|
- lib/fugle/http/client.rb
|
120
|
+
- lib/fugle/http/error.rb
|
121
121
|
- lib/fugle/http/parameters.rb
|
122
122
|
- lib/fugle/http/query.rb
|
123
123
|
- lib/fugle/information.rb
|
data/Gemfile.lock
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
fugle (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ast (2.4.0)
|
10
|
-
bundler-audit (0.6.1)
|
11
|
-
bundler (>= 1.2.0, < 3)
|
12
|
-
thor (~> 0.18)
|
13
|
-
childprocess (3.0.0)
|
14
|
-
coderay (1.1.2)
|
15
|
-
diff-lcs (1.3)
|
16
|
-
iniparse (1.4.4)
|
17
|
-
jaro_winkler (1.5.3)
|
18
|
-
method_source (0.9.2)
|
19
|
-
overcommit (0.51.0)
|
20
|
-
childprocess (>= 0.6.3, < 4)
|
21
|
-
iniparse (~> 1.4)
|
22
|
-
parallel (1.18.0)
|
23
|
-
parser (2.6.5.0)
|
24
|
-
ast (~> 2.4.0)
|
25
|
-
pry (0.12.2)
|
26
|
-
coderay (~> 1.1.0)
|
27
|
-
method_source (~> 0.9.0)
|
28
|
-
rainbow (3.0.0)
|
29
|
-
rake (10.5.0)
|
30
|
-
rspec (3.9.0)
|
31
|
-
rspec-core (~> 3.9.0)
|
32
|
-
rspec-expectations (~> 3.9.0)
|
33
|
-
rspec-mocks (~> 3.9.0)
|
34
|
-
rspec-core (3.9.0)
|
35
|
-
rspec-support (~> 3.9.0)
|
36
|
-
rspec-expectations (3.9.0)
|
37
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
-
rspec-support (~> 3.9.0)
|
39
|
-
rspec-mocks (3.9.0)
|
40
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.9.0)
|
42
|
-
rspec-support (3.9.0)
|
43
|
-
rubocop (0.76.0)
|
44
|
-
jaro_winkler (~> 1.5.1)
|
45
|
-
parallel (~> 1.10)
|
46
|
-
parser (>= 2.6)
|
47
|
-
rainbow (>= 2.2.2, < 4.0)
|
48
|
-
ruby-progressbar (~> 1.7)
|
49
|
-
unicode-display_width (>= 1.4.0, < 1.7)
|
50
|
-
ruby-progressbar (1.10.1)
|
51
|
-
thor (0.20.3)
|
52
|
-
unicode-display_width (1.6.0)
|
53
|
-
|
54
|
-
PLATFORMS
|
55
|
-
ruby
|
56
|
-
|
57
|
-
DEPENDENCIES
|
58
|
-
bundler (~> 1.17)
|
59
|
-
bundler-audit (~> 0.6.1)
|
60
|
-
fugle!
|
61
|
-
overcommit (~> 0.51.0)
|
62
|
-
pry
|
63
|
-
rake (~> 10.0)
|
64
|
-
rspec (~> 3.0)
|
65
|
-
rubocop (~> 0.76.0)
|
66
|
-
|
67
|
-
BUNDLED WITH
|
68
|
-
1.17.2
|