locomotivecms_coal 1.6.0.rc1 → 1.6.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +1 -1
  4. data/Gemfile +0 -4
  5. data/Gemfile.lock +7 -8
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +18 -3
  8. data/lib/locomotive/coal/client.rb +8 -0
  9. data/lib/locomotive/coal/resources/accounts.rb +33 -0
  10. data/lib/locomotive/coal/resources/concerns/request.rb +19 -1
  11. data/lib/locomotive/coal/version.rb +1 -1
  12. data/lib/locomotive/coal.rb +1 -0
  13. data/locomotivecms_coal.gemspec +1 -1
  14. data/spec/fixtures/coal_cassettes/accounts.yml +214 -0
  15. data/spec/fixtures/coal_cassettes/client.yml +277 -163
  16. data/spec/fixtures/coal_cassettes/content_assets.yml +144 -445
  17. data/spec/fixtures/coal_cassettes/content_entries.yml +963 -1647
  18. data/spec/fixtures/coal_cassettes/content_types.yml +387 -209
  19. data/spec/fixtures/coal_cassettes/current_site.yml +89 -49
  20. data/spec/fixtures/coal_cassettes/memberships.yml +143 -77
  21. data/spec/fixtures/coal_cassettes/my_account.yml +163 -99
  22. data/spec/fixtures/coal_cassettes/pages.yml +177 -99
  23. data/spec/fixtures/coal_cassettes/sections.yml +121 -78
  24. data/spec/fixtures/coal_cassettes/sites.yml +108 -141
  25. data/spec/fixtures/coal_cassettes/snippets.yml +140 -76
  26. data/spec/fixtures/coal_cassettes/theme_assets.yml +142 -254
  27. data/spec/fixtures/coal_cassettes/token.yml +64 -43
  28. data/spec/fixtures/coal_cassettes/translations.yml +140 -76
  29. data/spec/fixtures/coal_cassettes/version.yml +54 -30
  30. data/spec/integration/resources/accounts_spec.rb +38 -0
  31. data/spec/integration/resources/sections_spec.rb +1 -1
  32. data/spec/integration/resources/token_spec.rb +1 -1
  33. metadata +10 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 016e54d25e92d2c847f04ab46c99a6f1210b10d809c645df1f6d722eeb334818
4
- data.tar.gz: 1c292c1f79940c8e0aeaf1f3aadb7695c8b9e16eec2ac7db0b28021927648596
3
+ metadata.gz: 0cffc656b10f31319f68a44c11bba6d9d03efb69e82b352ab2ac1efbf5275f90
4
+ data.tar.gz: 194621c054114cdc1f98c13fa9e06624f69174aa181e06f3923535bd29657872
5
5
  SHA512:
6
- metadata.gz: 62cfb52c463a62bc09983389dde1a7988fee31c2beb8691aa5398adabfc79ee859e5990260707a3f3bbb97df4c20e6a1296879aaac68e8f5f5bb4bdf25309eae
7
- data.tar.gz: 2d9437086ce85442e17679eafa0a37499b9c39d68fe10d0a0843f5b5b328ee0ce1dc4efafb682ad86293e9b1a3a10c660d01c0a0ca3222fbc47cad31966d2f39
6
+ metadata.gz: f0f133d320ae1e222cae3f9c27dc6c476f4e67bfda9aa53496dd3cd9a39543f7ab31833d0d411120b53b2e05a9fe2dc46f983937d1826b29b1d006e9c9a537c9
7
+ data.tar.gz: 7e3a9abbf3e50eb7b3173c0a0479b6c42b6abc7f1ae28add3437a88dafbd08d39bbfa8df7d4e3dd1cb2e155e8353c14f1d7c6e319f34d13770554f4bd5a602d4
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  coverage/
2
2
  pkg/
3
3
  .DS_Store
4
+ .ruby-version
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.5.0
3
+ - 2.6.5
4
4
  env:
