wordpress_client 0.0.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +30 -0
  3. data/.codeclimate.yml +23 -0
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +147 -90
  6. data/.yardopts +1 -0
  7. data/Changelog.md +16 -0
  8. data/Gemfile +6 -1
  9. data/README.md +48 -14
  10. data/Rakefile +37 -0
  11. data/lib/wordpress_client/category.rb +2 -0
  12. data/lib/wordpress_client/client.rb +235 -79
  13. data/lib/wordpress_client/connection.rb +10 -10
  14. data/lib/wordpress_client/errors.rb +41 -6
  15. data/lib/wordpress_client/media.rb +49 -1
  16. data/lib/wordpress_client/media_parser.rb +3 -0
  17. data/lib/wordpress_client/paginated_collection.rb +61 -4
  18. data/lib/wordpress_client/post.rb +63 -16
  19. data/lib/wordpress_client/post_parser.rb +12 -39
  20. data/lib/wordpress_client/rest_parser.rb +4 -0
  21. data/lib/wordpress_client/tag.rb +2 -0
  22. data/lib/wordpress_client/term.rb +30 -0
  23. data/lib/wordpress_client/version.rb +5 -1
  24. data/lib/wordpress_client.rb +21 -5
  25. data/spec/client_spec.rb +17 -181
  26. data/spec/connection_spec.rb +15 -14
  27. data/spec/docker/Dockerfile +35 -10
  28. data/spec/docker/README.md +53 -16
  29. data/spec/docker/dbdump.sql.gz +0 -0
  30. data/spec/docker/restore-dbdump.sh +2 -2
  31. data/spec/docker/yum.repos.d/CentOS-Base.repo +25 -0
  32. data/spec/fixtures/image-media.json +1 -1
  33. data/spec/fixtures/post-with-metadata.json +99 -1
  34. data/spec/fixtures/simple-post.json +324 -1
  35. data/spec/integration/attachments_crud_spec.rb +1 -1
  36. data/spec/integration/posts_crud_spec.rb +1 -1
  37. data/spec/integration/posts_finding_spec.rb +0 -69
  38. data/spec/integration/posts_metadata_spec.rb +11 -11
  39. data/spec/integration/posts_with_attachments_spec.rb +20 -6
  40. data/spec/media_spec.rb +14 -0
  41. data/spec/post_spec.rb +5 -31
  42. data/spec/spec_helper.rb +1 -0
  43. data/spec/support/docker_runner.rb +33 -13
  44. data/spec/support/wordpress_server.rb +112 -74
  45. data/wordpress_client.gemspec +17 -17
  46. metadata +43 -31
  47. data/.hound.yml +0 -2
  48. data/.ruby-version +0 -1
  49. data/circle.yml +0 -3
  50. data/lib/wordpress_client/replace_metadata.rb +0 -81
  51. data/lib/wordpress_client/replace_terms.rb +0 -62
  52. data/spec/fixtures/post-with-forbidden-metadata.json +0 -1
  53. data/spec/integration/category_assignment_spec.rb +0 -29
  54. data/spec/integration/tag_assignment_spec.rb +0 -29
  55. data/spec/replace_metadata_spec.rb +0 -56
  56. data/spec/replace_terms_spec.rb +0 -51
@@ -1 +1,99 @@
1
- {"id":4,"date":null,"guid":{"rendered":"http:\/\/192.168.99.100:8181\/?p=4"},"modified":null,"modified_gmt":null,"slug":"","type":"post","link":"http:\/\/192.168.99.100:8181\/?p=4","title":{"rendered":"Metadata creation"},"content":{"rendered":""},"excerpt":{"rendered":""},"author":1,"featured_image":0,"comment_status":"open","ping_status":"open","sticky":false,"format":"standard","_links":{"self":[{"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/posts\/4"}],"collection":[{"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/posts"}],"author":[{"embeddable":true,"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/comments?post_id=4"}],"version-history":[{"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/posts\/4\/revisions"}],"https:\/\/api.w.org\/attachment":[{"embeddable":true,"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/media?post_parent=4"}],"https:\/\/api.w.org\/term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/posts\/4\/terms\/category"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/posts\/4\/terms\/tag"},{"taxonomy":"post_format","embeddable":true,"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/posts\/4\/terms\/post_format"}],"https:\/\/api.w.org\/meta":[{"embeddable":true,"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/posts\/4\/meta"}]},"_embedded":{"author":[{"avatar_urls":{"24":"http:\/\/2.gravatar.com\/avatar\/55502f40dc8b7c769880b10874abc9d0?s=24&d=mm&r=g","48":"http:\/\/2.gravatar.com\/avatar\/55502f40dc8b7c769880b10874abc9d0?s=48&d=mm&r=g","96":"http:\/\/2.gravatar.com\/avatar\/55502f40dc8b7c769880b10874abc9d0?s=96&d=mm&r=g"},"description":"","id":1,"link":"http:\/\/192.168.99.100:8181\/author\/test\/","name":"test","url":"","_links":{"self":[{"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/users\/1"}],"collection":[{"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/users"}]}}],"replies":[[{"id":1,"parent":0,"author":0,"author_name":"Mr WordPress","author_url":"https:\/\/wordpress.org\/","author_avatar_urls":{"24":"http:\/\/1.gravatar.com\/avatar\/?s=24&d=mm&r=g","48":"http:\/\/1.gravatar.com\/avatar\/?s=48&d=mm&r=g","96":"http:\/\/2.gravatar.com\/avatar\/?s=96&d=mm&r=g"},"date":"2015-11-03T07:47:41","content":{"rendered":"<p>Hi, this is a comment.<br \/>\nTo delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.<\/p>\n"},"link":"http:\/\/192.168.99.100:8181\/2015\/11\/03\/hello-world\/#comment-1","type":"comment","_links":{"self":[{"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/comments\/1"}],"collection":[{"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/comments"}],"up":[{"embeddable":true,"post_type":"post","href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/posts\/1"}]}}]],"https:\/\/api.w.org\/term":[[{"id":1,"link":"http:\/\/192.168.99.100:8181\/category\/uncategorized\/","name":"Uncategorized","slug":"uncategorized","taxonomy":"category","_links":{"self":[{"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/terms\/category\/1"}],"collection":[{"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/v2\/terms\/category"}]}}],[],[{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}]],"https:\/\/api.w.org\/meta":[[{"id":2,"key":"foo","value":"bar","_links":{"about":[{"embeddable":true,"href":"http:\/\/192.168.99.100:8181\/wp-json\/wp\/posts\/4"}]}}]]}}
1
+ {
2
+ "id": 1,
3
+ "date": "2015-11-03T07:47:41",
4
+ "date_gmt": "2015-11-03T07:47:41",
5
+ "guid": {
6
+ "rendered": "http://localhost:8080/?p=1"
7
+ },
8
+ "modified": "2017-07-25T15:07:30",
9
+ "modified_gmt": "2017-07-25T15:07:30",
10
+ "slug": "hello-world",
11
+ "status": "publish",
12
+ "type": "post",
13
+ "link": "http://localhost:8080/2015/11/03/hello-world/",
14
+ "title": {
15
+ "rendered": "Hello world!"
16
+ },
17
+ "content": {
18
+ "rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
19
+ "protected": false
20
+ },
21
+ "excerpt": {
22
+ "rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
23
+ "protected": false
24
+ },
25
+ "author": 1,
26
+ "featured_media": 0,
27
+ "comment_status": "open",
28
+ "ping_status": "open",
29
+ "sticky": false,
30
+ "template": "",
31
+ "format": "standard",
32
+ "meta": {
33
+ "foo": 1,
34
+ "bar": true,
35
+ "baz": "wohoo"
36
+ },
37
+ "categories": [
38
+ 1
39
+ ],
40
+ "tags": [],
41
+ "_links": {
42
+ "self": [
43
+ {
44
+ "href": "http://localhost:8080/wp-json/wp/v2/posts/1"
45
+ }
46
+ ],
47
+ "collection": [
48
+ {
49
+ "href": "http://localhost:8080/wp-json/wp/v2/posts"
50
+ }
51
+ ],
52
+ "about": [
53
+ {
54
+ "href": "http://localhost:8080/wp-json/wp/v2/types/post"
55
+ }
56
+ ],
57
+ "author": [
58
+ {
59
+ "embeddable": true,
60
+ "href": "http://localhost:8080/wp-json/wp/v2/users/1"
61
+ }
62
+ ],
63
+ "replies": [
64
+ {
65
+ "embeddable": true,
66
+ "href": "http://localhost:8080/wp-json/wp/v2/comments?post=1"
67
+ }
68
+ ],
69
+ "version-history": [
70
+ {
71
+ "href": "http://localhost:8080/wp-json/wp/v2/posts/1/revisions"
72
+ }
73
+ ],
74
+ "wp:attachment": [
75
+ {
76
+ "href": "http://localhost:8080/wp-json/wp/v2/media?parent=1"
77
+ }
78
+ ],
79
+ "wp:term": [
80
+ {
81
+ "taxonomy": "category",
82
+ "embeddable": true,
83
+ "href": "http://localhost:8080/wp-json/wp/v2/categories?post=1"
84
+ },
85
+ {
86
+ "taxonomy": "post_tag",
87
+ "embeddable": true,
88
+ "href": "http://localhost:8080/wp-json/wp/v2/tags?post=1"
89
+ }
90
+ ],
91
+ "curies": [
92
+ {
93
+ "name": "wp",
94
+ "href": "https://api.w.org/{rel}",
95
+ "templated": true
96
+ }
97
+ ]
98
+ }
99
+ }
@@ -1 +1,324 @@
1
- {"id":1,"date":"2015-11-03T07:47:41","guid":{"rendered":"http:\/\/example.com\/?p=1"},"modified":"2015-11-17T09:18:22","modified_gmt":"2015-11-17T09:18:22","slug":"hello-world","type":"post","link":"http:\/\/example.com\/2015\/11\/03\/hello-world\/","title":{"rendered":"Hello world!"},"content":{"rendered":"<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!<\/p>\n"},"excerpt":{"rendered":"<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!<\/p>\n"},"author":1,"featured_image":0,"comment_status":"open","ping_status":"open","sticky":false,"format":"standard","_links":{"self":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/posts\/1"}],"collection":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/posts"}],"author":[{"embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/v2\/comments?post_id=1"}],"version-history":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"https:\/\/api.w.org\/attachment":[{"embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/v2\/media?post_parent=1"}],"https:\/\/api.w.org\/term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/example.com\/wp-json\/wp\/v2\/posts\/1\/terms\/category"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/v2\/posts\/1\/terms\/tag"},{"taxonomy":"post_format","embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/v2\/posts\/1\/terms\/post_format"}],"https:\/\/api.w.org\/meta":[{"embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/v2\/posts\/1\/meta"}]},"_embedded":{"author":[{"avatar_urls":{"24":"http:\/\/2.gravatar.com\/avatar\/55502f40dc8b7c769880b10874abc9d0?s=24&d=mm&r=g","48":"http:\/\/2.gravatar.com\/avatar\/55502f40dc8b7c769880b10874abc9d0?s=48&d=mm&r=g","96":"http:\/\/2.gravatar.com\/avatar\/55502f40dc8b7c769880b10874abc9d0?s=96&d=mm&r=g"},"description":"","id":1,"link":"http:\/\/example.com\/author\/test\/","name":"test","url":"","_links":{"self":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/users\/1"}],"collection":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/users"}]}}],"replies":[[{"id":1,"parent":0,"author":0,"author_name":"Mr WordPress","author_url":"http:\/\/wordpress.org\/","author_avatar_urls":{"24":"http:\/\/1.gravatar.com\/avatar\/?s=24&d=mm&r=g","48":"http:\/\/2.gravatar.com\/avatar\/?s=48&d=mm&r=g","96":"http:\/\/2.gravatar.com\/avatar\/?s=96&d=mm&r=g"},"date":"2015-11-03T07:47:41","content":{"rendered":"<p>Hi, this is a comment.<br \/>\nTo delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.<\/p>\n"},"link":"http:\/\/example.com\/2015\/11\/03\/hello-world\/#comment-1","type":"comment","_links":{"self":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/comments\/1"}],"collection":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/comments"}],"up":[{"embeddable":true,"post_type":"post","href":"http:\/\/example.com\/wp-json\/wp\/v2\/posts\/1"}]}}]],"https:\/\/api.w.org\/term":[[{"id":1,"link":"http:\/\/example.com\/category\/uncategorized\/","name":"Uncategorized","slug":"uncategorized","taxonomy":"category","_links":{"self":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/terms\/category\/1"}],"collection":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/terms\/category"}]}}],[{"id":2,"link":"http:\/\/example.com\/tag\/foo\/","name":"Foo","slug":"foo","taxonomy":"post_tag","_links":{"self":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/terms\/tag\/2"}],"collection":[{"href":"http:\/\/example.com\/wp-json\/wp\/v2\/terms\/tag"}]}}],[{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}]],"https:\/\/api.w.org\/meta":[[{"id":3,"key":"Some test","value":"Definitely","_links":{"about":[{"embeddable":true,"href":"http:\/\/example.com\/wp-json\/wp\/posts\/1"}]}}]]}}
1
+ {
2
+ "id": 1,
3
+ "date": "2015-11-03T07:47:41",
4
+ "date_gmt": "2015-11-03T07:47:41",
5
+ "guid": {
6
+ "rendered": "http://example.com/?p=1"
7
+ },
8
+ "modified": "2017-07-31T13:26:39",
9
+ "modified_gmt": "2017-07-31T13:26:39",
10
+ "slug": "hello-world",
11
+ "status": "publish",
12
+ "type": "post",
13
+ "link": "http://example.com/2015/11/03/hello-world/",
14
+ "title": {
15
+ "rendered": "Hello world!"
16
+ },
17
+ "content": {
18
+ "rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
19
+ "protected": false
20
+ },
21
+ "excerpt": {
22
+ "rendered": "<p>Welcome to WordPress. This is your first post. Edit or delete it, then start writing!</p>\n",
23
+ "protected": false
24
+ },
25
+ "author": 1,
26
+ "featured_media": 5,
27
+ "comment_status": "open",
28
+ "ping_status": "open",
29
+ "sticky": false,
30
+ "template": "",
31
+ "format": "standard",
32
+ "meta": {
33
+ "foo": 0,
34
+ "bar": false,
35
+ "baz": "helo world!"
36
+ },
37
+ "categories": [
38
+ 1
39
+ ],
40
+ "tags": [
41
+ 2
42
+ ],
43
+ "_links": {
44
+ "self": [
45
+ {
46
+ "href": "http://example.com/wp-json/wp/v2/posts/1"
47
+ }
48
+ ],
49
+ "collection": [
50
+ {
51
+ "href": "http://example.com/wp-json/wp/v2/posts"
52
+ }
53
+ ],
54
+ "about": [
55
+ {
56
+ "href": "http://example.com/wp-json/wp/v2/types/post"
57
+ }
58
+ ],
59
+ "author": [
60
+ {
61
+ "embeddable": true,
62
+ "href": "http://example.com/wp-json/wp/v2/users/1"
63
+ }
64
+ ],
65
+ "replies": [
66
+ {
67
+ "embeddable": true,
68
+ "href": "http://example.com/wp-json/wp/v2/comments?post=1"
69
+ }
70
+ ],
71
+ "version-history": [
72
+ {
73
+ "href": "http://example.com/wp-json/wp/v2/posts/1/revisions"
74
+ }
75
+ ],
76
+ "wp:featuredmedia": [
77
+ {
78
+ "embeddable": true,
79
+ "href": "http://example.com/wp-json/wp/v2/media/5"
80
+ }
81
+ ],
82
+ "wp:attachment": [
83
+ {
84
+ "href": "http://example.com/wp-json/wp/v2/media?parent=1"
85
+ }
86
+ ],
87
+ "wp:term": [
88
+ {
89
+ "taxonomy": "category",
90
+ "embeddable": true,
91
+ "href": "http://example.com/wp-json/wp/v2/categories?post=1"
92
+ },
93
+ {
94
+ "taxonomy": "post_tag",
95
+ "embeddable": true,
96
+ "href": "http://example.com/wp-json/wp/v2/tags?post=1"
97
+ }
98
+ ],
99
+ "curies": [
100
+ {
101
+ "name": "wp",
102
+ "href": "https://api.w.org/{rel}",
103
+ "templated": true
104
+ }
105
+ ]
106
+ },
107
+ "_embedded": {
108
+ "author": [
109
+ {
110
+ "id": 1,
111
+ "name": "test",
112
+ "url": "",
113
+ "description": "",
114
+ "link": "http://example.com/author/test/",
115
+ "slug": "test",
116
+ "avatar_urls": {
117
+ "24": "http://2.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=24&d=mm&r=g",
118
+ "48": "http://2.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=48&d=mm&r=g",
119
+ "96": "http://2.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=96&d=mm&r=g"
120
+ },
121
+ "_links": {
122
+ "self": [
123
+ {
124
+ "href": "http://example.com/wp-json/wp/v2/users/1"
125
+ }
126
+ ],
127
+ "collection": [
128
+ {
129
+ "href": "http://example.com/wp-json/wp/v2/users"
130
+ }
131
+ ]
132
+ }
133
+ }
134
+ ],
135
+ "replies": [
136
+ [
137
+ {
138
+ "id": 1,
139
+ "parent": 0,
140
+ "author": 0,
141
+ "author_name": "Mr WordPress",
142
+ "author_url": "https://wordpress.org/",
143
+ "date": "2015-11-03T07:47:41",
144
+ "content": {
145
+ "rendered": "<p>Hi, this is a comment.<br />\nTo delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.</p>\n"
146
+ },
147
+ "link": "http://example.com/2015/11/03/hello-world/#comment-1",
148
+ "type": "comment",
149
+ "author_avatar_urls": {
150
+ "24": "http://0.gravatar.com/avatar/?s=24&d=mm&r=g",
151
+ "48": "http://1.gravatar.com/avatar/?s=48&d=mm&r=g",
152
+ "96": "http://2.gravatar.com/avatar/?s=96&d=mm&r=g"
153
+ },
154
+ "_links": {
155
+ "self": [
156
+ {
157
+ "href": "http://example.com/wp-json/wp/v2/comments/1"
158
+ }
159
+ ],
160
+ "collection": [
161
+ {
162
+ "href": "http://example.com/wp-json/wp/v2/comments"
163
+ }
164
+ ],
165
+ "up": [
166
+ {
167
+ "embeddable": true,
168
+ "post_type": "post",
169
+ "href": "http://example.com/wp-json/wp/v2/posts/1"
170
+ }
171
+ ]
172
+ }
173
+ }
174
+ ]
175
+ ],
176
+ "wp:featuredmedia": [
177
+ {
178
+ "id": 5,
179
+ "date": "2017-07-31T13:23:01",
180
+ "slug": "food-waffles-e1430873095640",
181
+ "type": "attachment",
182
+ "link": "http://example.com/2015/11/03/hello-world/food-waffles-e1430873095640/",
183
+ "title": {
184
+ "rendered": "food-waffles-e1430873095640"
185
+ },
186
+ "author": 1,
187
+ "caption": {
188
+ "rendered": ""
189
+ },
190
+ "alt_text": "",
191
+ "media_type": "image",
192
+ "mime_type": "image/png",
193
+ "media_details": {
194
+ "width": 128,
195
+ "height": 89,
196
+ "file": "2015/11/food-waffles-e1430873095640.png",
197
+ "image_meta": {
198
+ "aperture": "0",
199
+ "credit": "",
200
+ "camera": "",
201
+ "caption": "",
202
+ "created_timestamp": "0",
203
+ "copyright": "",
204
+ "focal_length": "0",
205
+ "iso": "0",
206
+ "shutter_speed": "0",
207
+ "title": "",
208
+ "orientation": "0",
209
+ "keywords": []
210
+ },
211
+ "sizes": {}
212
+ },
213
+ "source_url": "http://example.com/wp-content/uploads/2015/11/food-waffles-e1430873095640.png",
214
+ "_links": {
215
+ "self": [
216
+ {
217
+ "href": "http://example.com/wp-json/wp/v2/media/5"
218
+ }
219
+ ],
220
+ "collection": [
221
+ {
222
+ "href": "http://example.com/wp-json/wp/v2/media"
223
+ }
224
+ ],
225
+ "about": [
226
+ {
227
+ "href": "http://example.com/wp-json/wp/v2/types/attachment"
228
+ }
229
+ ],
230
+ "author": [
231
+ {
232
+ "embeddable": true,
233
+ "href": "http://example.com/wp-json/wp/v2/users/1"
234
+ }
235
+ ],
236
+ "replies": [
237
+ {
238
+ "embeddable": true,
239
+ "href": "http://example.com/wp-json/wp/v2/comments?post=5"
240
+ }
241
+ ]
242
+ }
243
+ }
244
+ ],
245
+ "wp:term": [
246
+ [
247
+ {
248
+ "id": 1,
249
+ "link": "http://example.com/category/uncategorized/",
250
+ "name": "Uncategorized",
251
+ "slug": "uncategorized",
252
+ "taxonomy": "category",
253
+ "_links": {
254
+ "self": [
255
+ {
256
+ "href": "http://example.com/wp-json/wp/v2/categories/1"
257
+ }
258
+ ],
259
+ "collection": [
260
+ {
261
+ "href": "http://example.com/wp-json/wp/v2/categories"
262
+ }
263
+ ],
264
+ "about": [
265
+ {
266
+ "href": "http://example.com/wp-json/wp/v2/taxonomies/category"
267
+ }
268
+ ],
269
+ "wp:post_type": [
270
+ {
271
+ "href": "http://example.com/wp-json/wp/v2/posts?categories=1"
272
+ }
273
+ ],
274
+ "curies": [
275
+ {
276
+ "name": "wp",
277
+ "href": "https://api.w.org/{rel}",
278
+ "templated": true
279
+ }
280
+ ]
281
+ }
282
+ }
283
+ ],
284
+ [
285
+ {
286
+ "id": 2,
287
+ "link": "http://example.com/tag/winamp/",
288
+ "name": "winamp",
289
+ "slug": "winamp",
290
+ "taxonomy": "post_tag",
291
+ "_links": {
292
+ "self": [
293
+ {
294
+ "href": "http://example.com/wp-json/wp/v2/tags/2"
295
+ }
296
+ ],
297
+ "collection": [
298
+ {
299
+ "href": "http://example.com/wp-json/wp/v2/tags"
300
+ }
301
+ ],
302
+ "about": [
303
+ {
304
+ "href": "http://example.com/wp-json/wp/v2/taxonomies/post_tag"
305
+ }
306
+ ],
307
+ "wp:post_type": [
308
+ {
309
+ "href": "http://example.com/wp-json/wp/v2/posts?tags=2"
310
+ }
311
+ ],
312
+ "curies": [
313
+ {
314
+ "name": "wp",
315
+ "href": "https://api.w.org/{rel}",
316
+ "templated": true
317
+ }
318
+ ]
319
+ }
320
+ }
321
+ ]
322
+ ]
323
+ }
324
+ }
@@ -40,7 +40,7 @@ describe "Attachments" do
40
40
  it "uses HTML for the title" do
41
41
  media = find_or_create_attachment
42
42
  updated = client.update_media(media.id, title: "Images & paint")
43
- expect(updated.title_html).to eq "Images &amp; paint"
43
+ expect(updated.title_html).to eq "Images &#038; paint"
44
44
  end
45
45
 
46
46
  def find_or_create_attachment
@@ -71,7 +71,7 @@ describe "Posts (CRUD)" do
71
71
  )
72
72
 
73
73
  expect(post.content_html.strip).to eq '<p class="hello-world">Hello world</p>'
74
- expect(post.title_html.strip).to eq 'HTML test &amp; verify'
74
+ expect(post.title_html.strip).to eq 'HTML test &#038; verify'
75
75
  end
76
76
 
77
77
  it "can move a post to the trash can" do
@@ -14,73 +14,4 @@ describe "Posts (finding)" do
14
14
  expect(posts.map(&:id)).to eq posts.sort_by(&:date).reverse.map(&:id)
15
15
  end
16
16
 
17
- it "can list articles in a specific category" do
18
- category = client.create_category(name: "Filtering time", slug: "filtering")
19
- post = client.create_post(
20
- category_ids: [category.id],
21
- status: "publish",
22
- title: "Some title",
23
- )
24
-
25
- expect(client.posts(category_slug: "filtering").map(&:id)).to eq [post.id]
26
- end
27
-
28
- it "can list articles in a specific tag" do
29
- tag = client.create_tag(name: "Taggged", slug: "tagged")
30
- post = client.create_post(
31
- tag_ids: [tag.id],
32
- status: "publish",
33
- title: "Some title",
34
- )
35
-
36
- expect(client.posts(tag_slug: "tagged").map(&:id)).to eq [post.id]
37
- end
38
-
39
- it "can list articles in a specific tag and category" do
40
- category = client.create_category(name: "Fishing", slug: "fish")
41
- tag = client.create_tag(name: "Soup", slug: "soup")
42
- post = client.create_post(
43
- category_ids: [category.id],
44
- tag_ids: [tag.id],
45
- status: "publish",
46
- title: "Some title",
47
- )
48
-
49
- _post_without_tag = client.create_post(
50
- category_ids: [category.id],
51
- status: "publish",
52
- title: "Some title",
53
- )
54
-
55
- _post_without_category = client.create_post(
56
- tag_ids: [tag.id],
57
- status: "publish",
58
- title: "Some title",
59
- )
60
-
61
- expect(client.posts(category_slug: "fish", tag_slug: "soup").map(&:id)).to eq [post.id]
62
- end
63
-
64
- describe "finding by slug" do
65
- it "finds the matching post" do
66
- post = client.create_post(title: "Oh hai", slug: "oh-hai")
67
- found = client.find_by_slug("oh-hai")
68
- expect(found.id).to eq post.id
69
- end
70
-
71
- it "raises NotFoundError when no post can be found" do
72
- expect {
73
- client.find_by_slug("clearly-does-not-exist-anywhere")
74
- }.to raise_error(WordpressClient::NotFoundError, /clearly/)
75
- end
76
-
77
- it "finds on the slug even if the title is wildly different" do
78
- post = client.create_post(
79
- title: "Updated title that doesn't match slug",
80
- slug: "original-concise-title",
81
- )
82
- found = client.find_by_slug("original-concise-title")
83
- expect(found.id).to eq post.id
84
- end
85
- end
86
17
  end
