{"id":15406761,"url":"https://github.com/dannyben/fredric","last_synced_at":"2025-04-18T02:51:27.644Z","repository":{"id":56847698,"uuid":"81651837","full_name":"DannyBen/fredric","owner":"DannyBen","description":"Federal Reserve Economic Data (FRED) API Library and Command Line","archived":false,"fork":false,"pushed_at":"2023-07-09T06:26:46.000Z","size":60,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T15:48:55.213Z","etag":null,"topics":["api","api-client","command-line","economic-data","fred","gem","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DannyBen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-11T12:34:29.000Z","updated_at":"2023-12-04T09:50:55.000Z","dependencies_parsed_at":"2024-10-19T12:33:21.772Z","dependency_job_id":"fddc7d85-ae01-4654-8a79-ffbe1d57240b","html_url":"https://github.com/DannyBen/fredric","commit_stats":{"total_commits":57,"total_committers":2,"mean_commits":28.5,"dds":"0.42105263157894735","last_synced_commit":"44ab29a94996a5b1bd899e203cb258a0b9d02763"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Ffredric","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Ffredric/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Ffredric/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Ffredric/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DannyBen","download_url":"https://codeload.github.com/DannyBen/fredric/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249416777,"owners_count":21268129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-client","command-line","economic-data","fred","gem","ruby"],"created_at":"2024-10-01T16:25:15.713Z","updated_at":"2025-04-18T02:51:27.615Z","avatar_url":"https://github.com/DannyBen.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FRED API Library and Command Line\n\n[![Gem Version](https://badge.fury.io/rb/fredric.svg)](https://badge.fury.io/rb/fredric)\n[![Build Status](https://github.com/DannyBen/fredric/workflows/Test/badge.svg)](https://github.com/DannyBen/fredric/actions?query=workflow%3ATest)\n[![Maintainability](https://api.codeclimate.com/v1/badges/4b0a8627ceb5343b55fa/maintainability)](https://codeclimate.com/github/DannyBen/fredric/maintainability)\n\n---\n\nCommand line interface and a Ruby library for the \n[Federal Reserve Economic Data (FRED)][1] API.\n\n---\n\n\n## Install\n\n```\n$ gem install fredric\n```\n\nOr with bundler:\n\n```ruby\ngem 'fredric'\n```\n\n\n## Features\n\n* Easy to use interface.\n* Use as a library or through the command line.\n* Access any FRED endpoint and option directly.\n* Display output as JSON, XML or CSV.\n* Save output to a file as JSON, XML or CSV.\n* Includes a built in file cache (disabled by default).\n\n\n## Usage\n\nFirst, require and initialize with your [FRED API Key][4].\n\n```ruby\nrequire 'fredric'\nfredric = Fredric::API.new 'your-api-key'\n```\n\nNow, you can access any FRED endpoint with any optional parameter, like\nthis:\n\n```ruby\nresult = fredric.get \"series/observations\", series_id: 'GNPCA'\n```\n\nIn addition, for convenience, you can use the first part of the endpoint as\na method name, like this:\n\n```ruby\nresult = fredric.series 'observations', series_id: 'GNPCA'\n```\n\nIn other words, these calls are the same:\n\n```ruby\nfredric.get 'endpoint', param: value\nfredric.endpoint, param: value\n```\n\nas well as these two:\n\n```ruby\nfredric.get 'endpoint/sub', param: value\nfredric.endpoint 'sub', param: value\n```\n\nBy default, you will get a ruby hash in return. If you wish to have more \ncontrol over the response, use the `get!` method instead:\n\n```ruby\nresult = fredric.get! \"series/ovservations\", series_id: 'GNPCA'\n\n# Request Object\np payload.request.class\n# =\u003e HTTParty::Request\n\n# Response Object\np payload.response.class\n# =\u003e Net::HTTPOK\n\np payload.response.body\n# =\u003e JSON string\n\np payload.response.code\n# =\u003e 200\n\np payload.response.msg\n# =\u003e OK\n\n# Headers Object\np payload.headers\n# =\u003e Hash with headers\n\n# Parsed Response Object\np payload.parsed_response\n# =\u003e Hash with HTTParty parsed response \n#    (this is the content returned with #get)\n```\n\nYou can get the response as CSV by calling `get_csv`:\n\n```ruby\nresult = fredric.get_csv \"series/overvations\", series_id: 'GNPCA'\n# =\u003e CSV string\n```\n\nFredric automatically decides which part of the data to convert to CSV.\nWhen there is an array in the response (for example, in the case of \n`observations`), it will be used as the CSV data. Otherwise, the entire\nresponse will be treated as a single-row CSV.\n\nTo save the output directly to a file, use the `save` method:\n\n```ruby\nfredric.save \"filename.json\", \"series/overvations\", series_id: 'GNPCA'\n```\n\nOr, to save CSV, use the `save_csv` method:\n\n```ruby\nfredric.save_csv \"filename.csv\", \"series/overvations\", series_id: 'GNPCA'\n```\n\n\n## Command Line\n\nThe command line utility `fred` acts in a similar way. To set your \nFRED API Key, simply set it in the environment variable `FRED_KEY`:\n\n`$ export FRED_KEY=y0urAP1k3y`\n\nThese commands are available:\n\n`$ fred get [--csv] PATH [PARAMS...]` - print the output.  \n`$ fred pretty PATH [PARAMS...]` - print a pretty JSON.  \n`$ fred see PATH [PARAMS...]` - print a colored output.  \n`$ fred url PATH [PARAMS...]` - show the constructed URL.  \n`$ fred save [--csv] FILE PATH [PARAMS...]` - save the output to a file.  \n\nRun `fred --help` for more information, or view the [full usage help][2].\n\nExamples:\n\n```bash\n# Shows details about a data series\n$ fred see series series_id:GNPCA\n\n# Shows data as CSV\n$ fred get --csv series/observations series_id:GNPCA\n\n# Pass arguments that require spaces\n$ fred see series/search \"search_text:consumer price index\" limit:3\n\n# Saves a file\n$ fred save --csv result.csv series/search search_text:cpi limit:3\n\n# Shows the URL that Fredric has constructed, good for debugging\n$ fred url series/observations query:interest limit:5\n# =\u003e https://api.stlouisfed.org/fred/series/observations?api_key=ce1e45e6551de5db555a09b88d23682f\u0026file_type=json\u0026query=interest\u0026limit=5\n\n```\n\n\n## Caching\n\nWe are using the [Lightly][3] gem for automatic HTTP caching.\nTo take the path of least surprises, caching is disabled by default.\n\nYou can enable and customize it by either passing options on \ninitialization, or by accessing the `Lightly` object directly at \na later stage.\n\n```ruby\nfredric = Fredric::API.new 'apikey', use_cache: true\nfredric = Fredric::API.new 'apikey', use_cache: true, cache_dir: 'tmp'\nfredric = Fredric::API.new 'apikey', use_cache: true, cache_life: 120\n\n# or \n\nfredric = Fredric::API.new 'apikey'\nfredric.cache.enable\nfredric.cache.dir = 'tmp/cache'   # Change cache folder\nfredric.cache.life = 120          # Change cache life to 2 minutes\n```\n\nTo enable caching for the command line, simply set one or both of \nthese environment variables:\n\n```\n$ export FRED_CACHE_DIR=cache   # default: 'cache'\n$ export FRED_CACHE_LIFE=120    # default: 3600 (1 hour)\n$ fred see category/children\n# =\u003e This call will be cached\n```\n\n\n[1]: https://research.stlouisfed.org/docs/api/fred/\n[2]: https://github.com/DannyBen/fredric/blob/master/lib/fredric/docopt.txt\n[3]: https://github.com/DannyBen/lightly\n[4]: https://research.stlouisfed.org/docs/api/api_key.html\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Ffredric","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdannyben%2Ffredric","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Ffredric/lists"}