buttercms-ruby 1.4 → 1.5

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
- SHA1:
3
- metadata.gz: 6892f2c65b2714c507d356db4c7a0fa1ca0efe53
4
- data.tar.gz: aeee01cf3ad4a68c8fe365124db34e494dbf9ca1
2
+ SHA256:
3
+ metadata.gz: 348ca14f5f921c18ed7368f6f49bc97f9649304fa55e64ee1819515060bfbe01
4
+ data.tar.gz: 00e814b0baece7fcf1bba2fc29d16ae42c17b47ab32e796b48c249db922357ef
5
5
  SHA512:
6
- metadata.gz: 7f71a3ae6a84b213bc03c42c96b0217d1241a8f812c4f1b9acb8ef968293a4d5a5db6e727316e5f5b290dabd3c5219df02ef58a03360cf4bd845bf199e9a4d12
7
- data.tar.gz: 7a3afc5ae7c6a3c7f0d3c41b48a63bbdd43bd4107cfbffb7cad501ba40d8461168f2d95726bb45d40509938fb7495a741d4f6994c410f9abc96877ee5fd200d1
6
+ metadata.gz: 5584f22c5db27a1556bea7370aaf02137b9ffdcf0f613899bad05e85ddfd2795d82ff9f94c0fe1f96b3c2e04dc6659bab08df68e85a80528cfa267307de542b7
7
+ data.tar.gz: '0215907376576dc8605406b2983aad57aa3fecdb800e3c291178c94a5cf97f84442236c4138d76c22c0ae088c3ca6e7b2d5a725c73b98f603910a4a7197bc157'
data/.gitignore CHANGED
@@ -19,4 +19,5 @@ tmp
19
19
  .ruby-version
20
20
  .rvmrc
21
21
  *.rdb
22
- *.store
22
+ *.store
23
+ test.rb
data/README.md CHANGED
@@ -44,8 +44,12 @@ page = ButterCMS::Page.get('news', 'hello-world', params)
44
44
  https://buttercms.com/docs/api/?ruby#retrieve-a-collection
45
45
 
