forked from twotoasters/RKCatalog-Server
/
server.rb
100 lines (91 loc) · 3.16 KB
/
server.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# RestKit RKCatalog Sample
require 'rubygems'
require 'sinatra/base'
require 'json'
class RKExampleServer < Sinatra::Base
self.app_file = __FILE__
configure do
set :logging, true
set :dump_errors, true
set :show_exceptions, true
end
post '/RKParamsExample' do
"OK"
end
get '/RKRequestQueueExample' do
sleep(1.0)
"OK"
end
get '/RKBackgroundRequestExample' do
content_type 'text/plain'
sleep(5)
"OK"
end
get '/RKKeyValueMappingExample' do
content_type 'application/json'
%Q{{
"id": 1234,
"name": "Personal Checking",
"balance": 5013.26,
"transactions": [
{"id": 1, "payee": "Joe Blow", "amount": 50.16},
{"id": 2, "payee": "Grocery Store", "amount": 200.15},
{"id": 3, "payee": "John Doe", "amount": 325.00},
{"id": 4, "payee": "Grocery Store", "amount": 25.15}]
}}
end
# Used by the Relationship mapping examples
get '/RKRelationshipMappingExample' do
content_type 'application/json'
%Q{
[{"project": {
"id": 123,
"name": "Produce RestKit Sample Code",
"description": "We need more sample code!",
"user": {
"id": 1,
"name": "Blake Watters",
"email": "blake@twotoasters.com"
},
"tasks": [
{"id": 1, "name": "Identify samples to write", "assigned_user_id": 1},
{"id": 2, "name": "Write the code", "assigned_user_id": 1},
{"id": 3, "name": "Push to Github", "assigned_user_id": 1},
{"id": 4, "name": "Update the mailing list", "assigned_user_id": 1}
]
}},
{"project": {
"id": 456,
"name": "Document Object Mapper",
"description": "The object mapper could really use some docs!",
"user": {
"id": 2,
"name": "Jeremy Ellison",
"email": "jeremy@twotoasters.com"
},
"tasks": [
{"id": 5, "name": "Mark up methods with Doxygen markup", "assigned_user_id": 2},
{"id": 6, "name": "Generate docs and review formatting", "assigned_user_id": 2},
{"id": 7, "name": "Review docs for accuracy and completeness", "assigned_user_id": 1},
{"id": 8, "name": "Publish to Github", "assigned_user_id": 2}
]
}},
{"project": {
"id": 789,
"name": "Wash the Cat",
"description": "Mr. Fluffy is looking like Mr. Scruffy! Time for a bath!",
"user": {
"id": 3,
"name": "Rachit Shukla",
"email": "rachit@twotoasters.com"
},
"tasks": [
{"id": 9, "name": "Place cat in bathtub", "assigned_user_id": 3},
{"id": 10, "name": "Run water", "assigned_user_id": 3},
{"id": 11, "name": "Try not to get scratched", "assigned_user_id": 3}
]
}}]
}
end
end
RKExampleServer.run!