yahoofinance-symbolsuggest 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/README.md +49 -0
  6. data/Rakefile +5 -0
  7. data/doc/Gemfile.html +93 -0
  8. data/doc/Rakefile.html +90 -0
  9. data/doc/YahooFinance.html +117 -0
  10. data/doc/YahooFinance/SymbolSuggest.html +580 -0
  11. data/doc/YahooFinance/SymbolSuggest/YahooSymbolSuggest.html +239 -0
  12. data/doc/_index.html +125 -0
  13. data/doc/class_list.html +54 -0
  14. data/doc/created.rid +5 -0
  15. data/doc/css/common.css +1 -0
  16. data/doc/css/full_list.css +57 -0
  17. data/doc/css/style.css +338 -0
  18. data/doc/file.README.html +132 -0
  19. data/doc/file_list.html +56 -0
  20. data/doc/frames.html +26 -0
  21. data/doc/images/brick.png +0 -0
  22. data/doc/images/brick_link.png +0 -0
  23. data/doc/images/bug.png +0 -0
  24. data/doc/images/bullet_black.png +0 -0
  25. data/doc/images/bullet_toggle_minus.png +0 -0
  26. data/doc/images/bullet_toggle_plus.png +0 -0
  27. data/doc/images/date.png +0 -0
  28. data/doc/images/find.png +0 -0
  29. data/doc/images/loadingAnimation.gif +0 -0
  30. data/doc/images/macFFBgHack.png +0 -0
  31. data/doc/images/package.png +0 -0
  32. data/doc/images/page_green.png +0 -0
  33. data/doc/images/page_white_text.png +0 -0
  34. data/doc/images/page_white_width.png +0 -0
  35. data/doc/images/plugin.png +0 -0
  36. data/doc/images/ruby.png +0 -0
  37. data/doc/images/tag_green.png +0 -0
  38. data/doc/images/wrench.png +0 -0
  39. data/doc/images/wrench_orange.png +0 -0
  40. data/doc/images/zoom.png +0 -0
  41. data/doc/index.html +132 -0
  42. data/doc/js/app.js +219 -0
  43. data/doc/js/darkfish.js +116 -0
  44. data/doc/js/full_list.js +178 -0
  45. data/doc/js/jquery.js +4 -0
  46. data/doc/js/quicksearch.js +114 -0
  47. data/doc/js/thickbox-compressed.js +10 -0
  48. data/doc/lib/yahoofinance-symbolsuggest/version_rb.html +52 -0
  49. data/doc/lib/yahoofinance-symbolsuggest_rb.html +62 -0
  50. data/doc/method_list.html +83 -0
  51. data/doc/rdoc.css +759 -0
  52. data/doc/top-level-namespace.html +112 -0
  53. data/lib/yahoofinance-symbolsuggest.rb +99 -0
  54. data/lib/yahoofinance-symbolsuggest/version.rb +5 -0
  55. data/spec/spec_helper.rb +18 -0
  56. data/spec/yahoo_finance/symbol_suggest_spec.rb +16 -0
  57. data/yahoofinance-symbolsuggest.gemspec +22 -0
  58. metadata +132 -0
