<ConnectionManager Name="OpenTable" RuntimeVersion="" Help="http://www.cozyroc.com/ssis/opentable-connection" xmlns="http://www.cozyroc.com/schema/rcm-config-1.0.xsd">
	<Service EndPoint="https://platform.opentable.com/" />

	<Authentication Name="OAuth">
		<Documentation>https://platform.opentable.com/documentation/#obtaining-an-access-token</Documentation>

		<User>
			<Parameter Name="client_id">
				<Documentation>Required. Specify client ID.</Documentation>
			</Parameter>
			<Parameter Name="client_secret" Type="password">
				<Documentation>Required. Specify client secret.</Documentation>
			</Parameter>
		</User>

		<Token Url="https://{{=connection.serverHost.indexOf('otqa.') == -1 ? 'oauth' : 'oauth-pp'}}.opentable.com/api/v2/oauth/token" Method="POST" Result="{{=response.access_token}}">
			<Parameters>
				<Parameter Name="Authorization" Value="Basic {{=Base64.encode(connection.user.client_id + ':' + connection.user.client_secret)}}" Type="HttpHeader" />
				<Parameter Name="grant_type" Value="client_credentials" />
			</Parameters>

			<Refresh Url="https://{{=connection.serverHost.indexOf('otqa.') == -1 ? 'oauth' : 'oauth-pp'}}.opentable.com/api/v2/oauth/token" Method="POST" Result="{{=response.access_token}}" Expiration="{{=Date.now() + (response.expires_in - 300) * 1000}}">
				<Parameters>
					<Parameter Name="Authorization" Value="Basic {{=Base64.encode(connection.user.client_id + ':' + connection.user.client_secret)}}" Type="HttpHeader" />
					<Parameter Name="grant_type" Value="client_credentials" />
				</Parameters>
			</Refresh>
		</Token>

		<Parameters>
			<Parameter Name="Authorization" Value="bearer {{=token.Access}}" Type="HttpHeader" />
		</Parameters>
	</Authentication>

	<Resources>
		<Template>
			<Field Name="ShortText" DataType="DT_WSTR" Length="255" />
			<Field Name="LongText" DataType="DT_WSTR" Length="1000" />
			<Field Name="DateTime" DataType="DT_DBTIMESTAMP" />
			<Field Name="Date" DataType="DT_DBDATE" />

			<Resource Name="Base">
				<Read Result="{{=response}}">
					<Parameters>
						<Parameter Name="offset" Value="{{=parameters.iterator}}" />
						<Parameter Name="limit" Value="{{=parameters.batchSize}}" />
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
					</Parameters>

					<Iterator>
						<Next Value="{{=parseInt(parameters.iterator || 0) + parameters.batchSize}}" />
					</Iterator>
				</Read>

				<Create Method="POST">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="application/json" Value="{{=item}}" Type="Body" />
					</Parameters>
				</Create>

				<Update Method="PUT">
					<Parameters>
						<Parameter Name="_includeUserParameters" Value="{{=parameters}}" />
						<Parameter Name="application/json" Value="{{=item}}" Type="Body" />
					</Parameters>
				</Update>

				<Delete Method="DELETE" />
			</Resource>
		</Template>
	</Resources>

	<Script>
		<Module Name="Main">
			<![CDATA[
require("underscore");
require("base64");

		]]>
		</Module>
	</Script>
</ConnectionManager>