buttercms-ruby 1.9 → 2.2

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: a0f437a3187e885b9c7250f9afbe5ff41cebb2dbc84127dd36ae0963b34fcba1
4
- data.tar.gz: 2a9673e85ef2155f5b55f2febe48932dacf28fc4d7e7fdf4ffa050cb18d69c49
3
+ metadata.gz: f315c57a5804e6b7817e7f840f85e406ccccd73021ebdfbb5e84e9fad8ea7475
4
+ data.tar.gz: aa26b058d512ebf1ff34aa5edef920517a8ba893a775949c1c61b173dc9421a1
5
5
  SHA512:
6
- metadata.gz: 46738145c68da934fc76e9a8e3c8fdaa2ee8e9462e8c07ed69af2ad557cb1e659a657fc164f1573d9d9a5f0fd35b8eceec046f2fae2c40dbe5a518c374cd970a
7
- data.tar.gz: f47192c16cf33c9557aa151e90db0538bf3e3a31dd03e68fe4666cd72093b1c6f95414d640d1121a19eabc491dcbdb10939a8940175de409d7ebcabef4268a65
6
+ metadata.gz: b28741a244c0b3ca0e05adc58518754b65fe6d5713ccb6bd22b1948064db992cc894e0fb9b2e1e38df83fc76e996e2aa0cee3f8badc6dd226406fcfc2548610b
7
+ data.tar.gz: ac4decef965cc92fadf790ebbb3925a676e3874434c8b192f58f5286aaa10e53dd91d4d74ad6fe28a40fd7c9d5eddc05624719a136fa7167c98847f3d45313ec
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"
@@ -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 = '1.9'
2
+ VERSION = '2.2'
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'
@@ -71,7 +72,13 @@ module ButterCMS
71
72
  query[:test] = 1
72
73
  end
73
74
 
74
- path = "#{@api_url.path}#{URI.encode_www_form(path)}?#{URI.encode_www_form(query)}"
75
+ # If the user has passed in a "/" leading path, don't interpret that
76
+ # as wanting to get rid of the API prefix
77
+ if path.start_with?("/")
78
+ path = path[1..-1]
79
+ end
80
+
81
+ path = Pathname.new(@api_url.path).join(path).to_s + "?#{URI.encode_www_form(query)}"
75
82
 
76
83
  response =
77
84
  Net::HTTP.start(@api_url.host, @api_url.port, http_options) do |http|
@@ -14,6 +14,22 @@ describe ButterCMS do
14
14
  ButterCMS.request('')
15
15
  expect(request).to have_been_made
16
16
  end
17
+
18
+ it "should properly escape paths" do
19
+ request = stub_request(
20
+ :get,
21
+ "https://api.buttercms.com/v2/pages/*/homepage%20en?auth_token=test123"
22
+ ).to_return(body: JSON.generate({data: {test: 'test'}}))
23
+
24
+ # support leading slashes
25
+ ButterCMS.request('/pages/*/homepage en')
26
+
27
+ # and no leading slashes
28
+ ButterCMS.request('pages/*/homepage en')
29
+
30
+
31
+ expect(request).to have_been_made.twice
32
+ end
17
33
  end
18
34
 
19
35
  context 'without an api token' do
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: '1.9'
4
+ version: '2.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - ButterCMS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-26 00:00:00.000000000 Z
11
+ date: 2022-04-07 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