@@ -0,0 +1,112 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.8.7.3
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '';
20
+ framesUrl = "frames.html#!" + escape(window.location.href);
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="_index.html">Index</a> &raquo;
35
+
36
+
37
+ <span class="title">Top Level Namespace</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Top Level Namespace
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ </dl>
82
+ <div class="clear"></div>
83
+
84
+ <h2>Defined Under Namespace</h2>
85
+ <p class="children">
86
+
87
+
88
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="YahooFinance.html" title="YahooFinance (module)">YahooFinance</a></span>
89
+
90
+
91
+
92
+
93
+ </p>
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ </div>
104
+
105
+ <div id="footer">
106
+ Generated on Sun Feb 9 06:40:06 2014 by
107
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
+ 0.8.7.3 (ruby-2.1.0).
109
+ </div>
110
+
111
+ </body>
112
+ </html>
@@ -0,0 +1,99 @@
1
+ require 'yahoofinance-symbolsuggest/version'
2
+
3
+ # Both net/http, uri and cgi belong to the Ruby standard library.
4
+ require 'net/http'
5
+ require 'uri'
6
+ require 'cgi'
7
+
8
+ # http://flori.github.com/json
9
+ require 'json'
10
+
11
+ module YahooFinance
12
+ module SymbolSuggest
13
+ # This constant is important for two reasons:
14
+ # 1. it appears in the URL query;
15
+ # 2. it appears in the JSONP response.
16
+ #
17
+ # The URL query string is everything after the question mark. The
18
+ # undocumented non-public interface to Yahoo's symbol-suggest
19
+ # auto-completion services requires two query fields: query and callback,
20
+ # where “query” specifies the symbol on which to base the suggestions,
21
+ # and where “callback” specifies the JavaScript callback function. But
22
+ # note, this callback function cannot have just any name for the Yahoo
23
+ # service to accept the request. It must match this string.
24
+ CALLBACK = 'YAHOO.Finance.SymbolSuggest.ssCallback'
25
+
26
+ # Answers an URL given a ticker symbol or company name; Yahoo Finance
27
+ # matches both simultaneously. Send an HTTP GET request to this URL and
28
+ # Yahoo will reply with a padded JSON response containing some useful
29
+ # suggestions for matching companies. Use suggestions_from_jsonp to decode the
30
+ # response.
31
+ def self.url_from_symbol(symbol)
32
+ # Escape the query string using CGI rather than URI because URI fails to
33
+ # encode ampersands.
34
+ URI.parse("http://d.yimg.com/aq/autoc?query=#{CGI.escape(symbol)}&callback=#{CALLBACK}")
35
+ end
36
+
37
+ # Parses JSONP and extracts the encoded set of results. Answers a hash
38
+ # comprising two keys: +Query+ and +Result+. The +Query+ value is the
39
+ # original query string. The +Result+ value is an array of hashes, the
40
+ # results proper. Each hash has keys describing the symbol suggestion,
41
+ # including +symbol+ for the ticker symbol, +name+ for the name of the
42
+ # company, etc. See query method.
43
+ def self.results_from_jsonp(jsonp)
44
+ # The answer from the GET request to Yahoo Finance's symbol-suggest
45
+ # service is a piece of JSONP: JSON with padding, where the padding is the
46
+ # callback function. The following padding parser utilises Ruby 1.9 String
47
+ # methods. Is that a good thing? It makes the implementation dependent on
48
+ # 1.9.
49
+ prefix = CALLBACK + '('
50
+ suffix = ')'
51
+ if jsonp.start_with?(prefix) && jsonp.end_with?(suffix)
52
+ JSON.parse(jsonp[prefix.length, jsonp.length - prefix.length - suffix.length])['ResultSet']
53
+ else
54
+ nil
55
+ end
56
+ end
57
+
58
+ # Answers an array of hashes representing symbol suggestions given a set of
59
+ # results; in other words, discards the +Query+ key. The results argument
60
+ # typically comes from the results_from_jsonp method.
61
+ def self.suggestions_from_results(results)
62
+ results['Result']
63
+ end
64
+
65
+ # Answers an array of symbol suggestions given some JSONP sent by the Yahoo
66
+ # Finance symbol-suggestion service.
67
+ def self.suggestions_from_jsonp(jsonp)
68
+ suggestions_from_results(results_from_jsonp(jsonp))
69
+ end
70
+
71
+ # Queries the given ticker symbol or company name against Yahoo Finance's
72
+ # symbol suggest web service. Answers an array of prioritised suggestions in
73
+ # the form of hashes where each hash has the following keys.
74
+ #
75
+ # [exch] symbol of the exchange, e.g. NYQ for NYSE
76
+ # [exchDisp] display name for the exchange, e.g. “NYSE”
77
+ # [name] name of the company
78
+ # [symbol] ticker symbol
79
+ # [type] type of stock, e.g. S for “Equity”
80
+ # [typeDisp] display type for stock
81
+ #
82
+ # == Design Notes
83
+ #
84
+ # The design uses a module-scoped method to wrap the GET request sent to
85
+ # Yahoo Finance, though this may need refactoring at some point in the
86
+ # future. The +query+ method handles the query synchronously, meaning that
87
+ # the caller waits for the response. Future implementations may abstract
88
+ # away the response handling as well as the request handling, in order to
89
+ # support other caller-callee paradigms, including asynchronous ones.
90
+ #
91
+ # To facilitate alternative approaches, including asynchronous loading, the
92
+ # design refactors URL-from-symbol and suggestions-from-JSONP behaviour as
93
+ # separate module methods. Hence +query+ is just a convenience method that
94
+ # sends a synchronous HTTP GET request using the Ruby standard library.
95
+ def self.query(symbol)
96
+ suggestions_from_jsonp(Net::HTTP.get(url_from_symbol(symbol)))
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,5 @@
1
+ module YahooFinance
2
+ module SymbolSuggest
3
+ VERSION = '0.1.0' # :nodoc:
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ require 'yahoofinance-symbolsuggest'
6
+
7
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ class Array
4
+ def has_all_of?(klass)
5
+ all? { |element| klass === element }
6
+ end
7
+ end
8
+
9
+ describe YahooFinance::SymbolSuggest do
10
+ it 'queries AAPL' do
11
+ suggestions = YahooFinance::SymbolSuggest.query("aapl")
12
+ expect(suggestions).to be_an(Array)
13
+ expect(suggestions).not_to be_empty
14
+ expect(suggestions).to have_all_of(Hash)
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'yahoofinance-symbolsuggest/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'yahoofinance-symbolsuggest'
7
+ s.version = YahooFinance::SymbolSuggest::VERSION
8
+ s.authors = ['Roy Ratcliffe']
9
+ s.email = ['roy@pioneeringsoftware.co.uk']
10
+ s.homepage = ''
11
+ s.summary = %q{Sends a Symbol Suggest request to Yahoo Finance web services}
12
+ s.description = %q{Wraps a very straightforward piece of functionality: sending a HTTP GET request to Yahoo Finance web service, answering a prioritised array of stock symbol suggestions.}
13
+
14
+ s.rubyforge_project = 'yahoofinance-symbolsuggest'
15
+ s.add_runtime_dependency 'json'
16
+ s.add_development_dependency 'rspec'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ['lib']
22
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yahoofinance-symbolsuggest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roy Ratcliffe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: 'Wraps a very straightforward piece of functionality: sending a HTTP
42
+ GET request to Yahoo Finance web service, answering a prioritised array of stock
43
+ symbol suggestions.'
44
+ email:
45
+ - roy@pioneeringsoftware.co.uk
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".rspec"
52
+ - Gemfile
53
+ - README.md
54
+ - Rakefile
55
+ - doc/Gemfile.html
56
+ - doc/Rakefile.html
57
+ - doc/YahooFinance.html
58
+ - doc/YahooFinance/SymbolSuggest.html
59
+ - doc/YahooFinance/SymbolSuggest/YahooSymbolSuggest.html
60
+ - doc/_index.html
61
+ - doc/class_list.html
62
+ - doc/created.rid
63
+ - doc/css/common.css
64
+ - doc/css/full_list.css
65
+ - doc/css/style.css
66
+ - doc/file.README.html
67
+ - doc/file_list.html
68
+ - doc/frames.html
69
+ - doc/images/brick.png
70
+ - doc/images/brick_link.png
71
+ - doc/images/bug.png
72
+ - doc/images/bullet_black.png
73
+ - doc/images/bullet_toggle_minus.png
74
+ - doc/images/bullet_toggle_plus.png
75
+ - doc/images/date.png
76
+ - doc/images/find.png
77
+ - doc/images/loadingAnimation.gif
78
+ - doc/images/macFFBgHack.png
79
+ - doc/images/package.png
80
+ - doc/images/page_green.png
81
+ - doc/images/page_white_text.png
82
+ - doc/images/page_white_width.png
83
+ - doc/images/plugin.png
84
+ - doc/images/ruby.png
85
+ - doc/images/tag_green.png
86
+ - doc/images/wrench.png
87
+ - doc/images/wrench_orange.png
88
+ - doc/images/zoom.png
89
+ - doc/index.html
90
+ - doc/js/app.js
91
+ - doc/js/darkfish.js
92
+ - doc/js/full_list.js
93
+ - doc/js/jquery.js
94
+ - doc/js/quicksearch.js
95
+ - doc/js/thickbox-compressed.js
96
+ - doc/lib/yahoofinance-symbolsuggest/version_rb.html
97
+ - doc/lib/yahoofinance-symbolsuggest_rb.html
98
+ - doc/method_list.html
99
+ - doc/rdoc.css
100
+ - doc/top-level-namespace.html
101
+ - lib/yahoofinance-symbolsuggest.rb
102
+ - lib/yahoofinance-symbolsuggest/version.rb
103
+ - spec/spec_helper.rb
104
+ - spec/yahoo_finance/symbol_suggest_spec.rb
105
+ - yahoofinance-symbolsuggest.gemspec
106
+ homepage: ''
107
+ licenses: []
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project: yahoofinance-symbolsuggest
125
+ rubygems_version: 2.2.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Sends a Symbol Suggest request to Yahoo Finance web services
129
+ test_files:
130
+ - spec/spec_helper.rb
131
+ - spec/yahoo_finance/symbol_suggest_spec.rb
132
+ has_rdoc: