wordpress-client 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wordpress-client.rb +9 -0
- data/lib/wordpress/api.rb +31 -39
- data/lib/wordpress/api/comments.rb +40 -18
- data/lib/wordpress/api/follow.rb +16 -15
- data/lib/wordpress/api/freshly_pressed.rb +8 -5
- data/lib/wordpress/api/me.rb +14 -6
- data/lib/wordpress/api/notifications.rb +20 -21
- data/lib/wordpress/api/posts.rb +64 -36
- data/lib/wordpress/api/sites.rb +10 -3
- data/lib/wordpress/api/taxonomy.rb +43 -48
- data/lib/wordpress/api/tests.rb +21 -7
- data/lib/wordpress/client.rb +5 -4
- data/lib/wordpress/configuration.rb +3 -1
- data/lib/wordpress/object/meta_object.rb +3 -2
- data/lib/wordpress/version.rb +1 -1
- data/spec/wordpress/api_spec.rb +38 -1
- data/spec/wordpress/client_spec.rb +20 -0
- metadata +2 -2
data/lib/wordpress-client.rb
CHANGED
data/lib/wordpress/api.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'wordpress/errors'
|
2
2
|
require 'wordpress/request'
|
3
|
+
Dir.glob(File.expand_path('../api/*.rb', __FILE__)) do |path|
|
4
|
+
require path
|
5
|
+
end
|
3
6
|
|
4
7
|
module Wordpress
|
5
8
|
module API
|
@@ -7,39 +10,44 @@ module Wordpress
|
|
7
10
|
base.send(:include, InstanceMethods)
|
8
11
|
base.extend(ClassMethods)
|
9
12
|
base.class_eval do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
include Posts
|
14
|
+
include Comments
|
15
|
+
include Sites
|
16
|
+
include Me
|
17
|
+
include Tests
|
18
|
+
include Follow
|
19
|
+
include Taxonomy
|
20
|
+
include Notifications
|
21
|
+
include FreshlyPressed
|
13
22
|
end
|
14
23
|
end
|
15
24
|
|
16
25
|
module ClassMethods
|
17
|
-
|
18
|
-
arg_names = path.scan(/\$([\w]+)/).map{ |a| a[0] }
|
19
|
-
|
20
|
-
@registered_apis ||= {}
|
21
|
-
@registered_apis[name] = {:method => method, :path => path, :arg_names => arg_names, :valid_keys => valid_keys, :response => response}
|
22
|
-
|
23
|
-
remove_method name if method_defined?(name)
|
24
|
-
define_method name do |*args|
|
25
|
-
params = args[-1].is_a?(Hash) ? args.pop : {}
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
module InstanceMethods
|
29
|
+
def exec_api(request, &response)
|
30
|
+
json = call(request, :bearer_token_request => true)
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
if !json['error'].nil?
|
33
|
+
raise Wordpress::ResponseError, json
|
34
|
+
end
|
35
|
+
|
36
|
+
if response.nil?
|
37
|
+
Wordpress::OpenStruct.new(json)
|
38
|
+
else
|
39
|
+
instance_exec(json, &response)
|
40
|
+
end
|
41
|
+
end
|
36
42
|
|
37
|
-
|
43
|
+
private
|
38
44
|
|
39
|
-
|
45
|
+
def validate_keys!(params, valid_keys)
|
46
|
+
params.keys.each do |key|
|
47
|
+
raise Wordpress::ArgumentError, "#{key} is not valid for this method." unless valid_keys.include?(key)
|
40
48
|
end
|
41
49
|
end
|
42
|
-
|
50
|
+
|
43
51
|
def default_keys
|
44
52
|
[:http_envelope, :pretty, :meta, :callback].freeze
|
45
53
|
end
|
@@ -47,22 +55,6 @@ module Wordpress
|
|
47
55
|
def search_keys
|
48
56
|
[:number, :offset, :page, :order, :order_by, :after, :before].freeze
|
49
57
|
end
|
50
|
-
|
51
|
-
def registered_apis
|
52
|
-
(@registered_apis || {}).freeze
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
module InstanceMethods
|
57
|
-
def call_api(request)
|
58
|
-
json = call(request, :bearer_token_request => true)
|
59
|
-
|
60
|
-
if !json['error'].nil?
|
61
|
-
raise Wordpress::ResponseError, json
|
62
|
-
end
|
63
|
-
|
64
|
-
json
|
65
|
-
end
|
66
58
|
end
|
67
59
|
end
|
68
60
|
end
|
@@ -1,26 +1,48 @@
|
|
1
1
|
require "wordpress/object/comments"
|
2
2
|
require "wordpress/object/comment"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Wordpress::API
|
5
|
+
module Comments
|
6
|
+
def get_comments(site, params = {})
|
7
|
+
validate_keys! params, [:context, :type, :status] + default_keys + search_keys
|
8
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/comments", params)) do |json|
|
9
|
+
Wordpress::Object::Comments.new(self, json)
|
10
|
+
end
|
11
|
+
end
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
|
13
|
+
def get_post_comments(site, post_id, params = {})
|
14
|
+
validate_keys! params, [:context] + default_keys
|
15
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/posts/#{post_id}/replies", params)) do |json|
|
16
|
+
Wordpress::Object::Comments.new(self, json)
|
17
|
+
end
|
18
|
+
end
|
11
19
|
|
12
|
-
|
13
|
-
|
14
|
-
|
20
|
+
def get_comment(site, comment_id, params = {})
|
21
|
+
validate_keys! params, [:context] + default_keys
|
22
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/comments/#{comment_id}", params)) do |json|
|
23
|
+
Wordpress::Object::Comment.new(self, json)
|
24
|
+
end
|
25
|
+
end
|
15
26
|
|
16
|
-
|
17
|
-
|
18
|
-
|
27
|
+
def update_comment(site, comment_id, data, params = {})
|
28
|
+
validate_keys! params, [:context] + default_keys
|
29
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/comments/#{comment_id}", params, data)) do |json|
|
30
|
+
Wordpress::Object::Comment.new(self, json)
|
31
|
+
end
|
32
|
+
end
|
19
33
|
|
20
|
-
|
21
|
-
|
22
|
-
|
34
|
+
def create_comment(site, post_id, data, params = {})
|
35
|
+
validate_keys! params, [:context] + default_keys
|
36
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/posts/#{post_id}/replies/new", params, data)) do |json|
|
37
|
+
Wordpress::Object::Comment.new(self, json)
|
38
|
+
end
|
39
|
+
end
|
23
40
|
|
24
|
-
|
25
|
-
|
26
|
-
|
41
|
+
def delete_comment(site, comment_id, data, params = {})
|
42
|
+
validate_keys! params, [:context] + default_keys
|
43
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/comments/#{comment_id}/delete", params, data)) do |json|
|
44
|
+
Wordpress::Object::Comment.new(self, json)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/wordpress/api/follow.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require "wordpress/ostruct"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Wordpress::API
|
4
|
+
module Follow
|
5
|
+
def create_follow(site, data, params = {})
|
6
|
+
validate_keys! params, [:context] + default_keys
|
7
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/follows/new", params, data))
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
10
|
+
def delete_follow(site, data, params = {})
|
11
|
+
validate_keys! params, [:context] + default_keys
|
12
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/follows/mine/delete", params, data))
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def get_follow(site, params = {})
|
16
|
+
validate_keys! params, [:context] + default_keys
|
17
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/follows/mine", params))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
require "wordpress/ostruct"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Wordpress::API
|
4
|
+
module FreshlyPressed
|
5
|
+
def freshly_pressed(params = {})
|
6
|
+
validate_keys! params, [:number, :after, :before, :content_width, :thumb_width, :thumb_height] + default_keys
|
7
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/freshly-pressed", params))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/wordpress/api/me.rb
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
require "wordpress/ostruct"
|
2
2
|
require "wordpress/object/user"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Wordpress::API
|
5
|
+
module Me
|
6
|
+
def me(params = {})
|
7
|
+
validate_keys! params, default_keys
|
8
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/me", params)) do |json|
|
9
|
+
Wordpress::Object::User.new(self, json)
|
10
|
+
end
|
11
|
+
end
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
|
13
|
+
def get_my_likes(params = {})
|
14
|
+
validate_keys! params, default_keys
|
15
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/me/likes", params))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,26 +1,25 @@
|
|
1
1
|
require "wordpress/ostruct"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module Wordpress::API
|
4
|
+
module Notifications
|
5
|
+
def get_notifications(params = {})
|
6
|
+
validate_keys! params, [:ids, :fields, :type, :unread, :read, :number, :since, :before, :num_note_items, :trap] + default_keys
|
7
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/notifications", params))
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
10
|
+
def get_notification(note_id, params = {})
|
11
|
+
validate_keys! params, [:context, :fields, :num_note_items] + default_keys
|
12
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/notifications/#{note_id}", params))
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
}
|
20
|
-
|
21
|
-
register_api :read_notification, :post, "/rest/v1/notifications/read",
|
22
|
-
[:context] + default_keys,
|
23
|
-
lambda{ |json|
|
24
|
-
Wordpress::OpenStruct.new(json)
|
25
|
-
}
|
15
|
+
def see_notifications(data, params = {})
|
16
|
+
validate_keys! params, [:context] + default_keys
|
17
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/notifications/seen", params, data))
|
18
|
+
end
|
26
19
|
|
20
|
+
def read_notifications(data, params = {})
|
21
|
+
validate_keys! params, [:context] + default_keys
|
22
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/notifications/read", params, data))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/wordpress/api/posts.rb
CHANGED
@@ -2,50 +2,78 @@ require "wordpress/ostruct"
|
|
2
2
|
require "wordpress/object/posts"
|
3
3
|
require "wordpress/object/post"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Wordpress::API
|
6
|
+
module Posts
|
7
|
+
def get_posts(site, params = {})
|
8
|
+
validate_keys! params, [:context, :tag, :category, :type, :status, :sticky, :author, :search, :meta_key, :meta_value] + default_keys + search_keys
|
9
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/posts", params)) do |json|
|
10
|
+
Wordpress::Object::Posts.new(self, json)
|
11
|
+
end
|
12
|
+
end
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
14
|
+
def get_post(site, post_id, params = {})
|
15
|
+
validate_keys! params, [:context] + default_keys
|
16
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/posts/#{post_id}", params)) do |json|
|
17
|
+
Wordpress::Object::Post.new(self, json)
|
18
|
+
end
|
19
|
+
end
|
12
20
|
|
13
|
-
|
14
|
-
|
15
|
-
|
21
|
+
def update_post(site, post_id, data, params = {})
|
22
|
+
validate_keys! params, [:context] + default_keys
|
23
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/posts/#{post_id}", params, data)) do |json|
|
24
|
+
Wordpress::Object::Post.new(self, json)
|
25
|
+
end
|
26
|
+
end
|
16
27
|
|
17
|
-
|
18
|
-
|
19
|
-
|
28
|
+
def get_post_by_slug(site, slug, params = {})
|
29
|
+
validate_keys! params, [:context] + default_keys
|
30
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/posts/slug:#{slug}", params)) do |json|
|
31
|
+
Wordpress::Object::Post.new(self, json)
|
32
|
+
end
|
33
|
+
end
|
20
34
|
|
21
|
-
|
22
|
-
|
23
|
-
|
35
|
+
def create_post(site, data, params = {})
|
36
|
+
validate_keys! params, [:context] + default_keys
|
37
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/posts/new", params, data)) do |json|
|
38
|
+
Wordpress::Object::Post.new(self, json)
|
39
|
+
end
|
40
|
+
end
|
24
41
|
|
25
|
-
|
26
|
-
|
27
|
-
|
42
|
+
def delete_post(site, post_id, data, params = {})
|
43
|
+
validate_keys! params, [:context] + default_keys
|
44
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/posts/#{post_id}/delete", params, data)) do |json|
|
45
|
+
Wordpress::Object::Post.new(self, json)
|
46
|
+
end
|
47
|
+
end
|
28
48
|
|
29
|
-
|
30
|
-
|
31
|
-
|
49
|
+
def get_likes(site, post_id, params = {})
|
50
|
+
validate_keys! params, default_keys
|
51
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/posts/#{post_id}/likes", params))
|
52
|
+
end
|
32
53
|
|
33
|
-
|
34
|
-
|
35
|
-
|
54
|
+
def create_like(site, post_id, data, params = {})
|
55
|
+
validate_keys! params, default_keys
|
56
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/posts/#{post_id}/likes/new", params, data))
|
57
|
+
end
|
36
58
|
|
37
|
-
|
38
|
-
|
39
|
-
|
59
|
+
def delete_like(site, post_id, data, params = {})
|
60
|
+
validate_keys! params, default_keys
|
61
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/posts/#{post_id}/likes/mine/delete", params, data))
|
62
|
+
end
|
40
63
|
|
41
|
-
|
42
|
-
|
43
|
-
|
64
|
+
def get_like_status(site, post_id, params = {})
|
65
|
+
validate_keys! params, default_keys
|
66
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/posts/#{post_id}/likes/mine", params))
|
67
|
+
end
|
44
68
|
|
45
|
-
|
46
|
-
|
47
|
-
|
69
|
+
def get_reblog_status(site, post_id, params = {})
|
70
|
+
validate_keys! params, default_keys
|
71
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/posts/#{post_id}/reblogs/mine", params))
|
72
|
+
end
|
48
73
|
|
49
|
-
|
50
|
-
|
51
|
-
|
74
|
+
def create_reblog(site, post_id, data, params = {})
|
75
|
+
validate_keys! params, default_keys
|
76
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/posts/#{post_id}/reblogs/new", params, data))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/wordpress/api/sites.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
require "wordpress/object/site"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Wordpress::API
|
4
|
+
module Sites
|
5
|
+
def get_site(site, params = {})
|
6
|
+
validate_keys! params, default_keys
|
7
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}", params)) do |json|
|
8
|
+
Wordpress::Object::Site.new(self, json)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,50 +1,45 @@
|
|
1
1
|
require "wordpress/ostruct"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
[:context] + default_keys,
|
47
|
-
lambda{ |json|
|
48
|
-
Wordpress::OpenStruct.new(json)
|
49
|
-
}
|
50
|
-
|
3
|
+
module Wordpress::API
|
4
|
+
module Taxonomy
|
5
|
+
def get_category(site, slug, params = {})
|
6
|
+
validate_keys! params, [:context] + default_keys
|
7
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/categories/slug:#{slug}", params))
|
8
|
+
end
|
9
|
+
|
10
|
+
def update_category(site, slug, data, params = {})
|
11
|
+
validate_keys! params, [:context] + default_keys
|
12
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/categories/slug:#{slug}", params, data))
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_tag(site, slug, params = {})
|
16
|
+
validate_keys! params, [:context] + default_keys
|
17
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/sites/#{site}/tags/slug:#{slug}", params))
|
18
|
+
end
|
19
|
+
|
20
|
+
def update_tag(site, slug, data, params = {})
|
21
|
+
validate_keys! params, [:context] + default_keys
|
22
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/tags/slug:#{slug}", params, data))
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_category(site, data, params = {})
|
26
|
+
validate_keys! params, [:context] + default_keys
|
27
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/categories/new", params, data))
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_tag(site, data, params = {})
|
31
|
+
validate_keys! params, [:context] + default_keys
|
32
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/tags/new", params, data))
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_category(site, slug, data, params = {})
|
36
|
+
validate_keys! params, [:context] + default_keys
|
37
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/categories/slug:#{slug}/delete", params, data))
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_tag(site, slug, data, params = {})
|
41
|
+
validate_keys! params, [:context] + default_keys
|
42
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/sites/#{site}/tags/slug:#{slug}/delete", params, data))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/wordpress/api/tests.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
require "wordpress/object/test"
|
2
2
|
|
3
|
-
|
3
|
+
module Wordpress::API
|
4
|
+
module Tests
|
5
|
+
def get_test(id, params = {})
|
6
|
+
validate_keys! params, test_keys
|
7
|
+
exec_api(Wordpress::Request.new(:get, "/rest/v1/test/#{id}", params)) do |json|
|
8
|
+
Wordpress::Object::Test.new(self, json)
|
9
|
+
end
|
10
|
+
end
|
4
11
|
|
5
|
-
|
6
|
-
|
7
|
-
|
12
|
+
def post_test(id, data, params = {})
|
13
|
+
validate_keys! params, test_keys
|
14
|
+
exec_api(Wordpress::Request.new(:post, "/rest/v1/test/#{id}", params, data)) do |json|
|
15
|
+
Wordpress::Object::Test.new(self, json)
|
16
|
+
end
|
17
|
+
end
|
8
18
|
|
9
|
-
|
10
|
-
|
11
|
-
|
19
|
+
private
|
20
|
+
|
21
|
+
def test_keys
|
22
|
+
[:id, :default_string, :default_int, :boolean_whitelist_defaults_to_false, :boolean_whitelist_defaults_to_true, :string_whitelist_defaults_to_foo, :url, :datetime].freeze
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/wordpress/client.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'multi_json'
|
2
2
|
require 'faraday'
|
3
3
|
require 'faraday_middleware/gzip'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
require_relative 'base'
|
5
|
+
require_relative 'request'
|
6
|
+
require_relative 'api'
|
7
|
+
require_relative 'errors'
|
8
|
+
require_relative 'configuration'
|
8
9
|
|
9
10
|
module Wordpress
|
10
11
|
class Client < Base
|
@@ -24,8 +24,9 @@ module Wordpress::Object
|
|
24
24
|
def reload
|
25
25
|
if meta && meta.links && meta.links.self
|
26
26
|
request = Wordpress::Request.new(:get, meta.links.self)
|
27
|
-
|
28
|
-
|
27
|
+
client.exec_api(request) do |json|
|
28
|
+
self.assign(json)
|
29
|
+
end
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
data/lib/wordpress/version.rb
CHANGED
@@ -2,7 +2,7 @@ module Wordpress
|
|
2
2
|
class Version
|
3
3
|
MAJOR = 0 unless defined? Wordpress::Version::MAJOR
|
4
4
|
MINOR = 2 unless defined? Wordpress::Version::MINOR
|
5
|
-
PATCH =
|
5
|
+
PATCH = 1 unless defined? Wordpress::Version::PATCH
|
6
6
|
PRE = nil unless defined? Wordpress::Version::PRE
|
7
7
|
|
8
8
|
class << self
|
data/spec/wordpress/api_spec.rb
CHANGED
@@ -6,27 +6,64 @@ describe Wordpress::API do
|
|
6
6
|
Wordpress::Client.new
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
describe "\#exec_api" do
|
10
|
+
it "should raise error for error response" do
|
11
|
+
client.stub(:call).and_return({'error' => 'something wrong!'})
|
12
|
+
expect {
|
13
|
+
client.exec_api(nil)
|
14
|
+
}.to raise_error(Wordpress::ResponseError)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
10
18
|
{
|
19
|
+
# Me
|
11
20
|
'me' => {:args => [], :method => :get, :url => '/rest/v1/me', :response => Wordpress::Object::User},
|
12
21
|
'get_my_likes' => {:args => [], :method => :get, :url => '/rest/v1/me/likes', :response => Wordpress::OpenStruct},
|
22
|
+
# Posts
|
13
23
|
'get_posts' => {:args => ['sitename'], :method => :get, :url => '/rest/v1/sites/sitename/posts', :response => Wordpress::Object::Posts},
|
14
24
|
'get_post' => {:args => ['sitename', 1], :method => :get, :url => '/rest/v1/sites/sitename/posts/1', :response => Wordpress::Object::Post},
|
25
|
+
'update_post' => {:args => ['sitename', 1, {}], :method => :post, :url => '/rest/v1/sites/sitename/posts/1', :response => Wordpress::Object::Post},
|
15
26
|
'get_post_by_slug' => {:args => ['sitename', 1], :method => :get, :url => '/rest/v1/sites/sitename/posts/slug:1', :response => Wordpress::Object::Post},
|
27
|
+
'create_post' => {:args => ['sitename', {}], :method => :post, :url => '/rest/v1/sites/sitename/posts/new', :response => Wordpress::Object::Post},
|
28
|
+
'delete_post' => {:args => ['sitename', 1, {}], :method => :post, :url => '/rest/v1/sites/sitename/posts/1/delete', :response => Wordpress::Object::Post},
|
16
29
|
'get_likes' => {:args => ['sitename', 1], :method => :get, :url => '/rest/v1/sites/sitename/posts/1/likes', :response => Wordpress::OpenStruct},
|
30
|
+
'create_like' => {:args => ['sitename', 1, {}], :method => :post, :url => '/rest/v1/sites/sitename/posts/1/likes/new', :response => Wordpress::OpenStruct},
|
31
|
+
'delete_like' => {:args => ['sitename', 1, {}], :method => :post, :url => '/rest/v1/sites/sitename/posts/1/likes/mine/delete', :response => Wordpress::OpenStruct},
|
17
32
|
'get_like_status' => {:args => ['sitename', 1], :method => :get, :url => '/rest/v1/sites/sitename/posts/1/likes/mine', :response => Wordpress::OpenStruct},
|
18
33
|
'get_reblog_status' => {:args => ['sitename', 1], :method => :get, :url => '/rest/v1/sites/sitename/posts/1/reblogs/mine', :response => Wordpress::OpenStruct},
|
34
|
+
'create_reblog' => {:args => ['sitename', 1, {}], :method => :post, :url => '/rest/v1/sites/sitename/posts/1/reblogs/new', :response => Wordpress::OpenStruct},
|
35
|
+
# Sites
|
19
36
|
'get_site' => {:args => ['sitename'], :method => :get, :url => '/rest/v1/sites/sitename', :response => Wordpress::Object::Site},
|
37
|
+
# Comments
|
20
38
|
'get_comments' => {:args => ['sitename'], :method => :get, :url => '/rest/v1/sites/sitename/comments', :response => Wordpress::Object::Comments},
|
21
39
|
'get_post_comments' => {:args => ['sitename', 1], :method => :get, :url => '/rest/v1/sites/sitename/posts/1/replies', :response => Wordpress::Object::Comments},
|
22
40
|
'get_comment' => {:args => ['sitename', 1], :method => :get, :url => '/rest/v1/sites/sitename/comments/1', :response => Wordpress::Object::Comment},
|
41
|
+
'update_comment' => {:args => ['sitename', 1, {}], :method => :post, :url => '/rest/v1/sites/sitename/comments/1', :response => Wordpress::Object::Comment},
|
42
|
+
'create_comment' => {:args => ['sitename', 1, {}], :method => :post, :url => '/rest/v1/sites/sitename/posts/1/replies/new', :response => Wordpress::Object::Comment},
|
43
|
+
'delete_comment' => {:args => ['sitename', 1, {}], :method => :post, :url => '/rest/v1/sites/sitename/comments/1/delete', :response => Wordpress::Object::Comment},
|
44
|
+
# Tests
|
23
45
|
'get_test' => {:args => [1], :method => :get, :url => '/rest/v1/test/1', :response => Wordpress::Object::Test},
|
46
|
+
'post_test' => {:args => [1, {}], :method => :post, :url => '/rest/v1/test/1', :response => Wordpress::Object::Test},
|
47
|
+
# Taxonomy
|
24
48
|
'get_category' => {:args => ['sitename', 'cat_name'], :method => :get, :url => '/rest/v1/sites/sitename/categories/slug:cat_name', :response => Wordpress::OpenStruct},
|
49
|
+
'update_category' => {:args => ['sitename', 'cat_name', {}], :method => :post, :url => '/rest/v1/sites/sitename/categories/slug:cat_name', :response => Wordpress::OpenStruct},
|
25
50
|
'get_tag' => {:args => ['sitename', 'tag_name'], :method => :get, :url => '/rest/v1/sites/sitename/tags/slug:tag_name', :response => Wordpress::OpenStruct},
|
51
|
+
'update_tag' => {:args => ['sitename', 'tag_name', {}], :method => :post, :url => '/rest/v1/sites/sitename/tags/slug:tag_name', :response => Wordpress::OpenStruct},
|
52
|
+
'create_category' => {:args => ['sitename', {}], :method => :post, :url => '/rest/v1/sites/sitename/categories/new', :response => Wordpress::OpenStruct},
|
53
|
+
'create_tag' => {:args => ['sitename', {}], :method => :post, :url => '/rest/v1/sites/sitename/tags/new', :response => Wordpress::OpenStruct},
|
54
|
+
'delete_category' => {:args => ['sitename', 'cat_name', {}], :method => :post, :url => '/rest/v1/sites/sitename/categories/slug:cat_name/delete', :response => Wordpress::OpenStruct},
|
55
|
+
'delete_tag' => {:args => ['sitename', 'tag_name', {}], :method => :post, :url => '/rest/v1/sites/sitename/tags/slug:tag_name/delete', :response => Wordpress::OpenStruct},
|
56
|
+
# Follow
|
57
|
+
'create_follow' => {:args => ['sitename', {}], :method => :post, :url => '/rest/v1/sites/sitename/follows/new', :response => Wordpress::OpenStruct},
|
58
|
+
'delete_follow' => {:args => ['sitename', {}], :method => :post, :url => '/rest/v1/sites/sitename/follows/mine/delete', :response => Wordpress::OpenStruct},
|
26
59
|
'get_follow' => {:args => ['sitename'], :method => :get, :url => '/rest/v1/sites/sitename/follows/mine', :response => Wordpress::OpenStruct},
|
60
|
+
# FreshlyPressed
|
27
61
|
'freshly_pressed' => {:method => :get, :url => '/rest/v1/freshly-pressed', :response => Wordpress::OpenStruct},
|
62
|
+
# Notifications
|
28
63
|
'get_notifications' => {:method => :get, :url => '/rest/v1/notifications', :response => Wordpress::OpenStruct},
|
29
64
|
'get_notification' => {:args => [1], :method => :get, :url => '/rest/v1/notifications/1', :response => Wordpress::OpenStruct},
|
65
|
+
'see_notifications' => {:args => [{}], :method => :post, :url => '/rest/v1/notifications/seen', :response => Wordpress::OpenStruct},
|
66
|
+
'read_notifications' => {:args => [{}], :method => :post, :url => '/rest/v1/notifications/read', :response => Wordpress::OpenStruct},
|
30
67
|
}.each do |method, params|
|
31
68
|
describe "\##{method}" do
|
32
69
|
it "should return #{params[:response].name}" do
|
@@ -35,6 +35,26 @@ describe Wordpress::Client do
|
|
35
35
|
request = Wordpress::Request.new(:post, 'url', {}, {})
|
36
36
|
client.call(request)
|
37
37
|
end
|
38
|
+
|
39
|
+
it "should raise error for null response" do
|
40
|
+
request = Wordpress::Request.new(:get, 'url', {}, {})
|
41
|
+
Faraday::Connection.any_instance.stub(:get).and_return(Faraday::Response.new)
|
42
|
+
|
43
|
+
Faraday::Response.any_instance.stub(:body).and_return('null')
|
44
|
+
expect {
|
45
|
+
client.call(request)
|
46
|
+
}.to raise_error(Wordpress::ResponseError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should raise error for invalid response" do
|
50
|
+
request = Wordpress::Request.new(:get, 'url', {}, {})
|
51
|
+
Faraday::Connection.any_instance.stub(:get).and_return(Faraday::Response.new)
|
52
|
+
|
53
|
+
Faraday::Response.any_instance.stub(:body).and_return('/$%@#')
|
54
|
+
expect {
|
55
|
+
client.call(request)
|
56
|
+
}.to raise_error(Wordpress::ResponseError)
|
57
|
+
end
|
38
58
|
end
|
39
59
|
|
40
60
|
context "with bearer_token_request option" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wordpress-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-12-
|
12
|
+
date: 2013-12-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|