@@ -4,24 +4,24 @@ describe "Post meta" do
4
4
  setup_integration_client
5
5
 
6
6
  it "can be set on a post" do
7
- post = client.create_post(title: "Metadata creation", meta: {foo: "bar"})
8
- expect(post.meta).to eq("foo" => "bar")
7
+ post = client.create_post(title: "Metadata creation", meta: {"foo" => 7})
8
+ expect(post.meta).to include("foo" => 7)
9
9
  end
10
10
 
11
11
  it "can be updated on a post" do
12
- post = client.create_post(title: "Metadata creation", meta: {before: "now"})
13
- post = client.update_post(post.id, meta: {"before" => "then", "after" => "now"})
14
- expect(post.meta).to eq("before" => "then", "after" => "now")
12
+ post = client.create_post(title: "Metadata creation", meta: {"foo" => 1})
13
+ post = client.update_post(post.id, meta: {"foo" => 2, "bar" => true})
14
+ expect(post.meta).to include("foo" => 2, "bar" => true)
15
15
  end
16
16
 
17
17
  it "can remove metadata for a post" do
18
- post = client.create_post(title: "Metadata creation", meta: {one: "1", two: "2", three: "3"})
19
- post = client.update_post(post.id, meta: {three: "3", two: nil})
20
- expect(post.meta).to eq("three" => "3")
18
+ post = client.create_post(title: "Metadata creation", meta: {foo: 1, bar: true, baz: "foobar"})
19
+ post = client.update_post(post.id, meta: {foo: 5, baz: nil})
20
+ expect(post.meta).to eq("foo" => 5, "bar" => true, "baz" => "")
21
21
  end
