locomotivecms_coal 1.0.0.pre.alpha.1 → 1.0.0.pre.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +23 -12
- data/README.md +167 -10
- data/lib/locomotive/coal/client.rb +70 -20
- data/lib/locomotive/coal/client_v2.rb +31 -0
- data/lib/locomotive/coal/error.rb +46 -5
- data/lib/locomotive/coal/resources/base.rb +57 -0
- data/lib/locomotive/coal/resources/concerns/request.rb +101 -0
- data/lib/locomotive/coal/resources/content_assets.rb +9 -0
- data/lib/locomotive/coal/resources/content_entries.rb +17 -11
- data/lib/locomotive/coal/resources/{contents.rb → content_types.rb} +4 -5
- data/lib/locomotive/coal/resources/engine_version.rb +15 -0
- data/lib/locomotive/coal/resources/my_account.rb +14 -2
- data/lib/locomotive/coal/resources/pages.rb +25 -0
- data/lib/locomotive/coal/resources/sites.rb +5 -17
- data/lib/locomotive/coal/resources/snippets.rb +9 -0
- data/lib/locomotive/coal/resources/theme_assets.rb +13 -0
- data/lib/locomotive/coal/resources/token.rb +2 -2
- data/lib/locomotive/coal/resources/translations.rb +9 -0
- data/lib/locomotive/coal/upload_io.rb +11 -0
- data/lib/locomotive/coal/version.rb +1 -1
- data/lib/locomotive/coal.rb +11 -3
- data/locomotivecms_coal.gemspec +4 -4
- data/spec/fixtures/assets/locomotive.png +0 -0
- data/spec/fixtures/assets/rails.png +0 -0
- data/spec/fixtures/coal_cassettes/client.yml +333 -69
- data/spec/fixtures/coal_cassettes/content_assets.yml +595 -0
- data/spec/fixtures/coal_cassettes/content_entries.yml +1134 -223
- data/spec/fixtures/coal_cassettes/content_types.yml +616 -0
- data/spec/fixtures/coal_cassettes/my_account.yml +167 -47
- data/spec/fixtures/coal_cassettes/pages.yml +281 -0
- data/spec/fixtures/coal_cassettes/sites.yml +93 -117
- data/spec/fixtures/coal_cassettes/snippets.yml +227 -0
- data/spec/fixtures/coal_cassettes/theme_assets.yml +406 -0
- data/spec/fixtures/coal_cassettes/token.yml +37 -55
- data/spec/fixtures/coal_cassettes/translations.yml +227 -0
- data/spec/fixtures/coal_cassettes/version.yml +89 -0
- data/spec/integration/client_spec.rb +37 -3
- data/spec/integration/resources/content_assets_spec.rb +42 -0
- data/spec/integration/resources/content_entries_spec.rb +45 -18
- data/spec/integration/resources/content_types_spec.rb +44 -0
- data/spec/integration/resources/engine_version_spec.rb +17 -0
- data/spec/integration/resources/my_account_spec.rb +22 -5
- data/spec/integration/resources/pages_spec.rb +43 -0
- data/spec/integration/resources/sites_spec.rb +9 -9
- data/spec/integration/resources/snippets_spec.rb +38 -0
- data/spec/integration/resources/theme_assets_spec.rb +43 -0
- data/spec/integration/resources/token_spec.rb +7 -7
- data/spec/integration/resources/translations_spec.rb +38 -0
- data/spec/spec_helper.rb +2 -13
- data/spec/support/api_settings.rb +7 -3
- data/spec/support/assets.rb +4 -0
- data/spec/support/vcr.rb +10 -0
- data/spec/unit/error_spec.rb +28 -0
- metadata +71 -13
- data/lib/locomotive/coal/request.rb +0 -63
- data/spec/fixtures/coal_cassettes/contents.yml +0 -120
- data/spec/integration/resources/contents_spec.rb +0 -22
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Locomotive::Coal::Resources::Sites do
|
3
|
+
describe Locomotive::Coal::Resources::Sites, order: :defined do
|
4
4
|
|
5
5
|
before { VCR.insert_cassette 'sites', record: :new_episodes }
|
6
6
|
after { VCR.eject_cassette }
|
7
7
|
|
8
|
-
let(:uri)
|
9
|
-
let(:
|
10
|
-
let(:sites)
|
8
|
+
let(:uri) { TEST_API_V3_URI }
|
9
|
+
let(:credentials) { { email: TEST_API_EMAIL, token: api_token } }
|
10
|
+
let(:sites) { described_class.new(uri, credentials) }
|
11
11
|
|
12
12
|
describe '#all' do
|
13
13
|
|
@@ -25,19 +25,19 @@ describe Locomotive::Coal::Resources::Sites do
|
|
25
25
|
it { expect(subject._id).not_to eq nil }
|
26
26
|
end
|
27
27
|
|
28
|
-
describe '#
|
29
|
-
subject { sites.
|
28
|
+
describe '#by_handle' do
|
29
|
+
subject { sites.by_handle('sample') }
|
30
30
|
it { expect(subject._id).not_to eq nil }
|
31
31
|
end
|
32
32
|
|
33
33
|
describe '#destroy' do
|
34
|
-
let(:new_site) { sites.
|
34
|
+
let(:new_site) { sites.by_handle('acme') || create_site }
|
35
35
|
subject { sites.destroy(new_site._id) }
|
36
|
-
it { expect(subject._id).
|
36
|
+
it { expect(subject._id).not_to eq nil }
|
37
37
|
end
|
38
38
|
|
39
39
|
def create_site
|
40
|
-
sites.create(name: 'Acme',
|
40
|
+
sites.create(name: 'Acme', handle: 'acme', locales: ['en'])
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Coal::Resources::Snippets, order: :defined do
|
4
|
+
|
5
|
+
before { VCR.insert_cassette 'snippets', record: :new_episodes }
|
6
|
+
after { VCR.eject_cassette }
|
7
|
+
|
8
|
+
let(:uri) { TEST_SITE_API_V3_URI }
|
9
|
+
let(:credentials) { { email: TEST_API_EMAIL, token: api_token } }
|
10
|
+
let(:snippets) { described_class.new(uri, credentials) }
|
11
|
+
|
12
|
+
describe '#all' do
|
13
|
+
subject { snippets.all }
|
14
|
+
it { expect(subject).not_to eq nil }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#create' do
|
18
|
+
subject { create_snippet }
|
19
|
+
it { expect(subject._id).not_to eq nil }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#update' do
|
23
|
+
let(:snippet) { snippets.all.detect { |s| s.slug == 'footer' } || create_snippet }
|
24
|
+
subject { snippets.update(snippet._id, template: 'Locomotive rocks. period') }
|
25
|
+
it { expect(subject.template).to eq 'Locomotive rocks. period' }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#destroy' do
|
29
|
+
let(:snippet) { snippets.all.detect { |s| s.slug == 'footer' } || create_snippet }
|
30
|
+
subject { snippets.destroy(snippet._id) }
|
31
|
+
it { expect(subject._id).not_to eq nil }
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_snippet
|
35
|
+
snippets.create(name: 'Footer', slug: 'footer', template: 'Locomotive rocks!')
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Coal::Resources::ThemeAssets, order: :defined do
|
4
|
+
|
5
|
+
before { VCR.insert_cassette 'theme_assets', record: :new_episodes }
|
6
|
+
after { VCR.eject_cassette }
|
7
|
+
|
8
|
+
let(:uri) { TEST_SITE_API_V3_URI }
|
9
|
+
let(:credentials) { { email: TEST_API_EMAIL, token: api_token } }
|
10
|
+
let(:theme_assets) { described_class.new(uri, credentials) }
|
11
|
+
|
12
|
+
describe '#all' do
|
13
|
+
subject { theme_assets.all }
|
14
|
+
it { expect(subject).not_to eq nil }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#create' do
|
18
|
+
subject { create_theme_asset }
|
19
|
+
it { expect(subject._id).not_to eq nil }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#update' do
|
23
|
+
let(:theme_asset) { single_theme_asset || create_theme_asset }
|
24
|
+
subject { theme_assets.update(theme_asset._id, folder: 'header') }
|
25
|
+
it { expect(subject.url).to match /theme\/images\/header\/rails.png$/ }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#destroy' do
|
29
|
+
let(:theme_asset) { single_theme_asset || create_theme_asset }
|
30
|
+
subject { theme_assets.destroy(theme_asset._id) }
|
31
|
+
it { expect(subject._id).not_to eq nil }
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_theme_asset
|
35
|
+
file = Locomotive::Coal::UploadIO.new(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'assets', 'rails.png'))
|
36
|
+
theme_assets.create(source: file, folder: 'footer' )
|
37
|
+
end
|
38
|
+
|
39
|
+
def single_theme_asset
|
40
|
+
theme_assets.all.detect { |a| a.url =~ /theme\/images\/footer\/rails.png$/ }
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -14,22 +14,22 @@ describe Locomotive::Coal::Resources::Token do
|
|
14
14
|
subject { token.get }
|
15
15
|
|
16
16
|
context 'uri not pointing to a Locomotive engine' do
|
17
|
-
let(:uri) { URI('http://
|
18
|
-
let(:credentials) {
|
17
|
+
let(:uri) { URI('http://acme.example.com:3000') }
|
18
|
+
let(:credentials) { TEST_API_CREDENTIALS }
|
19
19
|
it { expect { subject }.to raise_error Locomotive::Coal::UnknownResourceError }
|
20
20
|
end
|
21
21
|
|
22
22
|
context 'valid uri' do
|
23
|
-
let(:uri) {
|
23
|
+
let(:uri) { TEST_API_V3_URI }
|
24
24
|
|
25
25
|
context 'email + password as credentials' do
|
26
|
-
let(:credentials) {
|
27
|
-
it { is_expected.to match(/^[a-zA-Z0-
|
26
|
+
let(:credentials) { TEST_API_CREDENTIALS }
|
27
|
+
it { is_expected.to match(/^[a-zA-Z0-9_-]{,20}$/) }
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'api key as credentials' do
|
31
|
-
let(:credentials) {
|
32
|
-
it { is_expected.to match(/^[a-zA-Z0-
|
31
|
+
let(:credentials) { TEST_API_CREDENTIALS_WITH_KEY }
|
32
|
+
it { is_expected.to match(/^[a-zA-Z0-9_-]{,20}$/) }
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Coal::Resources::Translations, order: :defined do
|
4
|
+
|
5
|
+
before { VCR.insert_cassette 'translations', record: :new_episodes }
|
6
|
+
after { VCR.eject_cassette }
|
7
|
+
|
8
|
+
let(:uri) { TEST_SITE_API_V3_URI }
|
9
|
+
let(:credentials) { { email: TEST_API_EMAIL, token: api_token } }
|
10
|
+
let(:translations) { described_class.new(uri, credentials) }
|
11
|
+
|
12
|
+
describe '#all' do
|
13
|
+
subject { translations.all }
|
14
|
+
it { expect(subject).not_to eq nil }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#create' do
|
18
|
+
subject { create_translation }
|
19
|
+
it { expect(subject._id).not_to eq nil }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#update' do
|
23
|
+
let(:translation) { translations.all.detect { |s| s.key == 'hello' } || create_translation }
|
24
|
+
subject { translations.update(translation._id, values: { 'en' => 'Hello world!', 'fr' => 'Bonjour le monde!' }) }
|
25
|
+
it { expect(subject.values).to eq('en' => 'Hello world!', 'fr' => 'Bonjour le monde!') }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#destroy' do
|
29
|
+
let(:translation) { translations.all.detect { |s| s.key == 'hello' } || create_translation }
|
30
|
+
subject { translations.destroy(translation._id) }
|
31
|
+
it { expect(subject._id).not_to eq nil }
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_translation
|
35
|
+
translations.create(key: 'hello', values: { 'en' => 'Hello world', 'fr' => 'Bonjour le monde' })
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,21 +16,10 @@ end
|
|
16
16
|
require 'rubygems'
|
17
17
|
require 'bundler/setup'
|
18
18
|
|
19
|
-
|
20
|
-
require
|
21
|
-
|
22
|
-
# VCR config
|
23
|
-
VCR.configure do |c|
|
24
|
-
c.cassette_library_dir = 'spec/fixtures/coal_cassettes'
|
25
|
-
c.hook_into :webmock
|
26
|
-
c.ignore_hosts 'codeclimate.com'
|
27
|
-
c.configure_rspec_metadata!
|
19
|
+
Dir["#{File.expand_path('../support', __FILE__)}/*.rb"].each do |file|
|
20
|
+
require file
|
28
21
|
end
|
29
22
|
|
30
|
-
require_relative 'support/default_resources'
|
31
|
-
require_relative 'support/api_settings'
|
32
|
-
require_relative 'support/pry'
|
33
|
-
|
34
23
|
require_relative '../lib/locomotive/coal'
|
35
24
|
|
36
25
|
RSpec.configure do |config|
|
@@ -1,6 +1,10 @@
|
|
1
|
-
TEST_API_URI = URI('http://
|
2
|
-
|
1
|
+
TEST_API_URI = URI('http://localhost:3000').freeze
|
2
|
+
TEST_API_V3_URI = URI('http://localhost:3000/locomotive/api/v3').freeze
|
3
|
+
TEST_SITE_API_V3_URI = URI('http://localhost:3000/locomotive/sample/api/v3').freeze
|
4
|
+
TEST_API_EMAIL = 'admin@locomotivecms.com'
|
5
|
+
TEST_API_CREDENTIALS = { email: TEST_API_EMAIL, password: 'locomotive' }.freeze
|
6
|
+
TEST_API_CREDENTIALS_WITH_KEY = { email: TEST_API_EMAIL, api_key: 'd49cd50f6f0d2b163f48fc73cb249f0244c37074' }.freeze
|
3
7
|
|
4
8
|
def api_token(uri = nil, credentials = nil)
|
5
|
-
Locomotive::Coal::Resources::Token.new(uri ||
|
9
|
+
Locomotive::Coal::Resources::Token.new(uri || TEST_API_V3_URI, credentials || TEST_API_CREDENTIALS.dup).get
|
6
10
|
end
|
data/spec/support/vcr.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Locomotive::Coal::Error do
|
4
|
+
|
5
|
+
let(:status) { nil }
|
6
|
+
let(:body) { {} }
|
7
|
+
let(:response) { instance_double('Response', status: status, body: body) }
|
8
|
+
let(:error) { described_class.from_response(response) }
|
9
|
+
|
10
|
+
describe '#message' do
|
11
|
+
|
12
|
+
subject { error.message }
|
13
|
+
|
14
|
+
context 'error caused by a wrong answer from the server' do
|
15
|
+
|
16
|
+
context 'invalid resource (422)' do
|
17
|
+
let(:status) { 422 }
|
18
|
+
let(:body) { { 'error' => 'Resource invalid', 'attributes' => { 'name' => ["can't be blank"] } } }
|
19
|
+
|
20
|
+
it { is_expected.to eq "Resource invalid: name can't be blank" }
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locomotivecms_coal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.alpha.
|
4
|
+
version: 1.0.0.pre.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Didier Lafforgue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,19 +39,33 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 10.4.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: faraday
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.9.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.9.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday_middleware
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.9.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.9.1
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: activesupport
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,13 +80,14 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: 4.2.1
|
69
|
-
description: The LocomotiveCMS
|
83
|
+
description: The LocomotiveCMS Coal is the API ruby client for the LocomotiveCMS platform
|
70
84
|
email:
|
71
85
|
- did@locomotivecms.com
|
72
86
|
executables: []
|
73
87
|
extensions: []
|
74
88
|
extra_rdoc_files: []
|
75
89
|
files:
|
90
|
+
- ".DS_Store"
|
76
91
|
- ".gitignore"
|
77
92
|
- ".rspec"
|
78
93
|
- ".travis.yml"
|
@@ -83,34 +98,60 @@ files:
|
|
83
98
|
- Rakefile
|
84
99
|
- lib/locomotive/coal.rb
|
85
100
|
- lib/locomotive/coal/client.rb
|
101
|
+
- lib/locomotive/coal/client_v2.rb
|
86
102
|
- lib/locomotive/coal/error.rb
|
87
103
|
- lib/locomotive/coal/paginated_resources.rb
|
88
|
-
- lib/locomotive/coal/request.rb
|
89
104
|
- lib/locomotive/coal/resource.rb
|
105
|
+
- lib/locomotive/coal/resources/base.rb
|
106
|
+
- lib/locomotive/coal/resources/concerns/request.rb
|
107
|
+
- lib/locomotive/coal/resources/content_assets.rb
|
90
108
|
- lib/locomotive/coal/resources/content_entries.rb
|
91
|
-
- lib/locomotive/coal/resources/
|
109
|
+
- lib/locomotive/coal/resources/content_types.rb
|
110
|
+
- lib/locomotive/coal/resources/engine_version.rb
|
92
111
|
- lib/locomotive/coal/resources/my_account.rb
|
112
|
+
- lib/locomotive/coal/resources/pages.rb
|
93
113
|
- lib/locomotive/coal/resources/sites.rb
|
114
|
+
- lib/locomotive/coal/resources/snippets.rb
|
115
|
+
- lib/locomotive/coal/resources/theme_assets.rb
|
94
116
|
- lib/locomotive/coal/resources/token.rb
|
117
|
+
- lib/locomotive/coal/resources/translations.rb
|
118
|
+
- lib/locomotive/coal/upload_io.rb
|
95
119
|
- lib/locomotive/coal/version.rb
|
96
120
|
- locomotivecms_coal.gemspec
|
121
|
+
- spec/fixtures/assets/locomotive.png
|
122
|
+
- spec/fixtures/assets/rails.png
|
97
123
|
- spec/fixtures/coal_cassettes/client.yml
|
124
|
+
- spec/fixtures/coal_cassettes/content_assets.yml
|
98
125
|
- spec/fixtures/coal_cassettes/content_entries.yml
|
99
|
-
- spec/fixtures/coal_cassettes/
|
126
|
+
- spec/fixtures/coal_cassettes/content_types.yml
|
100
127
|
- spec/fixtures/coal_cassettes/my_account.yml
|
128
|
+
- spec/fixtures/coal_cassettes/pages.yml
|
101
129
|
- spec/fixtures/coal_cassettes/sites.yml
|
130
|
+
- spec/fixtures/coal_cassettes/snippets.yml
|
131
|
+
- spec/fixtures/coal_cassettes/theme_assets.yml
|
102
132
|
- spec/fixtures/coal_cassettes/token.yml
|
133
|
+
- spec/fixtures/coal_cassettes/translations.yml
|
134
|
+
- spec/fixtures/coal_cassettes/version.yml
|
103
135
|
- spec/integration/client_spec.rb
|
136
|
+
- spec/integration/resources/content_assets_spec.rb
|
104
137
|
- spec/integration/resources/content_entries_spec.rb
|
105
|
-
- spec/integration/resources/
|
138
|
+
- spec/integration/resources/content_types_spec.rb
|
139
|
+
- spec/integration/resources/engine_version_spec.rb
|
106
140
|
- spec/integration/resources/my_account_spec.rb
|
141
|
+
- spec/integration/resources/pages_spec.rb
|
107
142
|
- spec/integration/resources/sites_spec.rb
|
143
|
+
- spec/integration/resources/snippets_spec.rb
|
144
|
+
- spec/integration/resources/theme_assets_spec.rb
|
108
145
|
- spec/integration/resources/token_spec.rb
|
146
|
+
- spec/integration/resources/translations_spec.rb
|
109
147
|
- spec/spec_helper.rb
|
110
148
|
- spec/support/api_settings.rb
|
149
|
+
- spec/support/assets.rb
|
111
150
|
- spec/support/default_resources.rb
|
112
151
|
- spec/support/pry.rb
|
152
|
+
- spec/support/vcr.rb
|
113
153
|
- spec/unit/client_spec.rb
|
154
|
+
- spec/unit/error_spec.rb
|
114
155
|
- spec/unit/paginated_resources_spec.rb
|
115
156
|
- spec/unit/resource_spec.rb
|
116
157
|
homepage: https://github.com/locomotivecms/coal
|
@@ -136,24 +177,41 @@ rubyforge_project:
|
|
136
177
|
rubygems_version: 2.4.5
|
137
178
|
signing_key:
|
138
179
|
specification_version: 4
|
139
|
-
summary: The LocomotiveCMS
|
180
|
+
summary: The LocomotiveCMS Coal is the API ruby client for the LocomotiveCMS platform
|
140
181
|
test_files:
|
182
|
+
- spec/fixtures/assets/locomotive.png
|
183
|
+
- spec/fixtures/assets/rails.png
|
141
184
|
- spec/fixtures/coal_cassettes/client.yml
|
185
|
+
- spec/fixtures/coal_cassettes/content_assets.yml
|
142
186
|
- spec/fixtures/coal_cassettes/content_entries.yml
|
143
|
-
- spec/fixtures/coal_cassettes/
|
187
|
+
- spec/fixtures/coal_cassettes/content_types.yml
|
144
188
|
- spec/fixtures/coal_cassettes/my_account.yml
|
189
|
+
- spec/fixtures/coal_cassettes/pages.yml
|
145
190
|
- spec/fixtures/coal_cassettes/sites.yml
|
191
|
+
- spec/fixtures/coal_cassettes/snippets.yml
|
192
|
+
- spec/fixtures/coal_cassettes/theme_assets.yml
|
146
193
|
- spec/fixtures/coal_cassettes/token.yml
|
194
|
+
- spec/fixtures/coal_cassettes/translations.yml
|
195
|
+
- spec/fixtures/coal_cassettes/version.yml
|
147
196
|
- spec/integration/client_spec.rb
|
197
|
+
- spec/integration/resources/content_assets_spec.rb
|
148
198
|
- spec/integration/resources/content_entries_spec.rb
|
149
|
-
- spec/integration/resources/
|
199
|
+
- spec/integration/resources/content_types_spec.rb
|
200
|
+
- spec/integration/resources/engine_version_spec.rb
|
150
201
|
- spec/integration/resources/my_account_spec.rb
|
202
|
+
- spec/integration/resources/pages_spec.rb
|
151
203
|
- spec/integration/resources/sites_spec.rb
|
204
|
+
- spec/integration/resources/snippets_spec.rb
|
205
|
+
- spec/integration/resources/theme_assets_spec.rb
|
152
206
|
- spec/integration/resources/token_spec.rb
|
207
|
+
- spec/integration/resources/translations_spec.rb
|
153
208
|
- spec/spec_helper.rb
|
154
209
|
- spec/support/api_settings.rb
|
210
|
+
- spec/support/assets.rb
|
155
211
|
- spec/support/default_resources.rb
|
156
212
|
- spec/support/pry.rb
|
213
|
+
- spec/support/vcr.rb
|
157
214
|
- spec/unit/client_spec.rb
|
215
|
+
- spec/unit/error_spec.rb
|
158
216
|
- spec/unit/paginated_resources_spec.rb
|
159
217
|
- spec/unit/resource_spec.rb
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module Locomotive::Coal
|
2
|
-
|
3
|
-
module Request
|
4
|
-
|
5
|
-
def get(endpoint, parameters = {}, raw = false)
|
6
|
-
safe_request_call(raw) do
|
7
|
-
Unirest.get "#{uri.to_s}/#{endpoint}.json",
|
8
|
-
headers: { 'Accept' => 'application/json' },
|
9
|
-
auth: uri.userinfo,
|
10
|
-
parameters: parameters.merge(auth_token: token)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def post(endpoint, parameters = {})
|
15
|
-
parameters = parameters.merge(auth_token: token) if respond_to?(:token)
|
16
|
-
|
17
|
-
safe_request_call do
|
18
|
-
Unirest.post "#{uri.to_s}/#{endpoint}.json",
|
19
|
-
auth: uri.userinfo,
|
20
|
-
headers: { 'Accept' => 'application/json' },
|
21
|
-
parameters: parameters
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def put(endpoint, parameters = {})
|
26
|
-
parameters = parameters.merge(auth_token: token) if respond_to?(:token)
|
27
|
-
|
28
|
-
safe_request_call do
|
29
|
-
Unirest.put "#{uri.to_s}/#{endpoint}.json",
|
30
|
-
auth: uri.userinfo,
|
31
|
-
headers: { 'Accept' => 'application/json' },
|
32
|
-
parameters: parameters
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def delete(endpoint, id)
|
37
|
-
safe_request_call do
|
38
|
-
Unirest.delete "#{uri.to_s}/#{endpoint}/#{id}.json",
|
39
|
-
auth: uri.userinfo,
|
40
|
-
headers: { 'Accept' => 'application/json' },
|
41
|
-
parameters: { auth_token: token }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def safe_request_call(raw = false, &block)
|
48
|
-
response = begin
|
49
|
-
yield
|
50
|
-
rescue Exception => e
|
51
|
-
raise Locomotive::Coal::BadRequestError.new(e)
|
52
|
-
end
|
53
|
-
|
54
|
-
if response.code == 200
|
55
|
-
raw ? response : response.body
|
56
|
-
else
|
57
|
-
raise Locomotive::Coal::Error.from_response(response)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: post
|
5
|
-
uri: http://sample.lvh.me:4000/locomotive/api/tokens.json
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: email=john%40doe.net&password=easyone
|
9
|
-
headers:
|
10
|
-
Accept:
|
11
|
-
- application/json
|
12
|
-
Accept-Encoding:
|
13
|
-
- gzip
|
14
|
-
User-Agent:
|
15
|
-
- unirest-ruby/1.1
|
16
|
-
Content-Length:
|
17
|
-
- '37'
|
18
|
-
Content-Type:
|
19
|
-
- application/x-www-form-urlencoded
|
20
|
-
response:
|
21
|
-
status:
|
22
|
-
code: 200
|
23
|
-
message: OK
|
24
|
-
headers:
|
25
|
-
Date:
|
26
|
-
- Thu, 26 Mar 2015 12:13:40 GMT
|
27
|
-
Status:
|
28
|
-
- 200 OK
|
29
|
-
Connection:
|
30
|
-
- close
|
31
|
-
Location:
|
32
|
-
- http://sample.lvh.me:4000/locomotive/
|
33
|
-
Content-Type:
|
34
|
-
- application/json; charset=utf-8
|
35
|
-
X-Ua-Compatible:
|
36
|
-
- IE=Edge
|
37
|
-
Etag:
|
38
|
-
- '"557f8d72cf11ab5399621eddec942c29"'
|
39
|
-
Cache-Control:
|
40
|
-
- max-age=0, private, must-revalidate
|
41
|
-
Set-Cookie:
|
42
|
-
- _locomotive_session=KiLaEKykMgXNNfD6itS7bVfmjss; domain=.sample.lvh.me; path=/;
|
43
|
-
HttpOnly
|
44
|
-
X-Request-Id:
|
45
|
-
- 8a693be630caf70d8a7ecfbebc0b4c9e
|
46
|
-
X-Runtime:
|
47
|
-
- '0.023604'
|
48
|
-
body:
|
49
|
-
encoding: UTF-8
|
50
|
-
string: '{"token":"9GLRWwc2MGTCF7SHiZSg"}'
|
51
|
-
http_version:
|
52
|
-
recorded_at: Thu, 26 Mar 2015 12:13:40 GMT
|
53
|
-
- request:
|
54
|
-
method: get
|
55
|
-
uri: http://sample.lvh.me:4000/locomotive/api/content_types.json?auth_token=9GLRWwc2MGTCF7SHiZSg
|
56
|
-
body:
|
57
|
-
encoding: US-ASCII
|
58
|
-
string: ''
|
59
|
-
headers:
|
60
|
-
Accept:
|
61
|
-
- application/json
|
62
|
-
Accept-Encoding:
|
63
|
-
- gzip
|
64
|
-
User-Agent:
|
65
|
-
- unirest-ruby/1.1
|
66
|
-
response:
|
67
|
-
status:
|
68
|
-
code: 200
|
69
|
-
message: OK
|
70
|
-
headers:
|
71
|
-
Date:
|
72
|
-
- Thu, 26 Mar 2015 12:13:40 GMT
|
73
|
-
Status:
|
74
|
-
- 200 OK
|
75
|
-
Connection:
|
76
|
-
- close
|
77
|
-
Content-Type:
|
78
|
-
- application/json; charset=utf-8
|
79
|
-
X-Ua-Compatible:
|
80
|
-
- IE=Edge
|
81
|
-
Etag:
|
82
|
-
- '"7dbb8592219d2f208083b29864ef8522"'
|
83
|
-
Cache-Control:
|
84
|
-
- max-age=0, private, must-revalidate
|
85
|
-
Set-Cookie:
|
86
|
-
- _locomotive_session=F8r7t2KiM9Y_08jfTgR3-2_uWeg; domain=.sample.lvh.me; path=/;
|
87
|
-
HttpOnly
|
88
|
-
X-Request-Id:
|
89
|
-
- c5995e9d19527d56c352a1894b74baf7
|
90
|
-
X-Runtime:
|
91
|
-
- '0.069300'
|
92
|
-
body:
|
93
|
-
encoding: UTF-8
|
94
|
-
string: '[{"id":"54eb4b662475804b2b00000a","_id":"54eb4b662475804b2b00000a","created_at":"2015-02-23T15:46:46Z","updated_at":"2015-02-23T15:46:47Z","name":"Bands","slug":"bands","entries_custom_fields":[{"id":"54eb4b662475804b2b00000b","_id":"54eb4b662475804b2b00000b","name":"name","label":"Name","type":"string","required":true,"localized":false,"unique":false,"hint":"Name
|
95
|
-
of the band","position":0},{"id":"54eb4b662475804b2b00000c","_id":"54eb4b662475804b2b00000c","name":"leader","label":"Fullname
|
96
|
-
of the leader","type":"string","required":false,"localized":false,"unique":false,"position":1},{"id":"54eb4b662475804b2b00000d","_id":"54eb4b662475804b2b00000d","name":"kind","label":"Music
|
97
|
-
kind (grunge, rock, pop, country)","type":"select","required":false,"localized":false,"unique":false,"position":2,"select_options":[{"_id":"54eb4b662475804b2b00000f","name":"grunge","position":0,"id":"54eb4b662475804b2b00000f"},{"_id":"54eb4b662475804b2b000010","name":"rock","position":1,"id":"54eb4b662475804b2b000010"},{"_id":"54eb4b662475804b2b000011","name":"country","position":2,"id":"54eb4b662475804b2b000011"}],"raw_select_options":[{"id":"54eb4b662475804b2b00000f","name":{"en":"grunge"},"position":2},{"id":"54eb4b662475804b2b000010","name":{"en":"rock"},"position":2},{"id":"54eb4b662475804b2b000011","name":{"en":"country"},"position":2}]},{"id":"54eb4b662475804b2b00002d","_id":"54eb4b662475804b2b00002d","name":"songs","label":"Songs","type":"has_many","required":false,"localized":false,"unique":false,"position":3,"class_name":"Locomotive::ContentEntry54eb4b662475804b2b00001e","inverse_of":"band","ui_enabled":true,"class_slug":"songs"},{"id":"54eb4b662475804b2b00000e","_id":"54eb4b662475804b2b00000e","name":"featured","label":"Featured","type":"boolean","required":false,"localized":false,"unique":false,"position":4}],"description":"List
|
98
|
-
of bands","label_field_name":"name","order_by":"54eb4b662475804b2b00000b","order_direction":"asc","order_by_field_name":"name","public_submission_enabled":false,"public_submission_account_emails":[]},{"id":"54eb4bb52475804b2b000037","_id":"54eb4bb52475804b2b000037","created_at":"2015-02-23T15:48:05Z","updated_at":"2015-02-23T15:48:05Z","name":"Events","slug":"events","entries_custom_fields":[{"id":"54eb4bb52475804b2b000038","_id":"54eb4bb52475804b2b000038","name":"place","label":"Place","type":"string","required":true,"localized":false,"unique":false,"hint":"Name
|
99
|
-
of the place","position":0},{"id":"54eb4bb52475804b2b000039","_id":"54eb4bb52475804b2b000039","name":"date","label":"Date","type":"date","required":false,"localized":false,"unique":false,"hint":"Date
|
100
|
-
of the event","position":1},{"id":"54eb4bb52475804b2b00003a","_id":"54eb4bb52475804b2b00003a","name":"city","label":"City
|
101
|
-
of the event","type":"string","required":false,"localized":false,"unique":false,"position":2},{"id":"54eb4bb52475804b2b00003b","_id":"54eb4bb52475804b2b00003b","name":"state","label":"State
|
102
|
-
of the event","type":"string","required":false,"localized":false,"unique":false,"position":3},{"id":"54eb4bb52475804b2b00003c","_id":"54eb4bb52475804b2b00003c","name":"notes","label":"Notes","type":"text","required":false,"localized":false,"unique":false,"position":4,"text_formatting":""},{"id":"54eb4bb52475804b2b00003d","_id":"54eb4bb52475804b2b00003d","name":"tags","label":"List
|
103
|
-
of tags","type":"tags","required":false,"localized":false,"unique":false,"position":5},{"id":"54eb4bb52475804b2b00003e","_id":"54eb4bb52475804b2b00003e","name":"price","label":"Price
|
104
|
-
of the event","type":"float","required":false,"localized":false,"unique":false,"position":6}],"description":"List
|
105
|
-
of upcoming events","label_field_name":"place","order_by":"created_at","order_direction":"asc","order_by_field_name":"created_at","public_submission_enabled":false,"public_submission_account_emails":[]},{"id":"54eb4b662475804b2b00001a","_id":"54eb4b662475804b2b00001a","created_at":"2015-02-23T15:46:46Z","updated_at":"2015-02-23T15:46:46Z","name":"Messages","slug":"messages","entries_custom_fields":[{"id":"54eb4b662475804b2b00001b","_id":"54eb4b662475804b2b00001b","name":"name","label":"Name","type":"string","required":true,"localized":false,"unique":false,"hint":"Full
|
106
|
-
name","position":0},{"id":"54eb4b662475804b2b00001c","_id":"54eb4b662475804b2b00001c","name":"email","label":"Email","type":"string","required":true,"localized":false,"unique":false,"hint":"Email","position":1},{"id":"54eb4b662475804b2b00001d","_id":"54eb4b662475804b2b00001d","name":"message","label":"Message","type":"text","required":true,"localized":false,"unique":false,"hint":"Customer
|
107
|
-
message","position":2,"text_formatting":""}],"description":"Messages posted
|
108
|
-
by new potential customers","label_field_name":"name","order_by":"created_at","order_direction":"asc","order_by_field_name":"created_at","public_submission_enabled":true,"public_submission_account_emails":[]},{"id":"54eb4b662475804b2b00001e","_id":"54eb4b662475804b2b00001e","created_at":"2015-02-23T15:46:46Z","updated_at":"2015-02-23T15:46:47Z","name":"Songs","slug":"songs","entries_custom_fields":[{"id":"54eb4b662475804b2b00001f","_id":"54eb4b662475804b2b00001f","name":"title","label":"Title","type":"string","required":true,"localized":false,"unique":false,"hint":"Title
|
109
|
-
of your song","position":0},{"id":"54eb4b672475804b2b00002e","_id":"54eb4b672475804b2b00002e","name":"band","label":"Band","type":"belongs_to","required":false,"localized":false,"unique":false,"position":1,"class_name":"Locomotive::ContentEntry54eb4b662475804b2b00000a","ui_enabled":true,"class_slug":"bands"},{"id":"54eb4b662475804b2b000020","_id":"54eb4b662475804b2b000020","name":"cover","label":"Cover","type":"file","required":true,"localized":false,"unique":false,"position":2},{"id":"54eb4b662475804b2b000021","_id":"54eb4b662475804b2b000021","name":"short_description","label":"Short
|
110
|
-
description","type":"text","required":false,"localized":false,"unique":false,"position":3,"text_formatting":"html"},{"id":"54eb4b662475804b2b000022","_id":"54eb4b662475804b2b000022","name":"audio_url","label":"Audio
|
111
|
-
url","type":"string","required":false,"localized":false,"unique":false,"hint":"Url
|
112
|
-
to a service like Blip for instance","position":4},{"id":"54eb4b662475804b2b000023","_id":"54eb4b662475804b2b000023","name":"duration","label":"Duration","type":"string","required":false,"localized":false,"unique":false,"hint":"format
|
113
|
-
like: mm:ss","position":5}],"label_field_name":"title","order_by":"_position","order_direction":"asc","order_by_field_name":"_position","public_submission_enabled":false,"public_submission_account_emails":[]},{"id":"54eb4b662475804b2b000024","_id":"54eb4b662475804b2b000024","created_at":"2015-02-23T15:46:46Z","updated_at":"2015-02-23T15:46:46Z","name":"Updates","slug":"updates","entries_custom_fields":[{"id":"54eb4b662475804b2b000025","_id":"54eb4b662475804b2b000025","name":"title","label":"Title","type":"string","required":true,"localized":true,"unique":false,"hint":"Not
|
114
|
-
displayed in the website","position":0},{"id":"54eb4b662475804b2b000026","_id":"54eb4b662475804b2b000026","name":"text","label":"Text","type":"text","required":false,"localized":true,"unique":false,"hint":"Text
|
115
|
-
displayed in the home page","position":1,"text_formatting":"html"},{"id":"54eb4b662475804b2b000027","_id":"54eb4b662475804b2b000027","name":"category","label":"Category","type":"select","required":false,"localized":true,"unique":false,"hint":"Pick
|
116
|
-
a category","position":2,"select_options":[{"_id":"54eb4b662475804b2b000029","name":"General","position":0,"id":"54eb4b662475804b2b000029"},{"_id":"54eb4b662475804b2b00002a","name":"Gigs","position":1,"id":"54eb4b662475804b2b00002a"},{"_id":"54eb4b662475804b2b00002b","name":"Bands","position":2,"id":"54eb4b662475804b2b00002b"},{"_id":"54eb4b662475804b2b00002c","name":"Albums","position":3,"id":"54eb4b662475804b2b00002c"}],"raw_select_options":[{"id":"54eb4b662475804b2b000029","name":{"en":"General","fr":"G\u00e9n\u00e9ral"},"position":2},{"id":"54eb4b662475804b2b00002a","name":{"en":"Gigs","fr":"Concerts"},"position":2},{"id":"54eb4b662475804b2b00002b","name":{"en":"Bands","fr":"Groupes"},"position":2},{"id":"54eb4b662475804b2b00002c","name":{"en":"Albums"},"position":2}]},{"id":"54eb4b662475804b2b000028","_id":"54eb4b662475804b2b000028","name":"date","label":"Date","type":"date","required":false,"localized":false,"unique":false,"hint":"Date
|
117
|
-
of the update","position":3}],"description":"List of updates","label_field_name":"title","order_by":"54eb4b662475804b2b000028","order_direction":"asc","order_by_field_name":"date","public_submission_enabled":false,"public_submission_account_emails":[]}]'
|
118
|
-
http_version:
|
119
|
-
recorded_at: Thu, 26 Mar 2015 12:13:40 GMT
|
120
|
-
recorded_with: VCR 2.9.3
|