spore 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'json'
3
+ require 'yaml'
4
+ require 'spore/middleware'
5
+
6
+ class Spore
7
+ class Middleware
8
+ class Format < Spore::Middleware
9
+
10
+ class UnsupportedFormat < Exception
11
+ end
12
+
13
+ def expected_params
14
+ [ :format ]
15
+ end
16
+
17
+ def process_response(resp, env)
18
+ return if resp.nil?
19
+
20
+ if resp.code.to_s.match(/^2\d\d/)
21
+
22
+ # empty string is considered nil object
23
+ if resp.body.content.length == 0
24
+ resp.body = nil
25
+ return resp
26
+ end
27
+
28
+ # non-empty string are deserialized accordingly
29
+ if self.format.downcase == 'json'
30
+ resp.body = JSON.parse(resp.body.content)
31
+ elsif self.format.match(/yaml/)
32
+ resp.body = YAML.load(resp.body.content)
33
+ else
34
+ raise UnsupportedFormat, "don't know how to handle this format '#{self.format}'"
35
+ end
36
+ return resp
37
+ end
38
+
39
+ return resp
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ class Spore
3
+ class Middleware
4
+
5
+ class Runtime < Spore::Middleware
6
+ def process_request(env)
7
+ env['sporex.runtime.start'] = Time.now
8
+ return nil
9
+ end
10
+
11
+ def process_response(resp, env)
12
+ elapsed_time = Time.now - env['sporex.runtime.start']
13
+
14
+ resp.header['X-Spore-Runtime'] = elapsed_time
15
+ return resp
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'json'
4
+ class Spore
5
+ module SpecParser
6
+ class Json
7
+
8
+ attr_reader :specs
9
+
10
+ def initialize(file)
11
+ @file = file
12
+ @specs = nil
13
+ load_file
14
+ end
15
+
16
+ def self.load_file(f)
17
+ self.new(f).specs
18
+ end
19
+
20
+ protected
21
+
22
+ def load_file
23
+ File.open(@file,'r') do |file|
24
+ @specs = JSON.parse(file.read)
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'yaml'
4
+ class Spore
5
+ module SpecParser
6
+ class Yaml
7
+ attr_reader :specs
8
+
9
+ def self.load_file(f)
10
+ YAML.load_file(f)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,185 @@
1
+ {
2
+ "base_url" : "http://github.com/api/v2/",
3
+ "version" : "0.2",
4
+ "methods" : {
5
+ "follow" : {
6
+ "required_params" : [
7
+ "user",
8
+ "format"
9
+ ],
10
+ "path" : "/:format/user/follow/:user",
11
+ "method" : "POST",
12
+ "authentication" : true
13
+ },
14
+ "user_search" : {
15
+ "required_params" : [
16
+ "format",
17
+ "search"
18
+ ],
19
+ "path" : "/:format/user/search/:search",
20
+ "method" : "GET"
21
+ },
22
+ "unfollow" : {
23
+ "required_params" : [
24
+ "user",
25
+ "format"
26
+ ],
27
+ "path" : "/:format/user/unfollow/:user",
28
+ "method" : "POST",
29
+ "authentication" : true
30
+ },
31
+ "unwatch_repo" : {
32
+ "required_params" : [
33
+ "format",
34
+ "user",
35
+ "repo"
36
+ ],
37
+ "path" : "/:format/repos/unwatch/:user/:repo",
38
+ "method" : "GET",
39
+ "authentication" : true
40
+ },
41
+ "user_information" : {
42
+ "required_params" : [
43
+ "username",
44
+ "format"
45
+ ],
46
+ "path" : "/:format/user/show/:username",
47
+ "method" : "GET"
48
+ },
49
+ "list_public_keys" : {
50
+ "required_params" : [
51
+ "format"
52
+ ],
53
+ "path" : "/:format/user/keys",
54
+ "method" : "GET",
55
+ "authentication" : true
56
+ },
57
+ "repos_info" : {
58
+ "required_params" : [
59
+ "format",
60
+ "user",
61
+ "repo"
62
+ ],
63
+ "path" : "/:format/repos/:user/:repo",
64
+ "method" : "GET"
65
+ },
66
+ "add_public_key" : {
67
+ "required_params" : [
68
+ "format"
69
+ ],
70
+ "path" : "/:format/user/key/add",
71
+ "method" : "POST",
72
+ "authentication" : true
73
+ },
74
+ "fork_repos" : {
75
+ "required_params" : [
76
+ "format",
77
+ "user",
78
+ "repo"
79
+ ],
80
+ "path" : "/:format/repos/fork/:user/:repo",
81
+ "method" : "GET",
82
+ "authentication" : true
83
+ },
84
+ "my_information" : {
85
+ "required_params" : [
86
+ "username",
87
+ "format"
88
+ ],
89
+ "path" : "/:format/user/show/:username",
90
+ "method" : "GET",
91
+ "authentication" : true
92
+ },
93
+ "list_all_repos" : {
94
+ "required_params" : [
95
+ "format",
96
+ "user",
97
+ "repo"
98
+ ],
99
+ "path" : "/:format/repos/show/:user",
100
+ "method" : "GET"
101
+ },
102
+ "repos_search" : {
103
+ "required_params" : [
104
+ "format",
105
+ "q"
106
+ ],
107
+ "path" : "/:format/repos/search/:q",
108
+ "method" : "GET"
109
+ },
110
+ "update_profile" : {
111
+ "required_params" : [
112
+ "username",
113
+ "format"
114
+ ],
115
+ "path" : "/:format/user/show/:username",
116
+ "method" : "POST",
117
+ "authentication" : true
118
+ },
119
+ "watch_repo" : {
120
+ "required_params" : [
121
+ "format",
122
+ "user",
123
+ "repo"
124
+ ],
125
+ "path" : "/:format/repos/watch/:user/:repo",
126
+ "method" : "GET",
127
+ "authentication" : true
128
+ },
129
+ "create_repo" : {
130
+ "required_params" : [
131
+ "format"
132
+ ],
133
+ "path" : "/:format/repos/create",
134
+ "method" : "POST",
135
+ "authentication" : true
136
+ },
137
+ "user_following" : {
138
+ "required_params" : [
139
+ "user",
140
+ "format"
141
+ ],
142
+ "path" : "/:format/user/show/:user/following",
143
+ "method" : "GET"
144
+ },
145
+ "set_repo_info" : {
146
+ "required_params" : [
147
+ "format",
148
+ "user",
149
+ "repo"
150
+ ],
151
+ "path" : "/:format/repos/show/:user/:repo",
152
+ "method" : "POST",
153
+ "authentication" : true
154
+ },
155
+ "watched_repos" : {
156
+ "required_params" : [
157
+ "format",
158
+ "user"
159
+ ],
160
+ "path" : "/:format/user/watched/:user",
161
+ "method" : "GET"
162
+ },
163
+ "user_followers" : {
164
+ "required_params" : [
165
+ "user",
166
+ "format"
167
+ ],
168
+ "path" : "/:format/user/show/:user/followers",
169
+ "method" : "GET"
170
+ },
171
+ "del_public_key" : {
172
+ "required_params" : [
173
+ "format"
174
+ ],
175
+ "path" : "/:format/user/key/remove",
176
+ "method" : "POST",
177
+ "authentication" : true
178
+ }
179
+ },
180
+ "name" : "GitHub",
181
+ "authority" : "GITHUB:franckcuny",
182
+ "meta" : {
183
+ "documentation" : "http://develop.github.com/"
184
+ }
185
+ }
@@ -0,0 +1,87 @@
1
+ <opt name="GitHub" base_url="http://github.com/api/v2/" version="0.2" authority="GITHUB:franckcuny">
2
+ <methods>
3
+ <list_public_keys authentication="true" method="GET" path="/:format/user/keys">
4
+ <required_params>format</required_params>
5
+ </list_public_keys>
6
+ <unfollow authentication="true" method="POST" path="/:format/user/unfollow/:user">
7
+ <required_params>user</required_params>
8
+ <required_params>format</required_params>
9
+ </unfollow>
10
+ <create_repo authentication="true" method="POST" path="/:format/repos/create">
11
+ <required_params>format</required_params>
12
+ </create_repo>
13
+ <user_information method="GET" path="/:format/user/show/:username">
14
+ <required_params>username</required_params>
15
+ <required_params>format</required_params>
16
+ </user_information>
17
+ <my_information authentication="true" method="GET" path="/:format/user/show/:username">
18
+ <required_params>username</required_params>
19
+ <required_params>format</required_params>
20
+ </my_information>
21
+ <set_repo_info authentication="true" method="POST" path="/:format/repos/show/:user/:repo">
22
+ <required_params>format</required_params>
23
+ <required_params>user</required_params>
24
+ <required_params>repo</required_params>
25
+ </set_repo_info>
26
+ <user_followers method="GET" path="/:format/user/show/:user/followers">
27
+ <required_params>user</required_params>
28
+ <required_params>format</required_params>
29
+ </user_followers>
30
+ <list_all_repos method="GET" path="/:format/repos/show/:user">
31
+ <required_params>format</required_params>
32
+ <required_params>user</required_params>
33
+ <required_params>repo</required_params>
34
+ </list_all_repos>
35
+ <watch_repo authentication="true" method="GET" path="/:format/repos/watch/:user/:repo">
36
+ <required_params>format</required_params>
37
+ <required_params>user</required_params>
38
+ <required_params>repo</required_params>
39
+ </watch_repo>
40
+ <repos_info method="GET" path="/:format/repos/:user/:repo">
41
+ <required_params>format</required_params>
42
+ <required_params>user</required_params>
43
+ <required_params>repo</required_params>
44
+ </repos_info>
45
+ <follow authentication="true" method="POST" path="/:format/user/follow/:user">
46
+ <required_params>user</required_params>
47
+ <required_params>format</required_params>
48
+ </follow>
49
+ <fork_repos authentication="true" method="GET" path="/:format/repos/fork/:user/:repo">
50
+ <required_params>format</required_params>
51
+ <required_params>user</required_params>
52
+ <required_params>repo</required_params>
53
+ </fork_repos>
54
+ <unwatch_repo authentication="true" method="GET" path="/:format/repos/unwatch/:user/:repo">
55
+ <required_params>format</required_params>
56
+ <required_params>user</required_params>
57
+ <required_params>repo</required_params>
58
+ </unwatch_repo>
59
+ <add_public_key authentication="true" method="POST" path="/:format/user/key/add">
60
+ <required_params>format</required_params>
61
+ </add_public_key>
62
+ <user_search method="GET" path="/:format/user/search/:search">
63
+ <required_params>format</required_params>
64
+ <required_params>search</required_params>
65
+ </user_search>
66
+ <user_following method="GET" path="/:format/user/show/:user/following">
67
+ <required_params>user</required_params>
68
+ <required_params>format</required_params>
69
+ </user_following>
70
+ <watched_repos method="GET" path="/:format/user/watched/:user">
71
+ <required_params>format</required_params>
72
+ <required_params>user</required_params>
73
+ </watched_repos>
74
+ <del_public_key authentication="true" method="POST" path="/:format/user/key/remove">
75
+ <required_params>format</required_params>
76
+ </del_public_key>
77
+ <repos_search method="GET" path="/:format/repos/search/:q">
78
+ <required_params>format</required_params>
79
+ <required_params>q</required_params>
80
+ </repos_search>
81
+ <update_profile authentication="true" method="POST" path="/:format/user/show/:username">
82
+ <required_params>username</required_params>
83
+ <required_params>format</required_params>
84
+ </update_profile>
85
+ </methods>
86
+ <meta documentation="http://develop.github.com/" />
87
+ </opt>
@@ -0,0 +1,142 @@
1
+ ---
2
+ name: GitHub
3
+ methods:
4
+ list_public_keys:
5
+ authentication: true
6
+ method: GET
7
+ path: /:format/user/keys
8
+ required_params:
9
+ - format
10
+ create_repo:
11
+ authentication: true
12
+ method: POST
13
+ path: /:format/repos/create
14
+ required_params:
15
+ - format
16
+ unfollow:
17
+ authentication: true
18
+ method: POST
19
+ path: /:format/user/unfollow/:user
20
+ required_params:
21
+ - user
22
+ - format
23
+ user_information:
24
+ method: GET
25
+ path: /:format/user/show/:username
26
+ required_params:
27
+ - username
28
+ - format
29
+ user_followers:
30
+ method: GET
31
+ path: /:format/user/show/:user/followers
32
+ required_params:
33
+ - user
34
+ - format
35
+ set_repo_info:
36
+ authentication: true
37
+ method: POST
38
+ path: /:format/repos/show/:user/:repo
39
+ required_params:
40
+ - format
41
+ - user
42
+ - repo
43
+ my_information:
44
+ authentication: true
45
+ method: GET
46
+ path: /:format/user/show/:username
47
+ required_params:
48
+ - username
49
+ - format
50
+ watch_repo:
51
+ authentication: true
52
+ method: GET
53
+ path: /:format/repos/watch/:user/:repo
54
+ required_params:
55
+ - format
56
+ - user
57
+ - repo
58
+ list_all_repos:
59
+ method: GET
60
+ path: /:format/repos/show/:user
61
+ required_params:
62
+ - format
63
+ - user
64
+ - repo
65
+ repos_info:
66
+ method: GET
67
+ path: /:format/repos/:user/:repo
68
+ required_params:
69
+ - format
70
+ - user
71
+ - repo
72
+ fork_repos:
73
+ authentication: true
74
+ method: GET
75
+ path: /:format/repos/fork/:user/:repo
76
+ required_params:
77
+ - format
78
+ - user
79
+ - repo
80
+ follow:
81
+ authentication: true
82
+ method: POST
83
+ path: /:format/user/follow/:user
84
+ required_params:
85
+ - user
86
+ - format
87
+ add_public_key:
88
+ authentication: true
89
+ method: POST
90
+ path: /:format/user/key/add
91
+ required_params:
92
+ - format
93
+ unwatch_repo:
94
+ authentication: true
95
+ method: GET
96
+ path: /:format/repos/unwatch/:user/:repo
97
+ required_params:
98
+ - format
99
+ - user
100
+ - repo
101
+ user_search:
102
+ method: GET
103
+ path: /:format/user/search/:search
104
+ required_params:
105
+ - format
106
+ - search
107
+ del_public_key:
108
+ authentication: true
109
+ method: POST
110
+ path: /:format/user/key/remove
111
+ required_params:
112
+ - format
113
+ watched_repos:
114
+ method: GET
115
+ path: /:format/user/watched/:user
116
+ required_params:
117
+ - format
118
+ - user
119
+ user_following:
120
+ method: GET
121
+ path: /:format/user/show/:user/following
122
+ required_params:
123
+ - user
124
+ - format
125
+ update_profile:
126
+ authentication: true
127
+ method: POST
128
+ path: /:format/user/show/:username
129
+ required_params:
130
+ - username
131
+ - format
132
+ repos_search:
133
+ method: GET
134
+ path: /:format/repos/search/:q
135
+ required_params:
136
+ - format
137
+ - q
138
+ meta:
139
+ documentation: http://develop.github.com/
140
+ base_url: http://github.com/api/v2/
141
+ version: "0.2"
142
+ authority: GITHUB:franckcuny