5
5
  - CODECLIMATE_REPO_TOKEN=8d9c25de4eff1cd06d3accdc09775397e1a81be67e2a159453ba4e4408acae16
6
6
  addons:
data/Gemfile CHANGED
@@ -19,7 +19,3 @@ group :test do
19
19
  gem 'codeclimate-test-reporter', '~> 1.0.7', require: false
20
20
  gem 'coveralls', '~> 0.8.19', require: false
21
21
  end
22
-
23
- platform :ruby do
24
- ruby '2.5.0'
25
- end
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- locomotivecms_coal (1.6.0.rc1)
5
- activesupport (>= 5.1.5, < 6.0)
4
+ locomotivecms_coal (1.6.0.rc2)
5
+ activesupport (>= 5.1.5, <= 6.0)
6
6
  faraday (~> 0.15.4)
7
7
  faraday_middleware (~> 0.13.1)
8
8
  httpclient (~> 2.8.3)
@@ -11,11 +11,12 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (5.2.3)
14
+ activesupport (6.0.0)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
16
  i18n (>= 0.7, < 2)
17
17
  minitest (~> 5.1)
18
18
  tzinfo (~> 1.1)
19
+ zeitwerk (~> 2.1, >= 2.1.8)
19
20
  addressable (2.5.2)
20
21
  public_suffix (>= 2.0.2, < 4.0)
21
22
  byebug (9.0.6)
@@ -43,7 +44,7 @@ GEM
43
44
  http-cookie (1.0.3)
44
45
  domain_name (~> 0.5)
45
46
  httpclient (2.8.3)
46
- i18n (1.6.0)
47
+ i18n (1.7.0)
47
48
  concurrent-ruby (~> 1.0)
48
49
  json (2.1.0)
49
50
  json_spec (1.1.5)
@@ -53,7 +54,7 @@ GEM
53
54
  mime-types (3.1)
54
55
  mime-types-data (~> 3.2015)
55
56
  mime-types-data (3.2016.0521)
56
- minitest (5.11.3)
57
+ minitest (5.13.0)
57
58
  multi_json (1.13.1)
58
59
  multipart-post (2.1.1)
59
60
  netrc (0.11.0)
@@ -103,6 +104,7 @@ GEM
103
104
  addressable (>= 2.3.6)
104
105
  crack (>= 0.3.2)
105
106
  hashdiff
107
+ zeitwerk (2.2.1)
106
108
 
107
109
  PLATFORMS
108
110
  ruby
@@ -119,8 +121,5 @@ DEPENDENCIES
119
121
  vcr
120
122
  webmock
121
123
 
122
- RUBY VERSION
123
- ruby 2.5.0p0
124
-
125
124
  BUNDLED WITH
126
125
  1.17.3
