locomotivecms_coal 1.0.0.pre.alpha.3 → 1.0.0.pre.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +7 -7
  3. data/README.md +60 -3
  4. data/lib/locomotive/coal/client.rb +10 -3
  5. data/lib/locomotive/coal/error.rb +4 -3
  6. data/lib/locomotive/coal/resources/concerns/request.rb +3 -3
  7. data/lib/locomotive/coal/resources/content_entries.rb +9 -0
  8. data/lib/locomotive/coal/resources/current_site.rb +25 -0
  9. data/lib/locomotive/coal/resources/memberships.rb +13 -0
  10. data/lib/locomotive/coal/resources/pages.rb +1 -1
  11. data/lib/locomotive/coal/resources/snippets.rb +8 -0
  12. data/lib/locomotive/coal/version.rb +1 -1
  13. data/lib/locomotive/coal.rb +3 -0
  14. data/locomotivecms_coal.gemspec +2 -2
  15. data/spec/fixtures/coal_cassettes/client.yml +117 -160
  16. data/spec/fixtures/coal_cassettes/content_assets.yml +47 -71
  17. data/spec/fixtures/coal_cassettes/content_entries.yml +510 -388
  18. data/spec/fixtures/coal_cassettes/content_types.yml +128 -196
  19. data/spec/fixtures/coal_cassettes/current_site.yml +124 -0
  20. data/spec/fixtures/coal_cassettes/memberships.yml +203 -0
  21. data/spec/fixtures/coal_cassettes/my_account.yml +40 -62
  22. data/spec/fixtures/coal_cassettes/pages.yml +82 -108
  23. data/spec/fixtures/coal_cassettes/sites.yml +43 -59
  24. data/spec/fixtures/coal_cassettes/snippets.yml +48 -70
  25. data/spec/fixtures/coal_cassettes/theme_assets.yml +46 -70
  26. data/spec/fixtures/coal_cassettes/token.yml +25 -31
  27. data/spec/fixtures/coal_cassettes/translations.yml +46 -70
  28. data/spec/fixtures/coal_cassettes/version.yml +18 -28
  29. data/spec/integration/resources/content_entries_spec.rb +11 -0
  30. data/spec/integration/resources/current_site_spec.rb +22 -0
  31. data/spec/integration/resources/memberships_spec.rb +39 -0
  32. metadata +16 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2d33fc0152aa303a2de3a82826a9b4b3d153ff8
4
- data.tar.gz: 5d9720c5e28c435a0b0d299eb437477779deaf33
3
+ metadata.gz: 5d3bba571ef565ff121673ddae199ba423c19159
4
+ data.tar.gz: f9fa0cb7d2455455122c710b32f7d54bfdbae34f
5
5
  SHA512:
6
- metadata.gz: 492dda6e3af90dd2438d0a3f4f5057bd4aa4e449fbe22e5945369cb60da0e59e4016759267572b96e1657aaad14228a8bf971ba190c677836c622c09ba69cfca
7
- data.tar.gz: e13be9b37035568852e0484e18a89dbb1094b46624059a3efce9387cf197d88a0639aba03d9be8fa2798c2e91cb7c07ccbff2b92584e4c8e5369d7a605a15e6f
6
+ metadata.gz: 875b5f487b4d2547210e50e4f444238dd4bf9453d9e5d3ef58d4ec9e19033f61ab0e3ad0f0b78b67a26ef4cad4921018bf614dc349814025a17aed86ca0c4088
7
+ data.tar.gz: 1f718e96033b2b03df927b3a8dfb17b04ccb5e24c6cbd4a118aadd5d178332f46d3953acc211670b1fee4f6dd0e60ec91d2c57350c69386ef2b0fb14599f5057
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_coal (1.0.0.pre.alpha.3)
5
- activesupport (~> 4.2.1)
4
+ locomotivecms_coal (1.0.0.pre.beta.1)
5
+ activesupport (~> 4.2.3)
6
6
  faraday (~> 0.9.1)
