astronomy_engine 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +11 -0
- data/astronomy_engine.gemspec +29 -0
- data/lib/astronomy_engine.rb +31 -0
- data/lib/astronomy_engine/version.rb +3 -0
- data/spec/astronomy_engine_spec.rb +170 -0
- data/spec/spec_helper.rb +10 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc163ed7ab5163f914ea00c0ddb13c2482714200
|
4
|
+
data.tar.gz: 4fc04e6d5ce1b2344813b5ff08b79af05e1d7831
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ef6bc5f0bc57a91dc3047bc70f60819c534980db48d5b6b231851c418642771a39057233051f4a5baa64ee50807619e8c72725d633a95dae418ebfe35858a77
|
7
|
+
data.tar.gz: 983e616f20903f6d807e5352a51a953329d2facd5cdbb0313e8e050f1511d8d8a59d59c418506a431a71d1fd8d9221fc1dea8e3ac10f775e4e146fc7ce0a01b7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Nick Aschenbach
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# AstronomyEngine
|
2
|
+
|
3
|
+
A mountable engine for the `astronomy` gem
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'astronomy_engine'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install astronomy_engine
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Add the mount point for the engine in your rails app:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Rails.application.routes.draw do
|
27
|
+
...
|
28
|
+
mount AstronomyEngine::App => '/astronomy'
|
29
|
+
...
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
Request the list of categories:
|
34
|
+
|
35
|
+
```bash
|
36
|
+
curl {APPLICATION_ROOT}/astronomy/categories
|
37
|
+
```
|
38
|
+
|
39
|
+
Request all topics for a given category:
|
40
|
+
|
41
|
+
```bash
|
42
|
+
curl {APPLICATION_ROOT}/astronomy/categories/Star/topics
|
43
|
+
```
|
44
|
+
|
45
|
+
Search all topic names and descriptions:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
curl {APPLICATION_ROOT}/astronomy/topics?q=cluster
|
49
|
+
```
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it ( https://github.com/[my-github-username]/astronomy_engine/fork )
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'astronomy_engine/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'astronomy_engine'
|
8
|
+
spec.version = AstronomyEngine::VERSION
|
9
|
+
spec.authors = ['Nick Aschenbach']
|
10
|
+
spec.email = ['nick.aschenbach@gmail.com']
|
11
|
+
spec.summary = %q{A light weight, mountable engine for the 'astronomy' gem}
|
12
|
+
spec.description = %q{A light weight, mountable engine for the 'astronomy' gem. Search or browse various astronomical phenomena}
|
13
|
+
spec.homepage = 'https://github.com/nick-aschenbach/astronomy-engine'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'capybara', '~> 2.4'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
|
26
|
+
spec.add_runtime_dependency 'sinatra', '~> 1.4'
|
27
|
+
spec.add_runtime_dependency 'sinatra-contrib', '~> 1.4'
|
28
|
+
spec.add_runtime_dependency 'astronomy', '~> 0.2'
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'astronomy_engine/version'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'astronomy'
|
4
|
+
require 'sinatra/json'
|
5
|
+
|
6
|
+
module AstronomyEngine
|
7
|
+
class App < Sinatra::Base
|
8
|
+
helpers Sinatra::JSON
|
9
|
+
|
10
|
+
set :astronomy, Astronomy::Information.new
|
11
|
+
before { content_type 'application/json' }
|
12
|
+
|
13
|
+
get '/categories' do
|
14
|
+
json settings.astronomy.categories
|
15
|
+
end
|
16
|
+
|
17
|
+
get '/categories/*/topics' do
|
18
|
+
result = settings.astronomy.topics(params['splat'].first)
|
19
|
+
|
20
|
+
return [404, 'Invalid category'] if result.nil?
|
21
|
+
json result
|
22
|
+
end
|
23
|
+
|
24
|
+
get '/topics' do
|
25
|
+
return [400, 'Must specify a search term `q`'] if params['q'].nil?
|
26
|
+
return [400, 'Please specify a valid value for `q`'] if params['q'].strip.empty?
|
27
|
+
|
28
|
+
json settings.astronomy.search(params['q'].strip)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AstronomyEngine::App do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
AstronomyEngine::App
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:astronomy_instance) { app.new.settings.astronomy }
|
11
|
+
|
12
|
+
let(:sample_topic_data) {
|
13
|
+
[{'name' => 'Brie', 'description' => 'A soft aged creamy spreadable cheese'},
|
14
|
+
{'name' => 'Cheddar', 'description' => 'A yellow, sharp, hard cheese'},
|
15
|
+
{'name' => 'Swiss', 'description' => 'A holey white cheese'}]
|
16
|
+
}
|
17
|
+
|
18
|
+
describe 'application configuration' do
|
19
|
+
it 'sets an instance of Astronomy::Information to astronomy config setting' do
|
20
|
+
expect(astronomy_instance.class).to eq(Astronomy::Information)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'get categories' do
|
25
|
+
it 'delegates the request to the gem' do
|
26
|
+
expect(astronomy_instance).to receive(:categories)
|
27
|
+
|
28
|
+
get '/categories'
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns successfully' do
|
32
|
+
get '/categories'
|
33
|
+
|
34
|
+
expect(last_response).to be_ok
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns the correct body' do
|
38
|
+
fake_categories = %w[apples pears bananas]
|
39
|
+
allow(astronomy_instance).to receive(:categories).and_return(fake_categories)
|
40
|
+
get '/categories'
|
41
|
+
|
42
|
+
expect(JSON.parse(last_response.body)).to eq(fake_categories)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'renders the results as json' do
|
46
|
+
get '/categories'
|
47
|
+
|
48
|
+
expect(last_response.header['Content-Type']).to eq('application/json')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'get category topics' do
|
53
|
+
let(:category) { 'cheese' }
|
54
|
+
|
55
|
+
it 'delegates the request to the gem' do
|
56
|
+
expect(astronomy_instance).to receive(:topics).with(category)
|
57
|
+
|
58
|
+
get "/categories/#{category}/topics"
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when a valid category is passed in' do
|
62
|
+
before do
|
63
|
+
expect(astronomy_instance).to receive(:topics).with(category).and_return(sample_topic_data)
|
64
|
+
get "/categories/#{category}/topics"
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns successfully' do
|
69
|
+
expect(last_response).to be_ok
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns the correct body' do
|
73
|
+
expect(JSON.parse(last_response.body)).to eq(sample_topic_data)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns the correct content type' do
|
77
|
+
expect(last_response.header['Content-Type']).to eq('application/json')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when an invalid category is passed in' do
|
82
|
+
before do
|
83
|
+
allow(astronomy_instance).to receive(:topics).and_return(nil)
|
84
|
+
get "/categories/#{category}/topics"
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns a 404' do
|
88
|
+
expect(last_response.status).to eq(404)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns a body with error message' do
|
92
|
+
expect(last_response.body).to eq('Invalid category')
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'search topics' do
|
98
|
+
context 'when the query string parameter is valid' do
|
99
|
+
let(:q) { 'candy' }
|
100
|
+
let(:endpoint_with_query_param) { "/topics?q=#{q}" }
|
101
|
+
|
102
|
+
it 'ignores leading and trailing whitespace' do
|
103
|
+
expect(astronomy_instance).to receive(:search).with('foo')
|
104
|
+
|
105
|
+
get '/topics?q=%20%20%20%20%20%20%20%20%20%20foo%20%20%20%20%20'
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'delegates the request to the gem' do
|
109
|
+
expect(astronomy_instance).to receive(:search).with(q)
|
110
|
+
|
111
|
+
get endpoint_with_query_param
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'returns successfully' do
|
115
|
+
get endpoint_with_query_param
|
116
|
+
|
117
|
+
expect(last_response).to be_ok
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'returns the correct body' do
|
121
|
+
allow(astronomy_instance).to receive(:search).and_return(sample_topic_data)
|
122
|
+
|
123
|
+
get endpoint_with_query_param
|
124
|
+
expect(JSON.parse(last_response.body)).to eq(sample_topic_data)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'returns the correct content type' do
|
128
|
+
get endpoint_with_query_param
|
129
|
+
|
130
|
+
expect(last_response.header['Content-Type']).to eq('application/json')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'when no search term is provided' do
|
135
|
+
before { get '/topics' }
|
136
|
+
|
137
|
+
it 'returns a 400' do
|
138
|
+
expect(last_response.status).to eq(400)
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'returns a body with an error message' do
|
142
|
+
expect(last_response.body).to eq('Must specify a search term `q`')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'when it is an empty string' do
|
147
|
+
before { get '/topics?q=' }
|
148
|
+
|
149
|
+
it 'returns a 400' do
|
150
|
+
expect(last_response.status).to eq(400)
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'returns a body with an error message' do
|
154
|
+
expect(last_response.body).to eq('Please specify a valid value for `q`')
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'when it is just white space' do
|
159
|
+
before { get '/topics?q=%20%20%20' }
|
160
|
+
|
161
|
+
it 'returns a 400' do
|
162
|
+
expect(last_response.status).to eq(400)
|
163
|
+
end
|
164
|
+
|
165
|
+
it 'returns a body with an error message' do
|
166
|
+
expect(last_response.body).to eq('Please specify a valid value for `q`')
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: astronomy_engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Aschenbach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-25 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capybara
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.4'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sinatra-contrib
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.4'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.4'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: astronomy
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.2'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.2'
|
111
|
+
description: A light weight, mountable engine for the 'astronomy' gem. Search or browse
|
112
|
+
various astronomical phenomena
|
113
|
+
email:
|
114
|
+
- nick.aschenbach@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- astronomy_engine.gemspec
|
125
|
+
- lib/astronomy_engine.rb
|
126
|
+
- lib/astronomy_engine/version.rb
|
127
|
+
- spec/astronomy_engine_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
homepage: https://github.com/nick-aschenbach/astronomy-engine
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.4.5
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: A light weight, mountable engine for the 'astronomy' gem
|
153
|
+
test_files:
|
154
|
+
- spec/astronomy_engine_spec.rb
|
155
|
+
- spec/spec_helper.rb
|