{"id":13878987,"url":"https://github.com/ianks/attr-gather","last_synced_at":"2025-04-14T00:42:08.274Z","repository":{"id":35930804,"uuid":"217208304","full_name":"ianks/attr-gather","owner":"ianks","description":"Hit a million different APIs and combine the results in one simple hash (without pulling your hair out). A simple workflow system to gather aggregate attributes for something. ","archived":false,"fork":false,"pushed_at":"2023-04-17T21:58:05.000Z","size":241,"stargazers_count":40,"open_issues_count":5,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T14:52:38.672Z","etag":null,"topics":["aggregator","api","dry-rb","rails","ruby","workflows"],"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/ianks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-10-24T04:03:23.000Z","updated_at":"2025-02-07T03:38:29.000Z","dependencies_parsed_at":"2024-01-05T21:58:52.455Z","dependency_job_id":null,"html_url":"https://github.com/ianks/attr-gather","commit_stats":{"total_commits":78,"total_committers":5,"mean_commits":15.6,"dds":0.3717948717948718,"last_synced_commit":"34a50115539684c6a16a5e9f216bf2eeacb30f9f"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianks%2Fattr-gather","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianks%2Fattr-gather/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianks%2Fattr-gather/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianks%2Fattr-gather/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ianks","download_url":"https://codeload.github.com/ianks/attr-gather/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804719,"owners_count":21164127,"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":["aggregator","api","dry-rb","rails","ruby","workflows"],"created_at":"2024-08-06T08:02:06.166Z","updated_at":"2025-04-14T00:42:08.244Z","avatar_url":"https://github.com/ianks.png","language":"Ruby","funding_links":[],"categories":["Data Processing and ETL","Ruby"],"sub_categories":[],"readme":"# attr-gather\n\n![Actions Status](https://github.com/ianks/attr-gather/workflows/Build%20+%20Test%20+%20Lint/badge.svg)\n[![Maintainability](https://api.codeclimate.com/v1/badges/b825a3bc37ad6a76e005/maintainability)](https://codeclimate.com/github/ianks/attr-gather/maintainability)\n\nA gem for creating workflows that \"enhance\" entities with extra attributes. At a high level, [attr-gather](https://github.com/ianks/attr-gather) provides a process to fetch information from many data sources (such as third party APIs, legacy databases, etc.) in a fully parallelized fashion.\n\n## Usage\n\n### Defining your workflow\n\n```ruby\n# define a workflow\nclass EnhanceProfile\n  include Attr::Gather::Workflow\n\n  # contains all the task implementations\n  container TasksContainer\n\n  # filter out invalid data using a Dry::Validation::Contract\n  # anything that doesn't match this schema will be filtered out\n  filter_with_contract do\n    params do\n      required(:user_id).filled(:integer)\n\n      optional(:user).hash do\n        optional(:name).filled(:string)\n        optional(:email).filled(:string)\n        optional(:gravatar).filled(:string)\n        optional(:email_info).hash do\n          optional(:deliverable).filled(:bool?)\n          optional(:free).filled(:bool?)\n        end\n      end\n    end\n  end\n\n  # each task returns a hash of data that will be merged into the result\n  task :fetch_post do |t|\n    t.depends_on = []\n  end\n\n  # will run in parallel\n  task :fetch_user do |t|\n    t.depends_on = [:fetch_post]\n  end\n\n  # will run in parallel\n  task :fetch_email_info do |t|\n    t.depends_on = [:fetch_user]\n  end\nend\n```\n\n### Defining some tasks\n\n```ruby\nclass PostFetcher\n  def call(attrs)\n    res = HTTP.get(\"https://jsonplaceholder.typicode.com/posts/#{attrs[:id]}\")\n    post = JSON.parse(res.to_s, symbolize_names: true)\n\n    { title: post[:title], user_id: post[:userId], body: post[:body] }\n  end\nend\n```\n\n```ruby\nclass UserFetcher\n  # will have access to the PostFetcher attributes here\n  def call(attrs)\n    res = HTTP.get(\"https://jsonplaceholder.typicode.com/users/#{attrs[:user_id]}\")\n    user = JSON.parse(res.to_s, symbolize_names: true)\n\n    { user: { name: user[:name], email: user[:email] } }\n  end\nend\n```\n\n```ruby\nclass EmailInfoFetcher\n  # will have access to the PostFetcher attributes here\n  def call(user:)\n    res = HTTP.timeout(3).get(\"https://api.trumail.io/v2/lookups/json?email=#{user[:email]}\")\n    info = JSON.parse(res.to_s, symbolize_names: true)\n\n    # will deep merge with the final result\n    { user: { email_info: { deliverable: info[:deliverable], free: info[:free] } } }\n  end\nend\n```\n\n### Registering your tasks\n\n```ruby\nclass MyContainer\n  extend Dry::Container::Mixin\n  \n  register :fetch_post, PostFetcher\n  register :fetch_user, UserFetcher\n  register :fetch_email_info, EmailInfoFetcher\nend\n```\n\n### Run it!\n\n```ruby\nenhancer = EnhanceUserProfile.new\nenhancer.call(id: 12).value!\n```\n\nAnd this is the result...\n\n```ruby\n{\n  :id =\u003e 12,\n  :user_id =\u003e 2,\n  :user =\u003e {\n    :email =\u003e \"Shanna@melissa.tv\",\n    :name =\u003e \"Ervin Howell\",\n    :email_info =\u003e { :deliverable =\u003e true, :free =\u003e true },\n    :gravatar =\u003e \"https://www.gravatar.com/avatar/241af7d19a0a7438794aef21e4e19b79\"\n  }\n}\n```\n\nYou can even preview it as an SVG!\n\n```ruby\nenhancer.to_dot(preview: true) # requires graphviz (brew install graphviz)\n```\n\n## Features\n\n- Offers DSL for defining workflows and merging the results from each task\n- Execution engine optimally parallelizes the execution of the workflow dependency graph using [concurrent-ruby](https://github.com/ruby-concurrency/concurrent-ruby) Promises\n- Very easy to unit test\n- Ability to filter out bad/junky data using [dry-validation](https://dry-rb.org/gems/dry-validation) contracts\n\n## What are the main difference between this Ruby project and similar ones?\n\n- Operates on a single entity rather than a list, so easily adoptable in existing systems\n- Focuses on the \"fetching\" and filtering of data solely, and not transformation or storage\n- Focuses on having a clean PORO interface to make testing simple\n- Provides a declarative interface for merging results from many sources (APIs, legacy databases, etc.) which allows for prioritization\n\n## Links\n\n- [API Documentation](https://www.rubydoc.info/gems/attr-gather)\n\n## Examples\n\n| [![SVG of Workflow](./examples/post_enhancer.svg)](./examples/post_enhancer.rb) |\n| :-----------------------------------------------------------------------------: |\n|  [Example of workflow that enhances a blog post](./examples/post_enhancer.rb)   |\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'attr-gather'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install attr-gather\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run\n`rake spec` to run the tests. You can also run `bin/console` for an interactive\nprompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To\nrelease a new version, update the version number in `version.rb`, and then run\n`bundle exec rake release`, which will create a git tag for the version, push\ngit commits and tags, and push the `.gem` file to\n[rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at\nhttps://github.com/ianks/attr-gather. This project is intended to be a safe,\nwelcoming space for collaboration, and contributors are expected to adhere to\nthe [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT\nLicense](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Attr::Gather project’s codebases, issue trackers,\nchat rooms and mailing lists is expected to follow the [code of\nconduct](https://github.com/ianks/attr-gather/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianks%2Fattr-gather","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fianks%2Fattr-gather","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianks%2Fattr-gather/lists"}