Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
3792d7a0
Commit
3792d7a0
authored
Jan 20, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PUT api for configurations working. more helpers in models
parent
74dfc492
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
12 deletions
+61
-12
app.rb
app.rb
+34
-11
models.rb
models.rb
+27
-1
No files found.
app.rb
View file @
3792d7a0
...
@@ -126,20 +126,19 @@ namespace "/a" do
...
@@ -126,20 +126,19 @@ namespace "/a" do
end
end
namespace
'/c'
do
namespace
'/c'
do
# Need to move this out to configuration.
# Maybe bootstrap them from itself?
content_type_mapping
=
{
:yaml
=>
"text/x-yaml"
,
:json
=>
"application/json"
,
:xml
=>
"text/xml"
}
get
'/:appname/:element/?'
do
get
'/:appname/:element/?'
do
a
=
Application
.
find
(
:name
=>
params
[
:appname
]).
first
a
=
Application
.
find
(
:name
=>
params
[
:appname
]).
first
c
=
Configuration
.
find
(
:name
=>
params
[
:element
],
:application_id
=>
a
.
id
).
first
c
=
Configuration
.
find
(
:name
=>
params
[
:element
],
:application_id
=>
a
.
id
).
first
case
c
.
format
content_type
content_type_mapping
[
c
.
format
.
to_sym
]
if
content_type_mapping
[
c
.
format
.
to_sym
]
when
"json"
content_type
'application/json'
when
"xml"
content_type
'text/xml'
when
"yaml"
content_type
'text/x-yaml'
else
content_type
'text/plain'
end
"
#{
c
.
body
}
"
"
#{
c
.
body
}
"
end
end
...
@@ -156,6 +155,30 @@ namespace '/c' do
...
@@ -156,6 +155,30 @@ namespace '/c' do
"
#{
configs
.
to_json
}
"
"
#{
configs
.
to_json
}
"
end
end
put
'/:appname/:element?'
do
|
appname
,
item
|
begin
app
=
Application
.
find_or_create
(
:name
=>
appname
)
config
=
Configuration
.
find_or_create
(
:name
=>
item
,
:application_id
=>
app
.
id
)
required_params
=
[
"format"
,
"body"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
data
.
keys
.
sort
==
required_params
.
sort
?
(
config
.
format
=
data
[
"format"
];
config
.
body
=
data
[
"body"
])
:
(
raise
"Missing Parameters"
)
if
config
.
valid?
config
.
save
status
200
r
=
{
"result"
=>
"success"
,
"id"
=>
"
#{
config
.
id
}
"
}
r
.
to_json
else
status
500
r
=
{
"result"
=>
"failure"
,
"error"
=>
"
#{
config
.
errors
}
"
}
r
.
to_json
end
rescue
Exception
=>
e
status
500
r
=
{
"result"
=>
"failure"
,
"error"
=>
"
#{
e
.
message
}
"
}
r
.
to_json
end
end
end
end
# A route for adding a new host
# A route for adding a new host
...
...
models.rb
View file @
3792d7a0
...
@@ -68,6 +68,16 @@ class Configuration < Ohm::Model
...
@@ -68,6 +68,16 @@ class Configuration < Ohm::Model
def
to_hash
def
to_hash
super
.
merge
(
:name
=>
name
,
:format
=>
format
,
:body
=>
body
,
:update_at
=>
updated_at
,
:application
=>
Application
[
application_id
].
name
)
super
.
merge
(
:name
=>
name
,
:format
=>
format
,
:body
=>
body
,
:update_at
=>
updated_at
,
:application
=>
Application
[
application_id
].
name
)
end
end
class
<<
self
def
find_or_create
(
opts
=
{})
begin
find
(
opts
).
first
.
nil?
?
(
conf
=
create
(
opts
))
:
(
conf
=
find
(
opts
).
first
)
rescue
Exception
=>
e
e
.
message
end
end
end
end
end
class
Application
<
Ohm
::
Model
class
Application
<
Ohm
::
Model
...
@@ -90,6 +100,22 @@ class Application < Ohm::Model
...
@@ -90,6 +100,22 @@ class Application < Ohm::Model
configurations
.
sort
.
each
{
|
c
|
arr
<<
c
.
to_hash
}
configurations
.
sort
.
each
{
|
c
|
arr
<<
c
.
to_hash
}
super
.
merge
(
:name
=>
name
,
:updated_at
=>
updated_at
,
:configurations
=>
arr
)
super
.
merge
(
:name
=>
name
,
:updated_at
=>
updated_at
,
:configurations
=>
arr
)
end
end
class
<<
self
def
find_or_create
(
opts
=
{})
begin
find
(
opts
).
first
.
nil?
?
(
app
=
create
(
opts
))
:
(
app
=
find
(
opts
).
first
)
if
app
.
valid?
app
.
save
app
else
raise
app
.
errors
end
rescue
Exception
=>
e
e
.
message
end
end
end
end
end
class
Watcher
<
Ohm
::
Model
#NYI
class
Watcher
<
Ohm
::
Model
#NYI
...
@@ -111,7 +137,7 @@ class Watcher < Ohm::Model #NYI
...
@@ -111,7 +137,7 @@ class Watcher < Ohm::Model #NYI
end
end
end
end
# Some pluralized helper
object
s
# Some pluralized helper
model
s
class
Hosts
class
Hosts
def
self
.
all
(
options
=
{})
def
self
.
all
(
options
=
{})
options
.
empty?
?
Host
.
all
.
sort
:
Host
.
find
(
options
).
sort
options
.
empty?
?
Host
.
all
.
sort
:
Host
.
find
(
options
).
sort
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment