Skip to content

Commit 9be5cf9

Browse files
committed
specify input examples w/ the json helper
1 parent 4adef75 commit 9be5cf9

6 files changed

Lines changed: 44 additions & 71 deletions

File tree

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ API docs should look like:
3434

3535
### Input (request json body)
3636

37-
<pre class="highlight"><code class="language-javascript">
38-
{
39-
"field": "sample value"
40-
}
41-
</code></pre>
37+
<%= json :field => "sample value" %>
4238

4339
### Response
4440

content/v3/issues.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ direction
4242

4343
### Input
4444

45-
<pre class="highlight"><code class="language-javascript">
46-
{
47-
title: "String",
48-
body: "String",
49-
assignee: "String User login",
50-
milestone: "Integer Milestone number"
51-
}
52-
</code></pre>
45+
<%= json \
46+
:title => "String",
47+
:body => "String",
48+
:assignee => "String User login",
49+
:milestone => "Integer Milestone number"
50+
%>
5351

5452
### Response
5553

@@ -69,14 +67,12 @@ direction
6967

7068
### Input
7169

72-
<pre class="highlight"><code class="language-javascript">
73-
{
74-
title: "String",
75-
body: "String",
76-
assignee: "String",
77-
milestone: "Integer"
78-
}
79-
</code></pre>
70+
<%= json \
71+
:title => "String",
72+
:body => "String",
73+
:assignee => "String",
74+
:milestone => "Integer"
75+
%>
8076

8177
### Response
8278

content/v3/issues/comments.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ title: Issue Comments API v3 | dev.github.com
1818

1919
### Input
2020

21-
<pre class="highlight"><code class="language-javascript">
22-
{
23-
body: "String",
24-
}
25-
</code></pre>
21+
<%= json :body => "String" %>
2622

2723
### Response
2824

@@ -42,11 +38,7 @@ title: Issue Comments API v3 | dev.github.com
4238

4339
### Input
4440

45-
<pre class="highlight"><code class="language-javascript">
46-
{
47-
body: "String",
48-
}
49-
</code></pre>
41+
<%= json :body => "String" %>
5042

5143
### Response
5244

content/v3/issues/labels.md

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ title: Issue Labels API v3 | dev.github.com
1818

1919
### Input
2020

21-
<pre class="highlight"><code class="language-javascript">
22-
{
23-
name: "String",
24-
color: "hex" // "ffffff" (6 characters, no '#')
25-
}
26-
</code></pre>
21+
<%= json :name => "String", :color => "hex" %>
22+
23+
*Note*: `color` takes a 6 character hex code, without a leading `#`.
2724

2825
### Response
2926

@@ -43,12 +40,9 @@ title: Issue Labels API v3 | dev.github.com
4340

4441
### Input
4542

46-
<pre class="highlight"><code class="language-javascript">
47-
{
48-
name: "String",
49-
color: "hex" // "ffffff" (6 characters, no '#')
50-
}
51-
</code></pre>
43+
<%= json :name => "String", :color => "hex" %>
44+
45+
*Note*: `color` takes a 6 character hex code, without a leading `#`.
5246

5347
### Response
5448

@@ -70,17 +64,13 @@ title: Issue Labels API v3 | dev.github.com
7064

7165
<%= json(:label) { |h| [h] } %>
7266

73-
## Add a Label to an Issue
67+
## Add Labels to an Issue
7468

7569
POST /repos/:user/:repo/issues/:id/labels.json
7670

7771
### Input
7872

79-
<pre class="highlight"><code class="language-javascript">
80-
[{
81-
name: "String"
82-
}, ...]
83-
</code></pre>
73+
<%= json({name: "String"}) { |h| [h] } %>
8474

8575
### Response
8676

@@ -100,11 +90,7 @@ title: Issue Labels API v3 | dev.github.com
10090

10191
### Input
10292

103-
<pre class="highlight"><code class="language-javascript">
104-
[{
105-
name: "String"
106-
}, ...]
107-
</code></pre>
93+
<%= json({name: "String"}) { |h| [h] } %>
10894

10995
### Response
11096

content/v3/issues/milestones.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,12 @@ direction
2727

2828
### Input
2929

30-
<pre class="highlight"><code class="language-javascript">
31-
{
32-
title: "String",
33-
state: "String", // "open" or "closed"
34-
description: "String",
35-
due_on: "Time"
36-
}
37-
</code></pre>
30+
<%= json \
31+
:title => "String",
32+
:state => "open or closed",
33+
:description => "String",
34+
:due_on => "Time"
35+
%>
3836

3937
### Response
4038

@@ -54,14 +52,12 @@ direction
5452

5553
### Input
5654

57-
<pre class="highlight"><code class="language-javascript">
58-
{
59-
title: "String",
60-
state: "String", // "open" or "closed"
61-
description: "String",
62-
due_on: "Time"
63-
}
64-
</code></pre>
55+
<%= json \
56+
:title => "String",
57+
:state => "open or closed",
58+
:description => "String",
59+
:due_on => "Time"
60+
%>
6561

6662
### Response
6763

lib/resources.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ module GitHub
55
module Resources
66
module Helpers
77
def json(key)
8-
hash = Resources.const_get(key.to_s.upcase)
8+
hash = case key
9+
when Hash
10+
h = {}
11+
key.each { |k, v| h[k.to_s] = v }
12+
h
13+
else Resources.const_get(key.to_s.upcase)
14+
end
15+
916
hash = yield hash if block_given?
1017

1118
io = StringIO.new

0 commit comments

Comments
 (0)