data/MIT-LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 NoCoffee
3
+ Copyright (c) 2019 NoCoffee
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -11,6 +11,7 @@ The Ruby API Client for LocomotiveCMS V3.
11
11
  - [Authentication](#authentication)
12
12
  - [Resources](#resources)
13
13
  - [MyAccount](#my-account)
14
+ - [Accounts](#accounts)
14
15
  - [Sites](#sites)
15
16
  - [Pages](#pages)
16
17
  - [Content Types](#content-types)
@@ -69,6 +70,19 @@ We do not garantee that all the API resources will work with the V2 Client but P
69
70
 
70
71
  client.my_account.update(name: 'Jane Doe')
71
72
 
73
+ #### Accounts
74
+
75
+ **Only available for super administrators in the LocomotiveCMS engine**
76
+
77
+ **Create**
78
+
79
+ new_customer = client.accounts.create(name: 'John', email: 'johnn@doe.net', password: 'easyone', password_confirmation: 'easyone')
80
+ puts new_customer.name + " / " + my_account.email
81
+
82
+ **Update an account**
83
+
84
+ client.accounts.update(new_customer._id, name: 'Jane')
85
+
72
86
  #### Sites
73
87
 
74
88
  **Get all my sites**
@@ -149,7 +163,7 @@ It is required when we need the id of an existing page according to its fullpath
149
163
 
150
164
  *Note:* You can also use the following syntax
151
165
 
152
- content_type = site_client.contents.projects
166
+ content_type = site_client.contents.by_slug('projects')
153
167
  articles = site_client.content_entries(content_type).all
154
168
 
155
169
  **Create a content entry**
@@ -282,7 +296,7 @@ To get the snippets in the FR locale:
282
296
 
283
297
  **Update a membership**
284
298
 
285
- site_client.memberships.update(account_email: 'nic@example.com', role: 'admin')
299
+ site_client.memberships.update(membership._id, role: 'designer')
286
300
 
287
301
  **Destroy a membership**
288
302
 
@@ -316,10 +330,11 @@ Check the issues section of the repository to see what is missing.
316
330
  - edit your /etc/hosts file (*NIX systems) and add 2 lines
317
331
  127.0.0.0 www.example.com acme.example.com
318
332
 
333
+
319
334
  ## Credits
320
335
 
321
336
  [Christian](https://github.com/cblavier), [Greg](https://github.com/gregKawet) and [Ben](https://github.com/stiiig) from the Cogip/Insert International LTD who brainstormed with me (a very long time) to find this awesome name.
322
337
 
323
338
  ## License
324
339
 
325
- Copyright (c) 2018 NoCoffee. MIT Licensed, see LICENSE for details.
340
+ Copyright (c) 2019 NoCoffee. MIT Licensed, see LICENSE for details.
@@ -21,10 +21,18 @@ module Locomotive::Coal
21
21
  @my_account ||= Resources::MyAccount.new(uri, connection)
22
22
  end
23
23
 
24
+ def accounts
25
+ @accounts ||= Resources::Accounts.new(uri, connection)
26
+ end
27
+
24
28
  def sites
25
29
  @sites ||= Resources::Sites.new(uri, connection)
26
30
  end
27
31
 
32
+ def memberships
33
+ @memberships ||= Resources::Memberships.new(uri, connection)
34
+ end
35
+
28
36
  def current_site
29
37
  @current_site ||= Resources::CurrentSite.new(uri, connection)
30
38
  end
@@ -0,0 +1,33 @@
1
+ module Locomotive::Coal
2
+ module Resources
3
+
4
+ class Accounts < Base
5
+
6
+ def index(query = nil, options = {})
7
+ parameters = { where: (query || {}).to_json }.merge(options || {})
8
+
9
+ response = get(resources_name, parameters, true)
10
+
11
+ list = response.body.map { |attributes| Resource.new(attributes) }
12
+
13
+ PaginatedResources.new(list,
14
+ options[:page] || 1,
15
+ response.headers[:x_total_pages].to_i,
16
+ response.headers[:x_total_entries].to_i)
17
+ end
18
+
19
+ def each(query = nil, options = nil, &block)
20
+ page = 1
21
+ while page do
22
+ resources = all(query, (options || {}).merge(page: page))
23
+ resources.each(&block)
24
+ page = resources._next_page
25
+ end
26
+ end
27
+
28
+ alias :all :index
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -20,10 +20,28 @@ module Locomotive::Coal::Resources
20
20
  end
21
21
 
22
22
  def do_request(action, endpoint, parameters = {}, raw = false)
23
+ max_count = 5
23
24
  response = begin
25
+ # Just uncomment following line if you want to trace protocol between wagon & engine live
26
+ # puts "#{parameters}"
24
27
  _do_request(action, "#{uri.path}/#{endpoint}.json", parameters)
25
28
  rescue ::Timeout::Error, ::Errno::ETIMEDOUT, Faraday::Error::TimeoutError => e
26
- raise Locomotive::Coal::TimeoutError.new(e)
29
+ if max_count > 0
30
+ puts "\n Warning => timeout detected, attempts left: #{max_count}\n\n"
31
+ max_count -= 1
32
+ retry
33
+ else
34
+ raise Locomotive::Coal::TimeoutError.new(e)
35
+ end
36
+ rescue HTTPClient::KeepAliveDisconnected => e
37
+ if max_count > 0
38
+ puts "\n Warning => HTTPClient::KeepAliveDisconnected exception detected, attempts left: #{max_count}\n\n"
39
+ max_count -= 1
40
+ retry
41
+ else
42
+ puts "\n Error => HTTPClient::KeepAliveDisconnected exception detected, attempts left zero... raising exception\n\n"
43
+ raise HTTPClient::KeepAliveDisconnected.new(e)
44
+ end
27
45
  rescue Locomotive::Coal::Error
28
46
  raise
29
47
  rescue Exception => e
@@ -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.6.0.rc1'
6
+ VERSION = '1.6.0.rc2'
7
7
  end
8
8
  end
@@ -18,6 +18,7 @@ require_relative 'coal/resource'
18
18
  require_relative 'coal/resources/base'
19
19
  require_relative 'coal/resources/token'
20
20
  require_relative 'coal/resources/my_account'
21
+ require_relative 'coal/resources/accounts'
21
22
  require_relative 'coal/resources/sites'
22
23
  require_relative 'coal/resources/current_site'
23
24
  require_relative 'coal/resources/pages'
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency 'httpclient', '~> 2.8.3'
21
21
  spec.add_dependency 'faraday', '~> 0.15.4'
22
22
  spec.add_dependency 'faraday_middleware', '~> 0.13.1'
23
- spec.add_dependency 'activesupport', '>= 5.1.5', '< 6.0'
23
+ spec.add_dependency 'activesupport', '>= 5.1.5', '<= 6.0'
24
24
  spec.add_dependency 'mime-types', '~> 3.1.0'
25
25
 
26
26
  spec.required_ruby_version = '>= 2.0'
@@ -0,0 +1,214 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/locomotive/api/v3/tokens.json
6
+ body:
7
+ encoding: UTF-8
8
+ string: email=admin%40locomotivecms.com&password=locomotive
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.15.4
12
+ Accept:
13
+ - application/json
14
+ Accept-Encoding:
15
+ - gzip,deflate
16
+ Date:
17
+ - Sun, 17 Nov 2019 16:39:31 GMT
18
+ Content-Type:
19
+ - application/x-www-form-urlencoded
20
+ response:
21
+ status:
22
+ code: 201
23
+ message: Created
24
+ headers:
25
+ Content-Type:
26
+ - application/json
27
+ Content-Length:
28
+ - '32'
29
+ Connection:
30
+ - keep-alive
31
+ Status:
32
+ - 201 Created
33
+ Cache-Control:
34
+ - max-age=0, private, must-revalidate
35
+ Etag:
36
+ - W/"410e3d6fde24f39257a7cc619b61baa7"
37
+ X-Runtime:
38
+ - '0.003847'
39
+ X-Request-Id:
40
+ - 37641f2b-e3b4-4c75-a947-67001077f519
41
+ Date:
42
+ - Sun, 17 Nov 2019 16:39:31 GMT
43
+ X-Powered-By:
44
+ - Phusion Passenger 6.0.4
45
+ Server:
46
+ - nginx/1.17.3 + Phusion Passenger 6.0.4
47
+ body:
48
+ encoding: UTF-8
49
+ string: '{"token":"bzwAyFQzcchf_hgDQhz3"}'
50
+ http_version:
51
+ recorded_at: Sun, 17 Nov 2019 16:39:31 GMT
52
+ - request:
53
+ method: get
54
+ uri: http://localhost:3000/locomotive/api/v3/accounts.json?auth_token=bzwAyFQzcchf_hgDQhz3&where=%7B%7D
55
+ body:
56
+ encoding: UTF-8
57
+ string: ''
58
+ headers:
59
+ User-Agent:
60
+ - Faraday v0.15.4
61
+ Accept:
62
+ - application/json
63
+ Accept-Encoding:
64
+ - gzip,deflate
65
+ Date:
66
+ - Sun, 17 Nov 2019 16:39:31 GMT
67
+ X-Locomotive-Account-Email:
68
+ - admin@locomotivecms.com
69
+ X-Locomotive-Account-Token:
70
+ - bzwAyFQzcchf_hgDQhz3
71
+ response:
72
+ status:
73
+ code: 200
74
+ message: OK
75
+ headers:
76
+ Content-Type:
77
+ - application/json
78
+ Transfer-Encoding:
79
+ - chunked
80
+ Connection:
81
+ - keep-alive
82
+ Status:
83
+ - 200 OK
84
+ Cache-Control:
85
+ - max-age=0, private, must-revalidate
86
+ Etag:
87
+ - W/"b45c198e9ff3646c60b8055f5230fe83"
88
+ X-Runtime:
89
+ - '0.011734'
90
+ X-Request-Id:
91
+ - 5467f046-9d4c-49af-86aa-3ac502e50b13
92
+ Date:
93
+ - Sun, 17 Nov 2019 16:39:31 GMT
94
+ X-Powered-By:
95
+ - Phusion Passenger 6.0.4
96
+ Server:
97
+ - nginx/1.17.3 + Phusion Passenger 6.0.4
98
+ Content-Encoding:
99
+ - gzip
100
+ body:
101
+ encoding: UTF-8
102
+ string: '[{"_id":"5dd1779ba95330a94bf7253c","created_at":"2019-11-17T16:38:51Z","updated_at":"2019-11-17T16:39:30Z","name":"John
103
+ Doe","email":"admin@locomotivecms.com","locale":"en","api_key":"d49cd50f6f0d2b163f48fc73cb249f0244c37074","super_admin":true,"local_admin":true},{"_id":"5dd1779ba95330a94bf7253d","created_at":"2019-11-17T16:38:51Z","updated_at":"2019-11-17T16:38:51Z","name":"New
104
+ Admin","email":"new_admin@locomotivecms.com","locale":"en","api_key":"d49cd50f6f0d2b163f48fc73cb249f0244c37074","super_admin":false,"local_admin":false},{"_id":"5dd177c2a95330aa17f8f8df","created_at":"2019-11-17T16:39:30Z","updated_at":"2019-11-17T16:39:30Z","name":"Jack
105
+ Doe","email":"jack@doe.net","locale":"en","api_key":"b99855e630e7510ee902e0871f213328cfcbc552","super_admin":false,"local_admin":false}]'
106
+ http_version:
107
+ recorded_at: Sun, 17 Nov 2019 16:39:31 GMT
108
+ - request:
109
+ method: post
110
+ uri: http://localhost:3000/locomotive/api/v3/accounts.json
111
+ body:
112
+ encoding: UTF-8
113
+ string: account%5Bemail%5D=jane%40doe.net&account%5Bname%5D=Jane&account%5Bpassword%5D=easyone&account%5Bpassword_confirmation%5D=easyone&auth_token=bzwAyFQzcchf_hgDQhz3
114
+ headers:
115
+ User-Agent:
116
+ - Faraday v0.15.4
117
+ Accept:
118
+ - application/json
119
+ Accept-Encoding:
120
+ - gzip,deflate
121
+ Date:
122
+ - Sun, 17 Nov 2019 16:39:32 GMT
123
+ X-Locomotive-Account-Email:
124
+ - admin@locomotivecms.com
125
+ X-Locomotive-Account-Token:
126
+ - bzwAyFQzcchf_hgDQhz3
127
+ Content-Type:
128
+ - application/x-www-form-urlencoded
129
+ response:
130
+ status:
131
+ code: 201
132
+ message: Created
133
+ headers:
134
+ Content-Type:
135
+ - application/json
136
+ Content-Length:
137
+ - '250'
138
+ Connection:
139
+ - keep-alive
140
+ Status:
141
+ - 201 Created
142
+ Cache-Control:
143
+ - max-age=0, private, must-revalidate
144
+ Etag:
145
+ - W/"93c7e6382bd0ad95a3e47fac8db86283"
146
+ X-Runtime:
147
+ - '0.014507'
148
+ X-Request-Id:
149
+ - 4643a202-a742-423f-8f83-a39b66034328
150
+ Date:
151
+ - Sun, 17 Nov 2019 16:39:32 GMT
152
+ X-Powered-By:
153
+ - Phusion Passenger 6.0.4
154
+ Server:
155
+ - nginx/1.17.3 + Phusion Passenger 6.0.4
156
+ body:
157
+ encoding: UTF-8
158
+ string: '{"_id":"5dd177c4a95330aa17f8f8e7","created_at":"2019-11-17T16:39:32Z","updated_at":"2019-11-17T16:39:32Z","name":"Jane","email":"jane@doe.net","locale":"en","api_key":"55ce1c667d4da4509641fc5bcecd8e4542b72d76","super_admin":false,"local_admin":false}'
159
+ http_version:
160
+ recorded_at: Sun, 17 Nov 2019 16:39:32 GMT
161
+ - request:
162
+ method: delete
163
+ uri: http://localhost:3000/locomotive/api/v3/accounts/5dd177c4a95330aa17f8f8e7.json?auth_token=bzwAyFQzcchf_hgDQhz3
164
+ body:
165
+ encoding: UTF-8
166
+ string: ''
167
+ headers:
168
+ User-Agent:
169
+ - Faraday v0.15.4
170
+ Accept:
171
+ - application/json
172
+ Accept-Encoding:
173
+ - gzip,deflate
174
+ Date:
175
+ - Sun, 17 Nov 2019 16:39:32 GMT
176
+ X-Locomotive-Account-Email:
177
+ - admin@locomotivecms.com
178
+ X-Locomotive-Account-Token:
179
+ - bzwAyFQzcchf_hgDQhz3
180
+ response:
181
+ status:
182
+ code: 200
183
+ message: OK
184
+ headers:
185
+ Content-Type:
186
+ - application/json
187
+ Transfer-Encoding:
188
+ - chunked
189
+ Connection:
190
+ - keep-alive
191
+ Status:
192
+ - 200 OK
193
+ Cache-Control:
194
+ - max-age=0, private, must-revalidate
195
+ Etag:
196
+ - W/"93c7e6382bd0ad95a3e47fac8db86283"
197
+ X-Runtime:
198
+ - '0.019832'
199
+ X-Request-Id:
200
+ - 5e0ae3a4-71ea-4235-aaf4-1ce98404e225
201
+ Date:
202
+ - Sun, 17 Nov 2019 16:39:32 GMT
203
+ X-Powered-By:
204
+ - Phusion Passenger 6.0.4
205
+ Server:
206
+ - nginx/1.17.3 + Phusion Passenger 6.0.4
207
+ Content-Encoding:
208
+ - gzip
209
+ body:
210
+ encoding: UTF-8
211
+ string: '{"_id":"5dd177c4a95330aa17f8f8e7","created_at":"2019-11-17T16:39:32Z","updated_at":"2019-11-17T16:39:32Z","name":"Jane","email":"jane@doe.net","locale":"en","api_key":"55ce1c667d4da4509641fc5bcecd8e4542b72d76","super_admin":false,"local_admin":false}'
212
+ http_version:
213
+ recorded_at: Sun, 17 Nov 2019 16:39:32 GMT
214
+ recorded_with: VCR 4.0.0