{"id":13719465,"url":"https://github.com/peterhellberg/scb","last_synced_at":"2025-03-04T01:49:53.151Z","repository":{"id":8158917,"uuid":"9580105","full_name":"peterhellberg/scb","owner":"peterhellberg","description":"A small API client for the SCB API.","archived":false,"fork":false,"pushed_at":"2013-05-13T07:24:06.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-09-17T01:05:15.213Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/peterhellberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-21T13:56:34.000Z","updated_at":"2022-07-14T07:19:22.000Z","dependencies_parsed_at":"2022-09-14T13:31:30.012Z","dependency_job_id":null,"html_url":"https://github.com/peterhellberg/scb","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fscb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fscb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fscb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fscb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterhellberg","download_url":"https://codeload.github.com/peterhellberg/scb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241768278,"owners_count":20017129,"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":[],"created_at":"2024-08-03T01:00:49.316Z","updated_at":"2025-03-04T01:49:53.132Z","avatar_url":"https://github.com/peterhellberg.png","language":"Ruby","readme":"# SCB\n\nA small API client for the SCB API.\n\nYou probably want to read the [API\\_beskrivning.pdf](http://www.scb.se/Grupp/OmSCB/Dokument/API-beskrivning.pdf) (in Swedish)\n\n[![Build Status](https://travis-ci.org/peterhellberg/scb.png?branch=master)](https://travis-ci.org/peterhellberg/scb)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'scb'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install scb\n\n## Usage\n\nIt is probably a good idea to take a look in `specs`\n\nConfiguration of the API client is done automatically, but it is also possible to manually compose the objects:\n\n```ruby\n# Manual composition\nconfig = SCB::API.config.new\napi    = SCB::API.new(config)\ndb     = SCB::DB.new(api)\ntable  = db.table('ProdbrEl')\n\n# Short form\ntable = SCB.table('ProdbrEl')\n\n# Liquid renewable energy in 2009\ntable.query Bransle: 925, Tid: 2009\n```\n\n### Configuration\n\nNothing needs to be configured out of the box, but you can change the\n`api_host`, `api_name`, `api_version`, `language`, `database`, \n`http_client` and `json_parser` settings like this:\n\n```ruby\n# English config\nconfig = SCB::API::Config.new do |c|\n  c.language = 'en'\nend\n\n# You can also pass a block straight to SCB.api\nSCB.api { |c| c.api_host = 'scb.test' } \n```\n\n### Database\n\nThe database is divided into levels/sub-levels and tables.\n\nThe default language is 'sv' but there is also some data unde 'en'\n\n```ruby\ndb = SCB.db\n\n# The names of All the top levels\ndb.levels.map(\u0026:name)\n\n# The English title of LonArb07Privat\nSCB.db.en.table('LonArb07Privat').title\n```\n\n### Level\n\nThe database levels can contain sub-levels or tables. You are probably\nmore interested in the actual tables and their data. \n\n```ruby\n# All the levels below BO\nSCB.level('BO').levels\n\n# All the tables below HE0110A\nSCB.level('HE0110A').tables\n```\n\n### Table\n\nThis is probably where you want to spend most of your time.\n\nYou can ask the table for possible variables in order to construct your query. I’ve implemented a simplified query format along the lines: `Key: value` where value is automatically turned into an Array if you only want a single value.\n\n*Note:* Each value is also turned into a string.\n\n```ruby\n# Database table containing data on electricity production\ntable = SCB.table('EltillfM')\n\n# URI to the API endpoint for the table\ntable.uri\n\n# The variable codes for the table\ntable.variables.map(\u0026:code)\n\n# Query: Wind production in January and February of 2013\ntable.query Prodslag: \"Vind\", Tid: [\"2013M01\", \"2013M02\"]\n\n# Usage of the Internet\ntable = SCB.table('LE0108T05')\n\ntable.query Tid: 2012, Dem: \"25-34\"\n\n# You can also get the result as a png\nfilename = '/tmp/internet_usage_2011.png'\nquery    = { AnvOmr: 80, Tid: 2011, ContentsCode: \"LE0108A2\" }\n\ntable.write_png_query(filename, query)\n```\n*Note:* `write_png_query` will not overwrite existing files.\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","funding_links":[],"categories":["Misc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Fscb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterhellberg%2Fscb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Fscb/lists"}