46
46
  ```ruby
47
- params = {page: 1, page_size: 10, locale: 'en', preview: 1, fields.headline: 'foo bar', levels: 2} # optional
48
- ButterCMS::Content.fetch(['testimonials'], params)
47
+ # list each instance of a given collection with meta data for fetching the next page.
48
+ params = { page: 1, page_size: 10, locale: 'en', preview: 1, fields.headline: 'foo bar', levels: 2 } # optional
49
+ ButterCMS::Content.list('collection1', params)
50
+
51
+ # list instances for multiple collections, this will not return meta data for pagination control.
52
+ ButterCMS::Content.fetch(['collection1', 'collection2'], params)
49
53
 
50
54
  # Test mode can be used to setup a staging website for previewing Collections or for testing content during local development. To fetch content from test mode add the following configuration:
51
55
  ButterCMS::test_mode = true
@@ -131,3 +135,5 @@ ButterCMS::logger = MyLogger.new
131
135
  ### Other
132
136
 
133
137
  View Ruby [Blog engine](https://buttercms.com/ruby-blog-engine/) and [Full CMS](https://buttercms.com/ruby-cms/) for other examples of using ButterCMS with Ruby.
138
+
139
+ ### Development
@@ -1,22 +1,19 @@
1
1
  module ButterCMS
2
- class Content
3
- attr_reader :data
4
-
5
- def initialize(json)
6
- @json = json
7
- @data = HashToObject.convert(json["data"])
8
- end
9
-
10
- def inspect
11
- id_string = (self.respond_to?(:id) && !self.id.nil?) ? " id=#{self.id}" : ""
12
- "#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@json)
2
+ class Content < ButterResource
3
+ def self.resource_path
4
+ "/content/"
13
5
  end
14
6
 
15
- def self.fetch(keys = [], options = {})
16
- params = {keys: keys.join(',')}.merge(options)
17
-
18
- response = ButterCMS.request("/content/", params)
7
+ def self.list(collection_slug, options = {})
8
+ response = ButterCMS.request(self.endpoint(collection_slug), options)
19
9
 
10
+ self.create_collection(response)
11
+ end
12
+
13
+ def self.fetch(collection_slugs, options = {})
14
+ params = { keys: collection_slugs.join(',') }.merge(options)
15
+ response = ButterCMS.request(self.resource_path, params)
16
+
20
17
  self.new(response)
21
18
  end
22
19
  end
@@ -1,3 +1,3 @@
1
1
  module ButterCMS
2
- VERSION = '1.4'
2
+ VERSION = '1.5'
3
3
  end
@@ -0,0 +1,10 @@
1
+ require 'bundler/inline'
2
+
3
+ gemfile do
4
+ source 'https://rubygems.org'
5
+ gem 'buttercms-ruby', :path => '../buttercms-ruby'
6
+ end
7
+
8
+ # start a REPL session
9
+ ButterCMS::api_token = "" # add your dev token here
10
+ binding.irb
@@ -11,7 +11,7 @@ describe ButterCMS::ButterResource do
11
11
  describe '.all' do
12
12
 
13
13
  it 'should make a request with the correct endpoint' do
14
- expect(ButterCMS).to receive(:request).with('/', {})
14
+ expect(ButterCMS).to receive(:request).with('', {})
15
15
  ButterCMS::ButterResource.all()
16
16
  end
17
17
 
@@ -24,7 +24,7 @@ describe ButterCMS::ButterResource do
24
24
 
25
25
  describe '.find' do
26
26
  it 'should make a request with the correct endpoint' do
27
- expect(ButterCMS).to receive(:request).with('/1', {})
27
+ expect(ButterCMS).to receive(:request).with('1/', {})
28
28
  ButterCMS::ButterResource.find(1)
29
29
  end
30
30
 
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe ButterCMS::Content do
4
+ before do
5
+ allow(ButterCMS).to receive(:token).and_return('test123')
6
+ allow(ButterCMS).to receive(:request).and_return({
7
+ "meta"=>{
8
+ "next_page"=>2,
9
+ "previous_page"=>nil,
10
+ "count"=>2
11
+ },
12
+ "data"=>{
13
+ "author"=>[
14
+ { "name"=>"Charles Dickens"},
15
+ { "name"=>"J.K. Rowling"}
16
+ ]
17
+ }
18
+ })
19
+
20
+ @response = ButterCMS::Content.list('slug', {
21
+ page: 1,
22
+ page_size: 2
23
+ })
24
+ end
25
+
26
+ it "has meta and collection info" do
27
+ expect(@response.meta.next_page).to eq(2)
28
+ expect(@response.to_a.first.data.first).to eq('author')
29
+ expect(@response.to_a.first.data.last.first).to have_attributes(
30
+ name: "Charles Dickens"
31
+ )
32
+ end
33
+ 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: '1.4'
4
+ version: '1.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - ButterCMS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-18 00:00:00.000000000 Z
11
+ date: 2019-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -52,7 +52,6 @@ files:
52
52
  - LICENSE
53
53
  - README.md
54
54
  - Rakefile
55
- - VERSION
56
55
  - buttercms-ruby.gemspec
57
56
  - lib/buttercms-ruby.rb
58
57
  - lib/buttercms/author.rb
@@ -69,10 +68,12 @@ files:
69
68
  - lib/buttercms/post.rb
70
69
  - lib/buttercms/tag.rb
71
70
  - lib/buttercms/version.rb
71
+ - lib/console.rb
72
72
  - lib/core_ext/ostruct.rb
73
73
  - spec/lib/butter-ruby_spec.rb
74
74
  - spec/lib/buttercms/butter_collection_spec.rb
75
75
  - spec/lib/buttercms/butter_resource_spec.rb
76
+ - spec/lib/buttercms/content_spec.rb
76
77
  - spec/lib/buttercms/hash_to_object_spec.rb
77
78
  - spec/spec_helper.rb
78
79
  homepage: https://buttercms.com/docs
@@ -94,8 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
95
  - !ruby/object:Gem::Version
95
96
  version: '0'
96
97
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.6.12
98
+ rubygems_version: 3.0.3
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: A simple Ruby client for the buttercms.com REST API
@@ -103,5 +103,6 @@ test_files:
103
103
  - spec/lib/butter-ruby_spec.rb
104
104
  - spec/lib/buttercms/butter_collection_spec.rb
105
105
  - spec/lib/buttercms/butter_resource_spec.rb
106
+ - spec/lib/buttercms/content_spec.rb
106
107
  - spec/lib/buttercms/hash_to_object_spec.rb
107
108
  - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.4