22
22
 
23
- it "does not contain HTML data" do
24
- post = client.create_post(title: "Metadata HTML", meta: {foo: "bar&baz"})
25
- expect(post.meta).to eq("foo" => "bar&baz")
23
+ it "returns unescaped HTML" do
24
+ post = client.create_post(title: "Metadata HTML", meta: {baz: "larry&curly<moe>"})
25
+ expect(post.meta).to eq("baz" => "larry&curly<moe>", "foo" => 0, "bar" => false)
26
26
  end
27
27
  end
@@ -3,19 +3,33 @@ require "spec_helper"
3
3
  describe "Posts with attachments" do
4
4
  setup_integration_client
5
5
 
6
- it "exposes featured image as a Media instance" do
7
- media = find_or_upload_media
8
- post = client.create_post(title: "With media", featured_image: media.id)
6
+ it "exposes featured media as a Media instance" do
7
+ media = find_or_upload_image
8
+ post = client.create_post(title: "With image", featured_media: media.id)
9
+ expect(post.featured_media).to be_instance_of(WordpressClient::Media)
10
+ expect(post.featured_media.id).to eq media.id
11
+ expect(post.featured_media.slug).to eq media.slug
12
+ expect(post.featured_media.guid).to eq media.guid
13
+ expect(post.featured_media.source_url).to eq media.source_url
14
+ expect(post.featured_media_id).to eq media.id
15
+ end
9
16
 
