{"action":"created","comment":{"url":"https://api.github.com/repos/bundler/gemstash/pulls/comments/41086113","id":41086113,"diff_hunk":"@@ -0,0 +1,143 @@\n+require \"gemstash\"\n+require \"cgi\"\n+\n+module Gemstash\n+  module GemSource\n+    # GemSource that purely redirects to the upstream server.\n+    class RedirectSource < Gemstash::GemSource::Base\n+      def self.matches?(env)\n+        match = chomp_path(env, %r{\\A/redirect/([^/]+)})\n+        return false unless match\n+        env[\"gemstash.upstream\"] = CGI.unescape(match[1])\n+        true\n+      end\n+\n+      def serve_root\n+        cache_control :public, :max_age => 31_536_000\n+        redirect web_helper.url(nil, request.query_string)\n+      end\n+\n+      def serve_add_gem\n+        halt 403, \"Cannot add gem to an upstream server!\"\n+      end\n+\n+      def serve_yank\n+        halt 403, \"Cannot yank from an upstream server!\"\n+      end\n+\n+      def serve_unyank\n+        halt 403, \"Cannot unyank from an upstream server!\"\n+      end\n+\n+      def serve_add_spec_json\n+        halt 403, \"Cannot add spec to an upstream server!\"\n+      end\n+\n+      def serve_remove_spec_json\n+        halt 403, \"Cannot remove spec from an upstream server!\"\n+      end\n+\n+      def serve_dependencies\n+        redirect web_helper.url(\"/api/v1/dependencies\", request.query_string)\n+      end\n+\n+      def serve_dependencies_json\n+        redirect web_helper.url(\"/api/v1/dependencies.json\", request.query_string)\n+      end\n+\n+      def serve_names\n+        redirect web_helper.url(\"/names\", request.query_string)\n+      end\n+\n+      def serve_versions\n+        redirect web_helper.url(\"/versions\", request.query_string)\n+      end\n+\n+      def serve_info(name)\n+        redirect web_helper.url(\"/info/#{name}\", request.query_string)\n+      end\n+\n+      def serve_marshal(id)\n+        redirect web_helper.url(\"/quick/Marshal.4.8/#{id}\", request.query_string)\n+      end\n+\n+      def serve_actual_gem(id)\n+        redirect web_helper.url(\"/fetch/actual/gem/#{id}\", request.query_string)\n+      end\n+\n+      def serve_gem(id)\n+        redirect web_helper.url(\"/gems/#{id}\", request.query_string)\n+      end\n+\n+      def serve_latest_specs\n+        redirect web_helper.url(\"/latest_specs.4.8.gz\", request.query_string)\n+      end\n+\n+      def serve_specs\n+        redirect web_helper.url(\"/specs.4.8.gz\", request.query_string)\n+      end\n+\n+      def serve_prerelease_specs\n+        redirect web_helper.url(\"/prerelease_specs.4.8.gz\", request.query_string)\n+      end\n+\n+    private\n+\n+      def web_helper\n+        @web_helper ||= Gemstash::WebHelper.new(server_url: env[\"gemstash.upstream\"])","path":"lib/gemstash/gem_source/upstream_source.rb","position":87,"original_position":87,"commit_id":"a5e74108c5029e1ab14487c55a4ee2af9df32918","original_commit_id":"a5e74108c5029e1ab14487c55a4ee2af9df32918","user":{"login":"pcarranza","id":4496338,"avatar_url":"https://avatars.githubusercontent.com/u/4496338?v=3","gravatar_id":"","url":"https://api.github.com/users/pcarranza","html_url":"https://github.com/pcarranza","followers_url":"https://api.github.com/users/pcarranza/followers","following_url":"https://api.github.com/users/pcarranza/following{/other_user}","gists_url":"https://api.github.com/users/pcarranza/gists{/gist_id}","starred_url":"https://api.github.com/users/pcarranza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcarranza/subscriptions","organizations_url":"https://api.github.com/users/pcarranza/orgs","repos_url":"https://api.github.com/users/pcarranza/repos","events_url":"https://api.github.com/users/pcarranza/events{/privacy}","received_events_url":"https://api.github.com/users/pcarranza/received_events","type":"User","site_admin":false},"body":"Just to share a thought, I think we got to the same place with 2 different paths.\r\n\r\nThe branch I am working with I am basically building the \"helper\" (which I renamed to HTTPClient), but I am injecting a client builder which knows how to return *something* that knows how to create a client. This is so basically because of the same thing: we are changing the upstream url.\r\n\r\nBy injecting this \"builder\", you can also inject it in testing, and then you don't need to stub the methods to control that in testing. But this is a WIP in my branch still.","created_at":"2015-10-03T11:21:09Z","updated_at":"2015-10-03T11:21:09Z","html_url":"https://github.com/bundler/gemstash/pull/11#discussion_r41086113","pull_request_url":"https://api.github.com/repos/bundler/gemstash/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/comments/41086113"},"html":{"href":"https://github.com/bundler/gemstash/pull/11#discussion_r41086113"},"pull_request":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/bundler/gemstash/pulls/11","id":46615503,"html_url":"https://github.com/bundler/gemstash/pull/11","diff_url":"https://github.com/bundler/gemstash/pull/11.diff","patch_url":"https://github.com/bundler/gemstash/pull/11.patch","issue_url":"https://api.github.com/repos/bundler/gemstash/issues/11","number":11,"state":"open","locked":false,"title":"Gem sources","user":{"login":"smellsblue","id":150632,"avatar_url":"https://avatars.githubusercontent.com/u/150632?v=3","gravatar_id":"","url":"https://api.github.com/users/smellsblue","html_url":"https://github.com/smellsblue","followers_url":"https://api.github.com/users/smellsblue/followers","following_url":"https://api.github.com/users/smellsblue/following{/other_user}","gists_url":"https://api.github.com/users/smellsblue/gists{/gist_id}","starred_url":"https://api.github.com/users/smellsblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smellsblue/subscriptions","organizations_url":"https://api.github.com/users/smellsblue/orgs","repos_url":"https://api.github.com/users/smellsblue/repos","events_url":"https://api.github.com/users/smellsblue/events{/privacy}","received_events_url":"https://api.github.com/users/smellsblue/received_events","type":"User","site_admin":false},"body":"Factor gem sources to correspond to upstreams, use Rack middleware to figure out which source to use, and push all meaningful logic out of Gemstash::Web.","created_at":"2015-10-02T09:08:40Z","updated_at":"2015-10-03T11:21:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b05eb4121ebda7e3bd981601b3e305f810876c8b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bundler/gemstash/pulls/11/commits","review_comments_url":"https://api.github.com/repos/bundler/gemstash/pulls/11/comments","review_comment_url":"https://api.github.com/repos/bundler/gemstash/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bundler/gemstash/issues/11/comments","statuses_url":"https://api.github.com/repos/bundler/gemstash/statuses/a5e74108c5029e1ab14487c55a4ee2af9df32918","head":{"label":"smellsblue:gem-source","ref":"gem-source","sha":"a5e74108c5029e1ab14487c55a4ee2af9df32918","user":{"login":"smellsblue","id":150632,"avatar_url":"https://avatars.githubusercontent.com/u/150632?v=3","gravatar_id":"","url":"https://api.github.com/users/smellsblue","html_url":"https://github.com/smellsblue","followers_url":"https://api.github.com/users/smellsblue/followers","following_url":"https://api.github.com/users/smellsblue/following{/other_user}","gists_url":"https://api.github.com/users/smellsblue/gists{/gist_id}","starred_url":"https://api.github.com/users/smellsblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smellsblue/subscriptions","organizations_url":"https://api.github.com/users/smellsblue/orgs","repos_url":"https://api.github.com/users/smellsblue/repos","events_url":"https://api.github.com/users/smellsblue/events{/privacy}","received_events_url":"https://api.github.com/users/smellsblue/received_events","type":"User","site_admin":false},"repo":{"id":42747275,"name":"gemstash","full_name":"smellsblue/gemstash","owner":{"login":"smellsblue","id":150632,"avatar_url":"https://avatars.githubusercontent.com/u/150632?v=3","gravatar_id":"","url":"https://api.github.com/users/smellsblue","html_url":"https://github.com/smellsblue","followers_url":"https://api.github.com/users/smellsblue/followers","following_url":"https://api.github.com/users/smellsblue/following{/other_user}","gists_url":"https://api.github.com/users/smellsblue/gists{/gist_id}","starred_url":"https://api.github.com/users/smellsblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smellsblue/subscriptions","organizations_url":"https://api.github.com/users/smellsblue/orgs","repos_url":"https://api.github.com/users/smellsblue/repos","events_url":"https://api.github.com/users/smellsblue/events{/privacy}","received_events_url":"https://api.github.com/users/smellsblue/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/smellsblue/gemstash","description":null,"fork":true,"url":"https://api.github.com/repos/smellsblue/gemstash","forks_url":"https://api.github.com/repos/smellsblue/gemstash/forks","keys_url":"https://api.github.com/repos/smellsblue/gemstash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/smellsblue/gemstash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/smellsblue/gemstash/teams","hooks_url":"https://api.github.com/repos/smellsblue/gemstash/hooks","issue_events_url":"https://api.github.com/repos/smellsblue/gemstash/issues/events{/number}","events_url":"https://api.github.com/repos/smellsblue/gemstash/events","assignees_url":"https://api.github.com/repos/smellsblue/gemstash/assignees{/user}","branches_url":"https://api.github.com/repos/smellsblue/gemstash/branches{/branch}","tags_url":"https://api.github.com/repos/smellsblue/gemstash/tags","blobs_url":"https://api.github.com/repos/smellsblue/gemstash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/smellsblue/gemstash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/smellsblue/gemstash/git/refs{/sha}","trees_url":"https://api.github.com/repos/smellsblue/gemstash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/smellsblue/gemstash/statuses/{sha}","languages_url":"https://api.github.com/repos/smellsblue/gemstash/languages","stargazers_url":"https://api.github.com/repos/smellsblue/gemstash/stargazers","contributors_url":"https://api.github.com/repos/smellsblue/gemstash/contributors","subscribers_url":"https://api.github.com/repos/smellsblue/gemstash/subscribers","subscription_url":"https://api.github.com/repos/smellsblue/gemstash/subscription","commits_url":"https://api.github.com/repos/smellsblue/gemstash/commits{/sha}","git_commits_url":"https://api.github.com/repos/smellsblue/gemstash/git/commits{/sha}","comments_url":"https://api.github.com/repos/smellsblue/gemstash/comments{/number}","issue_comment_url":"https://api.github.com/repos/smellsblue/gemstash/issues/comments{/number}","contents_url":"https://api.github.com/repos/smellsblue/gemstash/contents/{+path}","compare_url":"https://api.github.com/repos/smellsblue/gemstash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/smellsblue/gemstash/merges","archive_url":"https://api.github.com/repos/smellsblue/gemstash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/smellsblue/gemstash/downloads","issues_url":"https://api.github.com/repos/smellsblue/gemstash/issues{/number}","pulls_url":"https://api.github.com/repos/smellsblue/gemstash/pulls{/number}","milestones_url":"https://api.github.com/repos/smellsblue/gemstash/milestones{/number}","notifications_url":"https://api.github.com/repos/smellsblue/gemstash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/smellsblue/gemstash/labels{/name}","releases_url":"https://api.github.com/repos/smellsblue/gemstash/releases{/id}","created_at":"2015-09-18T21:13:32Z","updated_at":"2015-09-18T21:13:33Z","pushed_at":"2015-10-02T09:54:19Z","git_url":"git://github.com/smellsblue/gemstash.git","ssh_url":"git@github.com:smellsblue/gemstash.git","clone_url":"https://github.com/smellsblue/gemstash.git","svn_url":"https://github.com/smellsblue/gemstash","homepage":null,"size":163,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"bundler:master","ref":"master","sha":"3718b6e5305f79f52cd7c929d437a20620549de2","user":{"login":"bundler","id":1137638,"avatar_url":"https://avatars.githubusercontent.com/u/1137638?v=3","gravatar_id":"","url":"https://api.github.com/users/bundler","html_url":"https://github.com/bundler","followers_url":"https://api.github.com/users/bundler/followers","following_url":"https://api.github.com/users/bundler/following{/other_user}","gists_url":"https://api.github.com/users/bundler/gists{/gist_id}","starred_url":"https://api.github.com/users/bundler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bundler/subscriptions","organizations_url":"https://api.github.com/users/bundler/orgs","repos_url":"https://api.github.com/users/bundler/repos","events_url":"https://api.github.com/users/bundler/events{/privacy}","received_events_url":"https://api.github.com/users/bundler/received_events","type":"Organization","site_admin":false},"repo":{"id":42746109,"name":"gemstash","full_name":"bundler/gemstash","owner":{"login":"bundler","id":1137638,"avatar_url":"https://avatars.githubusercontent.com/u/1137638?v=3","gravatar_id":"","url":"https://api.github.com/users/bundler","html_url":"https://github.com/bundler","followers_url":"https://api.github.com/users/bundler/followers","following_url":"https://api.github.com/users/bundler/following{/other_user}","gists_url":"https://api.github.com/users/bundler/gists{/gist_id}","starred_url":"https://api.github.com/users/bundler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bundler/subscriptions","organizations_url":"https://api.github.com/users/bundler/orgs","repos_url":"https://api.github.com/users/bundler/repos","events_url":"https://api.github.com/users/bundler/events{/privacy}","received_events_url":"https://api.github.com/users/bundler/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bundler/gemstash","description":null,"fork":false,"url":"https://api.github.com/repos/bundler/gemstash","forks_url":"https://api.github.com/repos/bundler/gemstash/forks","keys_url":"https://api.github.com/repos/bundler/gemstash/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bundler/gemstash/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bundler/gemstash/teams","hooks_url":"https://api.github.com/repos/bundler/gemstash/hooks","issue_events_url":"https://api.github.com/repos/bundler/gemstash/issues/events{/number}","events_url":"https://api.github.com/repos/bundler/gemstash/events","assignees_url":"https://api.github.com/repos/bundler/gemstash/assignees{/user}","branches_url":"https://api.github.com/repos/bundler/gemstash/branches{/branch}","tags_url":"https://api.github.com/repos/bundler/gemstash/tags","blobs_url":"https://api.github.com/repos/bundler/gemstash/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bundler/gemstash/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bundler/gemstash/git/refs{/sha}","trees_url":"https://api.github.com/repos/bundler/gemstash/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bundler/gemstash/statuses/{sha}","languages_url":"https://api.github.com/repos/bundler/gemstash/languages","stargazers_url":"https://api.github.com/repos/bundler/gemstash/stargazers","contributors_url":"https://api.github.com/repos/bundler/gemstash/contributors","subscribers_url":"https://api.github.com/repos/bundler/gemstash/subscribers","subscription_url":"https://api.github.com/repos/bundler/gemstash/subscription","commits_url":"https://api.github.com/repos/bundler/gemstash/commits{/sha}","git_commits_url":"https://api.github.com/repos/bundler/gemstash/git/commits{/sha}","comments_url":"https://api.github.com/repos/bundler/gemstash/comments{/number}","issue_comment_url":"https://api.github.com/repos/bundler/gemstash/issues/comments{/number}","contents_url":"https://api.github.com/repos/bundler/gemstash/contents/{+path}","compare_url":"https://api.github.com/repos/bundler/gemstash/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bundler/gemstash/merges","archive_url":"https://api.github.com/repos/bundler/gemstash/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bundler/gemstash/downloads","issues_url":"https://api.github.com/repos/bundler/gemstash/issues{/number}","pulls_url":"https://api.github.com/repos/bundler/gemstash/pulls{/number}","milestones_url":"https://api.github.com/repos/bundler/gemstash/milestones{/number}","notifications_url":"https://api.github.com/repos/bundler/gemstash/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bundler/gemstash/labels{/name}","releases_url":"https://api.github.com/repos/bundler/gemstash/releases{/id}","created_at":"2015-09-18T20:41:41Z","updated_at":"2015-09-28T23:35:09Z","pushed_at":"2015-10-02T09:54:20Z","git_url":"git://github.com/bundler/gemstash.git","ssh_url":"git@github.com:bundler/gemstash.git","clone_url":"https://github.com/bundler/gemstash.git","svn_url":"https://github.com/bundler/gemstash","homepage":null,"size":402,"stargazers_count":17,"watchers_count":17,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":4,"forks":3,"open_issues":4,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/11"},"html":{"href":"https://github.com/bundler/gemstash/pull/11"},"issue":{"href":"https://api.github.com/repos/bundler/gemstash/issues/11"},"comments":{"href":"https://api.github.com/repos/bundler/gemstash/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bundler/gemstash/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/bundler/gemstash/statuses/a5e74108c5029e1ab14487c55a4ee2af9df32918"}}}}