mixtli-mixtli-fred 0.1.5
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.
- data/.gitignore +2 -0
- data/Manifest +7 -0
- data/README.rdoc +0 -0
- data/Rakefile +23 -0
- data/VERSION +1 -0
- data/github-test.rb +22 -0
- data/init.rb +1 -0
- data/lib/fred.rb +108 -0
- data/mixtli-fred.gemspec +41 -0
- metadata +61 -0
data/.gitignore
ADDED
data/Manifest
ADDED
data/README.rdoc
ADDED
|
File without changes
|
data/Rakefile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Rakefile
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'rake'
|
|
4
|
+
#require 'echoe'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
begin
|
|
11
|
+
require 'jeweler'
|
|
12
|
+
Jeweler::Tasks.new do |gemspec|
|
|
13
|
+
gemspec.name = "mixtli-fred"
|
|
14
|
+
gemspec.summary = "Federal Reserve API"
|
|
15
|
+
gemspec.email = "mixtli@github.com"
|
|
16
|
+
gemspec.homepage = "http://github.com/mixtli/fred"
|
|
17
|
+
gemspec.description = "Federal Reserve API"
|
|
18
|
+
gemspec.authors = ["Ron McClain"]
|
|
19
|
+
end
|
|
20
|
+
rescue LoadError
|
|
21
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
|
22
|
+
end
|
|
23
|
+
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.5
|
data/github-test.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
if ARGV.size < 1
|
|
5
|
+
puts "Usage: github-test.rb my-project.gemspec"
|
|
6
|
+
exit
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
require 'rubygems/specification'
|
|
10
|
+
data = File.read(ARGV[0])
|
|
11
|
+
spec = nil
|
|
12
|
+
|
|
13
|
+
if data !~ %r{!ruby/object:Gem::Specification}
|
|
14
|
+
Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
|
|
15
|
+
else
|
|
16
|
+
spec = YAML.load(data)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
spec.validate
|
|
20
|
+
|
|
21
|
+
puts spec
|
|
22
|
+
puts "OK"
|
data/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "fred"
|
data/lib/fred.rb
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
require 'hpricot'
|
|
4
|
+
require 'activeresource'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module Fred
|
|
8
|
+
class Base
|
|
9
|
+
cattr_accessor :api_key
|
|
10
|
+
class_inheritable_accessor :base_url, :primary_key, :collection_path, :element_path
|
|
11
|
+
attr_reader :attributes
|
|
12
|
+
self.base_url = "http://api.stlouisfed.org/fred"
|
|
13
|
+
|
|
14
|
+
def initialize(attrs)
|
|
15
|
+
@attributes = attrs
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.get(id)
|
|
19
|
+
uri = base_url + "/#{element_path}?api_key=#{api_key}&#{primary_key}=#{id}"
|
|
20
|
+
RAILS_DEFAULT_LOGGER.debug uri
|
|
21
|
+
doc = Hpricot.XML(open(uri))
|
|
22
|
+
new(doc.search("/*/*")[1].attributes)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.find(params = {})
|
|
26
|
+
results = []
|
|
27
|
+
uri = base_url + "/" + collection_path + "?" + encode_params(params)
|
|
28
|
+
puts uri
|
|
29
|
+
doc = Hpricot.XML(open(uri))
|
|
30
|
+
doc.search("/*/*").each do |el|
|
|
31
|
+
results << new(el.attributes) if el.respond_to?(:attributes)
|
|
32
|
+
end
|
|
33
|
+
results
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.encode_params(args)
|
|
37
|
+
args['api_key'] ||= api_key
|
|
38
|
+
args.map { |k,v| "%s=%s" % [URI.encode(k.to_s), URI.encode(v.to_s)] }.join('&') unless args.blank?
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Category < Base
|
|
43
|
+
self.collection_path = "category"
|
|
44
|
+
self.element_path = "category"
|
|
45
|
+
self.primary_key = "category_id"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
class Release < Base
|
|
49
|
+
self.collection_path = "releases"
|
|
50
|
+
self.element_path = "release"
|
|
51
|
+
self.primary_key = "release_id"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class Series < Base
|
|
55
|
+
self.collection_path = "series/search"
|
|
56
|
+
self.element_path = "series"
|
|
57
|
+
self.primary_key = "series_id"
|
|
58
|
+
|
|
59
|
+
def observations(params = {})
|
|
60
|
+
data = []
|
|
61
|
+
puts params.inspect
|
|
62
|
+
params[:series_id] = attributes["id"]
|
|
63
|
+
uri = base_url + "/series/observations?" + self.class.encode_params(params)
|
|
64
|
+
puts "URI = " + uri
|
|
65
|
+
doc = Hpricot.XML(open(uri))
|
|
66
|
+
doc.search("/*/*").each do |el|
|
|
67
|
+
data << {:date => DateTime.parse(el.attributes['date']), :value => el.attributes['value'] } if el.respond_to?(:attributes)
|
|
68
|
+
#data << el.attributes if el.respond_to?(:attributes)
|
|
69
|
+
end
|
|
70
|
+
data
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
class Source < Base
|
|
75
|
+
self.collection_path = "sources"
|
|
76
|
+
self.element_path = "source"
|
|
77
|
+
self.primary_key = "source_id"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
#Fred::Base.api_key = "xxxxxxxxxxxxxxxxxxxx"
|
|
83
|
+
#
|
|
84
|
+
#puts "Category.get"
|
|
85
|
+
#puts Fred::Category.get(125).inspect
|
|
86
|
+
#
|
|
87
|
+
#puts "Category.find"
|
|
88
|
+
#puts Fred::Category.find.inspect
|
|
89
|
+
#
|
|
90
|
+
#puts "Release.get"
|
|
91
|
+
#puts Fred::Release.get(178).inspect
|
|
92
|
+
#
|
|
93
|
+
#puts "Release.find"
|
|
94
|
+
#puts Fred::Release.find.inspect
|
|
95
|
+
#
|
|
96
|
+
#puts "Series.find"
|
|
97
|
+
#puts Fred::Series.find(:search_text => 'money').inspect
|
|
98
|
+
#
|
|
99
|
+
#puts "Series.get"
|
|
100
|
+
#s = Fred::Series.get('M2ASL')
|
|
101
|
+
#puts s.observations.inspect
|
|
102
|
+
#
|
|
103
|
+
#
|
|
104
|
+
#puts "Source.find"
|
|
105
|
+
#puts Fred::Source.find.inspect
|
|
106
|
+
#
|
|
107
|
+
#puts "Source.get"
|
|
108
|
+
#puts Fred::Source.get(36).inspect
|
data/mixtli-fred.gemspec
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = %q{mixtli-fred}
|
|
5
|
+
s.version = "0.1.5"
|
|
6
|
+
|
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
8
|
+
s.authors = ["Ron McClain"]
|
|
9
|
+
s.date = %q{2009-06-06}
|
|
10
|
+
s.description = %q{Federal Reserve API}
|
|
11
|
+
s.email = %q{mixtli@github.com}
|
|
12
|
+
s.extra_rdoc_files = [
|
|
13
|
+
"README.rdoc"
|
|
14
|
+
]
|
|
15
|
+
s.files = [
|
|
16
|
+
".gitignore",
|
|
17
|
+
"Manifest",
|
|
18
|
+
"README.rdoc",
|
|
19
|
+
"Rakefile",
|
|
20
|
+
"VERSION",
|
|
21
|
+
"github-test.rb",
|
|
22
|
+
"init.rb",
|
|
23
|
+
"lib/fred.rb",
|
|
24
|
+
"mixtli-fred.gemspec"
|
|
25
|
+
]
|
|
26
|
+
s.homepage = %q{http://github.com/mixtli/fred}
|
|
27
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
28
|
+
s.require_paths = ["lib"]
|
|
29
|
+
s.rubygems_version = %q{1.3.3}
|
|
30
|
+
s.summary = %q{Federal Reserve API}
|
|
31
|
+
|
|
32
|
+
if s.respond_to? :specification_version then
|
|
33
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
34
|
+
s.specification_version = 3
|
|
35
|
+
|
|
36
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
37
|
+
else
|
|
38
|
+
end
|
|
39
|
+
else
|
|
40
|
+
end
|
|
41
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mixtli-mixtli-fred
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.5
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ron McClain
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-06-06 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: Federal Reserve API
|
|
17
|
+
email: mixtli@github.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README.rdoc
|
|
24
|
+
files:
|
|
25
|
+
- .gitignore
|
|
26
|
+
- Manifest
|
|
27
|
+
- README.rdoc
|
|
28
|
+
- Rakefile
|
|
29
|
+
- VERSION
|
|
30
|
+
- github-test.rb
|
|
31
|
+
- init.rb
|
|
32
|
+
- lib/fred.rb
|
|
33
|
+
- mixtli-fred.gemspec
|
|
34
|
+
has_rdoc: false
|
|
35
|
+
homepage: http://github.com/mixtli/fred
|
|
36
|
+
post_install_message:
|
|
37
|
+
rdoc_options:
|
|
38
|
+
- --charset=UTF-8
|
|
39
|
+
require_paths:
|
|
40
|
+
- lib
|
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: "0"
|
|
46
|
+
version:
|
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: "0"
|
|
52
|
+
version:
|
|
53
|
+
requirements: []
|
|
54
|
+
|
|
55
|
+
rubyforge_project:
|
|
56
|
+
rubygems_version: 1.2.0
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 3
|
|
59
|
+
summary: Federal Reserve API
|
|
60
|
+
test_files: []
|
|
61
|
+
|