Skip to content

Commit 7e6c7b8

Browse files
committed
simplify #headers helper
1 parent d9e8d24 commit 7e6c7b8

7 files changed

Lines changed: 41 additions & 44 deletions

File tree

content/v3/gists.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ including information about data format and authentication.
1616

1717
### Response
1818

19-
<%= headers :status => 200, :pagination => true %>
19+
<%= headers 200, :pagination => true %>
2020
<%= json(:gist) { |h| [h] } %>
2121

2222
## Get a single gist
@@ -25,7 +25,7 @@ including information about data format and authentication.
2525

2626
### Response
2727

28-
<%= headers :status => 200 %>
28+
<%= headers 200 %>
2929
<%= json :full_gist %>
3030

3131
## Create a new gist
@@ -43,7 +43,7 @@ including information about data format and authentication.
4343

4444
### Response
4545

46-
<%= headers :status => 201,
46+
<%= headers 201,
4747
:Location => "https://api.github.com/users/:user/gists/1.json" %>
4848
<%= json :full_gist %>
4949

@@ -59,7 +59,7 @@ including information about data format and authentication.
5959

6060
### Response
6161

62-
<%= headers :status => 200 %>
62+
<%= headers 200 %>
6363
<%= json :full_gist %>
6464

6565
## Delete a gist
@@ -68,5 +68,5 @@ including information about data format and authentication.
6868

6969
### Response
7070

71-
<%= headers :status => 204 %>
71+
<%= headers 204 %>
7272
<%= json({}) %>

content/v3/gists/comments.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ title: Gist Comments API v3 | dev.github.com
1010

1111
### Response
1212

13-
<%= headers :status => 200 %>
13+
<%= headers 200 %>
1414
<%= json(:gist_comment) { |h| [h] } %>
1515

1616
## Get
@@ -19,7 +19,7 @@ title: Gist Comments API v3 | dev.github.com
1919

2020
### Response
2121

22-
<%= headers :status => 200 %>
22+
<%= headers 200 %>
2323
<%= json :gist_comment %>
2424

2525
## Create
@@ -28,7 +28,7 @@ title: Gist Comments API v3 | dev.github.com
2828

2929
### Response
3030

31-
<%= headers :status => 201,
31+
<%= headers 201,
3232
:Location => "https://api.github.com/gists/comments/1.json" %>
3333
<%= json :gist_comment %>
3434

@@ -38,7 +38,7 @@ title: Gist Comments API v3 | dev.github.com
3838

3939
### Response
4040

41-
<%= headers :status => 200 %>
41+
<%= headers 200 %>
4242
<%= json :gist_comment %>
4343

4444
## Delete
@@ -47,6 +47,6 @@ title: Gist Comments API v3 | dev.github.com
4747

4848
### Response
4949

50-
<%= headers :status => 204 %>
50+
<%= headers 204 %>
5151
<%= json({}) %>
5252

content/v3/issues.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ direction
3434

3535
### Response
3636

37-
<%= headers :status => 200, :pagination => true %>
37+
<%= headers 200, :pagination => true %>
3838
<%= json(:issue) { |h| [h] } %>
3939

4040
## Create an Issue
@@ -52,7 +52,7 @@ direction
5252

5353
### Response
5454

55-
<%= headers :status => 201,
55+
<%= headers 201,
5656
:Location =>
5757
'https://api.github.com/repos/user/repo/issues/1.json' %>
5858
<%= json :issue %>
@@ -63,7 +63,7 @@ direction
6363

6464
### Response
6565

66-
<%= headers :status => 200 %>
66+
<%= headers 200 %>
6767
<%= json :issue %>
6868

6969
## Edit an Issue
@@ -81,7 +81,7 @@ direction
8181

8282
### Response
8383

84-
<%= headers :status => 200 %>
84+
<%= headers 200 %>
8585
<%= json :issue %>
8686

8787
## Delete an Issue
@@ -90,5 +90,5 @@ direction
9090

9191
### Response
9292

93-
<%= headers :status => 204 %>
93+
<%= headers 204 %>
9494
<%= json({}) %>

content/v3/issues/comments.md

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

1111
### Response
1212

13-
<%= headers :status => 200, :pagination => true %>
13+
<%= headers 200, :pagination => true %>
1414
<%= json(:issue_comment) { |h| [h] } %>
1515

1616
## Create a Comment for an Issue
@@ -23,7 +23,7 @@ title: Issue Comments API v3 | dev.github.com
2323

2424
### Response
2525

26-
<%= headers :status => 201,
26+
<%= headers 201,
2727
:Location =>
2828
"https://api.github.com/repos/user/repo/issues/comments/:id.json" %>
2929
<%= json :issue_comment %>
@@ -34,7 +34,7 @@ title: Issue Comments API v3 | dev.github.com
3434

3535
### Response
3636

37-
<%= headers :status => 200 %>
37+
<%= headers 200 %>
3838
<%= json :issue_comment %>
3939

4040
## Edit an Issue Comment
@@ -47,7 +47,7 @@ title: Issue Comments API v3 | dev.github.com
4747

4848
### Response
4949

50-
<%= headers :status => 200 %>
50+
<%= headers 200 %>
5151
<%= json :issue_comment %>
5252

5353
## Delete an Issue Comment
@@ -56,5 +56,5 @@ title: Issue Comments API v3 | dev.github.com
5656

5757
### Response
5858

59-
<%= headers :status => 204 %>
59+
<%= headers 204 %>
6060
<%= json({}) %>

content/v3/issues/labels.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ title: Issue Labels API v3 | dev.github.com
1010

1111
### Response
1212

