wordpress-api 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wordpress-api.rb +7 -132
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66bb53d8e461acd491ee10de02454577040bd7a4
|
4
|
+
data.tar.gz: 8aedffb4634db6f31f8670eabaf3cb338d17419f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d29ab3ee25aa7b8f524710760026508ca614db54d9e68d5738ffbe756eb4c419f8e05edc2f4b61fc4e7836f47d0915adcb69610b97661a2fea99b8d8d2ace6eb
|
7
|
+
data.tar.gz: 1f70e712e44ca217aadde985dac4cd009e3eb70a9d7702d1f99da65bbf2d4ec311c2723da4436b2d1d038f3c91076253edcf2003702b1ecbe8044b3677de9a62
|
data/lib/wordpress-api.rb
CHANGED
@@ -2,8 +2,10 @@ require 'net/http'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
class WordPress
|
5
|
+
def initalize
|
6
|
+
end
|
5
7
|
|
6
|
-
|
8
|
+
def self.set_source(source)
|
7
9
|
@source = source
|
8
10
|
end
|
9
11
|
|
@@ -15,142 +17,15 @@ class WordPress
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
18
|
-
def self.prepare_query(params)
|
19
|
-
args = Hash.new
|
20
|
-
if params.is_a?(Hash)
|
21
|
-
params.each{|x|
|
22
|
-
filter = "filter[#{x[0]}]";
|
23
|
-
arg = {filter => x[1]};
|
24
|
-
args = args.merge(arg);
|
25
|
-
return args
|
26
|
-
}
|
27
|
-
else
|
28
|
-
raise RuntimeError, "Something is wrong, perhaps you did not pass a hash."
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
20
|
def self.query_load_json(source, endpoint, params)
|
33
21
|
url = URI("#{source}#{endpoint}/")
|
34
|
-
|
35
|
-
args = prepare_query params
|
36
|
-
url.query = URI.encode_www_form(args)
|
37
|
-
end
|
22
|
+
url.query = URI.encode_www_form(params)
|
38
23
|
data = self.query_url(url)
|
39
24
|
content = JSON.load(data)
|
40
25
|
return content
|
41
26
|
end
|
42
27
|
|
43
|
-
# Get Posts from a WordPress source
|
44
|
-
#
|
45
|
-
# Requires:
|
46
|
-
# source (str): the url to the root API endpoint
|
47
|
-
# params (hash): a hash of parameters to filter by
|
48
|
-
#
|
49
|
-
# Note, the hash for the params argument should be formed like this:
|
50
|
-
#
|
51
|
-
# params = {'posts_per_page'=>'1','order'=>'ASC'}
|
52
|
-
#
|
53
|
-
# Even though WordPress requires the "filter" argument, we will prepend that
|
54
|
-
# for you in this method.
|
55
|
-
#
|
56
|
-
def self.get_posts(source, params = nil, post = nil)
|
57
|
-
if post.nil?
|
58
|
-
wpposts = self.query_load_json(source, "posts", params)
|
59
|
-
else
|
60
|
-
wpposts = self.get_post(source, post)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.get_post(source, post)
|
65
|
-
posts = self.query_load_json(source, "posts/#{post}", params = nil)
|
66
|
-
end
|
67
|
-
|
68
|
-
# Get Media from a WordPress source
|
69
|
-
#
|
70
|
-
# By default gets the 9 most recent media objects from the WordPress site. If
|
71
|
-
# passed optional parameters, will filter those posts accordingly. Like
|
72
|
-
# get_posts, this should be passed as a hash. If a specific attachment is
|
73
|
-
# given as the third parameter, it will return only that attachment's object
|
74
|
-
# and the `params` hash will be ignored (if passed)
|
75
|
-
#
|
76
|
-
# Requires:
|
77
|
-
# source (str): the url to the root API endpoint
|
78
|
-
# attachment (int, optional): a specific attachment to get
|
79
|
-
# params (hash, optional): a hash of parameters to filter by
|
80
|
-
#
|
81
|
-
# Note, the hash for the params argument should be formed like this:
|
82
|
-
#
|
83
|
-
# params = {'posts_per_page'=>'1','order'=>'ASC'}
|
84
|
-
#
|
85
|
-
# Even though WordPress requires the "filter" argument, we will prepend that
|
86
|
-
# for you in this method.
|
87
|
-
|
88
|
-
def self.get_media(source, params = nil, attachment = nil)
|
89
|
-
if attachment
|
90
|
-
posts = get_attachment(source, attachment)
|
91
|
-
else
|
92
|
-
posts = self.query_load_json(source, "media", params)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.get_attachment(source, attachment)
|
97
|
-
posts = self.query_load_json(source, "media/#{attachment}")
|
98
|
-
end
|
99
|
-
|
100
|
-
# Get Taxonomies from a WordPress source
|
101
|
-
#
|
102
|
-
# By default, returns all taxonomies registered in the WordPress database.
|
103
|
-
#
|
104
|
-
# If passed a hash of parameters, will filter the taxonomies accordingly.
|
105
|
-
# (See wp-json documentation at http://wp-api.org/#taxonomies_retrieve-all-taxonomies)
|
106
|
-
#
|
107
|
-
# Requires:
|
108
|
-
# source (str): the url to the root API endpoint
|
109
|
-
#
|
110
|
-
# Optional
|
111
|
-
# attachment (int): a specific attachment to get
|
112
|
-
# params (hash): a hash of parameters to filter by (currently no filters are
|
113
|
-
# documented at wp-api.org)
|
114
|
-
#
|
115
|
-
# Note, the hash for the params argument should be formed like this:
|
116
|
-
#
|
117
|
-
# params = {'posts_per_page'=>'1','order'=>'ASC'}
|
118
|
-
#
|
119
|
-
# Even though WordPress requires the "filter" argument, we will prepend that
|
120
|
-
# for you in this method.
|
121
|
-
|
122
|
-
def self.get_taxonomies(source, params = nil, taxonomy = nil)
|
123
|
-
if taxonomy
|
124
|
-
get_taxonomy(source, taxonomy)
|
125
|
-
else
|
126
|
-
taxonomies = self.query_load_json(source, "taxonomies")
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def self.get_taxonomy(source, taxonomy)
|
131
|
-
taxonomy = self.query_load_json(source, "taxonomies/#{taxonomy}")
|
132
|
-
end
|
133
|
-
|
134
|
-
# Get terms
|
135
|
-
#
|
136
|
-
# Retrieves all terms associated with a given taxonomy.
|
137
|
-
#
|
138
|
-
# Requires:
|
139
|
-
# source (str): the url to the root API endpoint
|
140
|
-
# taxonomy (str): the taxonomy from which to retrieve terms
|
141
|
-
#
|
142
|
-
# Optional:
|
143
|
-
# term (str): the slug of the term to retrieve
|
144
|
-
|
145
|
-
def self.get_terms(source, taxonomy, term = nil)
|
146
|
-
if term
|
147
|
-
terms = get_term(source, taxonomy, term)
|
148
|
-
else
|
149
|
-
terms = self.query_load_json(source, "/taxonomies/#{taxonomy}/terms")
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def get_term(source, taxonomy, term)
|
154
|
-
term = self.query_load_json(source, "/taxonomies/#{taxonomy}/terms/#{term}")
|
155
|
-
end
|
156
28
|
end
|
29
|
+
|
30
|
+
require_relative 'community'
|
31
|
+
require_relative 'jetpack'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wordpress-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Boone
|
@@ -10,10 +10,9 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
15
|
-
|
16
|
-
WordPress API homepage > http://wp-api.org.
|
13
|
+
description: "Methods for interfacing with the WordPress API. Currently\n supports
|
14
|
+
all unauthenticated get requests documented at the\n WordPress
|
15
|
+
API homepage > http://wp-api.org. Requires v2 of\n\t\t the AP"
|
17
16
|
email: greg@harmsboone.org
|
18
17
|
executables: []
|
19
18
|
extensions: []
|
@@ -40,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
39
|
version: '0'
|
41
40
|
requirements: []
|
42
41
|
rubyforge_project:
|
43
|
-
rubygems_version: 2.4.
|
42
|
+
rubygems_version: 2.4.6
|
44
43
|
signing_key:
|
45
44
|
specification_version: 4
|
46
45
|
summary: WordPress API
|