fredapi 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +6 -0
  5. data/LICENCE.md +20 -0
  6. data/README.md +0 -0
  7. data/bin/fredapi +2 -0
  8. data/fredapi.gemspec +26 -0
  9. data/lib/faraday/utils/utils.rb +24 -0
  10. data/lib/fredapi.rb +29 -0
  11. data/lib/fredapi/client.rb +41 -0
  12. data/lib/fredapi/client/category.rb +31 -0
  13. data/lib/fredapi/client/category/children.rb +23 -0
  14. data/lib/fredapi/client/category/related.rb +23 -0
  15. data/lib/fredapi/client/category/related_tags.rb +30 -0
  16. data/lib/fredapi/client/category/series.rb +30 -0
  17. data/lib/fredapi/client/category/tags.rb +30 -0
  18. data/lib/fredapi/client/related_tags.rb +27 -0
  19. data/lib/fredapi/client/release.rb +33 -0
  20. data/lib/fredapi/client/release/dates.rb +28 -0
  21. data/lib/fredapi/client/release/related_tags.rb +30 -0
  22. data/lib/fredapi/client/release/series.rb +30 -0
  23. data/lib/fredapi/client/release/sources.rb +23 -0
  24. data/lib/fredapi/client/release/tags.rb +30 -0
  25. data/lib/fredapi/client/releases.rb +29 -0
  26. data/lib/fredapi/client/releases/dates.rb +27 -0
  27. data/lib/fredapi/client/series.rb +37 -0
  28. data/lib/fredapi/client/series/categories.rb +23 -0
  29. data/lib/fredapi/client/series/observations.rb +33 -0
  30. data/lib/fredapi/client/series/release.rb +23 -0
  31. data/lib/fredapi/client/series/search.rb +38 -0
  32. data/lib/fredapi/client/series/search/related_tags.rb +32 -0
  33. data/lib/fredapi/client/series/search/tags.rb +32 -0
  34. data/lib/fredapi/client/series/tags.rb +25 -0
  35. data/lib/fredapi/client/series/updates.rb +26 -0
  36. data/lib/fredapi/client/series/vintage_dates.rb +27 -0
  37. data/lib/fredapi/client/source.rb +25 -0
  38. data/lib/fredapi/client/source/releases.rb +27 -0
  39. data/lib/fredapi/client/sources.rb +24 -0
  40. data/lib/fredapi/client/tags.rb +31 -0
  41. data/lib/fredapi/client/tags/series.rb +27 -0
  42. data/lib/fredapi/configuration.rb +45 -0
  43. data/lib/fredapi/connection.rb +32 -0
  44. data/lib/fredapi/request.rb +98 -0
  45. data/lib/fredapi/version.rb +3 -0
  46. data/spec/fredapi_spec.rb +23 -0
  47. data/spec/helper.rb +12 -0
  48. metadata +163 -0
