buttercms-ruby 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/buttercms-ruby.gemspec +1 -3
- data/lib/buttercms/author.rb +1 -1
- data/lib/buttercms/butter_resource.rb +4 -2
- data/lib/buttercms/category.rb +1 -1
- data/lib/buttercms/content.rb +1 -1
- data/lib/buttercms/errors.rb +9 -0
- data/lib/buttercms/feed.rb +1 -1
- data/lib/buttercms/post.rb +2 -2
- data/lib/buttercms/tag.rb +1 -1
- data/lib/buttercms/version.rb +1 -1
- data/lib/buttercms-ruby.rb +41 -25
- data/spec/lib/butter-ruby_spec.rb +19 -3
- data/spec/lib/buttercms/butter_resource_spec.rb +7 -15
- metadata +14 -34
- data/lib/buttercms/errors/buttercms_error.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b1eb7961f35d03a98b64dd179718d91cef63533
|
4
|
+
data.tar.gz: 0a39f2a75b721b3a859b413ffa0f2d91d1528bbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5620747eb99c3e1041106cdef205f259bdd63d8d2cc5fce2aa3af4639ddc2217135c2d707fde892b1a68555d43986ff21af6442ff44aca4f2c091a4bccd243ee
|
7
|
+
data.tar.gz: 1d964a1a8f9554fea737dc4f98b5a86df3902cfa2113f8da607082ae6a5766501494604b57ca70c28d076841bf534c350079dc57619880c02a172fee006836e1
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/buttercms-ruby.gemspec
CHANGED
@@ -14,9 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.homepage = "https://buttercms.com/docs"
|
15
15
|
s.license = 'MIT'
|
16
16
|
|
17
|
-
s.
|
18
|
-
|
19
|
-
s.add_development_dependency 'rspec', '~> 2.7'
|
17
|
+
s.add_development_dependency 'rspec'
|
20
18
|
s.add_development_dependency 'webmock'
|
21
19
|
s.required_ruby_version = '>= 1.9.3'
|
22
20
|
|
data/lib/buttercms/author.rb
CHANGED
@@ -20,8 +20,10 @@ module ButterCMS
|
|
20
20
|
"#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@json)
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.endpoint(id =
|
24
|
-
|
23
|
+
def self.endpoint(id = nil)
|
24
|
+
# Append trailing slash when id is added to path because
|
25
|
+
# API expects all endpoints to include trailing slashes
|
26
|
+
resource_path + (id ? "#{id}/" : '')
|
25
27
|
end
|
26
28
|
|
27
29
|
def self.resource_path
|
data/lib/buttercms/category.rb
CHANGED
data/lib/buttercms/content.rb
CHANGED
data/lib/buttercms/feed.rb
CHANGED
data/lib/buttercms/post.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module ButterCMS
|
2
2
|
class Post < ButterResource
|
3
3
|
def self.resource_path
|
4
|
-
"/posts"
|
4
|
+
"/posts/"
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.search(query = '', options = {})
|
8
|
-
response = ButterCMS.request('/search', {query: query}.merge(options))
|
8
|
+
response = ButterCMS.request('/search/', {query: query}.merge(options))
|
9
9
|
|
10
10
|
self.create_collection(response)
|
11
11
|
end
|
data/lib/buttercms/tag.rb
CHANGED
data/lib/buttercms/version.rb
CHANGED
data/lib/buttercms-ruby.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'httparty'
|
3
2
|
require 'ostruct'
|
4
3
|
require 'logger'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
4
|
+
require 'uri'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
require "buttercms/errors"
|
8
|
+
require 'buttercms/version'
|
9
|
+
require 'buttercms/hash_to_object'
|
10
|
+
require 'buttercms/butter_collection'
|
11
|
+
require 'buttercms/butter_resource'
|
12
|
+
require 'buttercms/author'
|
13
|
+
require 'buttercms/category'
|
14
|
+
require 'buttercms/tag'
|
15
|
+
require 'buttercms/post'
|
16
|
+
require 'buttercms/feed'
|
17
|
+
require 'buttercms/content'
|
17
18
|
|
18
19
|
# See https://github.com/jruby/jruby/issues/3113
|
19
20
|
if RUBY_VERSION < '2.0.0'
|
@@ -21,7 +22,7 @@ if RUBY_VERSION < '2.0.0'
|
|
21
22
|
end
|
22
23
|
|
23
24
|
module ButterCMS
|
24
|
-
@api_url = 'https://api.buttercms.com/v2'
|
25
|
+
@api_url = URI.parse('https://api.buttercms.com/v2')
|
25
26
|
|
26
27
|
class << self
|
27
28
|
attr_accessor :api_token
|
@@ -59,20 +60,35 @@ module ButterCMS
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def self.api_request(path, options = {})
|
62
|
-
|
63
|
-
|
64
|
-
}
|
63
|
+
query = options.dup
|
64
|
+
query[:auth_token] ||= api_token
|
65
65
|
|
66
66
|
if test_mode
|
67
|
-
|
67
|
+
query[:test] = 1
|
68
68
|
end
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
path = "#{@api_url.path}#{URI.encode(path)}?#{URI.encode_www_form(query)}"
|
71
|
+
|
72
|
+
http_options = {
|
73
|
+
open_timeout: 2.0,
|
74
|
+
read_timeout: 5.0,
|
75
|
+
ssl_timeout: 2.0,
|
76
|
+
use_ssl: @api_url.scheme == "https",
|
77
|
+
}
|
78
|
+
|
79
|
+
response =
|
80
|
+
Net::HTTP.start(@api_url.host, @api_url.port, http_options) do |http|
|
81
|
+
request = Net::HTTP::Get.new(path)
|
82
|
+
request["User-Agent"] = "ButterCMS/Ruby #{ButterCMS::VERSION}"
|
83
|
+
request["Accept"] = "application/json"
|
84
|
+
|
85
|
+
http.request(request)
|
86
|
+
end
|
87
|
+
|
88
|
+
case response
|
89
|
+
when Net::HTTPNotFound
|
90
|
+
raise ::ButterCMS::NotFound, JSON.parse(response.body)["detail"]
|
91
|
+
end
|
76
92
|
|
77
93
|
response.body
|
78
94
|
end
|
@@ -90,7 +106,7 @@ module ButterCMS
|
|
90
106
|
logger.info "Set key #{key}"
|
91
107
|
end
|
92
108
|
|
93
|
-
# TODO - more selective exception handling (
|
109
|
+
# TODO - more selective exception handling (SocketError)
|
94
110
|
rescue Exception => e
|
95
111
|
|
96
112
|
if data_store
|
@@ -4,12 +4,15 @@ describe ButterCMS do
|
|
4
4
|
describe '.request' do
|
5
5
|
context 'with an api token' do
|
6
6
|
before do
|
7
|
-
ButterCMS.
|
7
|
+
allow(ButterCMS).to receive(:api_token).and_return('test123')
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should make an api request' do
|
11
|
-
stub_request(:get,
|
12
|
-
|
11
|
+
request = stub_request(:get, "https://api.buttercms.com/v2?auth_token=test123")
|
12
|
+
.to_return(body: JSON.generate({data: {test: 'test'}}))
|
13
|
+
|
14
|
+
ButterCMS.request('')
|
15
|
+
expect(request).to have_been_made
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
@@ -18,5 +21,18 @@ describe ButterCMS do
|
|
18
21
|
expect{ ButterCMS.request() }.to raise_error(ArgumentError)
|
19
22
|
end
|
20
23
|
end
|
24
|
+
|
25
|
+
it "raises NotFound on 404" do
|
26
|
+
allow(ButterCMS).to receive(:api_token).and_return("test123")
|
27
|
+
|
28
|
+
request = stub_request(:get, %r{/posts/slug/})
|
29
|
+
.with(query: { auth_token: "test123" })
|
30
|
+
.to_return(status: 404, body: '{"detail":"Not found."}')
|
31
|
+
|
32
|
+
expect { ButterCMS.request("/posts/slug/") }
|
33
|
+
.to raise_error(ButterCMS::NotFound)
|
34
|
+
|
35
|
+
expect(request).to have_been_made
|
36
|
+
end
|
21
37
|
end
|
22
38
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ButterCMS::ButterResource do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
ButterCMS.stub(:request).and_return({"data" => [{"attribute" => 'test'}]})
|
4
|
+
before do
|
5
|
+
allow(ButterCMS).to receive(:token).and_return('test123')
|
6
|
+
allow(ButterCMS).to receive(:request).and_return({"data" => [{"attribute" => 'test'}]})
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
allow(ButterCMS::ButterResource).to receive(:resource_path).and_return('')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.all' do
|
12
12
|
|
13
13
|
it 'should make a request with the correct endpoint' do
|
14
14
|
expect(ButterCMS).to receive(:request).with('/', {})
|
@@ -23,14 +23,6 @@ describe ButterCMS::ButterResource do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
describe '.find' do
|
26
|
-
before do
|
27
|
-
ButterCMS.stub(:token).and_return('test123')
|
28
|
-
ButterCMS.stub(:request).and_return({"data" => {"attribute" => 'test'}})
|
29
|
-
|
30
|
-
ButterCMS::ButterResource.stub(:resource_path).
|
31
|
-
and_return('')
|
32
|
-
end
|
33
|
-
|
34
26
|
it 'should make a request with the correct endpoint' do
|
35
27
|
expect(ButterCMS).to receive(:request).with('/1', {})
|
36
28
|
ButterCMS::ButterResource.find(1)
|
metadata
CHANGED
@@ -1,61 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buttercms-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ButterCMS
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: httparty
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ~>
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.14'
|
20
|
-
- - '>='
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.14.0
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.14'
|
30
|
-
- - '>='
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 0.14.0
|
33
13
|
- !ruby/object:Gem::Dependency
|
34
14
|
name: rspec
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|
36
16
|
requirements:
|
37
|
-
- -
|
17
|
+
- - ">="
|
38
18
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
19
|
+
version: '0'
|
40
20
|
type: :development
|
41
21
|
prerelease: false
|
42
22
|
version_requirements: !ruby/object:Gem::Requirement
|
43
23
|
requirements:
|
44
|
-
- -
|
24
|
+
- - ">="
|
45
25
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
26
|
+
version: '0'
|
47
27
|
- !ruby/object:Gem::Dependency
|
48
28
|
name: webmock
|
49
29
|
requirement: !ruby/object:Gem::Requirement
|
50
30
|
requirements:
|
51
|
-
- -
|
31
|
+
- - ">="
|
52
32
|
- !ruby/object:Gem::Version
|
53
33
|
version: '0'
|
54
34
|
type: :development
|
55
35
|
prerelease: false
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
57
37
|
requirements:
|
58
|
-
- -
|
38
|
+
- - ">="
|
59
39
|
- !ruby/object:Gem::Version
|
60
40
|
version: '0'
|
61
41
|
description: Butter is a blogging platform loved by engineers. See https://buttercms.com
|
@@ -66,8 +46,8 @@ executables: []
|
|
66
46
|
extensions: []
|
67
47
|
extra_rdoc_files: []
|
68
48
|
files:
|
69
|
-
- .gitignore
|
70
|
-
- .rspec
|
49
|
+
- ".gitignore"
|
50
|
+
- ".rspec"
|
71
51
|
- Gemfile
|
72
52
|
- LICENSE
|
73
53
|
- README.md
|
@@ -82,7 +62,7 @@ files:
|
|
82
62
|
- lib/buttercms/content.rb
|
83
63
|
- lib/buttercms/data_store_adapters/redis.rb
|
84
64
|
- lib/buttercms/data_store_adapters/yaml.rb
|
85
|
-
- lib/buttercms/errors
|
65
|
+
- lib/buttercms/errors.rb
|
86
66
|
- lib/buttercms/feed.rb
|
87
67
|
- lib/buttercms/hash_to_object.rb
|
88
68
|
- lib/buttercms/post.rb
|
@@ -104,17 +84,17 @@ require_paths:
|
|
104
84
|
- lib
|
105
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
86
|
requirements:
|
107
|
-
- -
|
87
|
+
- - ">="
|
108
88
|
- !ruby/object:Gem::Version
|
109
89
|
version: 1.9.3
|
110
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
91
|
requirements:
|
112
|
-
- -
|
92
|
+
- - ">="
|
113
93
|
- !ruby/object:Gem::Version
|
114
94
|
version: '0'
|
115
95
|
requirements: []
|
116
96
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.6.8
|
118
98
|
signing_key:
|
119
99
|
specification_version: 4
|
120
100
|
summary: A simple Ruby client for the buttercms.com REST API
|