buttercms-ruby 2.2 → 2.4

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
  SHA256:
3
- metadata.gz: f315c57a5804e6b7817e7f840f85e406ccccd73021ebdfbb5e84e9fad8ea7475
4
- data.tar.gz: aa26b058d512ebf1ff34aa5edef920517a8ba893a775949c1c61b173dc9421a1
3
+ metadata.gz: 66bbe24c7759a4bbf8c026d8f70f42888e71ef2733cfcc0d02917c0e4049231b
4
+ data.tar.gz: 2bcbeb00f46e7f8e5039528a7c4cda0d84c12eb26b8af4bfcc40495c83ba4783
5
5
  SHA512:
6
- metadata.gz: b28741a244c0b3ca0e05adc58518754b65fe6d5713ccb6bd22b1948064db992cc894e0fb9b2e1e38df83fc76e996e2aa0cee3f8badc6dd226406fcfc2548610b
7
- data.tar.gz: ac4decef965cc92fadf790ebbb3925a676e3874434c8b192f58f5286aaa10e53dd91d4d74ad6fe28a40fd7c9d5eddc05624719a136fa7167c98847f3d45313ec
6
+ metadata.gz: eb1dab8986628b6a84233d826e1116f2dad712715c0cfd068e796f7ce1b6f8b124bdbe3324e444f3a9ecea33025a1ba22892cf283ebaabcaba3b052c73bc94e2
7
+ data.tar.gz: 7b3345cad1de8da899afa6e4cd14acc7e3d0bc09f5a19c6a0798ed7b21fd86ef55d8a08b239811cb1c0a6728e05318605aebcee74ee03ee860accce13d67330a
data/README.md CHANGED
@@ -134,6 +134,9 @@ ButterCMS::data_store = :yaml, "/File/Path/For/buttercms.store"
134
134
  # Use Redis
135
135
  ButterCMS::data_store = :redis, ENV['REDIS_URL']
136
136
 
137
+ # Use Redis over ssl store
138
+ ButterCMS.data_store = :redis_ssl, ENV["REDIS_URL"], { ca_file: "/path/to/ca.crt" }
139
+
137
140
  # Set logger (optional)
138
141
  ButterCMS::logger = MyLogger.new
139
142
  ```
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'redis'
3
+ rescue LoadError
4
+ puts "WARNING: redis >= 3.0.0 is required to use the redis data store."
5
+ raise
6
+ end
7
+
8
+ module ButterCMS
9
+ module DataStoreAdapters
10
+ class RedisSSL
11
+ def initialize(options)
12
+ redis_url = options.first
13
+ ssl_params = options.second && Hash[options.second]
14
+
15
+ @redis = ::Redis.new(url: redis_url, ssl_params:)
16
+ end
17
+
18
+ def set(key, value)
19
+ @redis.set(key, value)
20
+ end
21
+
22
+ def get(key)
23
+ @redis.get(key)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -6,6 +6,9 @@ module ButterCMS
6
6
  # NotFound is raised when a resource cannot be found
7
7
  class NotFound < Error
8
8
  end
9
+
10
+ class Unauthorized < Error
11
+ end
9
12
 
10
13
  class BadRequest < Error
11
14
  end
@@ -1,3 +1,3 @@
1
1
  module ButterCMS
2
- VERSION = '2.2'
2
+ VERSION = '2.4'
3
3
  end
@@ -59,6 +59,9 @@ module ButterCMS
59
59
  when :redis
60
60
  require_relative 'buttercms/data_store_adapters/redis'
61
61
  @data_store = ButterCMS::DataStoreAdapters::Redis.new(options)
62
+ when :redis_ssl
63
+ require_relative 'buttercms/data_store_adapters/redis_ssl'
64
+ @data_store = ButterCMS::DataStoreAdapters::RedisSSL.new(options)
62
65
  else
63
66
  raise ArgumentError.new "Invalid ButterCMS data store #{strategy}"
64
67
  end
@@ -92,6 +95,8 @@ module ButterCMS
92
95
  case response
93
96
  when Net::HTTPNotFound
94
97
  raise ::ButterCMS::NotFound, JSON.parse(response.body)["detail"]
98
+ when Net::HTTPUnauthorized
99
+ raise ::ButterCMS::Unauthorized, JSON.parse(response.body)['detail']
95
100
  end
96
101
 
97
102
  response.body
@@ -130,14 +135,14 @@ module ButterCMS
130
135
 
131
136
  return JSON.parse(result)
132
137
  end
133
-
138
+
134
139
  def self.write_request(path, options = {})
135
140
  raise ArgumentError.new "Please set your write API token" unless write_api_token
136
141
  result = write_api_request(path, options)
137
142
 
138
143
  return JSON.parse(result)
139
144
  end
140
-
145
+
141
146
  def self.write_api_request(path, options = {})
142
147
  query = options.dup
143
148
  token_for_request = query.delete(:auth_token) || write_api_token
@@ -175,9 +180,9 @@ module ButterCMS
175
180
 
176
181
  response.body
177
182
  end
178
-
183
+
179
184
  private
180
-
185
+
181
186
  def self.http_options
182
187
  {
183
188
  open_timeout: open_timeout || 2.0,
@@ -50,5 +50,18 @@ describe ButterCMS do
50
50
 
51
51
  expect(request).to have_been_made
52
52
  end
53
+
54
+ it "raises Unauthorized on 401" do
55
+ allow(ButterCMS).to receive(:api_token).and_return("test")
56
+
57
+ request = stub_request(:get, %r{/posts/slug/})
58
+ .with(query: { auth_token: "test" })
59
+ .to_return(status: 401, body: '{"detail":"Invalid token."}')
60
+
61
+ expect { ButterCMS.request("/posts/slug/") }
62
+ .to raise_error(ButterCMS::Unauthorized)
63
+
64
+ expect(request).to have_been_made
65
+ end
53
66
  end
54
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buttercms-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.2'
4
+ version: '2.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - ButterCMS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-07 00:00:00.000000000 Z
11
+ date: 2023-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -60,6 +60,7 @@ files:
60
60
  - lib/buttercms/category.rb
61
61
  - lib/buttercms/content.rb
62
62
  - lib/buttercms/data_store_adapters/redis.rb
63
+ - lib/buttercms/data_store_adapters/redis_ssl.rb
63
64
  - lib/buttercms/data_store_adapters/yaml.rb
64
65
  - lib/buttercms/errors.rb
65
66
  - lib/buttercms/feed.rb
@@ -95,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
98
  requirements: []
98
- rubygems_version: 3.0.3
99
+ rubygems_version: 3.0.3.1
99
100
  signing_key:
100
101
  specification_version: 4
101
102
  summary: Ruby API client for ButterCMS