13-
<%= headers :status => 200 %>
13+
<%= headers 200 %>
1414
<%= json(:label) { |h| [h] } %>
1515

1616
## Create a Label
@@ -25,7 +25,7 @@ title: Issue Labels API v3 | dev.github.com
2525

2626
### Response
2727

28-
<%= headers :status => 201,
28+
<%= headers 201,
2929
:Location =>
3030
"https://api.github.com/repos/user/repo/labels/foo.json" %>
3131
<%= json :label %>
@@ -36,7 +36,7 @@ title: Issue Labels API v3 | dev.github.com
3636

3737
### Response
3838

39-
<%= headers :status => 200 %>
39+
<%= headers 200 %>
4040
<%= json :label %>
4141

4242
## Update a Label
@@ -51,7 +51,7 @@ title: Issue Labels API v3 | dev.github.com
5151

5252
### Response
5353

54-
<%= headers :status => 200 %>
54+
<%= headers 200 %>
5555
<%= json :label %>
5656

5757
## Delete a label
@@ -60,16 +60,16 @@ title: Issue Labels API v3 | dev.github.com
6060

6161
### Response
6262

63-
<%= headers :status => 204 %>
64-
{}
63+
<%= headers 204 %>
64+
<%= json({}) %>
6565

6666
## List labels on the Issue
6767

6868
GET /repos/:user/:repo/issues/:id/labels.json
6969

7070
### Response
7171

72-
<%= headers :status => 200 %>
72+
<%= headers 200 %>
7373
<%= json(:label) { |h| [h] } %>
7474

7575
## Add Labels to an Issue
@@ -82,7 +82,7 @@ title: Issue Labels API v3 | dev.github.com
8282

8383
### Response
8484

85-
<%= headers :status => 200 %>
85+
<%= headers 200 %>
8686
<%= json(:label) { |h| [h] } %>
8787

8888
## Remove a Label from an Issue
@@ -91,7 +91,7 @@ title: Issue Labels API v3 | dev.github.com
9191

9292
### Response
9393

94-
<%= headers :status => 200 %>
94+
<%= headers 200 %>
9595
<%= json(:label) { |h| [h] } %>
9696

9797
## Replace all Labels for an Issue
@@ -104,7 +104,7 @@ title: Issue Labels API v3 | dev.github.com
104104

105105
### Response
106106

107-
<%= headers :status => 200 %>
107+
<%= headers 200 %>
108108
<%= json(:label) { |h| [h] } %>
109109

110110
## Remove all Labels from an Issue
@@ -113,7 +113,7 @@ title: Issue Labels API v3 | dev.github.com
113113

114114
### Response
115115

116-
<%= headers :status => 204 %>
116+
<%= headers 204 %>
117117
<%= json({}) %>
118118

119119
## Get Labels for every Issue in a Milestone
@@ -122,5 +122,5 @@ title: Issue Labels API v3 | dev.github.com
122122

123123
### Response
124124

125-
<%= headers :status => 200 %>
125+
<%= headers 200 %>
126126
<%= json(:label) { |h| [h] } %>

content/v3/issues/milestones.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ direction
1919

2020
### Response
2121

22-
<%= headers :status => 200, :pagination => true %>
22+
<%= headers 200, :pagination => true %>
2323
<%= json(:milestone) { |h| [h] } %>
2424

2525
## Create a Milestone
@@ -37,7 +37,7 @@ direction
3737

3838
### Response
3939

40-
<%= headers :status => 201,
40+
<%= headers 201,
4141
:Location =>
4242
"https://api.github.com/repos/user/repo/milestones/1.json" %>
4343
<%= json :milestone %>
@@ -48,7 +48,7 @@ direction
4848

4949
### Response
5050

51-
<%= headers :status => 200 %>
51+
<%= headers 200 %>
5252
<%= json :milestone %>
5353

5454
## Update a Milestone
@@ -66,7 +66,7 @@ direction
6666

6767
### Response
6868

69-
<%= headers :status => 200 %>
69+
<%= headers 200 %>
7070
<%= json :milestone %>
7171

7272
## Delete a Milestone
@@ -75,5 +75,5 @@ direction
7575

7676
### Response
7777

78-
<%= headers :status => 204 %>
78+
<%= headers 204 %>
7979
<%= json({}) %>

lib/resources.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ module Helpers
1818
500 => '500 Server Error'
1919
}
2020

21-
def headers(head)
22-
lines = []
21+
def headers(status, head = {})
22+
lines = ["Status: #{STATUSES[status]}"]
2323
head.each do |key, value|
2424
case key
2525
when :pagination
2626
lines << "X-Next: https://api.github.com/resource?page=2"
2727
lines << "X-Last: https://api.github.com/resource?page=5"
28-
when :status then lines << "Status: #{STATUSES[value]}"
2928
else lines << "#{key}: #{value}"
3029
end
3130
end
@@ -130,7 +129,6 @@ def json(key)
130129
"color" => "f29513"
131130
}
132131

133-
134132
ISSUE = {
135133
"url" => "https://api.github.com/repos/octocat/Hello-World/issues/1.json",
136134
"html_url" => "https://github.com/octocat/Hello-World/issues/1",
@@ -184,9 +182,8 @@ def json(key)
184182

185183
GIST = {
186184
"url" => "https://api.github.com/gists/1.json",
187-
"id" => "365370",
188-
"repo" => "365370",
189-
"description" => "",
185+
"id" => "1",
186+
"description" => "description of gist",
190187
"public" => true,
191188
"user" => USER,
192189
"files" => GIST_FILES,

0 commit comments

Comments
 (0)