@@ -0,0 +1,27 @@
1
+ module FREDAPI
2
+ class Client
3
+ module Series
4
+ # VintageDates module for fred/series/vintagedates endpoint
5
+ module VintageDates
6
+
7
+ # Get the dates in history when a series' data values
8
+ # were revised or new data values were released
9
+ #
10
+ # @param opts [Hash] options hash of parameters
11
+ # @option opts [Integer] api_key 32 character alpha-numeric lowercase string
12
+ # @option opts [String] file_type A key or file extension that indicates the type of file to send
13
+ # @option opts [Integer] series_id The id for a series
14
+ # @option opts [String] realtime_start The start of the real-time period
15
+ # @option opts [String] realtime_end The end of the real-time period
16
+ # @option opts [Integer] limit The maximum number of results to return
17
+ # @option opts [Integer] offset Non-negative integer
18
+ # @option opts [String] sort_order Sort results is ascending or descending order for attribute values specified by order_by
19
+ # @return [Hashie::Mash] Hash containing the results
20
+ def series_vintage_dates opts={}
21
+ get "fred/series/vintagedates", opts
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ require 'fredapi/client/source/releases'
2
+
3
+ module FREDAPI
4
+ class Client
5
+ # Source module for fred/source endpoint
6
+ module Source
7
+
8
+ # Get a source of economic data
9
+ #
10
+ # @param opts [Hash] options hash of parameters
11
+ # @option opts [Integer] api_key 32 character alpha-numeric lowercase string
12
+ # @option opts [String] file_type A key or file extension that indicates the type of file to send
13
+ # @option opts [Integer] source_id The id for a source
14
+ # @option opts [String] realtime_start The start of the real-time period
15
+ # @option opts [String] realtime_end The end of the real-time period
16
+ # @return [Hashie::Mash] Hash containing the results
17
+ def source opts={}
18
+ get "fred/source", opts
19
+ end
20
+
21
+ include FREDAPI::Client::Source::Releases
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ module FREDAPI
2
+ class Client
3
+ module Source
4
+ # Releases module for fred/source/releases endpoint
5
+ module Releases
6
+
7
+ # Get the releases for a source
8
+ #
9
+ # @param opts [Hash] options hash of parameters
10
+ # @option opts [Integer] api_key 32 character alpha-numeric lowercase string
11
+ # @option opts [String] file_type A key or file extension that indicates the type
12
+ # @option opts [Integer] source_id The id for a source
13
+ # @option opts [String] realtime_start The start of the real-time period
14
+ # @option opts [String] realtime_end The end of the real-time period
15
+ # @option opts [Integer] limit The maximum number of results to return
16
+ # @option opts [Integer] offset Non-negative integer
17
+ # @option opts [String] order_by Order results by values of the specified attribute
18
+ # @option opts [String] sort_order Sort results is ascending or descending order for attribute values specified by order_by
19
+ # @return [Hashie::Mash] Hash containing the results
20
+ def source_releases opts={}
21
+ get "fred/source/releases", opts
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ module FREDAPI
2
+ class Client
3
+ # Sources module for fred/sources endpoint
4
+ module Sources
5
+
6
+ # Get all sources of economic data
7
+ #
8
+ # @param opts [Hash] options hash of parameters
9
+ # @option opts [Integer] api_key 32 character alpha-numeric lowercase string
10
+ # @option opts [String] file_type A key or file extension that indicates the type of file to send
11
+ # @option opts [String] realtime_start The start of the real-time period
12
+ # @option opts [String] realtime_end The end of the real-time period
13
+ # @option opts [Integer] limit The maximum number of results to return
14
+ # @option opts [Integer] offset Non-negative integer
15
+ # @option opts [String] order_by Order results by values of the specified attribute
16
+ # @option opts [String] sort_order Sort results is ascending or descending order for attribute values specified by order_by
17
+ # @return [Hashie::Mash] Hash containing the results
18
+ def sources opts={}
19
+ get "fred/sources", opts
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ require 'fredapi/client/tags/series'
2
+
3
+ module FREDAPI
4
+ class Client
5
+ # Tags module for fred/tags endpoint
6
+ module Tags
7
+
8
+ # Get all tags, search for tags, or get tags by name
9
+ #
10
+ # @param opts [Hash] options hash of parameters
11
+ # @option opts [Integer] api_key 32 character alpha-numeric lowercase string
12
+ # @option opts [String] file_type A key or file extension that indicates the type of file to send
13
+ # @option opts [String] realtime_start The start of the real-time period
14
+ # @option opts [String] realtime_end The end of the real-time period
15
+ # @option opts [String] tag_group_id A tag group id to filter tags by type
16
+ # @option opts [String] tag_names A semicolon delimited list of tags to find related tags for
17
+ # @option opts [String] search_text The words to find matching tags with
18
+ # @option opts [Integer] limit The maximum number of results to return
19
+ # @option opts [Integer] offset Non-negative integer
20
+ # @option opts [String] order_by Order results by values of the specified attribute
21
+ # @option opts [String] sort_order Sort results is ascending or descending order for attribute values specified by order_by
22
+ # @return [Hashie::Mash] Hash containing the results
23
+ def tags opts={}
24
+ get "fred/tags", opts
25
+ end
26
+
27
+ include FREDAPI::Client::Tags::Series
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ module FREDAPI
2
+ class Client
3
+ module Tags
4
+ # Series module for fred/tags/series endpoint
5
+ module Series
6
+
7
+ # Get the series matching tags
8
+ #
9
+ # @param opts [Hash] options hash of parameters
10
+ # @option opts [Integer] api_key 32 character alpha-numeric lowercase string
11
+ # @option opts [String] file_type A key or file extension that indicates the type
12
+ # @option opts [String] tag_names A semicolon delimited list of tags to find related tags for
13
+ # @option opts [String] realtime_start The start of the real-time period
14
+ # @option opts [String] realtime_end The end of the real-time period
15
+ # @option opts [Integer] limit The maximum number of results to return
16
+ # @option opts [Integer] offset Non-negative integer
17
+ # @option opts [String] order_by Order results by values of the specified attribute
18
+ # @option opts [String] sort_order Sort results is ascending or descending order for attribute values specified by order_by
19
+ # @return [Hashie::Mash] Hash containing the results
20
+ def tags_series opts={}
21
+ get "fred/tags/series", opts
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ require 'faraday'
2
+
3
+ module FREDAPI
4
+ # Configuration module to set default and custom client credentials
5
+ module Configuration
6
+
7
+ OPTION_KEYS = [
8
+ 'adapter',
9
+ 'api_endpoint',
10
+ 'user_agent',
11
+ 'api_key',
12
+ 'file_type'
13
+ ].freeze
14
+
15
+ DEFAULT_ADAPTER = Faraday.default_adapter
16
+ DEFAULT_API_ENDPOINT = 'http://api.stlouisfed.org/'
17
+ DEFAULT_USER_AGENT = "FREDAPI Ruby Gem #{FREDAPI::VERSION}".freeze
18
+ DEFAULT_FILE_TYPE = 'json'
19
+
20
+ attr_accessor *OPTION_KEYS
21
+
22
+ # Extend hook
23
+ def self.extended(base)
24
+ base.reset
25
+ end
26
+
27
+ # Set configuration options using a block
28
+ def configure
29
+ yield self
30
+ end
31
+
32
+ # Convert option_keys to hash and return
33
+ def options
34
+ OPTION_KEYS.inject({}){|o,k|o.merge!(k => send(k))}
35
+ end
36
+
37
+ # Reset the configuration options
38
+ def reset
39
+ self.adapter = DEFAULT_ADAPTER
40
+ self.user_agent = DEFAULT_USER_AGENT
41
+ self.api_endpoint = DEFAULT_API_ENDPOINT
42
+ self.file_type = DEFAULT_FILE_TYPE
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,32 @@
1
+ require 'faraday_middleware'
2
+ require 'faraday/utils/utils'
3
+
4
+ module FREDAPI
5
+ # Connection module to handle requests
6
+ module Connection
7
+ private
8
+
9
+ # Create a connection to send request
10
+ def connection opts={}
11
+ connection = Faraday.new(opts) do |conn|
12
+
13
+ if opts[:force_urlencoded]
14
+ conn.request :url_encoded
15
+ else
16
+ conn.request :json
17
+ end
18
+
19
+ conn.request :json
20
+ conn.use FaradayMiddleware::FollowRedirects
21
+ conn.use FaradayMiddleware::Mashify
22
+ conn.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
23
+ conn.use FaradayMiddleware::ParseXml, :content_type => /\bxml$/
24
+ conn.adapter adapter
25
+ end
26
+
27
+ connection.headers[:user_agent] = user_agent
28
+ connection
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,98 @@
1
+ require 'multi_json'
2
+
3
+ module FREDAPI
4
+ # Request module to handle all requests to API
5
+ module Request
6
+
7
+ # Perform a get request
8
+ #
9
+ # @param path [String] URL path to send request
10
+ # @param opts [Hash] Request parameters
11
+ # @return [Hashie::Mash] Response body
12
+ def get path, opts={}
13
+ request(:get, path, opts).body
14
+ end
15
+
16
+ # Perform a delete request
17
+ #
18
+ # @param path [String] URL path to send request
19
+ # @param opts [Hash] Request parameters
20
+ # @return [Hashie::Mash] Response body
21
+ def delete path, opts={}
22
+ request(:delete, path, opts).body
23
+ end
24
+
25
+ # Perform a post request
26
+ #
27
+ # @param path [String] URL path to send request
28
+ # @param opts [Hash] Request parameters
29
+ # @return [Hashie::Mash] Response body
30
+ def post path, opts={}
31
+ request(:post, path, opts).body
32
+ end
33
+
34
+ # Perform a put request
35
+ #
36
+ # @param path [String] URL path to send request
37
+ # @param opts [Hash] Request parameters
38
+ # @return [Hashie::Mash] Response body
39
+ def put path, opts={}
40
+ request(:put, path, opts).body
41
+ end
42
+
43
+ # Perform a patch request
44
+ #
45
+ # @param path [String] URL path to send request
46
+ # @param opts [Hash] Request parameters
47
+ # @return [Hashie::Mash] Response body
48
+ def patch path, opts={}
49
+ request(:patch, path, opts).body
50
+ end
51
+
52
+ private
53
+
54
+ # Sets connection options
55
+ #
56
+ # @param opts [Hash] hash of opts passed
57
+ # @return [Hash] connection options
58
+ def connection_options opts
59
+ {
60
+ :headers => {
61
+ :user_agent => user_agent
62
+ },
63
+ :force_urlencoded => opts.delete(:force_urlencoded) || false,
64
+ :url => api_endpoint
65
+ }
66
+ end
67
+
68
+ # Perform a request
69
+ #
70
+ # @param method [String] Type of request path
71
+ # @param path [String] URL path to send request
72
+ # @param opts [Hash] Request parameters
73
+ # @return [Hashie::Mash] Response
74
+ def request method, path, opts={}
75
+ conn_options = connection_options opts
76
+ opts['api_key'] = api_key unless opts.has_key? 'api_key'
77
+ opts['file_type'] = file_type unless opts.has_key? 'file_type'
78
+
79
+ response = connection(conn_options).send(method) do |request|
80
+ case method
81
+ when :get
82
+ request.url path, opts
83
+ when :delete
84
+ request.url path, opts
85
+ when :patch, :post, :put
86
+ if conn_options[:force_urlencoded]
87
+ request.url path, opts
88
+ else
89
+ request.path = path
90
+ request.body = MultiJson.dump(opts) unless opts.empty?
91
+ end
92
+ end
93
+ end
94
+
95
+ response
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,3 @@
1
+ module FREDAPI
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ describe FREDAPI do
4
+
5
+ describe 'when called' do
6
+ it 'should be an instance of Module' do
7
+ FREDAPI.should be_an_instance_of Module
8
+ end
9
+ end
10
+
11
+ describe '.new' do
12
+ it 'is a FREDAPI::Client' do
13
+ expect(FREDAPI.new).to be_a FREDAPI::Client
14
+ end
15
+ end
16
+
17
+ describe '.respond_to?' do
18
+ it 'returns true if new method exists' do
19
+ expect(FREDAPI.respond_to?(:new, true)).to eq(true)
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,12 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+ require 'fredapi'
4
+
5
+ RSpec.configure do |config|
6
+ config.color_enabled = true
7
+ config.formatter = :documentation
8
+ end
9
+
10
+ def fixture_path
11
+ File.expand_path("../fixtures", __FILE__)
12
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fredapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Chrisp
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.13.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.13.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.12.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.12.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday_middleware
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: hashie
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.5
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.5
83
+ description: A Ruby wrapper for the FRED API
84
+ email: jonathan.chrisp@gmail.com
85
+ executables:
86
+ - fredapi
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENCE.md
94
+ - README.md
95
+ - bin/fredapi
96
+ - fredapi.gemspec
97
+ - lib/faraday/utils/utils.rb
98
+ - lib/fredapi.rb
99
+ - lib/fredapi/client.rb
100
+ - lib/fredapi/client/category.rb
101
+ - lib/fredapi/client/category/children.rb
102
+ - lib/fredapi/client/category/related.rb
103
+ - lib/fredapi/client/category/related_tags.rb
104
+ - lib/fredapi/client/category/series.rb
105
+ - lib/fredapi/client/category/tags.rb
106
+ - lib/fredapi/client/related_tags.rb
107
+ - lib/fredapi/client/release.rb
108
+ - lib/fredapi/client/release/dates.rb
109
+ - lib/fredapi/client/release/related_tags.rb
110
+ - lib/fredapi/client/release/series.rb
111
+ - lib/fredapi/client/release/sources.rb
112
+ - lib/fredapi/client/release/tags.rb
113
+ - lib/fredapi/client/releases.rb
114
+ - lib/fredapi/client/releases/dates.rb
115
+ - lib/fredapi/client/series.rb
116
+ - lib/fredapi/client/series/categories.rb
117
+ - lib/fredapi/client/series/observations.rb
118
+ - lib/fredapi/client/series/release.rb
119
+ - lib/fredapi/client/series/search.rb
120
+ - lib/fredapi/client/series/search/related_tags.rb
121
+ - lib/fredapi/client/series/search/tags.rb
122
+ - lib/fredapi/client/series/tags.rb
123
+ - lib/fredapi/client/series/updates.rb
124
+ - lib/fredapi/client/series/vintage_dates.rb
125
+ - lib/fredapi/client/source.rb
126
+ - lib/fredapi/client/source/releases.rb
127
+ - lib/fredapi/client/sources.rb
128
+ - lib/fredapi/client/tags.rb
129
+ - lib/fredapi/client/tags/series.rb
130
+ - lib/fredapi/configuration.rb
131
+ - lib/fredapi/connection.rb
132
+ - lib/fredapi/request.rb
133
+ - lib/fredapi/version.rb
134
+ - spec/fredapi_spec.rb
135
+ - spec/helper.rb
136
+ homepage: https://github.com/jonathanchrisp/fredapi
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: 1.9.2
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.1.2
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: FRED API Ruby Wrapper
160
+ test_files:
161
+ - spec/fredapi_spec.rb
162
+ - spec/helper.rb
163
+ has_rdoc: