├── spring-wpapi-test ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ └── java │ │ └── org │ │ └── kamranzafar │ │ └── spring │ │ └── wpapi │ │ └── test │ │ └── Application.java └── pom.xml ├── spring-wpapi-core ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── kamranzafar │ └── spring │ └── wpapi │ ├── Post.java │ ├── Guid.java │ ├── Title.java │ ├── Content.java │ ├── Excerpt.java │ ├── Page.java │ ├── RenderedContent.java │ ├── WpBase.java │ ├── Tag.java │ ├── MediaDetail.java │ ├── Category.java │ ├── PostType.java │ ├── Taxonomy.java │ ├── PostStatus.java │ ├── ImageMetaData.java │ ├── Media.java │ ├── Comment.java │ └── ContentBase.java ├── spring-wpapi-client ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── kamranzafar │ └── spring │ └── wpapi │ └── client │ ├── WpApiException.java │ ├── WpApiService.java │ ├── impl │ ├── TagService.java │ ├── PageService.java │ ├── PostService.java │ ├── MediaService.java │ ├── CommentService.java │ ├── CategoryService.java │ ├── PostTypeService.java │ ├── TaxonomyService.java │ └── PostStatusService.java │ ├── WpApiConfig.java │ ├── WpApiClient.java │ └── BaseService.java ├── README.md ├── .gitignore ├── pom.xml └── LICENSE.txt /spring-wpapi-test/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | wpapi.host=kamranzafar.org 2 | wpapi.port=443 3 | wpapi.https=true 4 | wpapi.username=admin 5 | wpapi.password=2012Inaaya! -------------------------------------------------------------------------------- /spring-wpapi-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | spring-wpapi 5 | org.kamranzafar.spring.wpapi 6 | 0.2-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | spring-wpapi-core 11 | 12 | 13 | -------------------------------------------------------------------------------- /spring-wpapi-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | spring-wpapi 5 | org.kamranzafar.spring.wpapi 6 | 0.2-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | spring-wpapi-client 11 | 12 | 13 | 14 | org.kamranzafar.spring.wpapi 15 | spring-wpapi-core 16 | ${project.version} 17 | 18 | 19 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Post.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | 22 | /** 23 | * Created by kamran on 07/08/16. 24 | */ 25 | @JsonIgnoreProperties(ignoreUnknown = true) 26 | public class Post extends ContentBase { 27 | } 28 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Guid.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | /** 21 | * Created by kamran on 05/08/16. 22 | */ 23 | public class Guid extends RenderedContent { 24 | public Guid() { 25 | } 26 | 27 | public Guid(String rendered) { 28 | super(rendered); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Title.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | /** 21 | * Created by kamran on 05/08/16. 22 | */ 23 | public class Title extends RenderedContent { 24 | public Title() { 25 | } 26 | 27 | public Title(String rendered) { 28 | super(rendered); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Content.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | /** 21 | * Created by kamran on 05/08/16. 22 | */ 23 | public class Content extends RenderedContent { 24 | public Content() { 25 | } 26 | 27 | public Content(String rendered) { 28 | super(rendered); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Excerpt.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | /** 21 | * Created by kamran on 05/08/16. 22 | */ 23 | public class Excerpt extends RenderedContent { 24 | public Excerpt() { 25 | } 26 | 27 | public Excerpt(String rendered) { 28 | super(rendered); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-wpapi-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | spring-wpapi 5 | org.kamranzafar.spring.wpapi 6 | 0.2-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | spring-wpapi-test 11 | 12 | 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-maven-plugin 17 | 18 | 19 | 20 | 21 | 22 | 23 | org.kamranzafar.spring.wpapi 24 | spring-wpapi-client 25 | ${project.version} 26 | 27 | 28 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/WpApiException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client; 19 | 20 | /** 21 | * Created by kamran on 07/08/16. 22 | */ 23 | public class WpApiException extends RuntimeException { 24 | public WpApiException(String message) { 25 | super(message); 26 | } 27 | 28 | public WpApiException(String message, Throwable cause) { 29 | super(message, cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/WpApiService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client; 19 | 20 | import java.util.Map; 21 | 22 | /** 23 | * Created by kamran on 07/08/16. 24 | */ 25 | public interface WpApiService { 26 | T[] getAll(); 27 | T[] getAll(Map params); 28 | T get(int id); 29 | T get(int id, Map params); 30 | void create(T obj); 31 | void update(T obj); 32 | void delete(int id); 33 | Class getType(); 34 | } 35 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Page.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | 22 | /** 23 | * Created by kamran on 05/08/16. 24 | */ 25 | @JsonIgnoreProperties(ignoreUnknown = true) 26 | public class Page extends ContentBase { 27 | private String template; 28 | 29 | public String getTemplate() { 30 | return template; 31 | } 32 | 33 | public void setTemplate(String template) { 34 | this.template = template; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/RenderedContent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | /** 21 | * Created by kamran on 05/08/16. 22 | */ 23 | public abstract class RenderedContent { 24 | protected String rendered; 25 | 26 | public RenderedContent() { 27 | } 28 | 29 | public RenderedContent(String rendered) { 30 | this.rendered = rendered; 31 | } 32 | 33 | public String getRendered() { 34 | return rendered; 35 | } 36 | 37 | public void setRendered(String rendered) { 38 | this.rendered = rendered; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return rendered; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/WpBase.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * Created by kamran on 07/08/16. 24 | */ 25 | public abstract class WpBase implements Serializable { 26 | private int id; 27 | private String link; 28 | private String slug; 29 | 30 | public int getId() { 31 | return id; 32 | } 33 | 34 | public void setId(int id) { 35 | this.id = id; 36 | } 37 | 38 | public String getLink() { 39 | return link; 40 | } 41 | 42 | public void setLink(String link) { 43 | this.link = link; 44 | } 45 | 46 | public String getSlug() { 47 | return slug; 48 | } 49 | 50 | public void setSlug(String slug) { 51 | this.slug = slug; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/impl/TagService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client.impl; 19 | 20 | import org.kamranzafar.spring.wpapi.Tag; 21 | import org.kamranzafar.spring.wpapi.client.BaseService; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Created by kamran on 07/08/16. 28 | */ 29 | @Service 30 | public class TagService extends BaseService { 31 | @Override 32 | public Tag[] getAll() { 33 | return restTemplate.getForObject(buildUri(), Tag[].class); 34 | } 35 | 36 | @Override 37 | public Tag[] getAll(Map params) { 38 | return restTemplate.getForObject(buildUri(params), Tag[].class); 39 | } 40 | 41 | @Override 42 | public String getUrlPostfix() { 43 | return wpApiConfig.getApiVersionBase() + "/tags"; 44 | } 45 | 46 | @Override 47 | public Class getType() { 48 | return Tag.class; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/impl/PageService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client.impl; 19 | 20 | import org.kamranzafar.spring.wpapi.Page; 21 | import org.kamranzafar.spring.wpapi.client.BaseService; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Created by kamran on 07/08/16. 28 | */ 29 | @Service 30 | public class PageService extends BaseService { 31 | @Override 32 | public Page[] getAll() { 33 | return restTemplate.getForObject(buildUri(), Page[].class); 34 | } 35 | 36 | @Override 37 | public Page[] getAll(Map params) { 38 | return restTemplate.getForObject(buildUri(params), Page[].class); 39 | } 40 | 41 | @Override 42 | public String getUrlPostfix() { 43 | return wpApiConfig.getApiVersionBase() + "/pages"; 44 | } 45 | 46 | @Override 47 | public Class getType() { 48 | return Page.class; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/impl/PostService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client.impl; 19 | 20 | import org.kamranzafar.spring.wpapi.Post; 21 | import org.kamranzafar.spring.wpapi.client.BaseService; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Created by kamran on 07/08/16. 28 | */ 29 | @Service 30 | public class PostService extends BaseService { 31 | @Override 32 | public Post[] getAll() { 33 | return restTemplate.getForObject(buildUri(), Post[].class); 34 | } 35 | 36 | @Override 37 | public Post[] getAll(Map params) { 38 | return restTemplate.getForObject(buildUri(params), Post[].class); 39 | } 40 | 41 | @Override 42 | public String getUrlPostfix() { 43 | return wpApiConfig.getApiVersionBase() + "/posts"; 44 | } 45 | 46 | @Override 47 | public Class getType() { 48 | return Post.class; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/impl/MediaService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client.impl; 19 | 20 | import org.kamranzafar.spring.wpapi.Media; 21 | import org.kamranzafar.spring.wpapi.client.BaseService; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Created by kamran on 07/08/16. 28 | */ 29 | @Service 30 | public class MediaService extends BaseService { 31 | @Override 32 | public Media[] getAll() { 33 | return restTemplate.getForObject(buildUri(), Media[].class); 34 | } 35 | 36 | @Override 37 | public Media[] getAll(Map params) { 38 | return restTemplate.getForObject(buildUri(params), Media[].class); 39 | } 40 | 41 | @Override 42 | public String getUrlPostfix() { 43 | return wpApiConfig.getApiVersionBase() + "/media"; 44 | } 45 | 46 | @Override 47 | public Class getType() { 48 | return Media.class; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/impl/CommentService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client.impl; 19 | 20 | import org.kamranzafar.spring.wpapi.Comment; 21 | import org.kamranzafar.spring.wpapi.client.BaseService; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Created by kamran on 07/08/16. 28 | */ 29 | @Service 30 | public class CommentService extends BaseService { 31 | @Override 32 | public Comment[] getAll() { 33 | return restTemplate.getForObject(buildUri(), Comment[].class); 34 | } 35 | 36 | @Override 37 | public Comment[] getAll(Map params) { 38 | return restTemplate.getForObject(buildUri(params), Comment[].class); 39 | } 40 | 41 | @Override 42 | public String getUrlPostfix() { 43 | return wpApiConfig.getApiVersionBase() + "/comments"; 44 | } 45 | 46 | @Override 47 | public Class getType() { 48 | return Comment.class; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/impl/CategoryService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client.impl; 19 | 20 | import org.kamranzafar.spring.wpapi.Category; 21 | import org.kamranzafar.spring.wpapi.client.BaseService; 22 | import org.springframework.stereotype.Service; 23 | 24 | import java.util.Map; 25 | 26 | /** 27 | * Created by kamran on 07/08/16. 28 | */ 29 | @Service 30 | public class CategoryService extends BaseService { 31 | @Override 32 | public Category[] getAll() { 33 | return restTemplate.getForObject(buildUri(), Category[].class); 34 | } 35 | 36 | @Override 37 | public Category[] getAll(Map params) { 38 | return restTemplate.getForObject(buildUri(params), Category[].class); 39 | } 40 | 41 | @Override 42 | public String getUrlPostfix() { 43 | return wpApiConfig.getApiVersionBase() + "/categories"; 44 | } 45 | 46 | @Override 47 | public Class getType() { 48 | return Category.class; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Tag.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | 22 | /** 23 | * Created by kamran on 05/08/16. 24 | */ 25 | @JsonIgnoreProperties(ignoreUnknown = true) 26 | public class Tag extends WpBase { 27 | private int count; 28 | private String description; 29 | private String name; 30 | private String taxonomy; 31 | 32 | public int getCount() { 33 | return count; 34 | } 35 | 36 | public void setCount(int count) { 37 | this.count = count; 38 | } 39 | 40 | public String getDescription() { 41 | return description; 42 | } 43 | 44 | public void setDescription(String description) { 45 | this.description = description; 46 | } 47 | 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | public void setName(String name) { 53 | this.name = name; 54 | } 55 | 56 | public String getTaxonomy() { 57 | return taxonomy; 58 | } 59 | 60 | public void setTaxonomy(String taxonomy) { 61 | this.taxonomy = taxonomy; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/MediaDetail.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | 22 | import java.io.Serializable; 23 | 24 | /** 25 | * Created by kamran on 07/08/16. 26 | */ 27 | public class MediaDetail implements Serializable { 28 | private int width; 29 | private int height; 30 | private String file; 31 | @JsonProperty("image_meta") 32 | private ImageMetaData imageMetaData; 33 | 34 | public int getWidth() { 35 | return width; 36 | } 37 | 38 | public void setWidth(int width) { 39 | this.width = width; 40 | } 41 | 42 | public int getHeight() { 43 | return height; 44 | } 45 | 46 | public void setHeight(int height) { 47 | this.height = height; 48 | } 49 | 50 | public String getFile() { 51 | return file; 52 | } 53 | 54 | public void setFile(String file) { 55 | this.file = file; 56 | } 57 | 58 | public ImageMetaData getImageMetaData() { 59 | return imageMetaData; 60 | } 61 | 62 | public void setImageMetaData(ImageMetaData imageMetaData) { 63 | this.imageMetaData = imageMetaData; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Category.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | 22 | /** 23 | * Created by kamran on 05/08/16. 24 | */ 25 | @JsonIgnoreProperties(ignoreUnknown = true) 26 | public class Category extends WpBase { 27 | private int count; 28 | private String description; 29 | private String name; 30 | private String taxonomy; 31 | private int parent; 32 | 33 | public int getCount() { 34 | return count; 35 | } 36 | 37 | public void setCount(int count) { 38 | this.count = count; 39 | } 40 | 41 | public String getDescription() { 42 | return description; 43 | } 44 | 45 | public void setDescription(String description) { 46 | this.description = description; 47 | } 48 | 49 | public String getName() { 50 | return name; 51 | } 52 | 53 | public void setName(String name) { 54 | this.name = name; 55 | } 56 | 57 | public String getTaxonomy() { 58 | return taxonomy; 59 | } 60 | 61 | public void setTaxonomy(String taxonomy) { 62 | this.taxonomy = taxonomy; 63 | } 64 | 65 | public int getParent() { 66 | return parent; 67 | } 68 | 69 | public void setParent(int parent) { 70 | this.parent = parent; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring WordPress WP-API Client 2 | 3 | This is a Spring client for [WordPress REST plugin](https://github.com/WP-API/), which makes it easy to integrate Spring Boot applications with WordPress CMS. 4 | 5 | ## Usage 6 | 7 | Add the following dependency to your Spring Boot Application 8 | 9 |
<dependency>
10 |     <groupId>org.kamranzafar.spring.wpapi</groupId>
11 |     <artifactId>spring-wpapi</artifactId>
12 |     <version>0.1</version>
13 | </dependency>
14 | 
15 | 16 | Below is a sample configuration we need in the application.properties file 17 | 18 |
wpapi.host=yoursite.com
19 | wpapi.port=443   # Optional, default is 80
20 | wpapi.https=true # Optional, default is false
21 | 
22 | 23 | The Spring WP-API client needs the RestTemplate so lets create a bean in our Application and autowire the Spring client. 24 | We also need to add component scan annotation so that Spring finds and autowires all the required dependencies. 25 | 26 |
@SpringBootApplication
27 | @ComponentScan("org.kamranzafar.spring.wpapi")
28 | public class Application implements CommandLineRunner {
29 |     public static void main(String args[]) {
30 |         SpringApplication.run(Application.class);
31 |     }
32 |  
33 |     @Autowired
34 |     private WpApiClient wpApiClient;
35 |  
36 |     @Bean
37 |     public RestTemplate restTemplate() {
38 |         return new RestTemplate();
39 |     }
40 | }
41 | 
42 | 43 | Now just use client to call the WordPress services 44 | 45 |
Map params = new HashMap<>();
46 | params.put("search", "Spring");
47 | params.put("per_page", "2"); // results per page
48 | params.put("page", "1"); // current page
49 |  
50 | // See WP-API Documentation more parameters
51 | // http://v2.wp-api.org/reference/
52 |  
53 | Post[] posts = wpApiClient.getPostService().getAll(params);
54 |  
55 | for (Post p : posts) {
56 |     log.info("Post: " + p.getId());
57 |     log.info("" + p.getContent());
58 | }
59 | 
60 | 61 | ## License 62 | 63 | Apache Software License 2.0 -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/impl/PostTypeService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client.impl; 19 | 20 | import org.kamranzafar.spring.wpapi.PostType; 21 | import org.kamranzafar.spring.wpapi.client.BaseService; 22 | import org.kamranzafar.spring.wpapi.client.WpApiException; 23 | import org.springframework.stereotype.Service; 24 | 25 | import java.util.Map; 26 | 27 | /** 28 | * Created by kamran on 07/08/16. 29 | */ 30 | @Service 31 | public class PostTypeService extends BaseService { 32 | @Override 33 | public PostType[] getAll() { 34 | return restTemplate.getForObject(buildUri(), PostType[].class); 35 | } 36 | 37 | @Override 38 | public PostType[] getAll(Map params) { 39 | return restTemplate.getForObject(buildUri(params), PostType[].class); 40 | } 41 | 42 | @Override 43 | public String getUrlPostfix() { 44 | return wpApiConfig.getApiVersionBase() + "/types"; 45 | } 46 | 47 | @Override 48 | public void create(PostType obj) { 49 | throw new WpApiException("Not supported"); 50 | } 51 | 52 | @Override 53 | public void update(PostType obj) { 54 | throw new WpApiException("Not supported"); 55 | } 56 | 57 | @Override 58 | public void delete(int id) { 59 | throw new WpApiException("Not supported"); 60 | } 61 | 62 | @Override 63 | public Class getType() { 64 | return PostType.class; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/impl/TaxonomyService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client.impl; 19 | 20 | import org.kamranzafar.spring.wpapi.Taxonomy; 21 | import org.kamranzafar.spring.wpapi.client.BaseService; 22 | import org.kamranzafar.spring.wpapi.client.WpApiException; 23 | import org.springframework.stereotype.Service; 24 | 25 | import java.util.Map; 26 | 27 | /** 28 | * Created by kamran on 07/08/16. 29 | */ 30 | @Service 31 | public class TaxonomyService extends BaseService { 32 | @Override 33 | public Taxonomy[] getAll() { 34 | return restTemplate.getForObject(buildUri(), Taxonomy[].class); 35 | } 36 | 37 | @Override 38 | public Taxonomy[] getAll(Map params) { 39 | return restTemplate.getForObject(buildUri(params), Taxonomy[].class); 40 | } 41 | 42 | @Override 43 | public String getUrlPostfix() { 44 | return wpApiConfig.getApiVersionBase() + "/taxonomies"; 45 | } 46 | 47 | @Override 48 | public void create(Taxonomy obj) { 49 | throw new WpApiException("Not supported"); 50 | } 51 | 52 | @Override 53 | public void update(Taxonomy obj) { 54 | throw new WpApiException("Not supported"); 55 | } 56 | 57 | @Override 58 | public void delete(int id) { 59 | throw new WpApiException("Not supported"); 60 | } 61 | 62 | @Override 63 | public Class getType() { 64 | return Taxonomy.class; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/PostType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | 22 | import java.io.Serializable; 23 | 24 | /** 25 | * Created by kamran on 07/08/16. 26 | */ 27 | @JsonIgnoreProperties(ignoreUnknown = true) 28 | public class PostType implements Serializable { 29 | private int[] capabilities; 30 | private String name; 31 | private String description; 32 | private boolean hierarchical; 33 | private String slug; 34 | 35 | public int[] getCapabilities() { 36 | return capabilities; 37 | } 38 | 39 | public void setCapabilities(int[] capabilities) { 40 | this.capabilities = capabilities; 41 | } 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public void setName(String name) { 48 | this.name = name; 49 | } 50 | 51 | public String getDescription() { 52 | return description; 53 | } 54 | 55 | public void setDescription(String description) { 56 | this.description = description; 57 | } 58 | 59 | public boolean isHierarchical() { 60 | return hierarchical; 61 | } 62 | 63 | public void setHierarchical(boolean hierarchical) { 64 | this.hierarchical = hierarchical; 65 | } 66 | 67 | public String getSlug() { 68 | return slug; 69 | } 70 | 71 | public void setSlug(String slug) { 72 | this.slug = slug; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/impl/PostStatusService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client.impl; 19 | 20 | import org.kamranzafar.spring.wpapi.PostStatus; 21 | import org.kamranzafar.spring.wpapi.client.BaseService; 22 | import org.kamranzafar.spring.wpapi.client.WpApiException; 23 | import org.springframework.stereotype.Service; 24 | 25 | import java.util.Map; 26 | 27 | /** 28 | * Created by kamran on 07/08/16. 29 | */ 30 | @Service 31 | public class PostStatusService extends BaseService { 32 | @Override 33 | public PostStatus[] getAll() { 34 | return restTemplate.getForObject(buildUri(), PostStatus[].class); 35 | } 36 | 37 | @Override 38 | public PostStatus[] getAll(Map params) { 39 | return restTemplate.getForObject(buildUri(params), PostStatus[].class); 40 | } 41 | 42 | @Override 43 | public void create(PostStatus obj) { 44 | throw new WpApiException("Not supported"); 45 | } 46 | 47 | @Override 48 | public void update(PostStatus obj) { 49 | throw new WpApiException("Not supported"); 50 | } 51 | 52 | @Override 53 | public void delete(int id) { 54 | throw new WpApiException("Not supported"); 55 | } 56 | 57 | @Override 58 | public String getUrlPostfix() { 59 | return wpApiConfig.getApiVersionBase() + "/statuses"; 60 | } 61 | 62 | @Override 63 | public Class getType() { 64 | return PostStatus.class; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Eclipse template 3 | 4 | .metadata 5 | bin/ 6 | tmp/ 7 | *.tmp 8 | *.bak 9 | *.swp 10 | *~.nib 11 | local.properties 12 | .settings/ 13 | .loadpath 14 | .recommenders 15 | 16 | # Eclipse Core 17 | .project 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # PyDev specific (Python IDE for Eclipse) 26 | *.pydevproject 27 | 28 | # CDT-specific (C/C++ Development Tooling) 29 | .cproject 30 | 31 | # JDT-specific (Eclipse Java Development Tools) 32 | .classpath 33 | 34 | # Java annotation processor (APT) 35 | .factorypath 36 | 37 | # PDT-specific (PHP Development Tools) 38 | .buildpath 39 | 40 | # sbteclipse plugin 41 | .target 42 | 43 | # Tern plugin 44 | .tern-project 45 | 46 | # TeXlipse plugin 47 | .texlipse 48 | 49 | # STS (Spring Tool Suite) 50 | .springBeans 51 | 52 | # Code Recommenders 53 | .recommenders/ 54 | ### Maven template 55 | target/ 56 | pom.xml.tag 57 | pom.xml.releaseBackup 58 | pom.xml.versionsBackup 59 | pom.xml.next 60 | release.properties 61 | dependency-reduced-pom.xml 62 | buildNumber.properties 63 | .mvn/timing.properties 64 | ### JetBrains template 65 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 66 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 67 | 68 | *.iml 69 | .idea/ 70 | 71 | ## File-based project format: 72 | *.iws 73 | 74 | ## Plugin-specific files: 75 | 76 | # IntelliJ 77 | /out/ 78 | 79 | # mpeltonen/sbt-idea plugin 80 | .idea_modules/ 81 | 82 | # JIRA plugin 83 | atlassian-ide-plugin.xml 84 | 85 | # Crashlytics plugin (for Android Studio and IntelliJ) 86 | com_crashlytics_export_strings.xml 87 | crashlytics.properties 88 | crashlytics-build.properties 89 | fabric.properties 90 | ### Java template 91 | *.class 92 | 93 | # Mobile Tools for Java (J2ME) 94 | .mtj.tmp/ 95 | 96 | # Package Files # 97 | *.jar 98 | *.war 99 | *.ear 100 | 101 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 102 | hs_err_pid* 103 | 104 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/WpApiConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client; 19 | 20 | import org.springframework.boot.context.properties.ConfigurationProperties; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | * Created by kamran on 07/08/16. 25 | */ 26 | @Component 27 | @ConfigurationProperties(prefix="wpapi") 28 | public class WpApiConfig { 29 | public static final int DEFAULT_PORT = 80; 30 | public static final String DEFAULT_API_BASE = "wp-json"; 31 | public static final String DEFAULT_API_VERSION_BASE = "wp/v2"; 32 | 33 | private String host; 34 | private int port = DEFAULT_PORT; 35 | private boolean https; 36 | private String apiBase = DEFAULT_API_BASE; 37 | private String apiVersionBase = DEFAULT_API_VERSION_BASE; 38 | 39 | public String getHost() { 40 | return host; 41 | } 42 | 43 | public void setHost(String host) { 44 | this.host = host; 45 | } 46 | 47 | public int getPort() { 48 | return port; 49 | } 50 | 51 | public void setPort(int port) { 52 | this.port = port; 53 | } 54 | 55 | public boolean isHttps() { 56 | return https; 57 | } 58 | 59 | public void setHttps(boolean https) { 60 | this.https = https; 61 | } 62 | 63 | public String getApiBase() { 64 | return apiBase; 65 | } 66 | 67 | public void setApiBase(String apiBase) { 68 | this.apiBase = apiBase; 69 | } 70 | 71 | public String getApiVersionBase() { 72 | return apiVersionBase; 73 | } 74 | 75 | public void setApiVersionBase(String apiVersionBase) { 76 | this.apiVersionBase = apiVersionBase; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/WpApiClient.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client; 19 | 20 | import org.kamranzafar.spring.wpapi.*; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.stereotype.Component; 23 | 24 | import java.util.List; 25 | 26 | /** 27 | * Created by kamran on 07/08/16. 28 | */ 29 | @Component 30 | public class WpApiClient { 31 | @Autowired 32 | List wpApiServices; 33 | 34 | public WpApiService getService(Class clazz) { 35 | return wpApiServices.stream() 36 | .filter(wpApiService -> wpApiService.getType().getName().equals(clazz.getName())).findFirst().get(); 37 | } 38 | 39 | public WpApiService getPostService(){ 40 | return getService(Post.class); 41 | } 42 | 43 | public WpApiService getPageService(){ 44 | return getService(Page.class); 45 | } 46 | 47 | public WpApiService getCommentService(){ 48 | return getService(Comment.class); 49 | } 50 | 51 | public WpApiService getMediaService(){ 52 | return getService(Media.class); 53 | } 54 | 55 | public WpApiService getPostStatusService(){ 56 | return getService(PostStatus.class); 57 | } 58 | 59 | public WpApiService getPostTypeService(){ 60 | return getService(PostType.class); 61 | } 62 | 63 | public WpApiService getTagService(){ 64 | return getService(Tag.class); 65 | } 66 | 67 | public WpApiService getCategoryService(){ 68 | return getService(Category.class); 69 | } 70 | 71 | public WpApiService getTaxonomyService(){ 72 | return getService(Taxonomy.class); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Taxonomy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | 22 | import java.io.Serializable; 23 | 24 | /** 25 | * Created by kamran on 05/08/16. 26 | */ 27 | public class Taxonomy implements Serializable { 28 | private int[] capabilities; 29 | private String name; 30 | private String description; 31 | private boolean hierarchical; 32 | private String slug; 33 | @JsonProperty("show_cloud") 34 | private boolean showCloud; 35 | private String[] types; 36 | 37 | public int[] getCapabilities() { 38 | return capabilities; 39 | } 40 | 41 | public void setCapabilities(int[] capabilities) { 42 | this.capabilities = capabilities; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public void setName(String name) { 50 | this.name = name; 51 | } 52 | 53 | public String getDescription() { 54 | return description; 55 | } 56 | 57 | public void setDescription(String description) { 58 | this.description = description; 59 | } 60 | 61 | public boolean isHierarchical() { 62 | return hierarchical; 63 | } 64 | 65 | public void setHierarchical(boolean hierarchical) { 66 | this.hierarchical = hierarchical; 67 | } 68 | 69 | public String getSlug() { 70 | return slug; 71 | } 72 | 73 | public void setSlug(String slug) { 74 | this.slug = slug; 75 | } 76 | 77 | public boolean isShowCloud() { 78 | return showCloud; 79 | } 80 | 81 | public void setShowCloud(boolean showCloud) { 82 | this.showCloud = showCloud; 83 | } 84 | 85 | public String[] getTypes() { 86 | return types; 87 | } 88 | 89 | public void setTypes(String[] types) { 90 | this.types = types; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /spring-wpapi-test/src/main/java/org/kamranzafar/spring/wpapi/test/Application.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.test; 19 | 20 | import org.kamranzafar.spring.wpapi.Post; 21 | import org.kamranzafar.spring.wpapi.client.WpApiClient; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | import org.springframework.boot.CommandLineRunner; 26 | import org.springframework.boot.SpringApplication; 27 | import org.springframework.boot.autoconfigure.SpringBootApplication; 28 | import org.springframework.context.annotation.Bean; 29 | import org.springframework.context.annotation.ComponentScan; 30 | import org.springframework.web.client.RestTemplate; 31 | 32 | import java.util.HashMap; 33 | import java.util.Map; 34 | 35 | /** 36 | * Created by kamran on 05/08/16. 37 | */ 38 | @SpringBootApplication 39 | @ComponentScan("org.kamranzafar.spring.wpapi") 40 | public class Application implements CommandLineRunner { 41 | 42 | private static final Logger log = LoggerFactory.getLogger(Application.class); 43 | 44 | public static void main(String args[]) { 45 | SpringApplication.run(Application.class); 46 | } 47 | 48 | @Autowired 49 | private WpApiClient wpApiClient; 50 | 51 | @Bean 52 | public RestTemplate restTemplate() { 53 | return new RestTemplate(); 54 | } 55 | 56 | @Override 57 | public void run(String... args) throws Exception { 58 | Map params = new HashMap<>(); 59 | params.put("search", "Spring"); 60 | params.put("per_page", "2"); // results per page 61 | params.put("page", "1"); // current page 62 | 63 | // See WP-API Documentation more parameters 64 | // http://v2.wp-api.org/reference/ 65 | 66 | Post[] posts = wpApiClient.getPostService().getAll(params); 67 | 68 | for (Post p : posts) { 69 | log.info("Post: " + p.getId()); 70 | log.info("" + p.getContent()); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /spring-wpapi-client/src/main/java/org/kamranzafar/spring/wpapi/client/BaseService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi.client; 19 | 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.web.client.RestTemplate; 22 | import org.springframework.web.util.UriComponentsBuilder; 23 | 24 | import java.net.URI; 25 | import java.util.Map; 26 | 27 | /** 28 | * Created by kamran on 07/08/16. 29 | */ 30 | public abstract class BaseService implements WpApiService { 31 | @Autowired 32 | protected WpApiConfig wpApiConfig; 33 | 34 | @Autowired 35 | protected RestTemplate restTemplate; 36 | 37 | @Override 38 | public T get(int id) { 39 | return restTemplate.getForObject(buildUri() + "/" + id, getType()); 40 | } 41 | 42 | @Override 43 | public T get(int id, Map params) { 44 | return restTemplate.getForObject(buildUri(buildUri() + "/" + id, params), getType()); 45 | } 46 | 47 | @Override 48 | public void create(T obj) { 49 | restTemplate.postForLocation(buildUri(), obj); 50 | } 51 | 52 | @Override 53 | public void update(T obj) { 54 | restTemplate.postForLocation(buildUri(), obj); 55 | } 56 | 57 | @Override 58 | public void delete(int id) { 59 | restTemplate.delete(buildUri() + "/" + id); 60 | } 61 | 62 | protected String buildUri() { 63 | return (wpApiConfig.isHttps() ? "https://" : "http://") + wpApiConfig.getHost() + ":" + wpApiConfig.getPort() + "/" + wpApiConfig.getApiBase() + "/" + getUrlPostfix(); 64 | } 65 | 66 | protected URI buildUri(String uri, Map params) { 67 | UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(uri); 68 | 69 | params.forEach((k, v) -> uriComponentsBuilder.queryParam(k, v)); 70 | 71 | return uriComponentsBuilder.build().toUri(); 72 | } 73 | 74 | protected URI buildUri(Map params) { 75 | return buildUri(buildUri(), params); 76 | } 77 | 78 | protected abstract String getUrlPostfix(); 79 | } 80 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/PostStatus.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | import java.io.Serializable; 24 | 25 | /** 26 | * Created by kamran on 07/08/16. 27 | */ 28 | @JsonIgnoreProperties(ignoreUnknown = true) 29 | public class PostStatus implements Serializable { 30 | private String name; 31 | @JsonProperty("public") 32 | private boolean postPublic; 33 | @JsonProperty("private") 34 | private boolean postPrivate; 35 | @JsonProperty("protected") 36 | private boolean postProtected; 37 | private boolean queryable; 38 | @JsonProperty("show_in_list") 39 | private boolean showInList; 40 | private String slug; 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public boolean isPostPublic() { 51 | return postPublic; 52 | } 53 | 54 | public void setPostPublic(boolean postPublic) { 55 | this.postPublic = postPublic; 56 | } 57 | 58 | public boolean isPostPrivate() { 59 | return postPrivate; 60 | } 61 | 62 | public void setPostPrivate(boolean postPrivate) { 63 | this.postPrivate = postPrivate; 64 | } 65 | 66 | public boolean isPostProtected() { 67 | return postProtected; 68 | } 69 | 70 | public void setPostProtected(boolean postProtected) { 71 | this.postProtected = postProtected; 72 | } 73 | 74 | public boolean isQueryable() { 75 | return queryable; 76 | } 77 | 78 | public void setQueryable(boolean queryable) { 79 | this.queryable = queryable; 80 | } 81 | 82 | public boolean isShowInList() { 83 | return showInList; 84 | } 85 | 86 | public void setShowInList(boolean showInList) { 87 | this.showInList = showInList; 88 | } 89 | 90 | public String getSlug() { 91 | return slug; 92 | } 93 | 94 | public void setSlug(String slug) { 95 | this.slug = slug; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/ImageMetaData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | 22 | import java.io.Serializable; 23 | import java.util.Date; 24 | 25 | /** 26 | * Created by kamran on 07/08/16. 27 | */ 28 | public class ImageMetaData implements Serializable { 29 | private String aperture; 30 | private String credit; 31 | private String camera; 32 | private String caption; 33 | @JsonProperty("created_timestamp") 34 | private Date createdAt; 35 | private String copyright; 36 | @JsonProperty("focal_length") 37 | private String focalLength; 38 | private String iso; 39 | @JsonProperty("shutter_speed") 40 | private String shutterSpeed; 41 | private String title; 42 | private String orientation; 43 | private String[] keywords; 44 | 45 | public String getAperture() { 46 | return aperture; 47 | } 48 | 49 | public void setAperture(String aperture) { 50 | this.aperture = aperture; 51 | } 52 | 53 | public String getCredit() { 54 | return credit; 55 | } 56 | 57 | public void setCredit(String credit) { 58 | this.credit = credit; 59 | } 60 | 61 | public String getCamera() { 62 | return camera; 63 | } 64 | 65 | public void setCamera(String camera) { 66 | this.camera = camera; 67 | } 68 | 69 | public String getCaption() { 70 | return caption; 71 | } 72 | 73 | public void setCaption(String caption) { 74 | this.caption = caption; 75 | } 76 | 77 | public Date getCreatedAt() { 78 | return createdAt; 79 | } 80 | 81 | public void setCreatedAt(Date createdAt) { 82 | this.createdAt = createdAt; 83 | } 84 | 85 | public String getCopyright() { 86 | return copyright; 87 | } 88 | 89 | public void setCopyright(String copyright) { 90 | this.copyright = copyright; 91 | } 92 | 93 | public String getFocalLength() { 94 | return focalLength; 95 | } 96 | 97 | public void setFocalLength(String focalLength) { 98 | this.focalLength = focalLength; 99 | } 100 | 101 | public String getIso() { 102 | return iso; 103 | } 104 | 105 | public void setIso(String iso) { 106 | this.iso = iso; 107 | } 108 | 109 | public String getShutterSpeed() { 110 | return shutterSpeed; 111 | } 112 | 113 | public void setShutterSpeed(String shutterSpeed) { 114 | this.shutterSpeed = shutterSpeed; 115 | } 116 | 117 | public String getTitle() { 118 | return title; 119 | } 120 | 121 | public void setTitle(String title) { 122 | this.title = title; 123 | } 124 | 125 | public String getOrientation() { 126 | return orientation; 127 | } 128 | 129 | public void setOrientation(String orientation) { 130 | this.orientation = orientation; 131 | } 132 | 133 | public String[] getKeywords() { 134 | return keywords; 135 | } 136 | 137 | public void setKeywords(String[] keywords) { 138 | this.keywords = keywords; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Media.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | 22 | import java.util.Date; 23 | 24 | /** 25 | * Created by kamran on 05/08/16. 26 | */ 27 | public class Media extends WpBase { 28 | private Guid guid; 29 | private Date date; 30 | private Date modified; 31 | private String type; 32 | private int author; 33 | @JsonProperty("comment_status") 34 | private String commentStatus; 35 | @JsonProperty("ping_status") 36 | private String pingStatus; 37 | @JsonProperty("alt_text") 38 | private String altText; 39 | private String caption; 40 | @JsonProperty("media_type") 41 | private String mediaType; 42 | @JsonProperty("mime_type") 43 | private String mimeType; 44 | @JsonProperty("source_url") 45 | private String sourceUrl; 46 | @JsonProperty("media_detail") 47 | private MediaDetail mediaDetail; 48 | 49 | public Guid getGuid() { 50 | return guid; 51 | } 52 | 53 | public void setGuid(Guid guid) { 54 | this.guid = guid; 55 | } 56 | 57 | public Date getDate() { 58 | return date; 59 | } 60 | 61 | public void setDate(Date date) { 62 | this.date = date; 63 | } 64 | 65 | public Date getModified() { 66 | return modified; 67 | } 68 | 69 | public void setModified(Date modified) { 70 | this.modified = modified; 71 | } 72 | 73 | public String getType() { 74 | return type; 75 | } 76 | 77 | public void setType(String type) { 78 | this.type = type; 79 | } 80 | 81 | public int getAuthor() { 82 | return author; 83 | } 84 | 85 | public void setAuthor(int author) { 86 | this.author = author; 87 | } 88 | 89 | public String getCommentStatus() { 90 | return commentStatus; 91 | } 92 | 93 | public void setCommentStatus(String commentStatus) { 94 | this.commentStatus = commentStatus; 95 | } 96 | 97 | public String getPingStatus() { 98 | return pingStatus; 99 | } 100 | 101 | public void setPingStatus(String pingStatus) { 102 | this.pingStatus = pingStatus; 103 | } 104 | 105 | public String getAltText() { 106 | return altText; 107 | } 108 | 109 | public void setAltText(String altText) { 110 | this.altText = altText; 111 | } 112 | 113 | public String getCaption() { 114 | return caption; 115 | } 116 | 117 | public void setCaption(String caption) { 118 | this.caption = caption; 119 | } 120 | 121 | public String getMediaType() { 122 | return mediaType; 123 | } 124 | 125 | public void setMediaType(String mediaType) { 126 | this.mediaType = mediaType; 127 | } 128 | 129 | public String getMimeType() { 130 | return mimeType; 131 | } 132 | 133 | public void setMimeType(String mimeType) { 134 | this.mimeType = mimeType; 135 | } 136 | 137 | public String getSourceUrl() { 138 | return sourceUrl; 139 | } 140 | 141 | public void setSourceUrl(String sourceUrl) { 142 | this.sourceUrl = sourceUrl; 143 | } 144 | 145 | public MediaDetail getMediaDetail() { 146 | return mediaDetail; 147 | } 148 | 149 | public void setMediaDetail(MediaDetail mediaDetail) { 150 | this.mediaDetail = mediaDetail; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/Comment.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | 23 | import java.io.Serializable; 24 | import java.util.Date; 25 | 26 | /** 27 | * Created by kamran on 05/08/16. 28 | */ 29 | @JsonIgnoreProperties(ignoreUnknown = true) 30 | public class Comment implements Serializable { 31 | private int id; 32 | private int author; 33 | @JsonProperty("author_email") 34 | private String authorEmail; 35 | @JsonProperty("author_name") 36 | private String authorName; 37 | @JsonProperty("author_ip") 38 | private String authorIp; 39 | @JsonProperty("author_url") 40 | private String authorUrl; 41 | @JsonProperty("author_user_agent") 42 | private String authorUserAgent; 43 | private Content content; 44 | private Date date; 45 | private int karma; 46 | private String link; 47 | private int parent; 48 | private int post; 49 | private String status; 50 | private String type; 51 | 52 | public int getId() { 53 | return id; 54 | } 55 | 56 | public void setId(int id) { 57 | this.id = id; 58 | } 59 | 60 | public int getAuthor() { 61 | return author; 62 | } 63 | 64 | public void setAuthor(int author) { 65 | this.author = author; 66 | } 67 | 68 | public String getAuthorName() { 69 | return authorName; 70 | } 71 | 72 | public void setAuthorName(String authorName) { 73 | this.authorName = authorName; 74 | } 75 | 76 | public String getAuthorEmail() { 77 | return authorEmail; 78 | } 79 | 80 | public void setAuthorEmail(String authorEmail) { 81 | this.authorEmail = authorEmail; 82 | } 83 | 84 | public String getAuthorIp() { 85 | return authorIp; 86 | } 87 | 88 | public void setAuthorIp(String authorIp) { 89 | this.authorIp = authorIp; 90 | } 91 | 92 | public String getAuthorUrl() { 93 | return authorUrl; 94 | } 95 | 96 | public void setAuthorUrl(String authorUrl) { 97 | this.authorUrl = authorUrl; 98 | } 99 | 100 | public String getAuthorUserAgent() { 101 | return authorUserAgent; 102 | } 103 | 104 | public void setAuthorUserAgent(String authorUserAgent) { 105 | this.authorUserAgent = authorUserAgent; 106 | } 107 | 108 | public Content getContent() { 109 | return content; 110 | } 111 | 112 | public void setContent(Content content) { 113 | this.content = content; 114 | } 115 | 116 | public Date getDate() { 117 | return date; 118 | } 119 | 120 | public void setDate(Date date) { 121 | this.date = date; 122 | } 123 | 124 | public int getKarma() { 125 | return karma; 126 | } 127 | 128 | public void setKarma(int karma) { 129 | this.karma = karma; 130 | } 131 | 132 | public String getLink() { 133 | return link; 134 | } 135 | 136 | public void setLink(String link) { 137 | this.link = link; 138 | } 139 | 140 | public int getParent() { 141 | return parent; 142 | } 143 | 144 | public void setParent(int parent) { 145 | this.parent = parent; 146 | } 147 | 148 | public int getPost() { 149 | return post; 150 | } 151 | 152 | public void setPost(int post) { 153 | this.post = post; 154 | } 155 | 156 | public String getStatus() { 157 | return status; 158 | } 159 | 160 | public void setStatus(String status) { 161 | this.status = status; 162 | } 163 | 164 | public String getType() { 165 | return type; 166 | } 167 | 168 | public void setType(String type) { 169 | this.type = type; 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /spring-wpapi-core/src/main/java/org/kamranzafar/spring/wpapi/ContentBase.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2016 Kamran Zafar 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package org.kamranzafar.spring.wpapi; 19 | 20 | import com.fasterxml.jackson.annotation.JsonProperty; 21 | 22 | import java.util.Date; 23 | 24 | /** 25 | * Created by kamran on 05/08/16. 26 | */ 27 | 28 | public abstract class ContentBase extends WpBase { 29 | private Guid guid; 30 | private Date date; 31 | private Date modified; 32 | private String type; 33 | private int author; 34 | @JsonProperty("comment_status") 35 | private String commentStatus; 36 | @JsonProperty("ping_status") 37 | private String pingStatus; 38 | private String password; 39 | private String status; 40 | private Content content; 41 | private Title title; 42 | private Excerpt excerpt; 43 | @JsonProperty("featured_media") 44 | private int featuredMedia; 45 | private String format; 46 | private boolean sticky; 47 | private int[] categories; 48 | private int[] tags; 49 | 50 | public Guid getGuid() { 51 | return guid; 52 | } 53 | 54 | public void setGuid(Guid guid) { 55 | this.guid = guid; 56 | } 57 | 58 | public Date getDate() { 59 | return date; 60 | } 61 | 62 | public void setDate(Date date) { 63 | this.date = date; 64 | } 65 | 66 | public Date getModified() { 67 | return modified; 68 | } 69 | 70 | public void setModified(Date modified) { 71 | this.modified = modified; 72 | } 73 | 74 | public String getType() { 75 | return type; 76 | } 77 | 78 | public void setType(String type) { 79 | this.type = type; 80 | } 81 | 82 | public int getAuthor() { 83 | return author; 84 | } 85 | 86 | public void setAuthor(int author) { 87 | this.author = author; 88 | } 89 | 90 | public String getCommentStatus() { 91 | return commentStatus; 92 | } 93 | 94 | public void setCommentStatus(String commentStatus) { 95 | this.commentStatus = commentStatus; 96 | } 97 | 98 | public String getPingStatus() { 99 | return pingStatus; 100 | } 101 | 102 | public void setPingStatus(String pingStatus) { 103 | this.pingStatus = pingStatus; 104 | } 105 | 106 | public String getPassword() { 107 | return password; 108 | } 109 | 110 | public void setPassword(String password) { 111 | this.password = password; 112 | } 113 | 114 | public String getStatus() { 115 | return status; 116 | } 117 | 118 | public void setStatus(String status) { 119 | this.status = status; 120 | } 121 | 122 | public Content getContent() { 123 | return content; 124 | } 125 | 126 | public void setContent(Content content) { 127 | this.content = content; 128 | } 129 | 130 | public Title getTitle() { 131 | return title; 132 | } 133 | 134 | public void setTitle(Title title) { 135 | this.title = title; 136 | } 137 | 138 | public Excerpt getExcerpt() { 139 | return excerpt; 140 | } 141 | 142 | public void setExcerpt(Excerpt excerpt) { 143 | this.excerpt = excerpt; 144 | } 145 | 146 | public int getFeaturedMedia() { 147 | return featuredMedia; 148 | } 149 | 150 | public void setFeaturedMedia(int featuredMedia) { 151 | this.featuredMedia = featuredMedia; 152 | } 153 | public String getFormat() { 154 | return format; 155 | } 156 | 157 | public void setFormat(String format) { 158 | this.format = format; 159 | } 160 | 161 | public boolean isSticky() { 162 | return sticky; 163 | } 164 | 165 | public void setSticky(boolean sticky) { 166 | this.sticky = sticky; 167 | } 168 | 169 | public int[] getCategories() { 170 | return categories; 171 | } 172 | 173 | public void setCategories(int[] categories) { 174 | this.categories = categories; 175 | } 176 | 177 | public int[] getTags() { 178 | return tags; 179 | } 180 | 181 | public void setTags(int[] tags) { 182 | this.tags = tags; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 1.4.0.RELEASE 9 | 10 | 11 | org.kamranzafar.spring.wpapi 12 | spring-wpapi 13 | 0.2-SNAPSHOT 14 | pom 15 | 16 | 17 | 18 | kamranzafar 19 | Kamran Zafar 20 | kamran@kamranzafar.org 21 | https://kamranzafar.org 22 | 23 | 24 | 25 | 26 | 27 | The Apache Software License, Version 2.0 28 | http://www.apache.org/licenses/LICENSE-2.0.txt 29 | repo 30 | 31 | 32 | 33 | 34 | 35 | scm:git:git@github.com:kamranzafar/spring-wpapi.git 36 | 37 | 38 | scm:git:git@github.com:kamranzafar/spring-wpapi.git 39 | 40 | git@github.com:kamranzafar/spring-wpapi.git 41 | 42 | HEAD 43 | 44 | 45 | 46 | spring-wpapi-core 47 | spring-wpapi-client 48 | spring-wpapi-test 49 | 50 | 51 | 52 | 53 | 54 | org.apache.maven.plugins 55 | maven-release-plugin 56 | 2.5.3 57 | 58 | true 59 | release 60 | deploy 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-starter 70 | 71 | 72 | org.springframework 73 | spring-web 74 | 75 | 76 | com.fasterxml.jackson.core 77 | jackson-databind 78 | 79 | 80 | 81 | 82 | 83 | ossrh 84 | https://oss.sonatype.org/content/repositories/snapshots 85 | 86 | 87 | ossrh 88 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 89 | 90 | 91 | 92 | 93 | 94 | release 95 | 96 | 97 | 98 | org.sonatype.plugins 99 | nexus-staging-maven-plugin 100 | true 101 | 102 | ossrh 103 | https://oss.sonatype.org/ 104 | true 105 | 106 | 107 | 108 | org.apache.maven.plugins 109 | maven-source-plugin 110 | 111 | 112 | attach-sources 113 | 114 | jar-no-fork 115 | 116 | 117 | 118 | 119 | 120 | org.apache.maven.plugins 121 | maven-javadoc-plugin 122 | 123 | 124 | attach-javadocs 125 | 126 | jar 127 | 128 | 129 | 130 | 131 | true 132 | 133 | 134 | 135 | org.apache.maven.plugins 136 | maven-gpg-plugin 137 | 138 | 139 | sign-artifacts 140 | verify 141 | 142 | sign 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 1.8 154 | 155 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. --------------------------------------------------------------------------------