locomotivecms_coal 1.0.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +8 -0
  5. data/Gemfile +23 -0
  6. data/Gemfile.lock +104 -0
  7. data/LICENSE +20 -0
  8. data/README.md +92 -0
  9. data/Rakefile +24 -0
  10. data/lib/locomotive/coal/client.rb +53 -0
  11. data/lib/locomotive/coal/error.rb +27 -0
  12. data/lib/locomotive/coal/paginated_resources.rb +20 -0
  13. data/lib/locomotive/coal/request.rb +63 -0
  14. data/lib/locomotive/coal/resource.rb +21 -0
  15. data/lib/locomotive/coal/resources/content_entries.rb +35 -0
  16. data/lib/locomotive/coal/resources/contents.rb +25 -0
  17. data/lib/locomotive/coal/resources/my_account.rb +15 -0
  18. data/lib/locomotive/coal/resources/sites.rb +31 -0
  19. data/lib/locomotive/coal/resources/token.rb +15 -0
  20. data/lib/locomotive/coal/version.rb +8 -0
  21. data/lib/locomotive/coal.rb +16 -0
  22. data/locomotivecms_coal.gemspec +26 -0
  23. data/spec/fixtures/coal_cassettes/client.yml +144 -0
  24. data/spec/fixtures/coal_cassettes/content_entries.yml +386 -0
  25. data/spec/fixtures/coal_cassettes/contents.yml +120 -0
  26. data/spec/fixtures/coal_cassettes/my_account.yml +97 -0
  27. data/spec/fixtures/coal_cassettes/sites.yml +204 -0
  28. data/spec/fixtures/coal_cassettes/token.yml +99 -0
  29. data/spec/integration/client_spec.rb +33 -0
  30. data/spec/integration/resources/content_entries_spec.rb +52 -0
  31. data/spec/integration/resources/contents_spec.rb +22 -0
  32. data/spec/integration/resources/my_account_spec.rb +17 -0
  33. data/spec/integration/resources/sites_spec.rb +43 -0
  34. data/spec/integration/resources/token_spec.rb +38 -0
  35. data/spec/spec_helper.rb +46 -0
  36. data/spec/support/api_settings.rb +6 -0
  37. data/spec/support/default_resources.rb +7 -0
  38. data/spec/support/pry.rb +4 -0
  39. data/spec/unit/client_spec.rb +25 -0
  40. data/spec/unit/paginated_resources_spec.rb +50 -0
  41. data/spec/unit/resource_spec.rb +18 -0
  42. metadata +159 -0
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Coal::Resources::Sites do
4
+
5
+ before { VCR.insert_cassette 'sites', record: :new_episodes }
6
+ after { VCR.eject_cassette }
7
+
8
+ let(:uri) { TEST_API_URI }
9
+ let(:token) { api_token }
10
+ let(:sites) { described_class.new(uri, token) }
11
+
12
+ describe '#all' do
13
+
14
+ subject { sites.all }
15
+ it { expect(subject.size).to be > 0 }
16
+
17
+ describe 'first site' do
18
+ subject { sites.all.first }
19
+ it { expect(subject.name).not_to eq nil }
20
+ end
21
+ end
22
+
23
+ describe '#create' do
24
+ subject { create_site }
25
+ it { expect(subject._id).not_to eq nil }
26
+ end
27
+
28
+ describe '#by_subdomain' do
29
+ subject { sites.by_subdomain('sample') }
30
+ it { expect(subject._id).not_to eq nil }
31
+ end
32
+
33
+ describe '#destroy' do
34
+ let(:new_site) { sites.by_subdomain('acme') || create_site }
35
+ subject { sites.destroy(new_site._id) }
36
+ it { expect(subject._id).to eq nil }
37
+ end
38
+
39
+ def create_site
40
+ sites.create(name: 'Acme', subdomain: 'acme', locales: ['en'])
41
+ end
42
+
43
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Coal::Resources::Token do
4
+
5
+ before { VCR.insert_cassette 'token', record: :new_episodes }
6
+ after { VCR.eject_cassette }
7
+
8
+ let(:uri) { nil }
9
+ let(:credentials) { nil }
10
+ let(:token) { described_class.new(uri, credentials) }
11
+
12
+ describe '#get' do
13
+
14
+ subject { token.get }
15
+
16
+ context 'uri not pointing to a Locomotive engine' do
17
+ let(:uri) { URI('http://www.example.com:4000') }
18
+ let(:credentials) { { email: 'john@doe.net', password: 'easyone' } }
19
+ it { expect { subject }.to raise_error Locomotive::Coal::UnknownResourceError }
20
+ end
21
+
22
+ context 'valid uri' do
23
+ let(:uri) { TEST_API_URI }
24
+
25
+ context 'email + password as credentials' do
26
+ let(:credentials) { { email: 'john@doe.net', password: 'easyone' } }
27
+ it { is_expected.to match(/^[a-zA-Z0-9]{,20}$/) }
28
+ end
29
+
30
+ context 'api key as credentials' do
31
+ let(:credentials) { { email: 'john@doe.net', api_key: 'a9ac1e08c2c22c1b6f3da6db77a70cac4a615bd7' } }
32
+ it { is_expected.to match(/^[a-zA-Z0-9]{,20}$/) }
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,46 @@
1
+ require 'simplecov'
2
+ require 'codeclimate-test-reporter'
3
+ require 'coveralls'
4
+
5
+ SimpleCov.start do
6
+ formatter SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ CodeClimate::TestReporter::Formatter,
9
+ Coveralls::SimpleCov::Formatter
10
+ ]
11
+
12
+ add_filter 'spec/'
13
+ add_filter 'lib/locomotive/coal/version.rb'
14
+ end
15
+
16
+ require 'rubygems'
17
+ require 'bundler/setup'
18
+
19
+ require 'webmock/rspec'
20
+ require 'vcr'
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!
28
+ end
29
+
30
+ require_relative 'support/default_resources'
31
+ require_relative 'support/api_settings'
32
+ require_relative 'support/pry'
33
+
34
+ require_relative '../lib/locomotive/coal'
35
+
36
+ RSpec.configure do |config|
37
+ # config.include Spec::Helpers
38
+
39
+ # config.filter_run focused: true
40
+ # config.run_all_when_everything_filtered = true
41
+
42
+ # config.before { reset! }
43
+ # config.after { reset! }
44
+
45
+ config.order = :random
46
+ end
@@ -0,0 +1,6 @@
1
+ TEST_API_URI = URI('http://sample.lvh.me:4000/locomotive/api').freeze
2
+ TEST_API_CREDENTIALS = { email: 'john@doe.net', password: 'easyone' }.freeze
3
+
4
+ def api_token(uri = nil, credentials = nil)
5
+ Locomotive::Coal::Resources::Token.new(uri || TEST_API_URI, credentials || TEST_API_CREDENTIALS.dup).get
6
+ end
@@ -0,0 +1,7 @@
1
+ # def create_acme_site(sites)
2
+ # sites.create(name: 'Acme', subdomain: 'acme', locales: ['en'])
3
+ # end
4
+
5
+ # def reset_acme_site(sites)
6
+ # sites.destroy()
7
+ # end
@@ -0,0 +1,4 @@
1
+ begin
2
+ require 'pry'
3
+ rescue LoadError
4
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Coal::Client do
4
+
5
+ let(:uri) { nil }
6
+ let(:credentials) { nil }
7
+ let(:client) { described_class.new(uri, credentials) }
8
+
9
+ describe '#initialize' do
10
+
11
+ subject { client }
12
+
13
+ context 'no uri' do
14
+ let(:credentials) { { email: 'fake' } }
15
+ it { expect { subject }.to raise_error Locomotive::Coal::MissingURIOrCredentialsError }
16
+ end
17
+
18
+ context 'no credentials' do
19
+ let(:uri) { 'http://sample.lvh.me:4000/locomotive/api' }
20
+ it { expect { subject }.to raise_error Locomotive::Coal::MissingURIOrCredentialsError }
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Coal::PaginatedResources do
4
+
5
+ let(:list) { ['a', 42, :foo] }
6
+ let(:page) { 1 }
7
+ let(:total_pages) { 1 }
8
+ let(:total_entries) { 3 }
9
+ let(:paginate) { described_class.new(list, page, total_pages, total_entries) }
10
+
11
+ describe '#find' do
12
+ subject { paginate.find { |el| el == 42 } }
13
+ it { is_expected.to eq 42 }
14
+ end
15
+
16
+ describe '#each' do
17
+ it { expect(paginate.respond_to?(:each)).to eq true }
18
+ end
19
+
20
+ describe '#_next_page' do
21
+ subject { paginate._next_page }
22
+ it { is_expected.to eq nil }
23
+
24
+ context '3 pages of entries' do
25
+ let(:total_pages) { 3 }
26
+ it { is_expected.to eq 2 }
27
+
28
+ context 'current page is the last one' do
29
+ let(:page) { 3 }
30
+ it { is_expected.to eq nil }
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '#_page' do
36
+ subject { paginate._page }
37
+ it { is_expected.to eq 1 }
38
+ end
39
+
40
+ describe '#_total_pages' do
41
+ subject { paginate._total_pages }
42
+ it { is_expected.to eq 1 }
43
+ end
44
+
45
+ describe '#_total_entries' do
46
+ subject { paginate._total_entries }
47
+ it { is_expected.to eq 3 }
48
+ end
49
+
50
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Locomotive::Coal::Resource do
4
+
5
+ let(:attributes) { { 'title' => 'Hello world' } }
6
+ let(:resource) { described_class.new(attributes) }
7
+
8
+ describe 'unknown attribute' do
9
+ subject { resource.name }
10
+ it { expect { subject }.to raise_error }
11
+ end
12
+
13
+ describe 'existing attribute' do
14
+ subject { resource.title }
15
+ it { is_expected.to eq 'Hello world' }
16
+ end
17
+
18
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: locomotivecms_coal
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre.alpha
5
+ platform: ruby
6
+ authors:
7
+ - Didier Lafforgue
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.9.1
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.9.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 10.4.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 10.4.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: unirest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.1.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.2.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.2.1
69
+ description: The LocomotiveCMS coal is the API ruby client for LocomotiveCMS
70
+ email:
71
+ - did@locomotivecms.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - lib/locomotive/coal.rb
85
+ - lib/locomotive/coal/client.rb
86
+ - lib/locomotive/coal/error.rb
87
+ - lib/locomotive/coal/paginated_resources.rb
88
+ - lib/locomotive/coal/request.rb
89
+ - lib/locomotive/coal/resource.rb
90
+ - lib/locomotive/coal/resources/content_entries.rb
91
+ - lib/locomotive/coal/resources/contents.rb
92
+ - lib/locomotive/coal/resources/my_account.rb
93
+ - lib/locomotive/coal/resources/sites.rb
94
+ - lib/locomotive/coal/resources/token.rb
95
+ - lib/locomotive/coal/version.rb
96
+ - locomotivecms_coal.gemspec
97
+ - spec/fixtures/coal_cassettes/client.yml
98
+ - spec/fixtures/coal_cassettes/content_entries.yml
99
+ - spec/fixtures/coal_cassettes/contents.yml
100
+ - spec/fixtures/coal_cassettes/my_account.yml
101
+ - spec/fixtures/coal_cassettes/sites.yml
102
+ - spec/fixtures/coal_cassettes/token.yml
103
+ - spec/integration/client_spec.rb
104
+ - spec/integration/resources/content_entries_spec.rb
105
+ - spec/integration/resources/contents_spec.rb
106
+ - spec/integration/resources/my_account_spec.rb
107
+ - spec/integration/resources/sites_spec.rb
108
+ - spec/integration/resources/token_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/support/api_settings.rb
111
+ - spec/support/default_resources.rb
112
+ - spec/support/pry.rb
113
+ - spec/unit/client_spec.rb
114
+ - spec/unit/paginated_resources_spec.rb
115
+ - spec/unit/resource_spec.rb
116
+ homepage: https://github.com/locomotivecms/coal
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '2.0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">"
132
+ - !ruby/object:Gem::Version
133
+ version: 1.3.1
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.4.5
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: The LocomotiveCMS coal is the API ruby client for LocomotiveCMS
140
+ test_files:
141
+ - spec/fixtures/coal_cassettes/client.yml
142
+ - spec/fixtures/coal_cassettes/content_entries.yml
143
+ - spec/fixtures/coal_cassettes/contents.yml
144
+ - spec/fixtures/coal_cassettes/my_account.yml
145
+ - spec/fixtures/coal_cassettes/sites.yml
146
+ - spec/fixtures/coal_cassettes/token.yml
147
+ - spec/integration/client_spec.rb
148
+ - spec/integration/resources/content_entries_spec.rb
149
+ - spec/integration/resources/contents_spec.rb
150
+ - spec/integration/resources/my_account_spec.rb
151
+ - spec/integration/resources/sites_spec.rb
152
+ - spec/integration/resources/token_spec.rb
153
+ - spec/spec_helper.rb
154
+ - spec/support/api_settings.rb
155
+ - spec/support/default_resources.rb
156
+ - spec/support/pry.rb
157
+ - spec/unit/client_spec.rb
158
+ - spec/unit/paginated_resources_spec.rb
159
+ - spec/unit/resource_spec.rb