module Support
  module Services
    class OwsNotifications
      include HTTParty

      base_uri DOMAINS[:ows_notifications]

      class << self
        def get_subscriptions(user_id, vendor_id, account_type)
          path = "/user/subscriptions"
          headers = { "Orchard-User-Id" => user_id.to_s,
                      "Grass-Account-Type" => account_type.to_s,
                      "Grass-Account-Id" => vendor_id.to_s }

          response = get(
            path,
            headers: headers
          )
          verify_success(response)
          JSON.parse(response.body)
        end

        private

        def verify_success(response)
          return if response.code == 200
          fail(
            "request to ows-notifications did not succeed:"\
            " #{JSON.parse(response.body)}"
          )
        end
      end
    end
  end
end
