esapiserver 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 +22 -0
- data/.project +18 -0
- data/Gemfile +9 -0
- data/Guardfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +68 -0
- data/Rakefile +25 -0
- data/esapiserver.gemspec +40 -0
- data/lib/esapiserver.rb +197 -0
- data/lib/esapiserver/version.rb +3 -0
- data/spec/esapiserver_spec.rb +108 -0
- data/spec/spec_helper.rb +15 -0
- metadata +296 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 33680dd437314e1cb518cea3a1f0e8933e660114
|
4
|
+
data.tar.gz: b7ada46fee8ba713cba8afd7756eeac3d1c34246
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48ea616d169c574614741b72aa2a2b618de04de65881d6490af1dd58fa39fe535fbea912b3d054ccec29cd95fd8bcd9ed265dfb4b595369a48a2341cfd3e94d5
|
7
|
+
data.tar.gz: 69ad24beade92bd1e1986003d60e05fd22cbf2898b94a6ddb46e8b28966b069d22960fd60439d34e9fffdf9effa93af8265d5341487cc6198f60edbf4ddb74c9
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.project
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>esapiserver</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>com.aptana.ide.core.unifiedBuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>com.aptana.ruby.core.rubynature</nature>
|
16
|
+
<nature>com.aptana.projects.webnature</nature>
|
17
|
+
</natures>
|
18
|
+
</projectDescription>
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 William Miles
|
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,68 @@
|
|
1
|
+
# Esapiserver
|
2
|
+
|
3
|
+
A Sinatra/MongoDB API server to use for EmberJS development
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Run:
|
8
|
+
|
9
|
+
Install the gem
|
10
|
+
$ gem install esapiserver
|
11
|
+
|
12
|
+
Start up your mongoDB server
|
13
|
+
$ mongoD
|
14
|
+
|
15
|
+
Start the Ember Sinatra/MongoDB API server
|
16
|
+
$ easapiserver
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Database related requests:
|
21
|
+
|
22
|
+
Load a db
|
23
|
+
http://localhost:4567/select_db/ember_test_db
|
24
|
+
|
25
|
+
Reset a db - this will drop and reload the DB
|
26
|
+
http://localhost:4567/reset_db/ember_test_db
|
27
|
+
|
28
|
+
List a collection of a selected db
|
29
|
+
http://localhost:4567/db_collections
|
30
|
+
|
31
|
+
|
32
|
+
POST request:
|
33
|
+
|
34
|
+
Creates a new thing
|
35
|
+
http://localhost:4567/api/:thing
|
36
|
+
|
37
|
+
|
38
|
+
GET requests:
|
39
|
+
|
40
|
+
Returns a list of things
|
41
|
+
http://localhost:4567/api/:thing
|
42
|
+
|
43
|
+
Returns a list of things that matches a specific query
|
44
|
+
http://localhost:4567/api/:thing?ids[]=id1&ids[]=id2
|
45
|
+
|
46
|
+
Returns a thing with a specific key/value
|
47
|
+
http://localhost:4567/api/:thing?key=value
|
48
|
+
|
49
|
+
Returns a thing with a specific id
|
50
|
+
http://localhost:4567/api/:thing/:id
|
51
|
+
|
52
|
+
DELETE request:
|
53
|
+
|
54
|
+
Deletes a thing with a specific id
|
55
|
+
http://localhost:4567/api/:thing/:id
|
56
|
+
|
57
|
+
PUT request:
|
58
|
+
|
59
|
+
Updates a thing with a specific id
|
60
|
+
http://localhost:4567/api/:thing/:id
|
61
|
+
|
62
|
+
## Contributing
|
63
|
+
|
64
|
+
1. Fork it ( https://github.com/[my-github-username]/esapiserver/fork )
|
65
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
66
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
67
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
68
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
def run(cmd, msg)
|
5
|
+
`#{cmd}`
|
6
|
+
if $?.exitstatus != 0
|
7
|
+
puts msg
|
8
|
+
exit 1
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "run sinatra app locally"
|
13
|
+
task :run do
|
14
|
+
require 'esapiserver'
|
15
|
+
#Sinatra::Application.run!
|
16
|
+
Esapiserver::Server.run!
|
17
|
+
end
|
18
|
+
|
19
|
+
# Default directory to look in is `/specs`
|
20
|
+
# Run with `rake spec`
|
21
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
22
|
+
task.rspec_opts = ['--color', '--format', 'documentation']
|
23
|
+
end
|
24
|
+
|
25
|
+
task :default => :spec
|
data/esapiserver.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'esapiserver/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "esapiserver"
|
8
|
+
spec.version = Esapiserver::VERSION
|
9
|
+
spec.authors = ["William Miles"]
|
10
|
+
spec.email = ["william@miles.dk"]
|
11
|
+
spec.summary = "Ember Sinatra API server"
|
12
|
+
spec.description = "A Sinatra/MongoDB API server to use for EmberJS development"
|
13
|
+
spec.homepage = "https://github.com/mawiza/esapiserver"
|
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.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "guard"
|
26
|
+
spec.add_development_dependency "guard-rspec"
|
27
|
+
spec.add_development_dependency "pry"
|
28
|
+
spec.add_development_dependency "pry-remote"
|
29
|
+
spec.add_development_dependency "pry-nav"
|
30
|
+
spec.add_development_dependency "pry-debugger"
|
31
|
+
spec.add_development_dependency "rack-test"
|
32
|
+
|
33
|
+
spec.add_runtime_dependency 'sinatra', '~> 1.4.5'
|
34
|
+
spec.add_runtime_dependency 'mongo', '~> 1.10.2'
|
35
|
+
spec.add_runtime_dependency 'bson_ext'
|
36
|
+
spec.add_runtime_dependency 'json', '~> 1.8.1'
|
37
|
+
spec.add_runtime_dependency 'sinatra-cross_origin', '~> 0.3.2'
|
38
|
+
spec.add_runtime_dependency 'activesupport-inflector', '~> 0.1.0'
|
39
|
+
spec.add_runtime_dependency 'i18n'
|
40
|
+
end
|
data/lib/esapiserver.rb
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'sinatra'
|
4
|
+
require 'mongo'
|
5
|
+
require 'json'
|
6
|
+
require 'sinatra/cross_origin'
|
7
|
+
require 'active_support/inflector'
|
8
|
+
require "esapiserver/version"
|
9
|
+
|
10
|
+
module Esapiserver
|
11
|
+
class Server < Sinatra::Application
|
12
|
+
mongoDB = Mongo::Connection.new
|
13
|
+
@@db = nil
|
14
|
+
|
15
|
+
#
|
16
|
+
#
|
17
|
+
#
|
18
|
+
configure do
|
19
|
+
enable :cross_origin
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Taking care of Access-Control-Allow
|
24
|
+
#
|
25
|
+
before do
|
26
|
+
if request.request_method == 'OPTIONS'
|
27
|
+
response.headers["Access-Control-Allow-Origin"] = "*"
|
28
|
+
response.headers["Access-Control-Allow-Methods"] = "POST, PUT, DELETE"
|
29
|
+
halt 200
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Select the DB - for example sip_ember_db for development and sip_ember_test_db when
|
35
|
+
# running tests.
|
36
|
+
#
|
37
|
+
get '/select_db/:db' do
|
38
|
+
@@db = mongoDB.db(params[:db], :pool_size => 5, :timeout => 5)
|
39
|
+
"DB #{params[:db]} selected"
|
40
|
+
end
|
41
|
+
|
42
|
+
#
|
43
|
+
# This will drop the DB and reload it - useful for cleaning up when running tests
|
44
|
+
#
|
45
|
+
get '/reset_db/:db' do
|
46
|
+
mongoDB.drop_database(params[:db])
|
47
|
+
@@db = mongoDB.db(params[:db], :pool_size => 5, :timeout => 5)
|
48
|
+
"DB #{params[:db]} dropped and reloaded"
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# Get a list of collections for a specific DB
|
53
|
+
#
|
54
|
+
get '/db_collections' do
|
55
|
+
if @@db == nil
|
56
|
+
"Please select a DB using /select_db/:db where :db is the name of the database"
|
57
|
+
else
|
58
|
+
collections = @@db.collection_names
|
59
|
+
"#{collections}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Returns a list of things or a list of things that matches a specific query
|
65
|
+
# http://localhost:4567/api/focusareas - will retrieve all the focusareas
|
66
|
+
# http://localhost:4567/api/focusareas?theme_id=53bb2eba19cfd247e4000002 - will retrieve all the focusareas
|
67
|
+
# belonging to the specified theme.
|
68
|
+
# Works only with a single query parameter or multiple ids[] parameters
|
69
|
+
get '/api/:thing' do
|
70
|
+
content_type :json
|
71
|
+
query = {}
|
72
|
+
result = {}
|
73
|
+
collection = @@db.collection(params[:thing])
|
74
|
+
|
75
|
+
if request.query_string.empty?
|
76
|
+
result = collection.find.to_a.map{|t| frombsonid(t, params[:thing])}.to_json
|
77
|
+
else
|
78
|
+
#TODO Handle a single ID
|
79
|
+
if request.query_string.include? 'ids[]' or request.query_string.include? 'ids%5B%5D'
|
80
|
+
ids = []
|
81
|
+
|
82
|
+
if request.query_string.include? '&'
|
83
|
+
queries = request.query_string.split('&')
|
84
|
+
queries.each do |q|
|
85
|
+
key, value = q.split('=')
|
86
|
+
if key != 'ids[]'
|
87
|
+
throw 'multiple query parameters not supported yet, except _ids[]='
|
88
|
+
end
|
89
|
+
ids << tobsonid(value)
|
90
|
+
end
|
91
|
+
else
|
92
|
+
key, value = request.query_string.split('=')
|
93
|
+
ids << tobsonid(value)
|
94
|
+
end
|
95
|
+
query = {"_id" => { "$in" => ids }}
|
96
|
+
else
|
97
|
+
key, value = request.query_string.split('=')
|
98
|
+
query = {modelName(params[:thing]) + "." + key => value}
|
99
|
+
end
|
100
|
+
result = collection.find(query).to_a.map{|t| frombsonid(t, params[:thing])}.to_json
|
101
|
+
end
|
102
|
+
serializeJSON(result, params[:thing])
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# Returns a thing with a specific id
|
107
|
+
#
|
108
|
+
get '/api/:thing/:id' do
|
109
|
+
content_type :json
|
110
|
+
find_one(params[:thing], params[:id])
|
111
|
+
end
|
112
|
+
|
113
|
+
#
|
114
|
+
# Create a new thing
|
115
|
+
#
|
116
|
+
post '/api/:thing' do
|
117
|
+
content_type :json
|
118
|
+
json = JSON.parse(request.body.read.to_s)
|
119
|
+
oid = @@db.collection(params[:thing]).insert(json)
|
120
|
+
find_one(params[:thing], oid.to_s)
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Delete a thing with a specific id
|
125
|
+
#
|
126
|
+
delete '/api/:thing/:id' do
|
127
|
+
content_type :json
|
128
|
+
@@db.collection(params[:thing]).remove({'_id' => tobsonid(params[:id])})
|
129
|
+
"{}"
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# Update a thing with a specific id
|
134
|
+
#
|
135
|
+
put '/api/:thing/:id' do
|
136
|
+
content_type :json
|
137
|
+
selector = {'_id' => tobsonid(params[:id])}
|
138
|
+
json = JSON.parse(request.body.read).reject{|k,v| k == 'id'}
|
139
|
+
document = {'$set' => json}
|
140
|
+
result = @@db.collection(params[:thing]).update(selector, document)
|
141
|
+
find_one(params[:thing], params[:id])
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# Convert the id to a BSON object id
|
146
|
+
#
|
147
|
+
def tobsonid(id)
|
148
|
+
BSON::ObjectId.from_string(id)
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Extract the BSON id, then replacing the '_id' key with a 'id' key
|
153
|
+
#
|
154
|
+
def frombsonid(obj, thing)
|
155
|
+
id = obj['_id'].to_s
|
156
|
+
obj.delete("_id")
|
157
|
+
obj.each{|t| t[1]['id'] = id}
|
158
|
+
end
|
159
|
+
|
160
|
+
#
|
161
|
+
# Serialize the Mongo JSON to Ember friendly JSON
|
162
|
+
#
|
163
|
+
def serializeJSON(json, thing)
|
164
|
+
hash = JSON.parse(json)
|
165
|
+
jsonArray = []
|
166
|
+
hash.each {|h| jsonArray << h[modelName(params[:thing])]}
|
167
|
+
newJson = {modelName(params[:thing]) => jsonArray}
|
168
|
+
newJson.to_json
|
169
|
+
end
|
170
|
+
|
171
|
+
#
|
172
|
+
# Utility method - find one and the sreialize to Ember Friendly JSON
|
173
|
+
#
|
174
|
+
def find_one(thing, id)
|
175
|
+
result = @@db.collection(thing).find_one(tobsonid(id))
|
176
|
+
jsonArray = []
|
177
|
+
if result != nil
|
178
|
+
normalizedResult = frombsonid(result, thing).to_json
|
179
|
+
hash = JSON.parse(normalizedResult)
|
180
|
+
jsonArray << hash[modelName(thing)]
|
181
|
+
newJson = {modelName(params[:thing]) => jsonArray}
|
182
|
+
newJson.to_json
|
183
|
+
else
|
184
|
+
noResults = {modelName(thing) => jsonArray}
|
185
|
+
noResults.to_json
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
#
|
190
|
+
# Very crude method to singularize the model name.
|
191
|
+
#
|
192
|
+
def modelName(thing)
|
193
|
+
#thing.chomp("s")
|
194
|
+
thing.singularize
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'esapiserver that' do
|
4
|
+
|
5
|
+
describe 'provide database related requests that' do
|
6
|
+
it 'loads a db' do
|
7
|
+
get '/select_db/test_db'
|
8
|
+
expect(last_response).to be_ok
|
9
|
+
expect(last_response.body).to eq('DB test_db selected')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'resets a db' do
|
13
|
+
get '/reset_db/test_db'
|
14
|
+
expect(last_response).to be_ok
|
15
|
+
expect(last_response.body).to eq('DB test_db dropped and reloaded')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'lists a collection of a selected db' do
|
19
|
+
get '/db_collections'
|
20
|
+
expect(last_response).to be_ok
|
21
|
+
expect(last_response.body).to eq('[]')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'handle POST requests that' do
|
26
|
+
it 'creates a new thing' do
|
27
|
+
payload = '{"post": {"name": "test"}}'
|
28
|
+
post '/api/posts', payload, "CONTENT_TYPE" => "application/json"
|
29
|
+
expect(last_response).to be_ok
|
30
|
+
expect(last_response.body).to include('{"post":[{"name":"test","id":')
|
31
|
+
#TODO should check to see if it is parsable by json
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'handle GET requests that' do
|
36
|
+
it 'returns a list of things' do
|
37
|
+
get '/api/posts'
|
38
|
+
expect(last_response).to be_ok
|
39
|
+
expect(last_response.body).to include('{"post":[{"name":"test","id"')
|
40
|
+
#TODO should check to see if it is parsable by json
|
41
|
+
end
|
42
|
+
|
43
|
+
#http://127.0.0.1:4567/api/focusareas?ids%5B%5D=53d7781819cfd232f4000085&ids%5B%5D=53d778e319cfd232f4000087
|
44
|
+
it 'returns a list of things that matches a specific query' do
|
45
|
+
#create another post
|
46
|
+
payload = '{"post": {"name": "test1"}}'
|
47
|
+
post '/api/posts', payload, "CONTENT_TYPE" => "application/json"
|
48
|
+
expect(last_response).to be_ok
|
49
|
+
#query the posts
|
50
|
+
get '/api/posts'
|
51
|
+
json_hash = JSON.parse(last_response.body)
|
52
|
+
#get the ids from the result
|
53
|
+
id1 = json_hash["post"][0]["id"]
|
54
|
+
id2 = json_hash["post"][1]["id"]
|
55
|
+
get '/api/posts?ids%5B%5D=' + id1 + '&ids%5B%5D=' + id2
|
56
|
+
expect(last_response).to be_ok
|
57
|
+
expect(last_response.body).to eq('{"post":[{"name":"test","id":"' + id1 + '"},{"name":"test1","id":"' + id2 + '"}]}')
|
58
|
+
get '/api/posts?ids%5B%5D=' + id1
|
59
|
+
expect(last_response).to be_ok
|
60
|
+
expect(last_response.body).to eq('{"post":[{"name":"test","id":"' + id1 + '"}]}')
|
61
|
+
#TODO should check to see if it is parsable by json
|
62
|
+
end
|
63
|
+
|
64
|
+
#http://localhost:4567/api/posts?name=test1
|
65
|
+
it 'returns a thing with a specific key/value' do
|
66
|
+
get '/api/posts?name=test1'
|
67
|
+
expect(last_response).to be_ok
|
68
|
+
expect(last_response.body).to include('{"post":[{"name":"test1","id"')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns a thing with a specific id' do
|
72
|
+
get '/api/posts'
|
73
|
+
json_hash = JSON.parse(last_response.body)
|
74
|
+
id = json_hash["post"][0]["id"]
|
75
|
+
get '/api/posts/' + id
|
76
|
+
expect(last_response).to be_ok
|
77
|
+
expect(last_response.body).to eq('{"post":[{"name":"test","id":"' + id + '"}]}')
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'handle DELETE requests that' do
|
83
|
+
it 'deletes a thing with a specific id' do
|
84
|
+
get '/api/posts'
|
85
|
+
json_hash = JSON.parse(last_response.body)
|
86
|
+
id = json_hash["post"][1]["id"]
|
87
|
+
delete '/api/posts/' + id
|
88
|
+
expect(last_response).to be_ok
|
89
|
+
get '/api/posts'
|
90
|
+
json_hash = JSON.parse(last_response.body)
|
91
|
+
expect(last_response).to be_ok
|
92
|
+
expect(json_hash["post"].length).to equal(1)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'handle PUT requests that' do
|
97
|
+
it 'updates a thing with a specific id' do
|
98
|
+
get '/api/posts?name=test'
|
99
|
+
json_hash = JSON.parse(last_response.body)
|
100
|
+
id = json_hash["post"][0]["id"]
|
101
|
+
payload = '{"post": {"name": "updated test"}}'
|
102
|
+
put '/api/posts/' + id, payload, "CONTENT_TYPE" => "application/json"
|
103
|
+
expect(last_response).to be_ok
|
104
|
+
expect(last_response.body).to eq('{"post":[{"name":"updated test","id":"' + id + '"}]}')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'esapiserver'
|
3
|
+
require 'rack/test'
|
4
|
+
|
5
|
+
ENV['RACK_ENV'] = 'test'
|
6
|
+
|
7
|
+
module RSpecMixin
|
8
|
+
include Rack::Test::Methods
|
9
|
+
def app() Esapiserver::Server end
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.include Rack::Test::Methods
|
14
|
+
config.include RSpecMixin
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,296 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: esapiserver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Miles
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-30 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-remote
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: pry-nav
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-debugger
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rack-test
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: sinatra
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ~>
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 1.4.5
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.4.5
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: mongo
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.10.2
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.10.2
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: bson_ext
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: json
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ~>
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 1.8.1
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ~>
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 1.8.1
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: sinatra-cross_origin
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ~>
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 0.3.2
|
216
|
+
type: :runtime
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ~>
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 0.3.2
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: activesupport-inflector
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ~>
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: 0.1.0
|
230
|
+
type: :runtime
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ~>
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: 0.1.0
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: i18n
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - '>='
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: '0'
|
244
|
+
type: :runtime
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - '>='
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: '0'
|
251
|
+
description: A Sinatra/MongoDB API server to use for EmberJS development
|
252
|
+
email:
|
253
|
+
- william@miles.dk
|
254
|
+
executables: []
|
255
|
+
extensions: []
|
256
|
+
extra_rdoc_files: []
|
257
|
+
files:
|
258
|
+
- .gitignore
|
259
|
+
- .project
|
260
|
+
- Gemfile
|
261
|
+
- Guardfile
|
262
|
+
- LICENSE.txt
|
263
|
+
- README.md
|
264
|
+
- Rakefile
|
265
|
+
- esapiserver.gemspec
|
266
|
+
- lib/esapiserver.rb
|
267
|
+
- lib/esapiserver/version.rb
|
268
|
+
- spec/esapiserver_spec.rb
|
269
|
+
- spec/spec_helper.rb
|
270
|
+
homepage: https://github.com/mawiza/esapiserver
|
271
|
+
licenses:
|
272
|
+
- MIT
|
273
|
+
metadata: {}
|
274
|
+
post_install_message:
|
275
|
+
rdoc_options: []
|
276
|
+
require_paths:
|
277
|
+
- lib
|
278
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
279
|
+
requirements:
|
280
|
+
- - '>='
|
281
|
+
- !ruby/object:Gem::Version
|
282
|
+
version: '0'
|
283
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
284
|
+
requirements:
|
285
|
+
- - '>='
|
286
|
+
- !ruby/object:Gem::Version
|
287
|
+
version: '0'
|
288
|
+
requirements: []
|
289
|
+
rubyforge_project:
|
290
|
+
rubygems_version: 2.0.14
|
291
|
+
signing_key:
|
292
|
+
specification_version: 4
|
293
|
+
summary: Ember Sinatra API server
|
294
|
+
test_files:
|
295
|
+
- spec/esapiserver_spec.rb
|
296
|
+
- spec/spec_helper.rb
|