kitco 0.0.5 → 0.0.6
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 +7 -0
- data/README.md +12 -12
- data/bin/kitco +19 -18
- data/lib/kitco.rb +11 -11
- metadata +15 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fdaabbfe22e8a4b0163b89406d407904522d2457
|
4
|
+
data.tar.gz: 5d6ca9252975f3a6885426aedbb43cc1544072dd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1bf922061043c2be413fd6bd23e70a2ddac5c953ac50ca9a4faf3a531558563b068763fe25241be0fab5a6e69f78151da56066d47b64c8a8c0b353b28e56a5c1
|
7
|
+
data.tar.gz: 59a28d8791fb347313acca6eb0f3cd6076992efb67bc81e0d486bd6e8dc45fd2b30ef7977655f4d6d6abeda6e0f880af5579f2baf5f9ec12a47be03b25f67786
|
data/README.md
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
Kitco Gem
|
2
|
-
|
1
|
+
# Kitco Gem
|
2
|
+
|
3
3
|
|
4
4
|
This gem retrieves data (via HTTParty) from Kitco Charts about Gold and other precious metals.
|
5
5
|
|
6
6
|
Use at your own discretion
|
7
7
|
|
8
|
-
Install
|
9
|
-
|
10
|
-
|
8
|
+
## Install
|
9
|
+
|
10
|
+
gem install kitco
|
11
|
+
|
12
|
+
|
13
|
+
## Examples
|
11
14
|
|
15
|
+
require 'kitco'
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
require 'kitco'
|
17
|
+
puts Kitco.gold
|
18
|
+
puts Kitco.silver
|
16
19
|
|
17
|
-
|
18
|
-
puts Kitco.silver
|
20
|
+
## Command Line Utility
|
19
21
|
|
20
|
-
Command Line Utility
|
21
|
-
--------------------
|
22
22
|
|
23
23
|
kitco gold
|
24
24
|
|
data/bin/kitco
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'optparse'
|
3
|
-
require 'kitco'
|
3
|
+
#require 'kitco'
|
4
|
+
require File.expand_path('../../lib/kitco', __FILE__)
|
4
5
|
|
5
6
|
options = { :color => true }
|
6
7
|
symbols = [:gold, :silver, :palladium, :rhodium]
|
7
8
|
|
8
9
|
optparse = OptionParser.new do |opts|
|
9
|
-
opts.banner
|
10
|
-
opts.banner << "
|
11
|
-
|
10
|
+
opts.banner = "usage: kitco [options] [symbol]\n\n"
|
11
|
+
opts.banner << "symbols (case-insensitive):\n#{ symbols.collect { |s| s.upcase }.join(' ') }\n\n\options:"
|
12
|
+
|
12
13
|
opts.on '-h', '--help', 'Display this message' do |arg|
|
13
14
|
options[:help] = arg
|
14
|
-
|
15
|
-
|
15
|
+
end
|
16
|
+
|
16
17
|
opts.on '-c', '--no-color', 'No color in output' do |arg|
|
17
18
|
options[:color] = arg
|
18
19
|
end
|
@@ -28,20 +29,20 @@ exit(1) unless symbols.include? symbol
|
|
28
29
|
|
29
30
|
if Kitco.public_methods.include? symbol
|
30
31
|
begin
|
31
|
-
|
32
|
+
body = Kitco.send(symbol).parsed_response
|
33
|
+
|
34
|
+
puts "Results for #{symbol.upcase} (#{body[:time].strftime('%H:%M %m/%d/%y')})"
|
35
|
+
puts "High #{body[:high]}\tLow #{body[:low]}"
|
36
|
+
puts "Bid #{body[:bid]}\tAsk #{body[:ask]}"
|
32
37
|
|
33
|
-
puts "Results for #{symbol.upcase} (#{body[:time].strftime('%H:%M %m/%d/%y')})"
|
34
|
-
puts "High #{body[:high]}\tLow #{body[:low]}"
|
35
|
-
puts "Bid #{body[:bid]}\tAsk #{body[:ask]}"
|
36
|
-
|
37
38
|
change = "#{body[:change]} (#{(body[:percentage] * 100.0).round(4)}%)"
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
if options[:color]
|
40
|
+
puts "Change: \e[#{body[:change] >= 0 ? '32m+' : '31m'}#{change}\e[0m"
|
41
|
+
else
|
42
|
+
puts "Change: #{change}"
|
43
|
+
end
|
44
|
+
|
44
45
|
rescue Exception => e
|
45
46
|
puts "Failure: #{e}"
|
46
47
|
end
|
47
|
-
end
|
48
|
+
end
|
data/lib/kitco.rb
CHANGED
@@ -9,38 +9,38 @@ class Kitco
|
|
9
9
|
parser lambda { |body, format|
|
10
10
|
# they don't send an XML content-type if its a bad request
|
11
11
|
return Crack::XML.parse(body) if body.include?('xml')
|
12
|
-
|
12
|
+
|
13
13
|
results = {}
|
14
14
|
data = Base64.decode64(body).split(',')
|
15
15
|
|
16
16
|
results[:time] = Time.parse data.shift
|
17
17
|
results[:percentage] = data.pop.to_f / 100.0
|
18
|
-
|
18
|
+
|
19
19
|
data.collect! { |n| n.to_f }
|
20
20
|
results.merge! Hash[ [:bid, :ask, :change, :low, :high].zip(data) ]
|
21
21
|
}
|
22
|
-
|
23
|
-
def self.gold
|
22
|
+
|
23
|
+
def self.gold
|
24
24
|
request :gold
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def self.silver
|
28
28
|
request :silver
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def self.palladium
|
32
32
|
request :palladium
|
33
|
-
end
|
34
|
-
|
33
|
+
end
|
34
|
+
|
35
35
|
def self.rhodium
|
36
36
|
request :rhodium
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
class << self
|
40
40
|
def request symbol
|
41
|
-
get '/RequestHandler', :query => {:requestName => 'getSymbolSnapshot', :Symbol => symbol.upcase }
|
41
|
+
get '/RequestHandler', :query => {:requestName => 'getSymbolSnapshot', :Symbol => symbol.to_s.upcase }
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
protected :request
|
45
45
|
end
|
46
46
|
end
|
metadata
CHANGED
@@ -1,28 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- mikeycgto
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
11
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
14
12
|
dependencies:
|
15
13
|
- !ruby/object:Gem::Dependency
|
16
14
|
name: httparty
|
17
|
-
requirement:
|
18
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
19
16
|
requirements:
|
20
|
-
- -
|
17
|
+
- - '>='
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: 0.7.8
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.8
|
26
27
|
description: An API for accessing data from Kitco Charts. Also includes a command
|
27
28
|
line utility
|
28
29
|
email: mikeycgto@gmail.com
|
@@ -34,30 +35,29 @@ files:
|
|
34
35
|
- README.md
|
35
36
|
- lib/kitco.rb
|
36
37
|
- bin/kitco
|
37
|
-
has_rdoc: true
|
38
38
|
homepage: https://github.com/mikeycgto/kitco
|
39
39
|
licenses: []
|
40
|
+
metadata: {}
|
40
41
|
post_install_message:
|
41
42
|
rdoc_options: []
|
42
43
|
require_paths:
|
43
44
|
- lib
|
44
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - '>='
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
-
none: false
|
52
51
|
requirements:
|
53
|
-
- -
|
52
|
+
- - '>='
|
54
53
|
- !ruby/object:Gem::Version
|
55
54
|
version: '0'
|
56
55
|
requirements: []
|
57
56
|
rubyforge_project:
|
58
|
-
rubygems_version:
|
57
|
+
rubygems_version: 2.0.3
|
59
58
|
signing_key:
|
60
|
-
specification_version:
|
59
|
+
specification_version: 4
|
61
60
|
summary: An API for accessing data from Kitco Charts. Also includes a command line
|
62
61
|
utility!
|
63
62
|
test_files: []
|
63
|
+
has_rdoc: false
|