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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf9827cc2965fecd6ca71d8ab14d8977e156691b
4
- data.tar.gz: 15b808878885da0a5888bd862eae95f5fcf03e46
3
+ metadata.gz: ed668d2eb460ba58937c6b1a1498be8ea5ed96ec
4
+ data.tar.gz: be49d6620e86435f0a0cafe482c220d1547b852d
5
5
  SHA512:
6
- metadata.gz: 07d4ef3d546e300f33c99887658d0efe9e3a231e13e7f7bd1e519d879d3b64c108ba21ce3e7720eac5e4d1dc534b2780e462b54463624872113e51686aed6825
7
- data.tar.gz: d1817d197e0a617c5321a833a6cf547023bdb93ce5ceb80e1cd73904bf8dece8c0d7a243f1e993402d749a5de1bc1378346a8220b39a6feb72657d59bf82dc89
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
- #accessor to set whether we're in privew mode
13
- attr_accessor :preview, :debug_requests, :debug_responses
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
- record.title_object[:rendered] = record.title
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
 
@@ -34,6 +34,8 @@ module Rooftop
34
34
  collect(&:name)
35
35
  end
36
36
 
37
+ alias_method :names, :field_names
38
+
37
39
  def method_missing(method, *args, &block)
38
40
  fields = named(method)
39
41
  if fields.length > 0
@@ -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
@@ -0,0 +1,6 @@
1
+ module Rooftop
2
+ module Content
3
+ class PreviewKeyMismatchError < NoMethodError; end
4
+ class PreviewKeyMissingError < NoMethodError; end
5
+ end
6
+ 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.preview
9
- env[:request_headers]['preview'] = "true"
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|
@@ -0,0 +1,11 @@
1
+ module Rooftop
2
+ class RecordNotFoundMiddleware < Faraday::Response::Middleware
3
+ def on_complete(env)
4
+ case env[:status]
5
+ when 404
6
+ raise Rooftop::RecordNotFoundError, '404 received from Rooftop API'
7
+ end
8
+ end
9
+ end
10
+
11
+ end
@@ -1,8 +1,27 @@
1
1
  module Rooftop
2
2
  class Taxonomy
3
3
  include Rooftop::Base
4
- collection_path "taxonomies"
4
+ self.api_version = 2
5
+ self.api_namespace = "wp"
6
+ self.api_endpoint = "taxonomies"
7
+
5
8
  primary_key "slug"
6
- has_many :terms, class_name: "Rooftop::TaxonomyTerm"
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
@@ -5,6 +5,7 @@ module Rooftop
5
5
  @page_classes << base unless @page_classes.include?(base)
6
6
  base.include Rooftop::Base
7
7
  base.include Rooftop::Nested
8
+ base.include Rooftop::Preview
8
9
  base.extend ClassMethods
9
10
  end
10
11
 
data/lib/rooftop/post.rb CHANGED
@@ -3,6 +3,7 @@ module Rooftop
3
3
  def self.included(base)
4
4
  base.include Rooftop::Base
5
5
  base.include Rooftop::Nested
6
+ base.include Rooftop::Preview
6
7
  base.extend ClassMethods
7
8
  end
8
9
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rooftop
2
- VERSION = "0.0.7.4"
2
+ VERSION = "0.1.1"
3
3
  end
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.0.7.4
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-05-01 00:00:00.000000000 Z
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