{"action":"created","comment":{"url":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/comments/31777455","id":31777455,"diff_hunk":"@@ -0,0 +1,104 @@\n+require 'csv'\n+\n+class ArchivesSpaceService < Sinatra::Base\n+\n+  Endpoint.get('/repositories/:repo_id/download_accessions')\n+    .description(\"Download Accessions as CSV\")\n+    .params([\"q\", String, \"A search query string\",\n+             :optional => true],\n+            [\"aq\", JSONModel(:advanced_query), \"A json string containing the advanced query\",\n+             :optional => true],\n+            [\"filter_term\", [String], \"A json string containing the term/value pairs to be applied as filters.  Of the form: {\\\"fieldname\\\": \\\"fieldvalue\\\"}.\",\n+             :optional => true],\n+            [\"repo_id\", :repo_id])\n+    .permissions([])\n+    .returns([200, \"\"]) \\\n+  do\n+\n+    [200, some_headers, content]\n+\n+  end\n+\n+\n+  def some_headers\n+    {\n+      \"Content-Type\" => \"text/csv; charset=UTF-8\",\n+      \"Content-Disposition\" => \"attachment; filename=\\\"accessions_#{Time.now.iso8601}.csv\\\"\"\n+    }\n+  end\n+\n+\n+  def content\n+    params[:filter_term] ||= []\n+    params[:filter_term] << {'primary_type' => 'accession'}.to_json\n+    params[:page] = 1\n+    params[:page_size] = 100","path":"backend/controllers/download_accessions_controller.rb","position":35,"original_position":35,"commit_id":"352ae4baf7c261eed09fb37554620482d4020cee","original_commit_id":"352ae4baf7c261eed09fb37554620482d4020cee","user":{"login":"payten","id":608337,"avatar_url":"https://avatars.githubusercontent.com/u/608337?v=3","gravatar_id":"","url":"https://api.github.com/users/payten","html_url":"https://github.com/payten","followers_url":"https://api.github.com/users/payten/followers","following_url":"https://api.github.com/users/payten/following{/other_user}","gists_url":"https://api.github.com/users/payten/gists{/gist_id}","starred_url":"https://api.github.com/users/payten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/payten/subscriptions","organizations_url":"https://api.github.com/users/payten/orgs","repos_url":"https://api.github.com/users/payten/repos","events_url":"https://api.github.com/users/payten/events{/privacy}","received_events_url":"https://api.github.com/users/payten/received_events","type":"User","site_admin":false},"body":"Perhaps could be a configuration?","created_at":"2015-06-04T23:48:29Z","updated_at":"2015-06-04T23:48:29Z","html_url":"https://github.com/hudmol/nla_accession_reports/pull/1#discussion_r31777455","pull_request_url":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/comments/31777455"},"html":{"href":"https://github.com/hudmol/nla_accession_reports/pull/1#discussion_r31777455"},"pull_request":{"href":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/1","id":36965051,"html_url":"https://github.com/hudmol/nla_accession_reports/pull/1","diff_url":"https://github.com/hudmol/nla_accession_reports/pull/1.diff","patch_url":"https://github.com/hudmol/nla_accession_reports/pull/1.patch","issue_url":"https://api.github.com/repos/hudmol/nla_accession_reports/issues/1","number":1,"state":"open","locked":false,"title":"CSV from search","user":{"login":"jambun","id":438290,"avatar_url":"https://avatars.githubusercontent.com/u/438290?v=3","gravatar_id":"","url":"https://api.github.com/users/jambun","html_url":"https://github.com/jambun","followers_url":"https://api.github.com/users/jambun/followers","following_url":"https://api.github.com/users/jambun/following{/other_user}","gists_url":"https://api.github.com/users/jambun/gists{/gist_id}","starred_url":"https://api.github.com/users/jambun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jambun/subscriptions","organizations_url":"https://api.github.com/users/jambun/orgs","repos_url":"https://api.github.com/users/jambun/repos","events_url":"https://api.github.com/users/jambun/events{/privacy}","received_events_url":"https://api.github.com/users/jambun/received_events","type":"User","site_admin":false},"body":"This isn't a great fit in this plugin but it kind of made sense to me. Happy to move it to its own plugin. Also was a bit unsure about what to call the backend endpoint - suggestions welcome.\r\n\r\nIt turned out all the required data is in the search results, so no need for a big sql query.\r\n\r\nI cadged the streaming code from the reports controller, so cut and pasty, but seemed warranted. There currently isn't a limit on the result set size that it will attempt to return. And maybe I should tune the page size - currently set to 100.\r\n\r\nThe column headers are hard coded and the enum values untranslated because the locale isn't available on the backend. I could do something about this if necessary.\r\n\r\nHad to override the pagination summary template to poke the button in.\r\n\r\ntl:dr","created_at":"2015-06-04T18:43:51Z","updated_at":"2015-06-04T23:48:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"62ef96f42b448b1183b7ea95d82cb89bea7244a8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/1/commits","review_comments_url":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/1/comments","review_comment_url":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hudmol/nla_accession_reports/issues/1/comments","statuses_url":"https://api.github.com/repos/hudmol/nla_accession_reports/statuses/352ae4baf7c261eed09fb37554620482d4020cee","head":{"label":"hudmol:csv-from-search","ref":"csv-from-search","sha":"352ae4baf7c261eed09fb37554620482d4020cee","user":{"login":"hudmol","id":1821448,"avatar_url":"https://avatars.githubusercontent.com/u/1821448?v=3","gravatar_id":"","url":"https://api.github.com/users/hudmol","html_url":"https://github.com/hudmol","followers_url":"https://api.github.com/users/hudmol/followers","following_url":"https://api.github.com/users/hudmol/following{/other_user}","gists_url":"https://api.github.com/users/hudmol/gists{/gist_id}","starred_url":"https://api.github.com/users/hudmol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hudmol/subscriptions","organizations_url":"https://api.github.com/users/hudmol/orgs","repos_url":"https://api.github.com/users/hudmol/repos","events_url":"https://api.github.com/users/hudmol/events{/privacy}","received_events_url":"https://api.github.com/users/hudmol/received_events","type":"Organization","site_admin":false},"repo":{"id":35139767,"name":"nla_accession_reports","full_name":"hudmol/nla_accession_reports","owner":{"login":"hudmol","id":1821448,"avatar_url":"https://avatars.githubusercontent.com/u/1821448?v=3","gravatar_id":"","url":"https://api.github.com/users/hudmol","html_url":"https://github.com/hudmol","followers_url":"https://api.github.com/users/hudmol/followers","following_url":"https://api.github.com/users/hudmol/following{/other_user}","gists_url":"https://api.github.com/users/hudmol/gists{/gist_id}","starred_url":"https://api.github.com/users/hudmol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hudmol/subscriptions","organizations_url":"https://api.github.com/users/hudmol/orgs","repos_url":"https://api.github.com/users/hudmol/repos","events_url":"https://api.github.com/users/hudmol/events{/privacy}","received_events_url":"https://api.github.com/users/hudmol/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hudmol/nla_accession_reports","description":"An ArchivesSpace plugin to introduce extra Accession reports","fork":false,"url":"https://api.github.com/repos/hudmol/nla_accession_reports","forks_url":"https://api.github.com/repos/hudmol/nla_accession_reports/forks","keys_url":"https://api.github.com/repos/hudmol/nla_accession_reports/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hudmol/nla_accession_reports/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hudmol/nla_accession_reports/teams","hooks_url":"https://api.github.com/repos/hudmol/nla_accession_reports/hooks","issue_events_url":"https://api.github.com/repos/hudmol/nla_accession_reports/issues/events{/number}","events_url":"https://api.github.com/repos/hudmol/nla_accession_reports/events","assignees_url":"https://api.github.com/repos/hudmol/nla_accession_reports/assignees{/user}","branches_url":"https://api.github.com/repos/hudmol/nla_accession_reports/branches{/branch}","tags_url":"https://api.github.com/repos/hudmol/nla_accession_reports/tags","blobs_url":"https://api.github.com/repos/hudmol/nla_accession_reports/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hudmol/nla_accession_reports/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hudmol/nla_accession_reports/git/refs{/sha}","trees_url":"https://api.github.com/repos/hudmol/nla_accession_reports/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hudmol/nla_accession_reports/statuses/{sha}","languages_url":"https://api.github.com/repos/hudmol/nla_accession_reports/languages","stargazers_url":"https://api.github.com/repos/hudmol/nla_accession_reports/stargazers","contributors_url":"https://api.github.com/repos/hudmol/nla_accession_reports/contributors","subscribers_url":"https://api.github.com/repos/hudmol/nla_accession_reports/subscribers","subscription_url":"https://api.github.com/repos/hudmol/nla_accession_reports/subscription","commits_url":"https://api.github.com/repos/hudmol/nla_accession_reports/commits{/sha}","git_commits_url":"https://api.github.com/repos/hudmol/nla_accession_reports/git/commits{/sha}","comments_url":"https://api.github.com/repos/hudmol/nla_accession_reports/comments{/number}","issue_comment_url":"https://api.github.com/repos/hudmol/nla_accession_reports/issues/comments{/number}","contents_url":"https://api.github.com/repos/hudmol/nla_accession_reports/contents/{+path}","compare_url":"https://api.github.com/repos/hudmol/nla_accession_reports/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hudmol/nla_accession_reports/merges","archive_url":"https://api.github.com/repos/hudmol/nla_accession_reports/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hudmol/nla_accession_reports/downloads","issues_url":"https://api.github.com/repos/hudmol/nla_accession_reports/issues{/number}","pulls_url":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls{/number}","milestones_url":"https://api.github.com/repos/hudmol/nla_accession_reports/milestones{/number}","notifications_url":"https://api.github.com/repos/hudmol/nla_accession_reports/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hudmol/nla_accession_reports/labels{/name}","releases_url":"https://api.github.com/repos/hudmol/nla_accession_reports/releases{/id}","created_at":"2015-05-06T04:41:35Z","updated_at":"2015-05-06T10:27:37Z","pushed_at":"2015-06-04T18:43:51Z","git_url":"git://github.com/hudmol/nla_accession_reports.git","ssh_url":"git@github.com:hudmol/nla_accession_reports.git","clone_url":"https://github.com/hudmol/nla_accession_reports.git","svn_url":"https://github.com/hudmol/nla_accession_reports","homepage":null,"size":184,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"hudmol:master","ref":"master","sha":"0fa72bf66768a91b316094e952f36f36c020e401","user":{"login":"hudmol","id":1821448,"avatar_url":"https://avatars.githubusercontent.com/u/1821448?v=3","gravatar_id":"","url":"https://api.github.com/users/hudmol","html_url":"https://github.com/hudmol","followers_url":"https://api.github.com/users/hudmol/followers","following_url":"https://api.github.com/users/hudmol/following{/other_user}","gists_url":"https://api.github.com/users/hudmol/gists{/gist_id}","starred_url":"https://api.github.com/users/hudmol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hudmol/subscriptions","organizations_url":"https://api.github.com/users/hudmol/orgs","repos_url":"https://api.github.com/users/hudmol/repos","events_url":"https://api.github.com/users/hudmol/events{/privacy}","received_events_url":"https://api.github.com/users/hudmol/received_events","type":"Organization","site_admin":false},"repo":{"id":35139767,"name":"nla_accession_reports","full_name":"hudmol/nla_accession_reports","owner":{"login":"hudmol","id":1821448,"avatar_url":"https://avatars.githubusercontent.com/u/1821448?v=3","gravatar_id":"","url":"https://api.github.com/users/hudmol","html_url":"https://github.com/hudmol","followers_url":"https://api.github.com/users/hudmol/followers","following_url":"https://api.github.com/users/hudmol/following{/other_user}","gists_url":"https://api.github.com/users/hudmol/gists{/gist_id}","starred_url":"https://api.github.com/users/hudmol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hudmol/subscriptions","organizations_url":"https://api.github.com/users/hudmol/orgs","repos_url":"https://api.github.com/users/hudmol/repos","events_url":"https://api.github.com/users/hudmol/events{/privacy}","received_events_url":"https://api.github.com/users/hudmol/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hudmol/nla_accession_reports","description":"An ArchivesSpace plugin to introduce extra Accession reports","fork":false,"url":"https://api.github.com/repos/hudmol/nla_accession_reports","forks_url":"https://api.github.com/repos/hudmol/nla_accession_reports/forks","keys_url":"https://api.github.com/repos/hudmol/nla_accession_reports/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hudmol/nla_accession_reports/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hudmol/nla_accession_reports/teams","hooks_url":"https://api.github.com/repos/hudmol/nla_accession_reports/hooks","issue_events_url":"https://api.github.com/repos/hudmol/nla_accession_reports/issues/events{/number}","events_url":"https://api.github.com/repos/hudmol/nla_accession_reports/events","assignees_url":"https://api.github.com/repos/hudmol/nla_accession_reports/assignees{/user}","branches_url":"https://api.github.com/repos/hudmol/nla_accession_reports/branches{/branch}","tags_url":"https://api.github.com/repos/hudmol/nla_accession_reports/tags","blobs_url":"https://api.github.com/repos/hudmol/nla_accession_reports/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hudmol/nla_accession_reports/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hudmol/nla_accession_reports/git/refs{/sha}","trees_url":"https://api.github.com/repos/hudmol/nla_accession_reports/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hudmol/nla_accession_reports/statuses/{sha}","languages_url":"https://api.github.com/repos/hudmol/nla_accession_reports/languages","stargazers_url":"https://api.github.com/repos/hudmol/nla_accession_reports/stargazers","contributors_url":"https://api.github.com/repos/hudmol/nla_accession_reports/contributors","subscribers_url":"https://api.github.com/repos/hudmol/nla_accession_reports/subscribers","subscription_url":"https://api.github.com/repos/hudmol/nla_accession_reports/subscription","commits_url":"https://api.github.com/repos/hudmol/nla_accession_reports/commits{/sha}","git_commits_url":"https://api.github.com/repos/hudmol/nla_accession_reports/git/commits{/sha}","comments_url":"https://api.github.com/repos/hudmol/nla_accession_reports/comments{/number}","issue_comment_url":"https://api.github.com/repos/hudmol/nla_accession_reports/issues/comments{/number}","contents_url":"https://api.github.com/repos/hudmol/nla_accession_reports/contents/{+path}","compare_url":"https://api.github.com/repos/hudmol/nla_accession_reports/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hudmol/nla_accession_reports/merges","archive_url":"https://api.github.com/repos/hudmol/nla_accession_reports/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hudmol/nla_accession_reports/downloads","issues_url":"https://api.github.com/repos/hudmol/nla_accession_reports/issues{/number}","pulls_url":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls{/number}","milestones_url":"https://api.github.com/repos/hudmol/nla_accession_reports/milestones{/number}","notifications_url":"https://api.github.com/repos/hudmol/nla_accession_reports/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hudmol/nla_accession_reports/labels{/name}","releases_url":"https://api.github.com/repos/hudmol/nla_accession_reports/releases{/id}","created_at":"2015-05-06T04:41:35Z","updated_at":"2015-05-06T10:27:37Z","pushed_at":"2015-06-04T18:43:51Z","git_url":"git://github.com/hudmol/nla_accession_reports.git","ssh_url":"git@github.com:hudmol/nla_accession_reports.git","clone_url":"https://github.com/hudmol/nla_accession_reports.git","svn_url":"https://github.com/hudmol/nla_accession_reports","homepage":null,"size":184,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/1"},"html":{"href":"https://github.com/hudmol/nla_accession_reports/pull/1"},"issue":{"href":"https://api.github.com/repos/hudmol/nla_accession_reports/issues/1"},"comments":{"href":"https://api.github.com/repos/hudmol/nla_accession_reports/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hudmol/nla_accession_reports/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/hudmol/nla_accession_reports/statuses/352ae4baf7c261eed09fb37554620482d4020cee"}}}}