/**
 * Copyright (C) 2015 Zalando SE (http://tech.zalando.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.zalando.github.spring;

import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriTemplate;
import org.zalando.github.Issue;
import org.zalando.github.IssueRequest;
import org.zalando.github.IssuesOperations;

/**
 * 
 * @author jbellmann
 *
 */
public class IssuesTemplate implements IssuesOperations {

	private RestTemplate restTemplate;

	public IssuesTemplate(RestTemplate restTemplate) {
		this.restTemplate = restTemplate;
	}

	@Override
	public List<Issue> listAllIssues() {
		return new ArrayList<Issue>(0);
	}

	@Override
	public List<Issue> listUserIssues() {
		return new ArrayList<Issue>(0);
	}

	@Override
	public List<Issue> listOrganizationIssues(String organization) {
		return new ArrayList<Issue>(0);
	}

	@Override
	public Issue createIssue(IssueRequest issueRequest, String owner, String repo) {
		Map<String, Object> uriVariables = new HashMap<>();
		uriVariables.put("owner", owner);
		uriVariables.put("repo", repo);

		URI uri = new UriTemplate(buildUriString("/repos/{owner}/{repo}/issues")).expand(uriVariables);
		RequestEntity<IssueRequest> entity = RequestEntity.post(uri).contentType(MediaType.APPLICATION_JSON)
				.body(issueRequest);

		ResponseEntity<Issue> responseEntity = getRestTemplate().exchange(entity, Issue.class);
		return responseEntity.getBody();
	}

	protected RestTemplate getRestTemplate() {
		return restTemplate;
	}

	protected UriTemplate buildUriTemplate(String path) {
		return new UriTemplate(buildUriString(path));
	}

	protected String buildUriString(String path) {
		return "https://api.github.com" + path;
	}

}

@@ -909,32 +909,86 @@
 ResponseEntity;%0A
+import org.springframework.web.client.RestOperations;%0A
 import org.sprin
@@ -1298,37 +1298,41 @@
 ate Rest
-Template restTemplate
+Operations restOperations
 ;%0A%0A%09publ
@@ -1357,67 +1357,75 @@
 Rest
-Template restTemplate) %7B%0A%09%09this.restTemplate = restTemplate
+Operations restOperations) %7B%0A%09%09this.restOperations = restOperations
 ;%0A%09%7D
@@ -2209,24 +2209,26 @@
  getRest
-Template
+Operations
 ().excha
@@ -2311,32 +2311,36 @@
 Rest
-Template getRestTemplate
+Operations getRestOperations
 () %7B
@@ -2353,24 +2353,26 @@
 urn rest
-Template
+Operations
 ;%0A%09%7D%0A%0A%09p

use RestOperations to use different implementations of RestTemplate