buttercms-ruby 2.0 → 2.3

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: 69371855dc4fc9883ba72a8eabd2ede8e8b5118a79b0435457da54609bde25f4
4
- data.tar.gz: 72c527a3185fc8ed00eb56735bc4e2f3abe343058214cef23ce6debba066c169
3
+ metadata.gz: 71c6d2ca16fa0a3f309ca70b3621a3a120037d0ce4928d1b5ebe8752e5e616b5
4
+ data.tar.gz: 8cdaeb87ff156acb02484dc1aa25f5d05a4a039d699a08a2f6a2206d8b792ee3
5
5
  SHA512:
6
- metadata.gz: 3c7f9c52c35df85a8ed5f38a3531deddee771529bbb2717c5d5b2cca2a788503a0aecea2672be6bb5f22837a1b453ecbcef7d4f4856dea4b7060e7fc98b74ebf
7
- data.tar.gz: 70f72d7bf27b9532904b37aff8c40d1060d33511f34d4bcc2d6c0c24aa24ab19f3a9d587b1d132390a672ecfa5c99172ea2c1880cff33263666ce5bf3330d42b
6
+ metadata.gz: aee2d3b066ec054493e4a130fbc1e4504609972b537e41630bfc6c58014514405437910c759fe06f3e1380843a230baeb9b8457ea94d9c015708d0507a387599
7
+ data.tar.gz: 73c8720bebf9154a7b18bc1fc07d49937f5fa92a5114842141a0f249e747b03c1f88e8c275f276dc1110b01ff9a3a09f1c5ab3c7e66fc3854d5543fe1a709576
data/README.md CHANGED
@@ -39,7 +39,10 @@ https://buttercms.com/docs/api/?ruby#pages
39
39
  ```ruby
40
40
  params = {page: 1, page_size: 10, locale: 'en', preview: 1, 'fields.headline': 'foo bar', levels: 2} # optional
41
41
  pages = ButterCMS::Page.list('news', params)
42
+
42
43
  page = ButterCMS::Page.get('news', 'hello-world', params)
44
+
45
+ pages = ButterCMS::Page.search('query', params)
43
46
  ```
44
47
 
45
48
  ## Collections
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
7
7
  s.name = "buttercms-ruby"
8
8
  s.version = ButterCMS::VERSION
9
9
  s.require_paths = ["lib"]
10
- s.summary = 'A simple Ruby client for the buttercms.com REST API'
11
- s.description = 'Butter is a blogging platform loved by engineers. See https://buttercms.com for details.'
10
+ s.summary = 'Ruby API client for ButterCMS'
11
+ s.description = 'Butter is the #1 developer rated headless CMS. See https://buttercms.com for details.'
12
12
  s.authors = ["ButterCMS"]
13
13
  s.email= ["support@buttercms.com"]
14
14
  s.homepage = "https://buttercms.com/docs"
@@ -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
@@ -15,5 +15,11 @@ module ButterCMS
15
15
 
16
16
  self.create_object(response)
17
17
  end
18
+
19
+ def self.search(query = '', options = {})
20
+ response = ButterCMS.request('/pages/search/', {query: query}.merge(options))
21
+
22
+ self.create_collection(response)
23
+ end
18
24
  end
19
25
  end
@@ -1,3 +1,3 @@
1
1
  module ButterCMS
2
- VERSION = '2.0'
2
+ VERSION = '2.3'
3
3
  end
@@ -3,6 +3,7 @@ require 'ostruct'
3
3
  require 'logger'
4
4
  require 'uri'
5
5
  require 'net/http'
6
+ require 'pathname'
6
7
 
7
8
  require "buttercms/errors"
8
9
  require 'buttercms/version'
@@ -91,6 +92,8 @@ module ButterCMS
91
92
  case response
92
93
  when Net::HTTPNotFound
93
94
  raise ::ButterCMS::NotFound, JSON.parse(response.body)["detail"]
95
+ when Net::HTTPUnauthorized
96
+ raise ::ButterCMS::Unauthorized, JSON.parse(response.body)['detail']
94
97
  end
95
98
 
96
99
  response.body
@@ -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.0'
4
+ version: '2.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - ButterCMS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-01 00:00:00.000000000 Z
11
+ date: 2022-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Butter is a blogging platform loved by engineers. See https://buttercms.com
42
- for details.
41
+ description: 'Butter is the #1 developer rated headless CMS. See https://buttercms.com
42
+ for details.'
43
43
  email:
44
44
  - support@buttercms.com
45
45
  executables: []
@@ -98,7 +98,7 @@ requirements: []
98
98
  rubygems_version: 3.0.3
99
99
  signing_key:
100
100
  specification_version: 4
101
- summary: A simple Ruby client for the buttercms.com REST API
101
+ summary: Ruby API client for ButterCMS
102
102
  test_files:
103
103
  - spec/lib/butter-ruby_spec.rb
104
104
  - spec/lib/buttercms/butter_collection_spec.rb