fugle 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3093fa3bd3690c82d23d454fb627e35d88e506c331619ffdb627d3be972ffa28
4
+ data.tar.gz: c191afb77360a1e6b4092cb8365aba13c56304d2f32268a2ef726a1a17887f0f
5
+ SHA512:
6
+ metadata.gz: 70c5b42f25a641c974216b3149ca08c9862731033ff4b3e17c76e35d225ecd32f5533a8cbb23095eb398ae7f587716ecf97c5f217194744c25ce7302ab8ab7ea
7
+ data.tar.gz: 6890d1bebcaceb04a7795c80780a42185f484f3a75733aa5512d24038875d6369ee37cc6a79a638de690f6e57f34b9f10aaadcb163c168a7c986857c4b926fa0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.overcommit.yml ADDED
@@ -0,0 +1,33 @@
1
+ # Use this file to configure the Overcommit hooks you wish to use. This will
2
+ # extend the default configuration defined in:
3
+ # https://github.com/sds/overcommit/blob/master/config/default.yml
4
+ #
5
+ # At the topmost level of this YAML file is a key representing type of hook
6
+ # being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
7
+ # customize each hook, such as whether to only run it on certain files (via
8
+ # `include`), whether to only display output if it fails (via `quiet`), etc.
9
+ #
10
+ # For a complete list of hooks, see:
11
+ # https://github.com/sds/overcommit/tree/master/lib/overcommit/hook
12
+ #
13
+ # For a complete list of options that you can use to customize hooks, see:
14
+ # https://github.com/sds/overcommit#configuration
15
+ #
16
+ # Uncomment the following lines to make the configuration take effect.
17
+
18
+ PreCommit:
19
+ AuthorName:
20
+ enabled: false
21
+ RuboCop:
22
+ enabled: true
23
+ on_warn: fail # Treat all warnings as failures
24
+ TrailingWhitespace:
25
+ enabled: true
26
+ BundleAudit:
27
+ enabled: true
28
+
29
+ PostCheckout:
30
+ ALL: # Special hook name that customizes all hooks of this type
31
+ quiet: true # Change all post-checkout hooks to only display output on failure
32
+ IndexTags:
33
+ enabled: true # Generate a tags file with `ctags` each time HEAD changes
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at elct9620@frost.tw. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in fugle.gemspec
8
+ gemspec
9
+
10
+ gem 'pry'
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
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
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ Fugle API
2
+ ===
3
+
4
+ This is Ruby gem implement Realtime API client for [Fugle.tw](https://fugle.tw)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'fugle'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install fugle
21
+
22
+ ## Usage
23
+
24
+ Currently only support HTTP API as below, for better use the API the result structure is modified.
25
+
26
+ ### Config
27
+
28
+ ```ruby
29
+ Fugle.config do |c|
30
+ c.api_token = 'XXX'
31
+ end
32
+ ```
33
+
34
+ > The token also loaded from `FUGLE_API_TOKEN` environment variable
35
+
36
+ You can temporary change config by `Fugle.use`
37
+
38
+ ```ruby
39
+ config = Fugle::Config.new(api_token: 'XXX')
40
+
41
+ Fugle.use(config) do
42
+ Fugle.intraday.meta(symbol: '0050')
43
+ end
44
+ ```
45
+
46
+ ### Chart
47
+
48
+ ```ruby
49
+ Fugle.intraday.chart(symbol: '0050').body.each do |item|
50
+ puts "Open: #{item.open} @ #{item.time}"
51
+ end
52
+ ```
53
+
54
+ ### Quote
55
+
56
+ ```ruby
57
+ Fugle.intraday.quote(symbol: '0050').body.closed?
58
+ ```
59
+
60
+ ### Meta
61
+
62
+ ```ruby
63
+ Fugle.intraday.meta(symbol: '0050').body.name
64
+ ```
65
+
66
+ ### Trades
67
+
68
+ ```ruby
69
+ Fugle.intraday.trades(symbol: '0050').body.each do |item|
70
+ puts "Price: #{item.price}"
71
+ end
72
+ ```
73
+
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/elct9620/fugle-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
83
+
84
+ ## Code of Conduct
85
+
86
+ Everyone interacting in the Fugle project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/elct9620/fugle-api/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'fugle'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require 'pry'
12
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/fugle.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'fugle/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'fugle'
9
+ spec.version = Fugle::VERSION
10
+ spec.authors = ['蒼時弦也']
11
+ spec.email = ['elct9620@frost.tw']
12
+
13
+ spec.summary = 'The Fugle.tw API Client'
14
+ spec.description = 'The Fugle.tw API Client'
15
+ spec.homepage = 'https://github.com/elct9620/fugle-api'
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files
19
+ # in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`
22
+ .split("\x0")
23
+ .reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.17'
30
+ spec.add_development_dependency 'bundler-audit', '~> 0.6.1'
31
+ spec.add_development_dependency 'overcommit', '~> 0.51.0'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rubocop', '~> 0.76.0'
35
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fugle
4
+ # @since 0.1.0
5
+ # @api private
6
+ class Config
7
+ attr_writer :api_token
8
+
9
+ # Create new config instance
10
+ #
11
+ # @param attributes [Hash] the default config
12
+ # @param block [Proc] the config block
13
+ #
14
+ # @since 0.1.0
15
+ # @api private
16
+ def initialize(attributes = {}, &block)
17
+ attributes.each do |name, value|
18
+ send("#{name}=", value)
19
+ end
20
+
21
+ instance_exec(self, &block) if block_given?
22
+ end
23
+
24
+ # The API Token
25
+ #
26
+ # @return [String] the api token
27
+ #
28
+ # @since 0.1.0
29
+ def api_token
30
+ @api_token || ENV['FUGLE_API_TOKEN']
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fugle/http/parameters'
4
+ require 'fugle/http/query'
5
+
6
+ module Fugle
7
+ module HTTP
8
+ # @since 0.1.0
9
+ # @api private
10
+ module API
11
+ # @since 0.1.0
12
+ # @api private
13
+ ENDPOINT = 'https://api.fugle.tw/realtime'
14
+
15
+ # @since 0.1.0
16
+ # @api private
17
+ VERSION = 'v0'
18
+
19
+ # @since 0.1.0
20
+ # @api private
21
+ def self.included(base)
22
+ base.class_eval do
23
+ @_path = nil
24
+ @_parameters = Parameters.new
25
+
26
+ extend ClassMethods
27
+ end
28
+ end
29
+
30
+ # @since 0.1.0
31
+ # @api private
32
+ module ClassMethods
33
+ # @since 0.1.0
34
+ # @api private
35
+ def path(value = nil)
36
+ return @_path if value.nil?
37
+
38
+ @_path = value
39
+ end
40
+
41
+ # @since 0.1.0
42
+ # @api private
43
+ def params(name, options = {})
44
+ @_parameters.add(name, options)
45
+ end
46
+
47
+ # @since 0.1.0
48
+ # @api private
49
+ def parameters
50
+ @_parameters
51
+ end
52
+
53
+ # @since 0.1.0
54
+ # @api private
55
+ def uri(query = {})
56
+ uri = URI("#{ENDPOINT}/#{VERSION}/#{path}")
57
+ uri.query = Query.new(
58
+ query.merge(apiToken: Fugle.config.api_token),
59
+ parameters
60
+ ).to_s
61
+ uri
62
+ end
63
+
64
+ # @since 0.1.0
65
+ # @api private
66
+ def data_name
67
+ @data_name ||= name.split('::').last.downcase
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ module Fugle
7
+ module HTTP
8
+ # The Fugle HTTP Client
9
+ #
10
+ # @since 0.1.0
11
+ # @api private
12
+ class Client
13
+ # @since 0.1.0
14
+ # @api private
15
+ def initialize
16
+ @api = Fugle
17
+ end
18
+
19
+ # @since 0.1.0
20
+ # @api private
21
+ def respond_to_missing?(_name)
22
+ super
23
+ end
24
+
25
+ # @since 0.1.0
26
+ # @api private
27
+ def method_missing(name, *args, &block)
28
+ @api = find(name)
29
+ return super if @api.nil?
30
+ return self unless @api.is_a?(Class)
31
+
32
+ uri = @api.uri(*args)
33
+ res = Response.new(@api, JSON.parse(Net::HTTP.get(uri)))
34
+ yield res.body if block_given?
35
+ res
36
+ end
37
+
38
+ private
39
+
40
+ # @since 0.1.0
41
+ # @api private
42
+ def find(name)
43
+ @api.const_get(name.capitalize)
44
+ rescue NameError
45
+ nil
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fugle
4
+ module HTTP
5
+ # @since 0.1.0
6
+ # @api private
7
+ class Parameters
8
+ # @since 0.1.0
9
+ # @api private
10
+ def initialize
11
+ @items = []
12
+ end
13
+
14
+ # @since 0.1.0
15
+ # @api private
16
+ def add(name, options = {})
17
+ @items.push(
18
+ name: name.to_sym,
19
+ required: options[:required] == true,
20
+ alias: options[:alias]
21
+ )
22
+ end
23
+
24
+ # @since 0.1.0
25
+ # @api private
26
+ def requires
27
+ @requires ||=
28
+ @items.select { |item| item[:required] }
29
+ end
30
+
31
+ # @since 0.1.0
32
+ # @api private
33
+ def [](name)
34
+ @items.find { |item| item[:name] == name }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fugle
4
+ module HTTP
5
+ # HTTP Query String
6
+ #
7
+ # @since 0.1.0
8
+ # @api private
9
+ class Query
10
+ # @since 0.1.0
11
+ # @api private
12
+ class MissingParameterError < RuntimeError; end
13
+
14
+ # Create new query
15
+ #
16
+ # @param query [Hash] the user inputs query
17
+ # @param parameters [Array<Hash>] the api parameter requirements
18
+ #
19
+ # @since 0.1.0
20
+ # @api private
21
+ def initialize(query, parameters)
22
+ @query = query
23
+ @parameters = parameters
24
+
25
+ verify!
26
+ end
27
+
28
+ # Verify parameters
29
+ #
30
+ # @since 0.1.0
31
+ # @api private
32
+ def verify!
33
+ raise MissingParameterError unless all_required?
34
+
35
+ true
36
+ end
37
+
38
+ # @since 0.1.0
39
+ # @api private
40
+ def all_required?
41
+ @parameters
42
+ .requires
43
+ .reduce(true) do |prev, curr|
44
+ @query[curr[:name]] && prev
45
+ end
46
+ end
47
+
48
+ # @since 0.1.0
49
+ # @api private
50
+ def to_h
51
+ @query
52
+ .map do |name, value|
53
+ as = @parameters[name]&.fetch(:alias, nil)
54
+ [as || name, value]
55
+ end
56
+ .to_h
57
+ end
58
+
59
+ # @since 0.1.0
60
+ # @api private
61
+ def to_s
62
+ URI.encode_www_form(to_h)
63
+ end
64
+ end
65
+ end
66
+ end
data/lib/fugle/http.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fugle/http/client'
4
+ require 'fugle/http/api'
5
+
6
+ module Fugle
7
+ # The HTTP Client
8
+ #
9
+ # @since 0.1.0
10
+ # @api private
11
+ module HTTP
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Fugle
6
+ # The Information
7
+ #
8
+ # @since 0.1.0
9
+ # @api private
10
+ class Information
11
+ # @since 0.1.0
12
+ # @api private
13
+ attr_reader :symbol, :mode, :timezone, :country_code, :update_at
14
+
15
+ # @since 0.1.0
16
+ # @api private
17
+ def initialize(attributes = {})
18
+ @symbol = attributes['symbolId']
19
+ @mode = attributes['mode']
20
+ @timezone = attributes['timeZone']
21
+ @country_code = attributes['countryCode']
22
+ @update_at = DateTime.parse(attributes['lastUpdatedAt'])
23
+ @date = Date.parse(attributes['date'])
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ module Fugle
6
+ module Intraday
7
+ # The Intraday Chart
8
+ #
9
+ # @since 0.1.0
10
+ # @api private
11
+ class Chart
12
+ include HTTP::API
13
+ include Enumerable
14
+
15
+ path 'intraday/chart'
16
+ params :symbol, require: true, alias: 'symbolId'
17
+
18
+ # @since 0.1.0
19
+ # @api private
20
+ def initialize(data)
21
+ @items = data.map do |time, row|
22
+ Item.new(row, time)
23
+ end
24
+ end
25
+
26
+ # @since 0.1.0
27
+ # @api private
28
+ def each(&block)
29
+ @items.each(&block)
30
+ end
31
+
32
+ # @since 0.1.0
33
+ # @api private
34
+ class Item
35
+ # @since 0.1.0
36
+ # @api private
37
+ attr_reader :open, :high, :low, :close, :unit, :volume, :time
38
+
39
+ # @since 0.1.0
40
+ # @api private
41
+ def initialize(attributes, time)
42
+ @time = DateTime.parse(time)
43
+ attributes.each do |name, value|
44
+ instance_variable_set("@#{name}", value)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fugle
4
+ module Intraday
5
+ # The Intraday Meta
6
+ #
7
+ # @since 0.1.0
8
+ # @api private
9
+ class Meta
10
+ using Utils
11
+ include HTTP::API
12
+ include Utils
13
+
14
+ path 'intraday/meta'
15
+ params :symbol, require: true, alias: 'symbolId'
16
+
17
+ # @since 0.1.0
18
+ # @api private
19
+ attr_reader :name, :industry, :type, :price
20
+
21
+ # @since 0.1.0
22
+ # @api private
23
+ STATES = %w[Index Terminated Suspended Warrant].freeze
24
+ PERMITS = %w[DayBuySell DaySellBuy ShortMargin ShortLend].freeze
25
+
26
+ # @since 0.1.0
27
+ # @api private
28
+ def initialize(data)
29
+ load_boolean STATES, data, prefix: 'is'
30
+ load_boolean PERMITS, data, prefix: 'can'
31
+
32
+ @name = data['nameZhTw']
33
+ @industry = data['industryZhTw']
34
+ @type = data['typeZhTw']
35
+ @price = Price.new(data)
36
+ end
37
+
38
+ # @since 0.1.0
39
+ # @api private
40
+ STATES.map(&:underscore).each do |state|
41
+ define_method("#{state}?") do
42
+ instance_variable_get("@#{state}") == true
43
+ end
44
+ end
45
+
46
+ # @since 0.1.0
47
+ # @api private
48
+ PERMITS.map(&:underscore).each do |permit|
49
+ define_method("#{permit}?") do
50
+ instance_variable_get("@#{permit}") == true
51
+ end
52
+ end
53
+
54
+ # @since 0.1.0
55
+ # @api private
56
+ class Price
57
+ # @since 0.1.0
58
+ # @api private
59
+ attr_reader :reference, :high_limit, :low_limit, :currency
60
+
61
+ # @since 0.1.0
62
+ # @api private
63
+ def initialize(data)
64
+ @reference = data['priceReference']
65
+ @high_limit = data['priceHighLimit']
66
+ @low_limit = data['priceLowLimit']
67
+ @currency = data['currency']
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'fugle/trade'
5
+
6
+ module Fugle
7
+ module Intraday
8
+ # The Intraday Quote
9
+ #
10
+ # @since 0.1.0
11
+ # @api private
12
+ class Quote
13
+ using Utils
14
+ include HTTP::API
15
+ include Utils
16
+
17
+ path 'intraday/quote'
18
+ params :symbol, require: true, alias: 'symbolId'
19
+
20
+ # @since 0.1.0
21
+ # @api private
22
+ attr_reader :total, :trial, :trade, :price, :orders
23
+
24
+ # @since 0.1.0
25
+ # @api private
26
+ STATES = %w[Curbing Trial OpenDelayed Halting Closed].freeze
27
+
28
+ # @since 0.1.0
29
+ # @api private
30
+ def initialize(data)
31
+ load_boolean STATES, data, prefix: 'is'
32
+
33
+ @total = Trade.new(data['total'])
34
+ @trial = Trade.new(data['trial'])
35
+ @trade = Trade.new(data['trade'])
36
+ @price = Price.new(data)
37
+ @order = Order.new(data['order'])
38
+ end
39
+
40
+ # @since 0.1.0
41
+ # @api private
42
+ STATES.map(&:underscore).each do |state|
43
+ define_method "#{state}?" do
44
+ instance_variable_get("@#{state}") == true
45
+ end
46
+ end
47
+
48
+ # @since 0.1.0
49
+ # @api private
50
+ class Price
51
+ # @since 0.1.0
52
+ # @api private
53
+ attr_reader :high, :low, :open
54
+
55
+ # @since 0.1.0
56
+ # @api private
57
+ def initialize(data)
58
+ @high = Trade.new(data['priceHigh'])
59
+ @low = Trade.new(data['priceLow'])
60
+ @open = Trade.new(data['priceOpen'])
61
+ end
62
+ end
63
+
64
+ # @since 0.1.0
65
+ # @api private
66
+ class Order
67
+ # @since 0.1.0
68
+ # @api private
69
+ attr_reader :update_at, :best_bids, :best_asks
70
+
71
+ # @since 0.1.0
72
+ # @api private
73
+ def initialize(data)
74
+ @update_at = DateTime.parse(data['at'])
75
+ @best_bids = data['bestBids'].map { |item| Trade.new(item) }
76
+ @best_asks = data['bestAsks'].map { |item| Trade.new(item) }
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fugle/trade'
4
+
5
+ module Fugle
6
+ module Intraday
7
+ # The Intraday Trades
8
+ #
9
+ # @since 0.1.0
10
+ # @api private
11
+ class Trades
12
+ include HTTP::API
13
+ include Enumerable
14
+
15
+ path 'intraday/trades'
16
+ params :symbol, require: true, alias: 'symbolId'
17
+
18
+ # @since 0.1.0
19
+ # @api private
20
+ def initialize(items)
21
+ @items = items.map { |item| Trade.new(item) }
22
+ end
23
+
24
+ # @since 0.1.0
25
+ # @api private
26
+ def each(&block)
27
+ @items.each(&block)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+
5
+ require 'fugle/intraday/chart'
6
+ require 'fugle/intraday/quote'
7
+ require 'fugle/intraday/trades'
8
+ require 'fugle/intraday/meta'
9
+
10
+ module Fugle
11
+ # The Intraday Module
12
+ #
13
+ # @since 0.1.0
14
+ # @api private
15
+ module Intraday
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fugle
4
+ # API Response
5
+ #
6
+ # @since 0.1.0
7
+ # @api private
8
+ class Response
9
+ # @since 0.1.0
10
+ # @api private
11
+ attr_reader :version, :info, :body
12
+
13
+ # Create a new response
14
+ #
15
+ # @param attributes [Hash] response Hash from API
16
+ #
17
+ # @since 0.1.0
18
+ # @api private
19
+ def initialize(body, attributes)
20
+ @version = attributes.fetch('apiVersion', nil)
21
+ @info = Information.new(attributes.dig('data', 'info'))
22
+ @body = body.new(attributes.dig('data', body.data_name))
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fugle
4
+ # The trade information
5
+ #
6
+ # @since 0.1.0
7
+ # @api private
8
+ class Trade
9
+ # @since 0.1.0
10
+ # @api private
11
+ attr_reader :price, :unit, :order, :volume, :serial
12
+
13
+ # @since 0.1.0
14
+ # @api private
15
+ def initialize(item)
16
+ @price = item['price']
17
+ @unit = item['unit']
18
+ @order = item['order']
19
+ @volume = item['volume']
20
+ @serial = item['serial']
21
+ @at = DateTime.parse(item['at']) if item['at']
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fugle
4
+ # Utils
5
+ #
6
+ # @since 0.1.0
7
+ # @api private
8
+ module Utils
9
+ refine String do
10
+ # Convert camel to underscore
11
+ #
12
+ # @since 0.1.0
13
+ # @api private
14
+ def underscore
15
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
16
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
17
+ .downcase
18
+ end
19
+ end
20
+
21
+ using self
22
+
23
+ private
24
+
25
+ # @since 0.1.0
26
+ # @api private
27
+ def load_boolean(attributes, data, prefix: 'is')
28
+ attributes.each do |name|
29
+ instance_variable_set(
30
+ "@#{name.underscore}",
31
+ data["#{prefix}#{name}"]
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fugle
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fugle
4
+ # The WebSocket Client
5
+ #
6
+ # @since 0.1.0
7
+ # @api private
8
+ module WebSocket
9
+ # NOTE: Unsupport for this version
10
+ end
11
+ end
data/lib/fugle.rb ADDED
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fugle/version'
4
+ require 'fugle/utils'
5
+ require 'fugle/config'
6
+ require 'fugle/http'
7
+ require 'fugle/intraday'
8
+ require 'fugle/response'
9
+ require 'fugle/information'
10
+
11
+ # The Fugle.tw API Client
12
+ #
13
+ # @api private
14
+ module Fugle
15
+ class Error < StandardError; end
16
+
17
+ # @since 0.1.0
18
+ # @api private
19
+ LOCK = Mutex.new
20
+
21
+ # The Fugle Config
22
+ #
23
+ # @param block [Proc] the configure block
24
+ #
25
+ # @return [Fugle::Config] the config
26
+ #
27
+ # @since 0.1.0
28
+ # @api private
29
+ def self.config(&block)
30
+ @config ||= Config.new
31
+ @config.instance_eval(&block) if block_given?
32
+ @config
33
+ end
34
+
35
+ # Temporary change config
36
+ #
37
+ # @param config [Fugle::Config] the config object
38
+ # @param block [Proc] the temporary working block
39
+ #
40
+ # @since 0.1.0
41
+ # @api private
42
+ def self.use(config, &_block)
43
+ LOCK.synchronize do
44
+ temp = Fugle.config
45
+ @config = config
46
+ res = yield
47
+ @config = temp
48
+ res
49
+ end
50
+ end
51
+
52
+ # @since 0.1.0
53
+ # @api private
54
+ def self.http
55
+ HTTP::Client.new
56
+ end
57
+
58
+ # @since 0.1.0
59
+ # @api private
60
+ def self.intraday
61
+ http.intraday
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fugle
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - 蒼時弦也
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler-audit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: overcommit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.51.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.51.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.76.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.76.0
97
+ description: The Fugle.tw API Client
98
+ email:
99
+ - elct9620@frost.tw
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".overcommit.yml"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - fugle.gemspec
116
+ - lib/fugle.rb
117
+ - lib/fugle/config.rb
118
+ - lib/fugle/http.rb
119
+ - lib/fugle/http/api.rb
120
+ - lib/fugle/http/client.rb
121
+ - lib/fugle/http/parameters.rb
122
+ - lib/fugle/http/query.rb
123
+ - lib/fugle/information.rb
124
+ - lib/fugle/intraday.rb
125
+ - lib/fugle/intraday/chart.rb
126
+ - lib/fugle/intraday/meta.rb
127
+ - lib/fugle/intraday/quote.rb
128
+ - lib/fugle/intraday/trades.rb
129
+ - lib/fugle/response.rb
130
+ - lib/fugle/trade.rb
131
+ - lib/fugle/utils.rb
132
+ - lib/fugle/version.rb
133
+ - lib/fugle/websocket.rb
134
+ homepage: https://github.com/elct9620/fugle-api
135
+ licenses: []
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubygems_version: 3.0.3
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: The Fugle.tw API Client
156
+ test_files: []