fred 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Fred
2
+
3
+ This is a Ruby wrapper for the St. Louis Federal Reserve Economic Data [Fred API](http://api.stlouisfed.org/).
4
+
5
+ ## Installation
6
+
7
+ In your Rails directory:
8
+
9
+ script/plugin install git://github.com/phuphighter/fred.git
10
+
11
+ ## Get a FRED API key
12
+
13
+ Sign up for a Fred API key: [http://api.stlouisfed.org/api_key.html](http://api.stlouisfed.org/api_key.html)
14
+
15
+ ## Usage
16
+
17
+ ### Instantiate a client
18
+
19
+ >> fred = Fred::Client.new(:api_key => 'your_api_key')
20
+
21
+ ### or configure once
22
+
23
+ >> Fred.configure do |config|
24
+ >> config.api_key = 'your_api_key'
25
+ >> end
26
+ >> fred = Fred::Client.new
27
+
28
+ #### Examples
29
+
30
+ >> fred.category(nil, :category_id => '125')
31
+ => {"categories"=>{"category"=>{"name"=>"Trade Balance", "id"=>"125", "parent_id"=>"13"}}}
32
+
33
+ >> fred.series("categories", :series_id => 'EXJPUS')
34
+ => {"categories"=>{"category"=>[{"name"=>"Monthly Rates", "id"=>"95", "parent_id"=>"15"}, {"name"=>"Japan", "id"=>"275", "parent_id"=>"158"}]}}
35
+
36
+ ## Copyright
37
+
38
+ Contact me if you have any suggestions and feel free to fork it!
39
+
40
+ Copyright (c) 2009 Johnny Khai Nguyen, released under the MIT license
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ begin
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "fred"
10
+ gem.summary = %Q{Ruby wrapper for the St. Louis Federal Reserve FRED API}
11
+ gem.description = %Q{Ruby wrapper for the St. Louis Federal Reserve FRED API}
12
+ gem.email = "johnnyn@gmail.com"
13
+ gem.homepage = "http://github.com/phuphighter/fred"
14
+ gem.authors = ["Johnny Khai Nguyen"]
15
+
16
+ gem.add_dependency('httparty', '>= 0.5.0')
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
21
+ end
22
+
23
+ desc 'Default: run unit tests.'
24
+ task :default => :test
25
+
26
+ desc 'Test the fred plugin.'
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'lib'
29
+ t.libs << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = true
32
+ end
33
+
34
+ desc 'Generate documentation for the fred plugin.'
35
+ Rake::RDocTask.new(:rdoc) do |rdoc|
36
+ rdoc.rdoc_dir = 'rdoc'
37
+ rdoc.title = 'Fred'
38
+ rdoc.options << '--line-numbers' << '--inline-source'
39
+ rdoc.rdoc_files.include('README')
40
+ rdoc.rdoc_files.include('lib/**/*.rb')
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ ./script/generate fred Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,8 @@
1
+ class FredGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # m.directory "lib"
5
+ # m.template 'README', "README"
6
+ end
7
+ end
8
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ # Include hook code here
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,36 @@
1
+ # Fred
2
+ require 'rubygems'
3
+ gem 'httparty'
4
+ require 'httparty'
5
+
6
+ directory = File.expand_path(File.dirname(__FILE__))
7
+
8
+ module Fred
9
+
10
+ # create config/initializers/fred.rb
11
+ #
12
+ # Fred.configure do |config|
13
+ # config.api_key = 'api_key'
14
+ # end
15
+ # client = Fred::Client.new
16
+ #
17
+ # or
18
+ #
19
+ # Fred.api_key = 'api_key'
20
+ #
21
+ # or
22
+ #
23
+ # Fred::Client.new(:api_key => 'api_key')
24
+
25
+ def self.configure
26
+ yield self
27
+ true
28
+ end
29
+
30
+ class << self
31
+ attr_accessor :api_key
32
+ end
33
+
34
+ end
35
+
36
+ require File.join(directory, 'fred', 'client')
@@ -0,0 +1,68 @@
1
+ module Fred
2
+
3
+ class Client
4
+ include HTTParty
5
+ base_uri "http://api.stlouisfed.org/fred"
6
+
7
+ attr_reader :api_key
8
+
9
+ def initialize(options={})
10
+ @api_key = options[:api_key] || Fred.api_key
11
+ end
12
+
13
+ def category(secondary, options={})
14
+ if secondary.nil?
15
+ response = self.class.get("/category", :query => options.merge(self.default_options))
16
+ else
17
+ response = self.class.get("/category/#{secondary}", :query => options.merge(self.default_options))
18
+ end
19
+ end
20
+
21
+ def releases(secondary, options={})
22
+ if secondary.nil?
23
+ response = self.class.get("/releases", :query => options.merge(self.default_options))
24
+ else
25
+ response = self.class.get("/releases/#{secondary}", :query => options.merge(self.default_options))
26
+ end
27
+ end
28
+
29
+ def release(secondary, options={})
30
+ if secondary.nil?
31
+ response = self.class.get("/release", :query => options.merge(self.default_options))
32
+ else
33
+ response = self.class.get("/release/#{secondary}", :query => options.merge(self.default_options))
34
+ end
35
+ end
36
+
37
+ def series(secondary, options={})
38
+ if secondary.nil?
39
+ response = self.class.get("/series", :query => options.merge(self.default_options))
40
+ else
41
+ response = self.class.get("/series/#{secondary}", :query => options.merge(self.default_options))
42
+ end
43
+ end
44
+
45
+ def sources(secondary, options={})
46
+ if secondary.nil?
47
+ response = self.class.get("/sources?", :query => options.merge(self.default_options))
48
+ else
49
+ response = self.class.get("/sources/#{secondary}", :query => options.merge(self.default_options))
50
+ end
51
+ end
52
+
53
+ def source(secondary, options={})
54
+ if secondary.nil?
55
+ response = self.class.get("/source", :query => options.merge(self.default_options))
56
+ else
57
+ response = self.class.get("/source/#{secondary}", :query => options.merge(self.default_options))
58
+ end
59
+ end
60
+
61
+ protected
62
+
63
+ def default_options
64
+ {:api_key => @api_key}
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :fred do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class FredTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/test_case'
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fred
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Johnny Khai Nguyen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-16 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: httparty
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 5
30
+ - 0
31
+ version: 0.5.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Ruby wrapper for the St. Louis Federal Reserve FRED API
35
+ email: johnnyn@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - README.md
42
+ files:
43
+ - MIT-LICENSE
44
+ - README.md
45
+ - Rakefile
46
+ - VERSION
47
+ - generators/fred/USAGE
48
+ - generators/fred/fred_generator.rb
49
+ - init.rb
50
+ - install.rb
51
+ - lib/fred.rb
52
+ - lib/fred/client.rb
53
+ - tasks/fred_tasks.rake
54
+ - test/fred_test.rb
55
+ - test/test_helper.rb
56
+ - uninstall.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/phuphighter/fred
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --charset=UTF-8
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.6
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Ruby wrapper for the St. Louis Federal Reserve FRED API
87
+ test_files:
88
+ - test/fred_test.rb
89
+ - test/test_helper.rb