mumukit-service 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +17 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +7 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/database.yml +4 -0
- data/lib/mumukit/service/collection.rb +117 -0
- data/lib/mumukit/service/database.rb +27 -0
- data/lib/mumukit/service/document.rb +50 -0
- data/lib/mumukit/service/document_array.rb +34 -0
- data/lib/mumukit/service/document_not_found_error.rb +2 -0
- data/lib/mumukit/service/document_validation_error.rb +2 -0
- data/lib/mumukit/service/env.rb +36 -0
- data/lib/mumukit/service/id_generator.rb +7 -0
- data/lib/mumukit/service/invalid_slug_format_error.rb +4 -0
- data/lib/mumukit/service/routes/auth.rb +27 -0
- data/lib/mumukit/service/routes.rb +79 -0
- data/lib/mumukit/service/slug.rb +43 -0
- data/lib/mumukit/service/version.rb +5 -0
- data/lib/mumukit/service.rb +22 -0
- data/mumukit-service.gemspec +39 -0
- metadata +197 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGUxYTFhODc1ZmQ3ZWUxNDgwZDk2YmU2NDYwYjk4NDc1MDU4YTNkMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NmI5Y2E0ZmZlMjE5N2RiOWNkYWRlNTA3Njg3YmQ3NGE5YmQ3NDcwOA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmEwMmU0MzE0NDk2ZTFmNGZmNTkxY2IyZTkzMzRkMWQ1Y2QzZWMyOGZlZjE2
|
10
|
+
OWE3ZjRmZTQ5OTI1Zjg1ODkwODI4YzQ3NmJiOWY2NTI3Yzc1NDI3YjdlODhm
|
11
|
+
ODIzOTM3YjE5MzRmZGMyZWY1OTYyZTRjMmNmYTQ1YmI1ZmRlMzk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjJiNzg5MjgwYzA1YTRiNTQ4MjdhMTk1YzVkODAxNTIzOWEyMzRkN2Q0OGMy
|
14
|
+
MjhlZDhlODE3N2I4NzkwNTY5NDUyNThhNzMxMDJlMDJjOWU1ZjQ2Nzk2Y2M4
|
15
|
+
NmY1Y2UwNWI0YjBiOTViYTc5NTVkOTdjODA1MWU0OTdiMWNiOTg=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
services: mongodb
|
5
|
+
addons:
|
6
|
+
code_climate:
|
7
|
+
repo_token: 98e49a73bc45170e285fa9382d3f6361465079a444fa8634fb91c4d27be4c38a
|
8
|
+
env:
|
9
|
+
- CODECLIMATE_REPO_TOKEN=98e49a73bc45170e285fa9382d3f6361465079a444fa8634fb91c4d27be4c38a
|
10
|
+
deploy:
|
11
|
+
provider: rubygems
|
12
|
+
api_key:
|
13
|
+
secure: Gw0E9N43ATQQm8eN8cAfDWcL42YtSzFRy+nD0DUlQZR57zI0QVIaYnBazkmWxpEMJjyLGjkvVntQBSUlYek9IqeZR+/gEvIM8qTR5nB+il6cdFclwuQlKHtTuUuMNfqK95Vat5KylX91d/ogr8iu2rmjN1cwAwUV+N5usKetPvrp1iU0iDO5Xst6TJ8C63Vg/X2oveBjHHAUc4JGEDAuZ/54qnkg0ZDkNmNe7mNQay6pAYa16ceTwqn6HJKzP9YTkgkbCP15W8pAipsbhALtpaAuP+TFfqB2Q5x2RtWzD27B2b6upGiKvE6cRA2X3tJ+xoUaprxV+dHBuO/p/bLYWZ/5VKL40L3IfvLYEwHG1dCuxlXUuGhZ68Opc+hPA5y97W4vZnLGlIfag3UQ34Toe7y/n3tmVS8GlrB1Wxt8Yn2RPN6Yo0qFBy51+qwx9GcXmrYRyF0Wti2vR0X/q5mywsPaijSE/ahiRNWKgPGk1+5y3CoRR/1MjkD9sZg9xWTFYQNZ1GABddwOuZQtT2H4k0izI/xCe7ff3RqV4Cy6dtgdrqhrMUCnGYZUDnrL9jTqaQbKEzdwWYzy82Q9QLibvkG7ocBrFlQ5GuxZ/ouTugOi9nwMHSStxFuUtngGK0RUvRCjuYa2gii5WDde3d7rYJ/XdDmfHZO4/xJR1ahKUP0=
|
14
|
+
gem: mumukit-service
|
15
|
+
on:
|
16
|
+
tags: true
|
17
|
+
repo: mumuki/mumukit-service
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Franco Leonardo Bulgarelli
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/mumuki/mumukit-service.svg)](https://travis-ci.org/mumuki/mumukit-service)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/mumuki/mumukit-service/badges/gpa.svg)](https://codeclimate.com/github/mumuki/mumukit-service)
|
3
|
+
[![Test Coverage](https://codeclimate.com/github/mumuki/mumukit-service/badges/coverage.svg)](https://codeclimate.com/github/mumuki/mumukit-service)
|
4
|
+
|
5
|
+
# Mumukit::Service
|
6
|
+
|
7
|
+
> Micro framework for quickly implement Mumuki services
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mumukit/service"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/config/database.yml
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
module Mumukit::Service
|
2
|
+
module Collection
|
3
|
+
|
4
|
+
def method_missing(name, *args, &block)
|
5
|
+
mongo_collection.send(name, *args, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def all
|
9
|
+
project
|
10
|
+
end
|
11
|
+
|
12
|
+
def count
|
13
|
+
mongo_collection.find.count
|
14
|
+
end
|
15
|
+
|
16
|
+
def any?(criteria)
|
17
|
+
mongo_collection.find(criteria).count > 0
|
18
|
+
end
|
19
|
+
|
20
|
+
def exists?(id)
|
21
|
+
any?(id: id)
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete!(id)
|
25
|
+
mongo_collection.delete_one(id: id)
|
26
|
+
end
|
27
|
+
|
28
|
+
def find(id)
|
29
|
+
find_by(id: id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_by(args)
|
33
|
+
_find_by(args).
|
34
|
+
try { |it| wrap it }
|
35
|
+
end
|
36
|
+
|
37
|
+
def find!(id)
|
38
|
+
find_by!(id: id)
|
39
|
+
end
|
40
|
+
|
41
|
+
def find_by!(args)
|
42
|
+
_find_by(args).
|
43
|
+
tap { |first| validate_presence(args, first) }.
|
44
|
+
try { |it| wrap it }
|
45
|
+
end
|
46
|
+
|
47
|
+
def insert!(json)
|
48
|
+
json.validate!
|
49
|
+
|
50
|
+
with_id new_id do |id|
|
51
|
+
mongo_collection.insert_one json.raw.merge(id)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def uniq(key, filter, uniq_value)
|
56
|
+
distinct(key, filter).uniq { |result| result[uniq_value] }
|
57
|
+
end
|
58
|
+
|
59
|
+
def where(args, projection={})
|
60
|
+
raw = find_projection(args, projection).map { |it| wrap it }
|
61
|
+
wrap_array raw
|
62
|
+
end
|
63
|
+
|
64
|
+
def first_by(args, options, projection={})
|
65
|
+
find_projection(args, projection).sort(options).first.try{ |it| wrap(it) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def order_by(args, options, projection={})
|
69
|
+
raw = find_projection(args, projection).sort(options).map { |it| wrap(it) }
|
70
|
+
wrap_array raw
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def validate_presence(args, first)
|
76
|
+
raise Mumukit::Service::DocumentNotFoundError, "document #{args.to_json} not found" unless first
|
77
|
+
end
|
78
|
+
|
79
|
+
def _find_by(args)
|
80
|
+
mongo_collection.find(args).projection(_id: 0).first
|
81
|
+
end
|
82
|
+
|
83
|
+
def mongo_collection
|
84
|
+
mongo_database.client[mongo_collection_name]
|
85
|
+
end
|
86
|
+
|
87
|
+
def find_projection(args={}, projection={})
|
88
|
+
mongo_collection.find(args).projection(projection.merge(_id: 0))
|
89
|
+
end
|
90
|
+
|
91
|
+
def project(&block)
|
92
|
+
raw = find_projection.map { |it| wrap it }
|
93
|
+
|
94
|
+
raw = raw.select(&block) if block_given?
|
95
|
+
|
96
|
+
wrap_array raw
|
97
|
+
end
|
98
|
+
|
99
|
+
def wrap(mongo_document)
|
100
|
+
Mumukit::Service::Document.new mongo_document
|
101
|
+
end
|
102
|
+
|
103
|
+
def wrap_array(array)
|
104
|
+
Mumukit::Service::DocumentArray.new array, default_key: mongo_collection_name
|
105
|
+
end
|
106
|
+
|
107
|
+
def new_id
|
108
|
+
Mumukit::Service::IdGenerator.next
|
109
|
+
end
|
110
|
+
|
111
|
+
def with_id(id)
|
112
|
+
id_object = {id: id}
|
113
|
+
yield id_object
|
114
|
+
id_object
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Mumukit::Service
|
5
|
+
module Database
|
6
|
+
def new_database_client(database)
|
7
|
+
Mongo::Client.new(
|
8
|
+
["#{config[:host]}:#{config[:port]}"],
|
9
|
+
database: database,
|
10
|
+
user: config[:user],
|
11
|
+
password: config[:password])
|
12
|
+
end
|
13
|
+
|
14
|
+
def config
|
15
|
+
environment = ENV['RACK_ENV'] || 'development'
|
16
|
+
@config ||= read_interpolated_yaml('config/database.yml').with_indifferent_access[environment]
|
17
|
+
end
|
18
|
+
|
19
|
+
def read_interpolated_yaml(filename)
|
20
|
+
YAML.load(ERB.new(File.read(filename)).result)
|
21
|
+
end
|
22
|
+
|
23
|
+
def clean!
|
24
|
+
client.collections.each(&:drop)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Mumukit::Service
|
2
|
+
class Document
|
3
|
+
attr_accessor :raw
|
4
|
+
|
5
|
+
def initialize(json)
|
6
|
+
@raw = json.to_h.symbolize_keys
|
7
|
+
end
|
8
|
+
|
9
|
+
def as_json(options={})
|
10
|
+
json.as_json(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(name, *args)
|
14
|
+
json[name]
|
15
|
+
end
|
16
|
+
|
17
|
+
def transforms(original)
|
18
|
+
{}
|
19
|
+
end
|
20
|
+
|
21
|
+
def defaults
|
22
|
+
{}
|
23
|
+
end
|
24
|
+
|
25
|
+
def errors
|
26
|
+
[]
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate!
|
30
|
+
e = errors
|
31
|
+
raise DocumentValidationError, e.join(', ') unless e.empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def json
|
35
|
+
@json ||= defaults.
|
36
|
+
merge(@raw).
|
37
|
+
merge(transforms(@raw))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
JsonWrapper = Document
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
class Hash
|
46
|
+
def to_document
|
47
|
+
Mumukit::Service::Document.new self
|
48
|
+
end
|
49
|
+
alias wrap_json to_document
|
50
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Mumukit::Service
|
2
|
+
class DocumentArray
|
3
|
+
attr_accessor :raw
|
4
|
+
|
5
|
+
def initialize(raw, options={})
|
6
|
+
@raw = raw
|
7
|
+
@default_key = options[:default_key]
|
8
|
+
end
|
9
|
+
|
10
|
+
def as_json(options={})
|
11
|
+
{}.tap do |json|
|
12
|
+
json[array_key] = raw.as_json(self.options.merge(options))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def array_key
|
17
|
+
@default_key || key
|
18
|
+
end
|
19
|
+
|
20
|
+
def options
|
21
|
+
{}
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def key
|
27
|
+
:array
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
JsonArrayWrapper = DocumentArray
|
33
|
+
end
|
34
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mumukit::Service::Env
|
2
|
+
class << self
|
3
|
+
def atheneum_url
|
4
|
+
ENV['MUMUKI_ATHENEUM_URL']
|
5
|
+
end
|
6
|
+
|
7
|
+
def atheneum_client_secret
|
8
|
+
ENV['MUMUKI_ATHENEUM_CLIENT_SECRET']
|
9
|
+
end
|
10
|
+
|
11
|
+
def atheneum_client_id
|
12
|
+
ENV['MUMUKI_ATHENEUM_CLIENT_ID']
|
13
|
+
end
|
14
|
+
|
15
|
+
def bot_username
|
16
|
+
ENV['MUMUKI_BOT_USERNAME']
|
17
|
+
end
|
18
|
+
|
19
|
+
def bot_email
|
20
|
+
ENV['MUMUKI_BOT_EMAIL']
|
21
|
+
end
|
22
|
+
|
23
|
+
def bot_api_token
|
24
|
+
ENV['MUMUKI_BOT_API_TOKEN']
|
25
|
+
end
|
26
|
+
|
27
|
+
def auth0_client_id
|
28
|
+
ENV['MUMUKI_AUTH0_CLIENT_ID']
|
29
|
+
end
|
30
|
+
|
31
|
+
def auth0_client_secret
|
32
|
+
ENV['MUMUKI_AUTH0_CLIENT_SECRET']
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'mumukit/auth'
|
2
|
+
|
3
|
+
helpers do
|
4
|
+
def authorization_header
|
5
|
+
env['HTTP_AUTHORIZATION']
|
6
|
+
end
|
7
|
+
|
8
|
+
def token
|
9
|
+
@token ||= Mumukit::Auth::Token.decode_header(authorization_header).tap(&:verify_client!)
|
10
|
+
end
|
11
|
+
|
12
|
+
def permissions
|
13
|
+
@permissions ||= token.permissions settings.app_name
|
14
|
+
end
|
15
|
+
|
16
|
+
def protect!
|
17
|
+
permissions.protect! slug.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
error Mumukit::Auth::InvalidTokenError do
|
22
|
+
halt 401
|
23
|
+
end
|
24
|
+
|
25
|
+
error Mumukit::Auth::UnauthorizedAccessError do
|
26
|
+
halt 403
|
27
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'sinatra/cross_origin'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
require 'json'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
access_logger = Logger.new('sinatra.log')
|
9
|
+
error_logfile = File.new('error.log', 'a+')
|
10
|
+
|
11
|
+
configure do
|
12
|
+
enable :cross_origin
|
13
|
+
set :allow_methods, [:get, :put, :post, :options, :delete]
|
14
|
+
set :show_exceptions, false
|
15
|
+
|
16
|
+
use ::Rack::CommonLogger, access_logger
|
17
|
+
Mongo::Logger.logger = ::Logger.new('mongo.log')
|
18
|
+
end
|
19
|
+
|
20
|
+
helpers do
|
21
|
+
def json_body
|
22
|
+
@json_body ||= JSON.parse(request.body.read) rescue nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def slug
|
26
|
+
if route_slug_parts.present?
|
27
|
+
Mumukit::Service::Slug.new(*route_slug_parts)
|
28
|
+
elsif subject
|
29
|
+
Mumukit::Service::Slug.from(subject.slug)
|
30
|
+
elsif json_body
|
31
|
+
Mumukit::Service::Slug.from(json_body['slug'])
|
32
|
+
else
|
33
|
+
raise Mumukit::Service::InvalidSlugFormatError.new('Slug not available')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def route_slug_parts
|
38
|
+
[]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
before do
|
43
|
+
content_type 'application/json', 'charset' => 'utf-8'
|
44
|
+
env["rack.errors"] = error_logfile
|
45
|
+
end
|
46
|
+
|
47
|
+
after do
|
48
|
+
error_message = env['sinatra.error']
|
49
|
+
if error_message.blank?
|
50
|
+
response.body = response.body.to_json
|
51
|
+
else
|
52
|
+
response.body = {message: env['sinatra.error'].message}.to_json
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
error JSON::ParserError do
|
57
|
+
halt 400
|
58
|
+
end
|
59
|
+
|
60
|
+
error Mumukit::Service::InvalidSlugFormatError do
|
61
|
+
halt 400
|
62
|
+
end
|
63
|
+
|
64
|
+
error Mumukit::Service::DocumentValidationError do
|
65
|
+
halt 400
|
66
|
+
end
|
67
|
+
|
68
|
+
error Mumukit::Service::DocumentNotFoundError do
|
69
|
+
halt 404
|
70
|
+
end
|
71
|
+
|
72
|
+
options '*' do
|
73
|
+
response.headers['Allow'] = settings.allow_methods.map { |it| it.to_s.upcase }.join(',')
|
74
|
+
response.headers['Access-Control-Allow-Headers'] = 'X-Mumuki-Auth-Token, X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept, Authorization'
|
75
|
+
200
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Mumukit::Service
|
2
|
+
class Slug
|
3
|
+
attr_accessor :organization, :repository
|
4
|
+
|
5
|
+
def initialize(organization, repository)
|
6
|
+
@organization = organization
|
7
|
+
@repository = repository
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
"#{organization}/#{repository}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def bibliotehca_guide_web_hook_url
|
15
|
+
"http://bibliotheca.mumuki.io/guides/import/#{to_s}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def bibliotehca_book_web_hook_url
|
19
|
+
"http://bibliotheca.mumuki.io/books/import/#{to_s}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def classroom_course_url
|
23
|
+
"http://classroom.mumuki.io/courses/#{to_s}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from(slug)
|
27
|
+
validate_slug! slug
|
28
|
+
|
29
|
+
self.new *slug.split('/')
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.validate_slug!(slug)
|
35
|
+
unless slug =~ /.*\/.*/
|
36
|
+
raise Mumukit::Service::InvalidSlugFormatError, 'Slug must be in organization/repository format'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'mongo'
|
2
|
+
require 'json/ext'
|
3
|
+
require 'mumukit/core'
|
4
|
+
|
5
|
+
module Mumukit
|
6
|
+
module Service
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
require 'mumukit/service/version'
|
13
|
+
require_relative './service/id_generator'
|
14
|
+
require_relative './service/slug'
|
15
|
+
require_relative './service/database'
|
16
|
+
require_relative './service/invalid_slug_format_error'
|
17
|
+
require_relative './service/document'
|
18
|
+
require_relative './service/document_array'
|
19
|
+
require_relative './service/document_not_found_error'
|
20
|
+
require_relative './service/document_validation_error'
|
21
|
+
require_relative './service/collection'
|
22
|
+
require_relative './service/env'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mumukit/service/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'mumukit-service'
|
8
|
+
spec.version = Mumukit::Service::VERSION
|
9
|
+
spec.authors = ['Franco Leonardo Bulgarelli']
|
10
|
+
spec.email = ['franco@mumki.org']
|
11
|
+
|
12
|
+
spec.summary = 'Little framework for building stateful mumuki services'
|
13
|
+
spec.homepage = 'https://github.com/mumuki/mumukit-service'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
30
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 2'
|
32
|
+
|
33
|
+
spec.add_dependency 'puma'
|
34
|
+
spec.add_dependency 'sinatra'
|
35
|
+
spec.add_dependency 'sinatra-cross_origin', '~> 0.3.1'
|
36
|
+
spec.add_dependency 'mongo', '~> 2.1'
|
37
|
+
spec.add_dependency 'bson_ext'
|
38
|
+
spec.add_dependency 'mumukit-core', '~> 0.2'
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mumukit-service
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Franco Leonardo Bulgarelli
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-09 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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: puma
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
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: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
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: sinatra-cross_origin
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.3.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.3.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mongo
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.1'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bson_ext
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
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: mumukit-core
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.2'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.2'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- franco@mumki.org
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- .gitignore
|
147
|
+
- .rspec
|
148
|
+
- .travis.yml
|
149
|
+
- CODE_OF_CONDUCT.md
|
150
|
+
- Gemfile
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- bin/console
|
155
|
+
- bin/setup
|
156
|
+
- config/database.yml
|
157
|
+
- lib/mumukit/service.rb
|
158
|
+
- lib/mumukit/service/collection.rb
|
159
|
+
- lib/mumukit/service/database.rb
|
160
|
+
- lib/mumukit/service/document.rb
|
161
|
+
- lib/mumukit/service/document_array.rb
|
162
|
+
- lib/mumukit/service/document_not_found_error.rb
|
163
|
+
- lib/mumukit/service/document_validation_error.rb
|
164
|
+
- lib/mumukit/service/env.rb
|
165
|
+
- lib/mumukit/service/id_generator.rb
|
166
|
+
- lib/mumukit/service/invalid_slug_format_error.rb
|
167
|
+
- lib/mumukit/service/routes.rb
|
168
|
+
- lib/mumukit/service/routes/auth.rb
|
169
|
+
- lib/mumukit/service/slug.rb
|
170
|
+
- lib/mumukit/service/version.rb
|
171
|
+
- mumukit-service.gemspec
|
172
|
+
homepage: https://github.com/mumuki/mumukit-service
|
173
|
+
licenses:
|
174
|
+
- MIT
|
175
|
+
metadata:
|
176
|
+
allowed_push_host: ! 'TODO: Set to ''http://mygemserver.com'''
|
177
|
+
post_install_message:
|
178
|
+
rdoc_options: []
|
179
|
+
require_paths:
|
180
|
+
- lib
|
181
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - ! '>='
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0'
|
186
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ! '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
requirements: []
|
192
|
+
rubyforge_project:
|
193
|
+
rubygems_version: 2.4.5
|
194
|
+
signing_key:
|
195
|
+
specification_version: 4
|
196
|
+
summary: Little framework for building stateful mumuki services
|
197
|
+
test_files: []
|