{"action":"created","comment":{"url":"https://api.github.com/repos/sharetribe/sharetribe/pulls/comments/77609336","id":77609336,"diff_hunk":"@@ -0,0 +1,73 @@\n+module ListingIndexService::Search\n+\n+  class DiscoveryAdapter < SearchEngineAdapter\n+    API_KEY = APP_CONFIG.external_search_apikey\n+    SEARCH_URL = APP_CONFIG.external_search_url\n+\n+    def initialize(raise_errors:)\n+      logger = ::Logger.new(STDOUT)\n+      logger.level = ::Logger::INFO # log only on INFO level so that secrets are not logged\n+      @conn = Faraday.new(url: SEARCH_URL) do |c|\n+         c.request  :url_encoded             # form-encode POST params\n+         c.response :logger, logger          # log requests to STDOUT\n+         c.response :encoding\n+         c.adapter  Faraday.default_adapter  # make requests with Net::HTTP\n+         c.use Faraday::Response::RaiseError if raise_errors\n+      end\n+    end\n+\n+    def search(community_id:, search:, includes: nil)\n+      path_base = \"/discovery/#{community_id}/listings/query\"\n+      begin\n+        res = @conn.get do |req|\n+          req.url(path_base, format_params(search))\n+          req.headers['Authorization'] = \"apikey key=#{API_KEY}\"\n+        end\n+        result = res.body\n+        Result::Success.new(result)\n+      rescue StandardError => e\n+        Result::Error.new(e)\n+      end\n+    end\n+\n+    private\n+\n+    def format_params(original)\n+      location_params =\n+        if(original[:latitude].present? && original[:longitude].present?)\n+          { :'search[lat]' => original[:latitude],\n+            :'search[lng]' => original[:longitude],\n+            :'search[distance_unit]' => original[:distance_unit],\n+            :'search[scale]' => original[:scale],\n+            :'search[offset]' => original[:offset],\n+            :'filter[distance_max]' => original[:distance_max] }\n+        else\n+          {}\n+        end\n+\n+      custom_fields = Maybe(original[:fields]).map { |fields|\n+        fields.select { |f| [:numeric_range, :selection_group].include?(f[:type]) }\n+        fields.map { |f|\n+          if f[:type]  == :numeric_range\n+            [:\"custom[#{f[:id]}]\", \"double:#{f[:value].first}:#{f[:value].last}\"]\n+          else\n+            [:\"custom[#{f[:id]}]\", \"opt:#{f[:operator]}:#{f[:value].join(\",\")}\"]\n+          end\n+        }.to_h\n+      }.or_else({})\n+\n+      {\n+       :'search[keywords]' => original[:keywords],\n+       :'page[number]' => original[:page],\n+       :'page[size]' => original[:per_page],\n+       :'filter[price_min]' => Maybe(original[:price_cents]).map{ |p| p.min }.or_else(nil),\n+       :'filter[price_max]' => Maybe(original[:price_cents]).map{ |p| p.max }.or_else(nil),\n+       :'filter[omit_closed]' => !original[:include_closed],\n+       :'filter[listing_shape_ids]' => Maybe(original[:listing_shape_ids]).join(\",\").or_else(nil),\n+       :'filter[category_ids]' => Maybe(original[:categories]).join(\",\").or_else(nil),\n+       :'search[locale]' => original[:locale],\n+       :sort => original[:sort]\n+      }.merge(location_params).merge(custom_fields).compact\n+    end\n+  end\n+end","path":"app/services/listing_index_service/search/discovery_adapter.rb","position":73,"original_position":73,"commit_id":"1afb107c10c896a0b0db6d4dc20fec537dbe3629","original_commit_id":"76bfef64d8314336afd3c28c4fcbfa175685238b","user":{"login":"Gnito","id":717315,"avatar_url":"https://avatars.githubusercontent.com/u/717315?v=3","gravatar_id":"","url":"https://api.github.com/users/Gnito","html_url":"https://github.com/Gnito","followers_url":"https://api.github.com/users/Gnito/followers","following_url":"https://api.github.com/users/Gnito/following{/other_user}","gists_url":"https://api.github.com/users/Gnito/gists{/gist_id}","starred_url":"https://api.github.com/users/Gnito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Gnito/subscriptions","organizations_url":"https://api.github.com/users/Gnito/orgs","repos_url":"https://api.github.com/users/Gnito/repos","events_url":"https://api.github.com/users/Gnito/events{/privacy}","received_events_url":"https://api.github.com/users/Gnito/received_events","type":"User","site_admin":false},"body":"👍 \r\nWe need to write something about this change to changelog.md. \r\n- DiscoveryAdapter might still change when Discovery API changes. \r\n- Change to pure DiscoveryAdapter (full deprecation) might still take a year or so (depends on how long we allow marketplaces to use current search page over the new one). ","created_at":"2016-09-06T10:23:00Z","updated_at":"2016-09-06T10:23:00Z","html_url":"https://github.com/sharetribe/sharetribe/pull/2507#discussion_r77609336","pull_request_url":"https://api.github.com/repos/sharetribe/sharetribe/pulls/2507","_links":{"self":{"href":"https://api.github.com/repos/sharetribe/sharetribe/pulls/comments/77609336"},"html":{"href":"https://github.com/sharetribe/sharetribe/pull/2507#discussion_r77609336"},"pull_request":{"href":"https://api.github.com/repos/sharetribe/sharetribe/pulls/2507"}}},"pull_request":{"url":"https://api.github.com/repos/sharetribe/sharetribe/pulls/2507","id":84080491,"html_url":"https://github.com/sharetribe/sharetribe/pull/2507","diff_url":"https://github.com/sharetribe/sharetribe/pull/2507.diff","patch_url":"https://github.com/sharetribe/sharetribe/pull/2507.patch","issue_url":"https://api.github.com/repos/sharetribe/sharetribe/issues/2507","number":2507,"state":"open","locked":false,"title":"Fetch home page data from Discovery API","user":{"login":"mporkola","id":432030,"avatar_url":"https://avatars.githubusercontent.com/u/432030?v=3","gravatar_id":"","url":"https://api.github.com/users/mporkola","html_url":"https://github.com/mporkola","followers_url":"https://api.github.com/users/mporkola/followers","following_url":"https://api.github.com/users/mporkola/following{/other_user}","gists_url":"https://api.github.com/users/mporkola/gists{/gist_id}","starred_url":"https://api.github.com/users/mporkola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mporkola/subscriptions","organizations_url":"https://api.github.com/users/mporkola/orgs","repos_url":"https://api.github.com/users/mporkola/repos","events_url":"https://api.github.com/users/mporkola/events{/privacy}","received_events_url":"https://api.github.com/users/mporkola/received_events","type":"User","site_admin":false},"body":"Use data from Discovery API to populate new browse view.","created_at":"2016-09-06T08:30:54Z","updated_at":"2016-09-06T10:23:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7b5811a26b2c6c753044e00a2102b7057aa3b7e8","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/sharetribe/sharetribe/pulls/2507/commits","review_comments_url":"https://api.github.com/repos/sharetribe/sharetribe/pulls/2507/comments","review_comment_url":"https://api.github.com/repos/sharetribe/sharetribe/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sharetribe/sharetribe/issues/2507/comments","statuses_url":"https://api.github.com/repos/sharetribe/sharetribe/statuses/1afb107c10c896a0b0db6d4dc20fec537dbe3629","head":{"label":"sharetribe:discovery-api-fetch","ref":"discovery-api-fetch","sha":"1afb107c10c896a0b0db6d4dc20fec537dbe3629","user":{"login":"sharetribe","id":1733898,"avatar_url":"https://avatars.githubusercontent.com/u/1733898?v=3","gravatar_id":"","url":"https://api.github.com/users/sharetribe","html_url":"https://github.com/sharetribe","followers_url":"https://api.github.com/users/sharetribe/followers","following_url":"https://api.github.com/users/sharetribe/following{/other_user}","gists_url":"https://api.github.com/users/sharetribe/gists{/gist_id}","starred_url":"https://api.github.com/users/sharetribe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharetribe/subscriptions","organizations_url":"https://api.github.com/users/sharetribe/orgs","repos_url":"https://api.github.com/users/sharetribe/repos","events_url":"https://api.github.com/users/sharetribe/events{/privacy}","received_events_url":"https://api.github.com/users/sharetribe/received_events","type":"Organization","site_admin":false},"repo":{"id":4447023,"name":"sharetribe","full_name":"sharetribe/sharetribe","owner":{"login":"sharetribe","id":1733898,"avatar_url":"https://avatars.githubusercontent.com/u/1733898?v=3","gravatar_id":"","url":"https://api.github.com/users/sharetribe","html_url":"https://github.com/sharetribe","followers_url":"https://api.github.com/users/sharetribe/followers","following_url":"https://api.github.com/users/sharetribe/following{/other_user}","gists_url":"https://api.github.com/users/sharetribe/gists{/gist_id}","starred_url":"https://api.github.com/users/sharetribe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharetribe/subscriptions","organizations_url":"https://api.github.com/users/sharetribe/orgs","repos_url":"https://api.github.com/users/sharetribe/repos","events_url":"https://api.github.com/users/sharetribe/events{/privacy}","received_events_url":"https://api.github.com/users/sharetribe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sharetribe/sharetribe","description":"Open source marketplace platform","fork":false,"url":"https://api.github.com/repos/sharetribe/sharetribe","forks_url":"https://api.github.com/repos/sharetribe/sharetribe/forks","keys_url":"https://api.github.com/repos/sharetribe/sharetribe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sharetribe/sharetribe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sharetribe/sharetribe/teams","hooks_url":"https://api.github.com/repos/sharetribe/sharetribe/hooks","issue_events_url":"https://api.github.com/repos/sharetribe/sharetribe/issues/events{/number}","events_url":"https://api.github.com/repos/sharetribe/sharetribe/events","assignees_url":"https://api.github.com/repos/sharetribe/sharetribe/assignees{/user}","branches_url":"https://api.github.com/repos/sharetribe/sharetribe/branches{/branch}","tags_url":"https://api.github.com/repos/sharetribe/sharetribe/tags","blobs_url":"https://api.github.com/repos/sharetribe/sharetribe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sharetribe/sharetribe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sharetribe/sharetribe/git/refs{/sha}","trees_url":"https://api.github.com/repos/sharetribe/sharetribe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sharetribe/sharetribe/statuses/{sha}","languages_url":"https://api.github.com/repos/sharetribe/sharetribe/languages","stargazers_url":"https://api.github.com/repos/sharetribe/sharetribe/stargazers","contributors_url":"https://api.github.com/repos/sharetribe/sharetribe/contributors","subscribers_url":"https://api.github.com/repos/sharetribe/sharetribe/subscribers","subscription_url":"https://api.github.com/repos/sharetribe/sharetribe/subscription","commits_url":"https://api.github.com/repos/sharetribe/sharetribe/commits{/sha}","git_commits_url":"https://api.github.com/repos/sharetribe/sharetribe/git/commits{/sha}","comments_url":"https://api.github.com/repos/sharetribe/sharetribe/comments{/number}","issue_comment_url":"https://api.github.com/repos/sharetribe/sharetribe/issues/comments{/number}","contents_url":"https://api.github.com/repos/sharetribe/sharetribe/contents/{+path}","compare_url":"https://api.github.com/repos/sharetribe/sharetribe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sharetribe/sharetribe/merges","archive_url":"https://api.github.com/repos/sharetribe/sharetribe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sharetribe/sharetribe/downloads","issues_url":"https://api.github.com/repos/sharetribe/sharetribe/issues{/number}","pulls_url":"https://api.github.com/repos/sharetribe/sharetribe/pulls{/number}","milestones_url":"https://api.github.com/repos/sharetribe/sharetribe/milestones{/number}","notifications_url":"https://api.github.com/repos/sharetribe/sharetribe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sharetribe/sharetribe/labels{/name}","releases_url":"https://api.github.com/repos/sharetribe/sharetribe/releases{/id}","deployments_url":"https://api.github.com/repos/sharetribe/sharetribe/deployments","created_at":"2012-05-25T15:34:17Z","updated_at":"2016-09-03T14:30:12Z","pushed_at":"2016-09-06T10:10:38Z","git_url":"git://github.com/sharetribe/sharetribe.git","ssh_url":"git@github.com:sharetribe/sharetribe.git","clone_url":"https://github.com/sharetribe/sharetribe.git","svn_url":"https://github.com/sharetribe/sharetribe","homepage":"https://www.sharetribe.com","size":117403,"stargazers_count":749,"watchers_count":749,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":503,"mirror_url":null,"open_issues_count":21,"forks":503,"open_issues":21,"watchers":749,"default_branch":"master"}},"base":{"label":"sharetribe:master","ref":"master","sha":"fa36e335c9b8bcb4ed4133f3ae33d050165be1eb","user":{"login":"sharetribe","id":1733898,"avatar_url":"https://avatars.githubusercontent.com/u/1733898?v=3","gravatar_id":"","url":"https://api.github.com/users/sharetribe","html_url":"https://github.com/sharetribe","followers_url":"https://api.github.com/users/sharetribe/followers","following_url":"https://api.github.com/users/sharetribe/following{/other_user}","gists_url":"https://api.github.com/users/sharetribe/gists{/gist_id}","starred_url":"https://api.github.com/users/sharetribe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharetribe/subscriptions","organizations_url":"https://api.github.com/users/sharetribe/orgs","repos_url":"https://api.github.com/users/sharetribe/repos","events_url":"https://api.github.com/users/sharetribe/events{/privacy}","received_events_url":"https://api.github.com/users/sharetribe/received_events","type":"Organization","site_admin":false},"repo":{"id":4447023,"name":"sharetribe","full_name":"sharetribe/sharetribe","owner":{"login":"sharetribe","id":1733898,"avatar_url":"https://avatars.githubusercontent.com/u/1733898?v=3","gravatar_id":"","url":"https://api.github.com/users/sharetribe","html_url":"https://github.com/sharetribe","followers_url":"https://api.github.com/users/sharetribe/followers","following_url":"https://api.github.com/users/sharetribe/following{/other_user}","gists_url":"https://api.github.com/users/sharetribe/gists{/gist_id}","starred_url":"https://api.github.com/users/sharetribe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharetribe/subscriptions","organizations_url":"https://api.github.com/users/sharetribe/orgs","repos_url":"https://api.github.com/users/sharetribe/repos","events_url":"https://api.github.com/users/sharetribe/events{/privacy}","received_events_url":"https://api.github.com/users/sharetribe/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sharetribe/sharetribe","description":"Open source marketplace platform","fork":false,"url":"https://api.github.com/repos/sharetribe/sharetribe","forks_url":"https://api.github.com/repos/sharetribe/sharetribe/forks","keys_url":"https://api.github.com/repos/sharetribe/sharetribe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sharetribe/sharetribe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sharetribe/sharetribe/teams","hooks_url":"https://api.github.com/repos/sharetribe/sharetribe/hooks","issue_events_url":"https://api.github.com/repos/sharetribe/sharetribe/issues/events{/number}","events_url":"https://api.github.com/repos/sharetribe/sharetribe/events","assignees_url":"https://api.github.com/repos/sharetribe/sharetribe/assignees{/user}","branches_url":"https://api.github.com/repos/sharetribe/sharetribe/branches{/branch}","tags_url":"https://api.github.com/repos/sharetribe/sharetribe/tags","blobs_url":"https://api.github.com/repos/sharetribe/sharetribe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sharetribe/sharetribe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sharetribe/sharetribe/git/refs{/sha}","trees_url":"https://api.github.com/repos/sharetribe/sharetribe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sharetribe/sharetribe/statuses/{sha}","languages_url":"https://api.github.com/repos/sharetribe/sharetribe/languages","stargazers_url":"https://api.github.com/repos/sharetribe/sharetribe/stargazers","contributors_url":"https://api.github.com/repos/sharetribe/sharetribe/contributors","subscribers_url":"https://api.github.com/repos/sharetribe/sharetribe/subscribers","subscription_url":"https://api.github.com/repos/sharetribe/sharetribe/subscription","commits_url":"https://api.github.com/repos/sharetribe/sharetribe/commits{/sha}","git_commits_url":"https://api.github.com/repos/sharetribe/sharetribe/git/commits{/sha}","comments_url":"https://api.github.com/repos/sharetribe/sharetribe/comments{/number}","issue_comment_url":"https://api.github.com/repos/sharetribe/sharetribe/issues/comments{/number}","contents_url":"https://api.github.com/repos/sharetribe/sharetribe/contents/{+path}","compare_url":"https://api.github.com/repos/sharetribe/sharetribe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sharetribe/sharetribe/merges","archive_url":"https://api.github.com/repos/sharetribe/sharetribe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sharetribe/sharetribe/downloads","issues_url":"https://api.github.com/repos/sharetribe/sharetribe/issues{/number}","pulls_url":"https://api.github.com/repos/sharetribe/sharetribe/pulls{/number}","milestones_url":"https://api.github.com/repos/sharetribe/sharetribe/milestones{/number}","notifications_url":"https://api.github.com/repos/sharetribe/sharetribe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sharetribe/sharetribe/labels{/name}","releases_url":"https://api.github.com/repos/sharetribe/sharetribe/releases{/id}","deployments_url":"https://api.github.com/repos/sharetribe/sharetribe/deployments","created_at":"2012-05-25T15:34:17Z","updated_at":"2016-09-03T14:30:12Z","pushed_at":"2016-09-06T10:10:38Z","git_url":"git://github.com/sharetribe/sharetribe.git","ssh_url":"git@github.com:sharetribe/sharetribe.git","clone_url":"https://github.com/sharetribe/sharetribe.git","svn_url":"https://github.com/sharetribe/sharetribe","homepage":"https://www.sharetribe.com","size":117403,"stargazers_count":749,"watchers_count":749,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":503,"mirror_url":null,"open_issues_count":21,"forks":503,"open_issues":21,"watchers":749,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sharetribe/sharetribe/pulls/2507"},"html":{"href":"https://github.com/sharetribe/sharetribe/pull/2507"},"issue":{"href":"https://api.github.com/repos/sharetribe/sharetribe/issues/2507"},"comments":{"href":"https://api.github.com/repos/sharetribe/sharetribe/issues/2507/comments"},"review_comments":{"href":"https://api.github.com/repos/sharetribe/sharetribe/pulls/2507/comments"},"review_comment":{"href":"https://api.github.com/repos/sharetribe/sharetribe/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sharetribe/sharetribe/pulls/2507/commits"},"statuses":{"href":"https://api.github.com/repos/sharetribe/sharetribe/statuses/1afb107c10c896a0b0db6d4dc20fec537dbe3629"}}}}
{"actor":{"display_login":"Gnito"}}