7
- faraday_middleware (~> 0.9.1)
7
+ faraday_middleware (~> 0.10.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- activesupport (4.2.1)
12
+ activesupport (4.2.3)
13
13
  i18n (~> 0.7)
14
14
  json (~> 1.7, >= 1.7.7)
15
15
  minitest (~> 5.1)
@@ -36,18 +36,18 @@ GEM
36
36
  unf (>= 0.0.5, < 1.0.0)
37
37
  faraday (0.9.1)
38
38
  multipart-post (>= 1.2, < 3)
39
- faraday_middleware (0.9.1)
39
+ faraday_middleware (0.10.0)
40
40
  faraday (>= 0.7.4, < 0.10)
41
41
  http-cookie (1.0.2)
42
42
  domain_name (~> 0.5)
43
43
  i18n (0.7.0)
44
- json (1.8.2)
44
+ json (1.8.3)
45
45
  json_spec (1.1.4)
46
46
  multi_json (~> 1.0)
47
47
  rspec (>= 2.0, < 4.0)
48
48
  method_source (0.8.2)
49
49
  mime-types (2.4.3)
50
- minitest (5.6.1)
50
+ minitest (5.7.0)
51
51
  multi_json (1.11.0)
52
52
  multipart-post (2.0.0)
53
53
  netrc (0.10.3)
data/README.md CHANGED
@@ -18,6 +18,8 @@ The Ruby API Client for LocomotiveCMS V3 (WIP).
18
18
  - [Snippets](#snippets)
19
19
  - [Theme Assets](#theme-assets)
20
20
  - [Content Assets](#content-assets)
21
+ - [Translations](#translations)
22
+ - [Memberships](#memberships)
21
23
  - [What is missing](#todo)
22
24
  - [Contributing](#contributing)
23
25
  - [How to write specs](#how-to-write-specs)
@@ -30,6 +32,10 @@ The Ruby API Client for LocomotiveCMS V3 (WIP).
30
32
 
31
33
  ## Usage
32
34
 
35
+ First, load the gem:
36
+
37
+ require 'locomotive/coal'
38
+
33
39
  ### Authentication
34
40
 
35
41
  client = Locomotive::Coal::Client.new('http://www.myengine.dev', { email: <EMAIL>, api_key: <API KEY> })
@@ -38,7 +44,11 @@ You can get the version of the remote running Engine by calling the following me
38
44
 
39
45
  client.engine_version
40
46
 
41
- *Note:* Coal only supports Engine version **~> 3.0.0**.
47
+ *Note:* Coal supports Engine version **~> 3.0.x**. However, if you do need to request an Engine running a 2.5.x version, use following code instead:
48
+
49
+ client = Locomotive::Coal::ClientV2.new('http://www.myengine.dev', { email: <EMAIL>, api_key: <API KEY> })
50
+
51
+ We do not garantee that all the API resources will work with the V2 Client but PRs are accepted of course.
42
52
 
43
53
  ### Resources
44
54
 
@@ -77,9 +87,17 @@ You can get the version of the remote running Engine by calling the following me
77
87
 
78
88
  *Note:* We first need to log in to the site. It can be done by calling the scope_by method of the client instance.
79
89
 
80
- site = client.sites.by_subdomain('acme')
90
+ site = client.sites.by_handle('acme')
81
91
  site_client = client.scope_by(site)
82
92
 
93
+ Or, in a shorter way:
94
+
95
+ site_client = client.scope_by('acme')
96
+
97
+ For the **V2 Client**, that would be this instead:
98
+
99
+ site = client.sites.by_subdomain('acme')
100
+
83
101
  **Get the list of pages in English**
84
102
 
85
103
  pages = site_client.pages.all(:en)
@@ -160,6 +178,10 @@ It is required when we need the id of an existing page according to its fullpath
160
178
 
161
179
  snippets = site_client.snippets.all
162
180
 
181
+ To get the snippets in the FR locale:
182
+
183
+ snippets_in_french = site_client.snippets.all('fr')
184
+
163
185
  **Create a snippet**
164
186
 
165
187
  snippet = site_client.snippets.create(name: 'Header', slug: 'header', template: 'Locomotive rocks!')
@@ -212,9 +234,44 @@ It is required when we need the id of an existing page according to its fullpath
212
234
 
213
235
  site_client.content_assets.destroy(asset._id)
214
236
 
237
+ #### Translations
238
+
239
+ **Get the list of translations**
240
+
241
+ translations = site_client.translations.all
242
+
243
+ **Create a translation**
244
+
245
+ translation = site_client.translations.create(key: 'hello_world', values: { en: 'Hello world!', fr: 'Bonjour monde' })
246
+
247
+ **Update a translation**
248
+
249
+ site_client.translations.update(translation._id, values: { en: 'Hello world!!!', fr: 'Bonjour monde !!!'} ))
250
+
251
+ **Destroy a translation**
252
+
253
+ site_client.translations.destroy(translation._id)
254
+
255
+ #### Memberships
256
+ **Get the list of memberships**
257
+
258
+ memberships = site_client.memberships.all
259
+
260
+ **Create a membership**
261
+
262
+ membership = site_client.memberships.create(role: 'author', account_email: 'nic@example.com')
263
+
264
+ **Update a membership**
265
+
266
+ site_client.memberships.update(account_email: 'nic@example.com', role: 'admin')
267
+
268
+ **Destroy a membership**
269
+
270
+ site_client.memberships.destroy(membership._id)
271
+
215
272
  ## What is missing?
216
273
 
217
- We only implemented a few resources (my_account, sites, content types and content entries) and for some of them, not all the actions have been implemented.
274
+ We only implemented a few resources (my_account, sites, content types, memberships and content entries) and for some of them, not all the actions have been implemented.
218
275
 
219
276
  Check the issues section of the repository to see what is missing.
220
277
 
@@ -25,6 +25,10 @@ module Locomotive::Coal
25
25
  @sites ||= Resources::Sites.new(uri, connection)
26
26
  end
27
27
 
28
+ def current_site
29
+ @current_site ||= Resources::CurrentSite.new(uri, connection)
30
+ end
31
+
28
32
  def pages
29
33
  @pages ||= Resources::Pages.new(uri, connection)
30
34
  end
@@ -62,13 +66,16 @@ module Locomotive::Coal
62
66
 
63
67
  alias version engine_version
64
68
 
65
- def scope_by(site)
66
- options[:handle] = site.handle
69
+ def scope_by(site_or_handle)
70
+ if site_or_handle.respond_to?(:handle)
71
+ @current_site, site_or_handle = site_or_handle, site_or_handle.handle
72
+ end
73
+ options[:handle] = site_or_handle
67
74
  self
68
75
  end
69
76
 
70
77
  def reset
71
- @token = @my_account = @sites = @pages = @content_types = @theme_assets = @content_assets = @translations = nil
78
+ @token = @my_account = @sites = @current_site = @pages = @content_types = @theme_assets = @content_assets = @translations = nil
72
79
  end
73
80
 
74
81
  def ssl?
@@ -51,7 +51,7 @@ module Locomotive::Coal
51
51
  private
52
52
 
53
53
  def build_message
54
- attributes = body['attributes'].map do |name, errors|
54
+ attributes = (body['attributes'] || body).map do |name, errors|
55
55
  if errors.is_a?(Hash)
56
56
  errors.map do |k, _errors|
57
57
  "#{name}.#{k}: #{_errors.join(' + ')}"
@@ -59,8 +59,9 @@ module Locomotive::Coal
59
59
  else
60
60
  "#{name} #{errors.join(' ')}"
61
61
  end
62
- end
63
- "#{body['error']}: #{attributes.join(', ')}"
62
+ end.join(', ')
63
+
64
+ body['error'] ? "#{body['error']}: #{attributes}" : attributes
64
65
  end
65
66
 
66
67
  end
@@ -53,10 +53,10 @@ module Locomotive::Coal::Resources
53
53
  _connection.send(action, endpoint) do |request|
54
54
  request.headers = _request_headers(parameters)
55
55
 
56
- if %i(create update).include?(action)
57
- request.params = parameters
58
- else
56
+ if %i(post put).include?(action)
59
57
  request.body = parameters
58
+ else
59
+ request.params = parameters
60
60
  end
61
61
  end
62
62
  end
@@ -25,6 +25,15 @@ module Locomotive::Coal
25
25
  response.headers[:x_total_entries].to_i)
26
26
  end
27
27
 
28
+ def each(query = nil, options = nil, locale = nil, &block)
29
+ page = 1
30
+ while page do
31
+ resources = all(query, (options || {}).merge(page: page), locale)
32
+ resources.each(&block)
33
+ page = resources._next_page
34
+ end
35
+ end
36
+
28
37
  alias :all :index
29
38
 
30
39
  alias :update :update_with_locale
@@ -0,0 +1,25 @@
1
+ module Locomotive::Coal
2
+ module Resources
3
+
4
+ class CurrentSite < Struct.new(:uri, :credentials)
5
+
6
+ include Concerns::Request
7
+
8
+ def get(locale = nil)
9
+ Resource.new(super('current_site', _locale: locale))
10
+ end
11
+
12
+ def update(attributes = {})
13
+ data = put('current_site', site: attributes)
14
+ Resource.new(data)
15
+ end
16
+
17
+ def destroy
18
+ data = delete('current_site')
19
+ Resource.new(data)
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ module Locomotive::Coal
2
+ module Resources
3
+
4
+ class Memberships < Base
5
+
6
+ # for create, accept email address.
7
+
8
+ alias :all :index
9
+
10
+ end
11
+
12
+ end
13
+ end
@@ -3,7 +3,7 @@ module Locomotive::Coal
3
3
 
4
4
  class Pages < Base
5
5
 
6
- def index(locale)
6
+ def index(locale = nil)
7
7
  get(resources_name, _locale: locale).map do |attributes|
8
8
  Resource.new(attributes)
9
9
  end
@@ -3,6 +3,14 @@ module Locomotive::Coal
3
3
 
4
4
  class Snippets < Base
5
5
 
6
+ def index(locale = nil)
7
+ get(resources_name, _locale: locale).map do |attributes|
8
+ Resource.new(attributes)
9
+ end
10
+ end
11
+
12
+ alias :all :index
13
+
6
14
  end
7
15
 
8
16
  end
@@ -3,6 +3,6 @@
3
3
  # 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0
4
4
  module Locomotive
5
5
  module Coal
6
- VERSION = '1.0.0-alpha.3'
6
+ VERSION = '1.0.0-beta.1'
7
7
  end
8
8
  end
@@ -18,6 +18,7 @@ require_relative 'coal/resources/base'
18
18
  require_relative 'coal/resources/token'
19
19
  require_relative 'coal/resources/my_account'
20
20
  require_relative 'coal/resources/sites'
21
+ require_relative 'coal/resources/current_site'
21
22
  require_relative 'coal/resources/pages'
22
23
  require_relative 'coal/resources/snippets'
23
24
  require_relative 'coal/resources/content_assets'
@@ -26,4 +27,6 @@ require_relative 'coal/resources/translations'
26
27
  require_relative 'coal/resources/content_types'
27
28
  require_relative 'coal/resources/content_entries'
28
29
  require_relative 'coal/resources/engine_version'
30
+ require_relative 'coal/resources/memberships'
29
31
  require_relative 'coal/client'
32
+ require_relative 'coal/client_v2'
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.add_development_dependency 'rake', '~> 10.4.2'
20
20
 
21
21
  spec.add_dependency 'faraday', '~> 0.9.1'
22
- spec.add_dependency 'faraday_middleware', '~> 0.9.1'
23
- spec.add_dependency 'activesupport', '~> 4.2.1'
22
+ spec.add_dependency 'faraday_middleware', '~> 0.10.0'
23
+ spec.add_dependency 'activesupport', '~> 4.2.3'
24
24
 
25
25
  spec.required_ruby_version = '>= 2.0'
26
26
  end