quotes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format nested
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in quotes.gemspec
4
+ gemspec
@@ -0,0 +1,103 @@
1
+ # Quotes
2
+
3
+ A simple and lightweight wrapper for the Yahoo stock quotes API.
4
+
5
+ ## Installation
6
+
7
+ [sudo] gem install quotes
8
+
9
+ ## Usage
10
+
11
+ quotes = Quotes.get("AAPL", "GOOG", "MSFT")
12
+ quotes["AAPL"].ask # => AAPL ask price
13
+ quotes["AAPL"].bid # => AAPL bid price
14
+ quotes["GOOG"].volume # => GOOG volume
15
+ quotes["GOOG"].dayslow # => GOOG day's low
16
+ quotes["MSFT"].dayshigh # => MSFT day's high
17
+ quotes["MSFT"].open # => MSFT opening price
18
+
19
+
20
+ #### List of quote qualities
21
+
22
+ afterhourschangerealtime
23
+ annualizedgain
24
+ ask
25
+ askrealtime
26
+ averagedailyvolume
27
+ bid
28
+ bidrealtime
29
+ bookvalue
30
+ change
31
+ change_percentchange
32
+ changefromfiftydaymovingaverage
33
+ changefromtwohundreddaymovingaverage
34
+ changefromyearhigh
35
+ changefromyearlow
36
+ changeinpercent
37
+ changepercentrealtime
38
+ changerealtime
39
+ commission
40
+ dayshigh
41
+ dayslow
42
+ daysrange
43
+ daysrangerealtime
44
+ daysvaluechange
45
+ daysvaluechangerealtime
46
+ dividendpaydate
47
+ dividendshare
48
+ dividendyield
49
+ earningsshare
50
+ ebitda
51
+ epsestimatecurrentyear
52
+ epsestimatenextquarter
53
+ epsestimatenextyear
54
+ errorindicationreturnedforsymbolchangedinvalid
55
+ exdividenddate
56
+ fiftydaymovingaverage
57
+ highlimit
58
+ holdingsgain
59
+ holdingsgainpercent
60
+ holdingsgainpercentrealtime
61
+ holdingsgainrealtime
62
+ holdingsvalue
63
+ holdingsvaluerealtime
64
+ lasttradedate
65
+ lasttradepriceonly
66
+ lasttraderealtimewithtime
67
+ lasttradetime
68
+ lasttradewithtime
69
+ lowlimit
70
+ marketcapitalization
71
+ marketcaprealtime
72
+ moreinfo
73
+ name
74
+ notes
75
+ oneyrtargetprice
76
+ open
77
+ orderbookrealtime
78
+ pegratio
79
+ peratio
80
+ peratiorealtime
81
+ percebtchangefromyearhigh
82
+ percentchange
83
+ percentchangefromfiftydaymovingaverage
84
+ percentchangefromtwohundreddaymovingaverage
85
+ percentchangefromyearlow
86
+ previousclose
87
+ pricebook
88
+ priceepsestimatecurrentyear
89
+ priceepsestimatenextyear
90
+ pricepaid
91
+ pricesales
92
+ sharesowned
93
+ shortratio
94
+ stockexchange
95
+ symbol
96
+ symbol
97
+ tickertrend
98
+ tradedate
99
+ twohundreddaymovingaverage
100
+ volume
101
+ yearhigh
102
+ yearlow
103
+ yearrange
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,50 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ module Quotes
5
+
6
+ # Yahoo API endpoint
7
+ ENDPOINT = "http://query.yahooapis.com/v1/public/yql?q="
8
+
9
+ def self.get(*symbols)
10
+ if symbols.length == 0 || symbols.include?("")
11
+ raise ArgumentError, "Enter symbol(s). Example: Quote.get(\"AAPL\")"
12
+ end
13
+
14
+ syms = symbols.map{|s| "\"#{s}\""}.join(", ")
15
+ url = ENDPOINT + URI.escape("select * from yahoo.finance.quotes where symbol in (#{syms})") + "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback="
16
+ resp = ''
17
+ open(url) do |f|
18
+ resp = f.read
19
+ end
20
+
21
+ info = JSON.parse(resp)['query']['results']['quote']
22
+
23
+ # returns a hash containing the ticker symbols as keys
24
+ if symbols.length == 1
25
+ quote = {}
26
+ quote[info['symbol']] = Quote.new(info)
27
+ return quote
28
+ else
29
+ quotes = {}
30
+ info.each_with_index do |q, i|
31
+ data = info[i]
32
+ quotes[data['symbol']] = Quote.new(data)
33
+ end
34
+ return quotes
35
+ end
36
+ end
37
+
38
+ class Quote
39
+
40
+ def initialize(data)
41
+ data.each do |k, v|
42
+ self.class.class_eval do
43
+ define_method("#{k.downcase}") { v }
44
+ end
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,3 @@
1
+ module Quotes
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "quotes/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "quotes"
7
+ s.version = Quotes::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Nizar Dhamani"]
10
+ s.email = ["nizar.dhamani@gmail.com"]
11
+ s.homepage = "https://github.com/nizardhamani/quotes"
12
+ s.summary = %q{A lightweight wrapper for the Yahoo stock quotes API.}
13
+ s.description = %q{A lightweight wrapper for the Yahoo stock quotes API.}
14
+
15
+ s.rubyforge_project = "quotes"
16
+
17
+ s.add_development_dependency('rspec', '>= 2.0.0')
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1 @@
1
+ require 'quotes'
@@ -0,0 +1,22 @@
1
+ require 'helper'
2
+
3
+ describe "Quotes" do
4
+ it "should return the AAPL quote when requested" do
5
+ q = Quotes.get("AAPL")
6
+ q["AAPL"].should_not == nil
7
+ end
8
+
9
+ it "should return a hash of 3 quotes when 3 quotes are requested" do
10
+ q = Quotes.get("AAPL", "GOOG", "MSFT")
11
+ q.size.should == 3
12
+ end
13
+
14
+ it "should raise an ArgumentError when there are no arguments" do
15
+ lambda { Quotes.get() }.should raise_error(ArgumentError)
16
+ end
17
+
18
+ it "should raise an ArgumentError if any of the quotes requested are blank" do
19
+ lambda { Quotes.get("AAPL", "", "MSFT") }.should raise_error(ArgumentError)
20
+ lambda { Quotes.get("") }.should raise_error(ArgumentError)
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quotes
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Nizar Dhamani
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-23 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 0
34
+ version: 2.0.0
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: A lightweight wrapper for the Yahoo stock quotes API.
38
+ email:
39
+ - nizar.dhamani@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - .rspec
49
+ - Gemfile
50
+ - README.mdown
51
+ - Rakefile
52
+ - lib/quotes.rb
53
+ - lib/quotes/version.rb
54
+ - quotes.gemspec
55
+ - spec/helper.rb
56
+ - spec/quotes/quotes_spec.rb
57
+ has_rdoc: true
58
+ homepage: https://github.com/nizardhamani/quotes
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project: quotes
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: A lightweight wrapper for the Yahoo stock quotes API.
91
+ test_files:
92
+ - spec/helper.rb
93
+ - spec/quotes/quotes_spec.rb