17
+ it "exposes featured media as featured image if Media is an image" do
18
+ media = find_or_upload_image
19
+ post = client.create_post(title: "With image", featured_media: media.id)
10
20
  expect(post.featured_image).to be_instance_of(WordpressClient::Media)
21
+ expect(post.featured_image.id).to eq media.id
11
22
  expect(post.featured_image.slug).to eq media.slug
12
23
  expect(post.featured_image.guid).to eq media.guid
13
24
  expect(post.featured_image.source_url).to eq media.source_url
14
- expect(post.featured_image_id).to eq media.id
15
25
  end
16
26
 
17
- def find_or_upload_media
18
- client.media(per_page: 1).first ||
27
+ def find_or_upload_image
28
+ find_media_of_type("image") ||
19
29
  client.upload_file(fixture_path("thoughtful.jpg"), mime_type: "image/jpeg")
20
30
  end
31
+
32
+ def find_media_of_type(type)
33
+ client.media(per_page: 10).detect { |media| media.media_type == type }
34
+ end
21
35
  end
data/spec/media_spec.rb CHANGED
@@ -8,8 +8,10 @@ module WordpressClient
8
8
  media = Media.parse(fixture)
9
9
 
10
10
  expect(media.id).to eq 5
11
+ expect(media.media_type).to eq "image"
11
12
  expect(media.title_html).to eq "thoughtful"
12
13
  expect(media.slug).to eq "thoughtful"
14
+ expect(media.alt_text).to eq "accessibility is cool"
13
15
  expect(media.description).to eq ""
14
16
 
15
17
  expect(media.guid).to eq "http://example.com/wp-content/uploads/2015/11/thoughtful.jpg"
@@ -59,5 +61,17 @@ module WordpressClient
59
61
  expect(media.updated_at).to eq Time.local(2001, 1, 1, 12, 0, 0)
60
62
  end
61
63
  end
64
+
65
+ describe "#as_image" do
66
+ it "returns self if media_type is image" do
67
+ media = Media.parse(fixture)
68
+ expect(media.as_image).to eq(media)
69
+ end
70
+
71
+ it "returns nil when media_type is not image" do
72
+ media = Media.parse(fixture.merge("media_type" => "video"))
73
+ expect(media.as_image).to be_nil
74
+ end
75
+ end
62
76
  end
63
77
  end