rooftop 0.0.7.4 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rooftop.rb +20 -2
- data/lib/rooftop/coercions/title_coercion.rb +6 -1
- data/lib/rooftop/content/collection.rb +2 -0
- data/lib/rooftop/content/content_fields.rb +12 -0
- data/lib/rooftop/errors/preview_key_mismatch.rb +6 -0
- data/lib/rooftop/middleware/headers.rb +2 -2
- data/lib/rooftop/middleware/record_not_found_middleware.rb +11 -0
- data/lib/rooftop/models/taxonomy.rb +22 -3
- data/lib/rooftop/page.rb +1 -0
- data/lib/rooftop/post.rb +1 -0
- data/lib/rooftop/preview.rb +20 -0
- data/lib/rooftop/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed668d2eb460ba58937c6b1a1498be8ea5ed96ec
|
4
|
+
data.tar.gz: be49d6620e86435f0a0cafe482c220d1547b852d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f108a0a84dcc99858b5d7d584160d9a7dfd1c40a2f815f8dec26de77e4aea4345f4edf3ab85cd6206851569778b1ee0db458db5393de1ece2722623dd4e945d0
|
7
|
+
data.tar.gz: efc3293ca6739a73bf786e80209a17fbbe1a699eea466a66126e63eab5c09e844de0da6c2b7f239cb5e6e7590a6661b35490c4e4087e6f7258f2bca0605ebd92
|
data/lib/rooftop.rb
CHANGED
@@ -9,8 +9,12 @@ module Rooftop
|
|
9
9
|
DEFAULT_API_VERSION = 2
|
10
10
|
|
11
11
|
class << self
|
12
|
-
|
13
|
-
|
12
|
+
extend Gem::Deprecate
|
13
|
+
#accessor to set whether we need to debug responses
|
14
|
+
attr_accessor :debug_requests, :debug_responses
|
15
|
+
|
16
|
+
# accessor to set whether to include drafts
|
17
|
+
attr_accessor :include_drafts
|
14
18
|
|
15
19
|
#access the configuration class as Rooftop.configuration
|
16
20
|
attr_accessor :configuration
|
@@ -22,6 +26,18 @@ module Rooftop
|
|
22
26
|
self.configuration.configure_connection
|
23
27
|
end
|
24
28
|
|
29
|
+
##################
|
30
|
+
# We're deprecating Rooftop.preview, because Rooftop previews are done per instance.
|
31
|
+
def preview=(preview)
|
32
|
+
@include_drafts = preview
|
33
|
+
end
|
34
|
+
|
35
|
+
def preview
|
36
|
+
@include_drafts
|
37
|
+
end
|
38
|
+
deprecate :preview=, :include_drafts=, 2016, 07
|
39
|
+
deprecate :preview, :include_drafts, 2016, 07
|
40
|
+
##################
|
25
41
|
end
|
26
42
|
|
27
43
|
class Configuration
|
@@ -64,6 +80,8 @@ module Rooftop
|
|
64
80
|
@user_agent = agent || @user_agent
|
65
81
|
end
|
66
82
|
|
83
|
+
|
84
|
+
|
67
85
|
# Return the Configuration object as a hash, with symbols as keys.
|
68
86
|
# @return [Hash]
|
69
87
|
def to_hash
|
@@ -8,7 +8,12 @@ module Rooftop
|
|
8
8
|
base.send(:before_save, ->(record) {
|
9
9
|
if record.respond_to?(:title) && record.respond_to?(:title_object)
|
10
10
|
record.title_object ||= {}
|
11
|
-
|
11
|
+
if record.title.nil?
|
12
|
+
record.restore_title!
|
13
|
+
record.restore_title_object!
|
14
|
+
else
|
15
|
+
record.title_object[:rendered] = record.title
|
16
|
+
end
|
12
17
|
end
|
13
18
|
})
|
14
19
|
|
@@ -40,5 +40,17 @@ module Rooftop
|
|
40
40
|
#TODO we need to write these back into the actual fields.
|
41
41
|
})
|
42
42
|
end
|
43
|
+
|
44
|
+
# test whether an instance has a field by name. Accepts a second argument if you want to test either the string value or the class.
|
45
|
+
def has_field?(name, comparison=nil)
|
46
|
+
has_field = fields.respond_to?(name.to_sym)
|
47
|
+
if comparison.present? && comparison.is_a?(String)
|
48
|
+
has_field && (fields.send(name.to_sym) == comparison)
|
49
|
+
elsif comparison.present?
|
50
|
+
has_field && fields.send(name.to_sym).is_a?(comparison)
|
51
|
+
else
|
52
|
+
has_field
|
53
|
+
end
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
@@ -5,8 +5,8 @@ module Rooftop
|
|
5
5
|
env[:request_headers]["Api-Token"] = Rooftop.configuration.api_token
|
6
6
|
end
|
7
7
|
|
8
|
-
if Rooftop.
|
9
|
-
env[:request_headers]['
|
8
|
+
if Rooftop.include_drafts
|
9
|
+
env[:request_headers]['include-drafts'] = "true"
|
10
10
|
end
|
11
11
|
|
12
12
|
Rooftop.configuration.extra_headers.each do |key,value|
|
@@ -1,8 +1,27 @@
|
|
1
1
|
module Rooftop
|
2
2
|
class Taxonomy
|
3
3
|
include Rooftop::Base
|
4
|
-
|
4
|
+
self.api_version = 2
|
5
|
+
self.api_namespace = "wp"
|
6
|
+
self.api_endpoint = "taxonomies"
|
7
|
+
|
5
8
|
primary_key "slug"
|
6
|
-
|
9
|
+
|
10
|
+
def self.all
|
11
|
+
taxonomies = []
|
12
|
+
get_raw(self.collection_path) do |parsed, raw|
|
13
|
+
parsed[:data].each do |tax,data|
|
14
|
+
taxonomies << Taxonomy.new(data)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
taxonomies.each do |t|
|
18
|
+
t.run_callbacks(:find)
|
19
|
+
end
|
20
|
+
return taxonomies
|
21
|
+
end
|
22
|
+
|
23
|
+
def terms
|
24
|
+
TaxonomyTerm.get(resource_links.find_by(link_type: "wp:items").first.href)
|
25
|
+
end
|
7
26
|
end
|
8
|
-
end
|
27
|
+
end
|
data/lib/rooftop/page.rb
CHANGED
data/lib/rooftop/post.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rooftop
|
2
|
+
module Preview
|
3
|
+
def preview
|
4
|
+
preview_path = "#{self.class.collection_path}/#{self.id}/preview"
|
5
|
+
@preview ||= self.class.get(preview_path)
|
6
|
+
# if there's no preview, return nil
|
7
|
+
if @preview.attributes.has_key?(:data) && @preview.data[:status] == 404
|
8
|
+
return nil
|
9
|
+
else
|
10
|
+
@preview.run_callbacks(:find)
|
11
|
+
return @preview
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def preview_key_matches?(key)
|
16
|
+
preview.present? && preview.preview_key == key
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/rooftop/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rooftop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ed Jones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/rooftop/content/content_fields.rb
|
118
118
|
- lib/rooftop/content/field.rb
|
119
119
|
- lib/rooftop/errors/field_not_found_error.rb
|
120
|
+
- lib/rooftop/errors/preview_key_mismatch.rb
|
120
121
|
- lib/rooftop/errors/record_not_found_error.rb
|
121
122
|
- lib/rooftop/errors/unmapped_object_error.rb
|
122
123
|
- lib/rooftop/errors/unresolveable_link_error.rb
|
@@ -128,6 +129,7 @@ files:
|
|
128
129
|
- lib/rooftop/middleware/embed_middleware.rb
|
129
130
|
- lib/rooftop/middleware/headers.rb
|
130
131
|
- lib/rooftop/middleware/pagination_middleware.rb
|
132
|
+
- lib/rooftop/middleware/record_not_found_middleware.rb
|
131
133
|
- lib/rooftop/models/author.rb
|
132
134
|
- lib/rooftop/models/media_item.rb
|
133
135
|
- lib/rooftop/models/taxonomy.rb
|
@@ -136,6 +138,7 @@ files:
|
|
136
138
|
- lib/rooftop/page.rb
|
137
139
|
- lib/rooftop/pagination.rb
|
138
140
|
- lib/rooftop/post.rb
|
141
|
+
- lib/rooftop/preview.rb
|
139
142
|
- lib/rooftop/queries/queries.rb
|
140
143
|
- lib/rooftop/resource_links/collection.rb
|
141
144
|
- lib/rooftop/resource_links/link.rb
|