fredric 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +203 -0
- data/bin/fred +9 -0
- data/lib/fredric.rb +5 -0
- data/lib/fredric/api.rb +74 -0
- data/lib/fredric/command_line.rb +122 -0
- data/lib/fredric/docopt.txt +61 -0
- data/lib/fredric/exceptions.rb +4 -0
- data/lib/fredric/version.rb +3 -0
- data/lib/fredric/web_api.rb +93 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4ab13d78501098fa5e1cafb3c9089f7deefac6f6
|
4
|
+
data.tar.gz: a8413186c16bff59656c73441a53fd94e75d0e11
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0f95fb9b07eb270839e83bd0af6c1545a447d98cf7fa3f9365cfeffd1006d9645d1c06ea69110de171132363195f2a5adf8655a0690a49202bd5f25d483d0ed5
|
7
|
+
data.tar.gz: a2d276a7191adce89b28e5a774c9e146c8d1205a3239decb56c3c42a6cd93e63bffac613987a67aeb9517ccb410013fa5d5d68f46bcdd35ae6700bdf275f687d
|
data/README.md
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
FRED API Library and Command Line
|
2
|
+
==================================================
|
3
|
+
|
4
|
+
[![Gem](https://img.shields.io/gem/v/fredric.svg?style=flat-square)](https://rubygems.org/gems/fredric)
|
5
|
+
[![Travis](https://img.shields.io/travis/DannyBen/fredric.svg?style=flat-square)](https://travis-ci.org/DannyBen/fredric)
|
6
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/DannyBen/fredric.svg?style=flat-square)](https://codeclimate.com/github/DannyBen/fredric)
|
7
|
+
[![Gemnasium](https://img.shields.io/gemnasium/DannyBen/fredric.svg?style=flat-square)](https://gemnasium.com/DannyBen/fredric)
|
8
|
+
|
9
|
+
---
|
10
|
+
|
11
|
+
This gem provides both a Ruby library and a command line interface for the
|
12
|
+
[FRED][1] data service.
|
13
|
+
|
14
|
+
---
|
15
|
+
|
16
|
+
|
17
|
+
Install
|
18
|
+
--------------------------------------------------
|
19
|
+
|
20
|
+
```
|
21
|
+
$ gem install fredric
|
22
|
+
```
|
23
|
+
|
24
|
+
Or with bundler:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'fredric'
|
28
|
+
```
|
29
|
+
|
30
|
+
|
31
|
+
Features
|
32
|
+
--------------------------------------------------
|
33
|
+
|
34
|
+
* Easy to use interface.
|
35
|
+
* Use as a library or through the command line.
|
36
|
+
* Access any FRED endpoint and option directly.
|
37
|
+
* Display output as JSON, XML or CSV.
|
38
|
+
* Save output to a file as JSON, XML or CSV.
|
39
|
+
* Includes a built in file cache (disabled by default).
|
40
|
+
|
41
|
+
|
42
|
+
Usage
|
43
|
+
--------------------------------------------------
|
44
|
+
|
45
|
+
First, require and initialize with your [FRED API Key][4].
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'fredric'
|
49
|
+
fredric = Fredric::API.new api_key: 'y0urAP1k3y'
|
50
|
+
```
|
51
|
+
|
52
|
+
Now, you can access any FRED endpoint with any optional parameter, like
|
53
|
+
this:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
result = fredric.get "series/observations", series_id: 'GNPCA'
|
57
|
+
```
|
58
|
+
|
59
|
+
In addition, for convenience, you can use the first part of the endpoint as
|
60
|
+
a method name, like this:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
result = fredric.series 'observations', series_id: 'GNPCA'
|
64
|
+
```
|
65
|
+
|
66
|
+
In other words, these calls are the same:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
fredric.get 'endpoint', param: value
|
70
|
+
fredric.endpoint, param: value
|
71
|
+
```
|
72
|
+
|
73
|
+
as well as these two:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
fredric.get 'endpoint/sub', param: value
|
77
|
+
fredric.endpoint 'sub', param: value
|
78
|
+
```
|
79
|
+
|
80
|
+
By default, you will get a ruby hash in return. If you wish to get the raw
|
81
|
+
output, you can use the `get!` method:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
result = fredric.get! "series/ovservations", series_id: 'GNPCA'
|
85
|
+
# => JSON string
|
86
|
+
```
|
87
|
+
|
88
|
+
You can get the response as CSV by calling `get_csv`:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
result = fredric.get_csv "series/overvations", series_id: 'GNPCA'
|
92
|
+
# => CSV string
|
93
|
+
```
|
94
|
+
|
95
|
+
Fredric automatically decides which part of the data to convert to CSV.
|
96
|
+
When there is an array in the response (for example, in the case of
|
97
|
+
`observations`), it will be used as the CSV data. Otherwise, the entire
|
98
|
+
response will be treated as a single-row CSV.
|
99
|
+
|
100
|
+
To save the output directly to a file, use the `save` method:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
fredric.save "filename.json", "series/overvations", series_id: 'GNPCA'
|
104
|
+
```
|
105
|
+
|
106
|
+
Or, to save CSV, use the `save_csv` method:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
fredric.save_csv "filename.csv", "series/overvations", series_id: 'GNPCA'
|
110
|
+
```
|
111
|
+
|
112
|
+
Debugging your request and adding "sticky" query parameters that stay with
|
113
|
+
you for the following requests is also easy:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
fredric.debug = true
|
117
|
+
fredric.param limit: 10, sort_order: :asc, file_type: :xml
|
118
|
+
puts fredric.series 'observations', series_id: 'GNPCA'
|
119
|
+
# => https://api.stlouisfed.org/fred/series/observations?api_key=...&file_type=xml&limit=10&sort_order=asc&series_id=GNPCA
|
120
|
+
|
121
|
+
fredric.param sort_order: nil # remove param
|
122
|
+
```
|
123
|
+
|
124
|
+
|
125
|
+
Command Line
|
126
|
+
--------------------------------------------------
|
127
|
+
|
128
|
+
The command line utility `fred` acts in a similar way. To set your
|
129
|
+
FRED API Key, simply set it in the environment variables
|
130
|
+
`FREDRIC_KEY`:
|
131
|
+
|
132
|
+
`$ export FREDRIC_KEY=y0urAP1k3y`
|
133
|
+
|
134
|
+
These commands are available:
|
135
|
+
|
136
|
+
`$ fred get [--csv] PATH [PARAMS...]` - print the output.
|
137
|
+
`$ fred pretty PATH [PARAMS...]` - print a pretty JSON.
|
138
|
+
`$ fred see PATH [PARAMS...]` - print a colored output.
|
139
|
+
`$ fred url PATH [PARAMS...]` - show the constructed URL.
|
140
|
+
`$ fred save [--csv] FILE PATH [PARAMS...]` - save the output to a file.
|
141
|
+
|
142
|
+
Run `fred --help` for more information, or view the [full usage help][2].
|
143
|
+
|
144
|
+
Examples:
|
145
|
+
|
146
|
+
```bash
|
147
|
+
# Shows details about a data series
|
148
|
+
$ fred see series series_id:GNPCA
|
149
|
+
|
150
|
+
# Shows data as CSV
|
151
|
+
$ fred get --csv series/observations series_id:GNPCA
|
152
|
+
|
153
|
+
# Pass arguments that require spaces
|
154
|
+
$ fred see series/search "search_text:consumer price index" limit:3
|
155
|
+
|
156
|
+
# Saves a file
|
157
|
+
$ fred save --csv result.csv series/search search_text:cpi limit:3
|
158
|
+
|
159
|
+
# Shows the URL that Fredric has constructed, good for debugging
|
160
|
+
$ fred url series/observations query:interest limit:5
|
161
|
+
# => https://api.stlouisfed.org/fred/series/observations?api_key=ce1e45e6551de5db555a09b88d23682f&file_type=json&query=interest&limit=5
|
162
|
+
|
163
|
+
```
|
164
|
+
|
165
|
+
|
166
|
+
Caching
|
167
|
+
--------------------------------------------------
|
168
|
+
|
169
|
+
We are using the [WebCache][3] gem for automatic HTTP caching.
|
170
|
+
To take the path of least surprises, caching is disabled by default.
|
171
|
+
|
172
|
+
You can enable and customize it by either passing options on
|
173
|
+
initialization, or by accessing the `WebCache` object directly at
|
174
|
+
a later stage.
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
fredric = Fredric::API.new 'apikey', use_cache: true
|
178
|
+
fredric = Fredric::API.new 'apikey', use_cache: true, cache_dir: 'tmp'
|
179
|
+
fredric = Fredric::API.new 'apikey', use_cache: true, cache_life: 120
|
180
|
+
|
181
|
+
# or
|
182
|
+
|
183
|
+
fredric = Fredric::API.new 'apikey'
|
184
|
+
fredric.cache.enable
|
185
|
+
fredric.cache.dir = 'tmp/cache' # Change cache folder
|
186
|
+
fredric.cache.life = 120 # Change cache life to 2 minutes
|
187
|
+
```
|
188
|
+
|
189
|
+
To enable caching for the command line, simply set one or both of
|
190
|
+
these environment variables:
|
191
|
+
|
192
|
+
```
|
193
|
+
$ export FREDRIC_CACHE_DIR=cache # default: 'cache'
|
194
|
+
$ export FREDRIC_CACHE_LIFE=120 # default: 3600 (1 hour)
|
195
|
+
$ fredric get indices
|
196
|
+
# => This call will be cached
|
197
|
+
```
|
198
|
+
|
199
|
+
|
200
|
+
[1]: https://research.stlouisfed.org/docs/api/fred/
|
201
|
+
[2]: https://github.com/DannyBen/fredric/blob/master/lib/fredric/docopt.txt
|
202
|
+
[3]: https://github.com/DannyBen/webcache
|
203
|
+
[4]: https://research.stlouisfed.org/docs/api/api_key.html
|
data/bin/fred
ADDED
data/lib/fredric.rb
ADDED
data/lib/fredric/api.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Fredric
|
5
|
+
# Provides access to all the FRED API endpoints
|
6
|
+
class API < WebAPI
|
7
|
+
attr_reader :api_key, :opts
|
8
|
+
|
9
|
+
def initialize(api_key, opts={})
|
10
|
+
@api_key = api_key
|
11
|
+
|
12
|
+
defaults = {
|
13
|
+
use_cache: false,
|
14
|
+
cache_dir: nil,
|
15
|
+
cache_life: nil,
|
16
|
+
base_url: "https://api.stlouisfed.org/fred"
|
17
|
+
}
|
18
|
+
|
19
|
+
opts = defaults.merge! opts
|
20
|
+
@opts = opts
|
21
|
+
|
22
|
+
cache.disable unless opts[:use_cache]
|
23
|
+
cache.dir = opts[:cache_dir] if opts[:cache_dir]
|
24
|
+
cache.life = opts[:cache_life] if opts[:cache_life]
|
25
|
+
|
26
|
+
param api_key: api_key if api_key
|
27
|
+
param file_type: :json
|
28
|
+
|
29
|
+
after_request do |response|
|
30
|
+
begin
|
31
|
+
JSON.parse response, symbolize_names: true
|
32
|
+
rescue JSON::ParserError
|
33
|
+
response
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
super opts[:base_url]
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_csv(*args)
|
41
|
+
response = get *args
|
42
|
+
|
43
|
+
raise Fredric::BadResponse, "API said '#{response}'" if response.is_a? String
|
44
|
+
raise Fredric::BadResponse, "Got a #{response.class}, expected a Hash" unless response.is_a? Hash
|
45
|
+
|
46
|
+
data = csv_node response
|
47
|
+
|
48
|
+
header = data.first.keys
|
49
|
+
result = CSV.generate do |csv|
|
50
|
+
csv << header
|
51
|
+
data.each { |row| csv << row.values }
|
52
|
+
end
|
53
|
+
|
54
|
+
result
|
55
|
+
end
|
56
|
+
|
57
|
+
def save_csv(file, *args)
|
58
|
+
data = get_csv *args
|
59
|
+
File.write file, data
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
# Determins which part of the data is best suited to be displayed
|
65
|
+
# as CSV.
|
66
|
+
# - In case there is an array in the data (like 'observations' or
|
67
|
+
# 'seriess'), it will be returned
|
68
|
+
# - Otherwise, we will use the entire response as a single row CSV
|
69
|
+
def csv_node(data)
|
70
|
+
arrays = data.keys.select { |key| data[key].is_a? Array }
|
71
|
+
arrays.empty? ? [data] : data[arrays.first]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'docopt'
|
3
|
+
require 'json'
|
4
|
+
require 'awesome_print'
|
5
|
+
|
6
|
+
module Fredric
|
7
|
+
|
8
|
+
# Handles the command line interface
|
9
|
+
class CommandLine
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
# Gets an array of arguments (e.g. ARGV), executes the command if valid
|
13
|
+
# and shows usage patterns / help otherwise.
|
14
|
+
def execute(argv=[])
|
15
|
+
doc = File.read File.dirname(__FILE__) + '/docopt.txt'
|
16
|
+
begin
|
17
|
+
args = Docopt::docopt(doc, argv: argv, version: VERSION)
|
18
|
+
handle args
|
19
|
+
rescue Docopt::Exit, Fredric::MissingAuth => e
|
20
|
+
puts e.message
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def fredric
|
25
|
+
@fredric ||= fredric!
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_reader :path, :params, :file, :csv
|
31
|
+
|
32
|
+
def fredric!
|
33
|
+
Fredric::API.new api_key, options
|
34
|
+
end
|
35
|
+
|
36
|
+
# Called when the arguments match one of the usage patterns. Will
|
37
|
+
# delegate action to other, more specialized methods.
|
38
|
+
def handle(args)
|
39
|
+
@path = args['PATH']
|
40
|
+
@params = translate_params args['PARAMS']
|
41
|
+
@file = args['FILE']
|
42
|
+
@csv = args['--csv']
|
43
|
+
|
44
|
+
unless api_key
|
45
|
+
raise Fredric::MissingAuth, "Missing Authentication\nPlease set FREDRIC_KEY=y0urAP1k3y"
|
46
|
+
end
|
47
|
+
|
48
|
+
return get if args['get']
|
49
|
+
return pretty if args['pretty']
|
50
|
+
return see if args['see']
|
51
|
+
return url if args['url']
|
52
|
+
return save if args['save']
|
53
|
+
end
|
54
|
+
|
55
|
+
def get
|
56
|
+
if csv
|
57
|
+
puts fredric.get_csv path, params
|
58
|
+
else
|
59
|
+
puts fredric.get! path, params
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def save
|
64
|
+
if csv
|
65
|
+
success = fredric.save_csv file, path, params
|
66
|
+
else
|
67
|
+
success = fredric.save file, path, params
|
68
|
+
end
|
69
|
+
puts success ? "Saved #{file}" : "Saving failed"
|
70
|
+
end
|
71
|
+
|
72
|
+
def pretty
|
73
|
+
response = fredric.get path, params
|
74
|
+
puts JSON.pretty_generate response
|
75
|
+
end
|
76
|
+
|
77
|
+
def see
|
78
|
+
ap fredric.get path, params
|
79
|
+
end
|
80
|
+
|
81
|
+
def url
|
82
|
+
fredric.debug = true
|
83
|
+
puts fredric.get path, params
|
84
|
+
fredric.debug = false
|
85
|
+
end
|
86
|
+
|
87
|
+
# Convert a params array like [key:value, key:value] to a hash like
|
88
|
+
# {key: value, key: value}
|
89
|
+
def translate_params(pairs)
|
90
|
+
result = {}
|
91
|
+
return result if pairs.empty?
|
92
|
+
pairs.each do |pair|
|
93
|
+
key, value = pair.split ':'
|
94
|
+
result[key.to_sym] = value
|
95
|
+
end
|
96
|
+
result
|
97
|
+
end
|
98
|
+
|
99
|
+
def options
|
100
|
+
result = {}
|
101
|
+
return result unless cache_dir || cache_life
|
102
|
+
|
103
|
+
result[:use_cache] = true
|
104
|
+
result[:cache_dir] = cache_dir if cache_dir
|
105
|
+
result[:cache_life] = cache_life.to_i if cache_life
|
106
|
+
result
|
107
|
+
end
|
108
|
+
|
109
|
+
def api_key
|
110
|
+
ENV['FREDRIC_KEY']
|
111
|
+
end
|
112
|
+
|
113
|
+
def cache_dir
|
114
|
+
ENV['FREDRIC_CACHE_DIR']
|
115
|
+
end
|
116
|
+
|
117
|
+
def cache_life
|
118
|
+
ENV['FREDRIC_CACHE_LIFE']
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
Fredric
|
2
|
+
|
3
|
+
Usage:
|
4
|
+
fred get [--csv] PATH [PARAMS...]
|
5
|
+
fred pretty PATH [PARAMS...]
|
6
|
+
fred see PATH [PARAMS...]
|
7
|
+
fred url PATH [PARAMS...]
|
8
|
+
fred save [--csv] FILE PATH [PARAMS...]
|
9
|
+
fred (-h|--help|--version)
|
10
|
+
|
11
|
+
Commands:
|
12
|
+
get
|
13
|
+
Downloads data and prints it to screen as it.
|
14
|
+
|
15
|
+
pretty
|
16
|
+
Downloads data and prints it as a prettified JSON output.
|
17
|
+
|
18
|
+
see
|
19
|
+
Downloads data and awesome-prints it.
|
20
|
+
|
21
|
+
url
|
22
|
+
Shows the URL constructed from the request.
|
23
|
+
|
24
|
+
save
|
25
|
+
Downloads data and saves it to a file.
|
26
|
+
|
27
|
+
Parameters:
|
28
|
+
PATH:
|
29
|
+
This is the FRED API path, without the query string.
|
30
|
+
For example: `series` or `series/ovservations`.
|
31
|
+
|
32
|
+
PARAMS:
|
33
|
+
An optional list of query string parameters, separated by a space, to
|
34
|
+
send with the request. Each parameter should be in the format of
|
35
|
+
key:value, for example: limit:25 offset:3
|
36
|
+
|
37
|
+
FILE:
|
38
|
+
Path to the output file.
|
39
|
+
|
40
|
+
Flags:
|
41
|
+
--csv
|
42
|
+
When this flag is provided, the data will be converted to CSV before
|
43
|
+
it is displayed or saved. Note that this works only with endpoints that
|
44
|
+
have a 'data' attribute.
|
45
|
+
|
46
|
+
Environment Variables:
|
47
|
+
FREDRIC_KEY=y0urAP1k3y
|
48
|
+
Set Your FRED api key. This variable is required.
|
49
|
+
|
50
|
+
FREDRIC_CACHE_LIFE=360
|
51
|
+
Set the number of seconds to consider the cache fresh. This variable
|
52
|
+
it optional.
|
53
|
+
|
54
|
+
FREDRIC_CACHE_DIR=./cache
|
55
|
+
Set the cache directory. This variable is optional.
|
56
|
+
If both FREDRIC_CACHE_DIR and FREDRIC_CACHE_LIFE are not set, requests
|
57
|
+
will not be cached.
|
58
|
+
|
59
|
+
Examples:
|
60
|
+
fred see series/observations series_id:GNPCA
|
61
|
+
fred get --csv series/observations series_id:GNPCA
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'webcache'
|
4
|
+
|
5
|
+
module Fredric
|
6
|
+
|
7
|
+
# A general purpose HTTP wrapper. This is poor man's HTTParty with
|
8
|
+
# dynamic methods.
|
9
|
+
class WebAPI
|
10
|
+
attr_reader :base_url, :after_request_block, :last_error
|
11
|
+
attr_accessor :debug, :format
|
12
|
+
|
13
|
+
def initialize(base_url)
|
14
|
+
@base_url = base_url
|
15
|
+
end
|
16
|
+
|
17
|
+
# Allow using any method as the first segment of the path
|
18
|
+
# object.user 'details' becomes object.get 'user/details'
|
19
|
+
def method_missing(method_sym, *arguments, &_block)
|
20
|
+
get "/#{method_sym}", *arguments
|
21
|
+
end
|
22
|
+
|
23
|
+
# Add one or more parameter to the default query string. Good for
|
24
|
+
# adding keys that are always needed, like API keys.
|
25
|
+
def param(params)
|
26
|
+
params.each do |key, value|
|
27
|
+
default_params[key] = value
|
28
|
+
default_params.delete key if value.nil?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def cache
|
33
|
+
@cache ||= WebCache.new
|
34
|
+
end
|
35
|
+
|
36
|
+
# Set a block to be executed after the request. This is called only when
|
37
|
+
# using `get` and not when using `get!`. Good for JSON decoding, for
|
38
|
+
# example.
|
39
|
+
def after_request(&block)
|
40
|
+
@after_request_block = block
|
41
|
+
end
|
42
|
+
|
43
|
+
# Return the response from the API.
|
44
|
+
def get(path, extra=nil, params={})
|
45
|
+
response = get! path, extra, params
|
46
|
+
response = after_request_block.call(response) if after_request_block
|
47
|
+
response
|
48
|
+
end
|
49
|
+
|
50
|
+
# Return the response from the API, without executing the after_request
|
51
|
+
# block.
|
52
|
+
def get!(path, extra=nil, params={})
|
53
|
+
if extra.is_a?(Hash) and params.empty?
|
54
|
+
params = extra
|
55
|
+
extra = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
path = "#{path}/#{extra}" if extra
|
59
|
+
url = construct_url path, params
|
60
|
+
|
61
|
+
return url if debug
|
62
|
+
|
63
|
+
response = cache.get(url)
|
64
|
+
@last_error = response.error
|
65
|
+
response.content
|
66
|
+
end
|
67
|
+
|
68
|
+
# Save the response from the API to a file.
|
69
|
+
def save(filename, path, params={})
|
70
|
+
response = get! path, nil, params
|
71
|
+
return response if debug
|
72
|
+
File.write filename, response.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
# Build a URL from all its explicit and implicit pieces.
|
76
|
+
def construct_url(path, params={})
|
77
|
+
path = "/#{path}" unless path[0] == '/'
|
78
|
+
all_params = default_params.merge params
|
79
|
+
result = "#{base_url}#{path}"
|
80
|
+
result = "#{result}.#{format}" if format && File.extname(result) == ''
|
81
|
+
unless all_params.empty?
|
82
|
+
all_params = URI.encode_www_form all_params
|
83
|
+
result = "#{result}?#{all_params}"
|
84
|
+
end
|
85
|
+
result
|
86
|
+
end
|
87
|
+
|
88
|
+
def default_params
|
89
|
+
@default_params ||= {}
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fredric
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danny Ben Shitrit
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: docopt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: awesome_print
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webcache
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: runfile
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: runfile-tasks
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.5'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rdoc
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '5.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '5.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '9.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '9.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.13'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.13'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: yard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.8'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.8'
|
153
|
+
description: Easy to use API for the Federal Reserve Economic Data service with a
|
154
|
+
command line interface
|
155
|
+
email: db@dannyben.com
|
156
|
+
executables:
|
157
|
+
- fred
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- README.md
|
162
|
+
- bin/fred
|
163
|
+
- lib/fredric.rb
|
164
|
+
- lib/fredric/api.rb
|
165
|
+
- lib/fredric/command_line.rb
|
166
|
+
- lib/fredric/docopt.txt
|
167
|
+
- lib/fredric/exceptions.rb
|
168
|
+
- lib/fredric/version.rb
|
169
|
+
- lib/fredric/web_api.rb
|
170
|
+
homepage: https://github.com/DannyBen/fred
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata: {}
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: 2.0.0
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 2.6.6
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: FRED API Library and Command Line
|
194
|
+
test_files: []
|