Skip to content

Commit 3c0627a

Browse files
committed
Initial commit
0 parents  commit 3c0627a

File tree

7 files changed

+214
-0
lines changed

7 files changed

+214
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.*
2+
!/.gitignore
3+
!/.travis.yml
4+
/bower_components/
5+
/node_modules/
6+
/output/

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: node_js
2+
sudo: false
3+
node_js:
4+
- 5
5+
install:
6+
- npm install -g bower
7+
- npm install
8+
script:
9+
- npm run build
10+
after_success:
11+
- >-
12+
test $TRAVIS_TAG &&
13+
psc-publish > .pursuit.json &&
14+
curl -X POST http://pursuit.purescript.org/packages \
15+
-d @.pursuit.json \
16+
-H 'Accept: application/json' \
17+
-H "Authorization: token ${GITHUB_TOKEN}"

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Gary Burgess
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# purescript-http-methods
2+
3+
[![Latest release](http://img.shields.io/bower/v/purescript-http-methods.svg)](https://github.com/purescript-contrib/purescript-http-methods/releases)
4+
[![Build Status](https://travis-ci.org/purescript-contrib/purescript-http-methods.svg?branch=master)](https://travis-ci.org/purescript-contrib/purescript-http-methods)
5+
[![Maintainer: garyb](https://img.shields.io/badge/maintainer-garyb-lightgrey.svg)](http://github.com/garyb)
6+
7+
HTTP method type.
8+
9+
## Installation
10+
11+
```
12+
bower install purescript-http-methods
13+
```
14+
15+
## Documentation
16+
17+
Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-http-methods).

bower.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "purescript-http-methods",
3+
"homepage": "https://github.com/purescript-contrib/purescript-http-methods",
4+
"description": "HTTP method type",
5+
"license": "MIT",
6+
"repository": {
7+
"type": "git",
8+
"url": "git://github.com/purescript-contrib/purescript-http-methods.git"
9+
},
10+
"ignore": [
11+
"**/.*",
12+
"bower_components",
13+
"node_modules",
14+
"output",
15+
"test",
16+
"bower.json",
17+
"package.json"
18+
],
19+
"dependencies": {
20+
"purescript-either": "^0.2.3",
21+
"purescript-generics": "^0.7.2",
22+
"purescript-prelude": "^0.1.4",
23+
"purescript-strings": "^0.7.1"
24+
}
25+
}

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"postinstall": "pulp dep install",
5+
"clean": "rimraf output && rimraf .pulp-cache",
6+
"build": "pulp build"
7+
},
8+
"devDependencies": {
9+
"pulp": "^8.0.0",
10+
"purescript": "^0.7.6",
11+
"rimraf": "^2.5.0"
12+
}
13+
}

src/Data/HTTP/Method.purs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
module Data.HTTP.Method
2+
( Method(..)
3+
, CustomMethod()
4+
, fromString
5+
, print
6+
) where
7+
8+
import Prelude
9+
10+
import Data.Either (Either(..), either)
11+
import Data.Generic (Generic, gCompare)
12+
import Data.String as Str
13+
14+
data Method
15+
-- HTTP/1.1
16+
= OPTIONS
17+
| GET
18+
| HEAD
19+
| POST
20+
| PUT
21+
| DELETE
22+
| TRACE
23+
| CONNECT
24+
25+
-- RFC 2518
26+
| PROPFIND
27+
| PROPPATCH
28+
| MKCOL
29+
| COPY
30+
| MOVE
31+
| LOCK
32+
| UNLOCK
33+
34+
-- RFC5789
35+
| PATCH
36+
37+
derive instance genericMethod :: Generic Method
38+
39+
instance eqMethod :: Eq Method where
40+
eq OPTIONS OPTIONS = true
41+
eq GET GET = true
42+
eq HEAD HEAD = true
43+
eq POST POST = true
44+
eq PUT PUT = true
45+
eq DELETE DELETE = true
46+
eq TRACE TRACE = true
47+
eq CONNECT CONNECT = true
48+
eq PROPFIND PROPFIND = true
49+
eq PROPPATCH PROPPATCH = true
50+
eq MKCOL MKCOL = true
51+
eq COPY COPY = true
52+
eq MOVE MOVE = true
53+
eq LOCK LOCK = true
54+
eq UNLOCK UNLOCK = true
55+
eq PATCH PATCH = true
56+
eq _ _ = false
57+
58+
instance ordMethod :: Ord Method where
59+
compare = gCompare
60+
61+
instance showMethod :: Show Method where
62+
show OPTIONS = "OPTIONS"
63+
show GET = "GET"
64+
show HEAD = "HEAD"
65+
show POST = "POST"
66+
show PUT = "PUT"
67+
show DELETE = "DELETE"
68+
show TRACE = "TRACE"
69+
show CONNECT = "CONNECT"
70+
show PROPFIND = "PROPFIND"
71+
show PROPPATCH = "PROPPATCH"
72+
show MKCOL = "MKCOL"
73+
show COPY = "COPY"
74+
show MOVE = "MOVE"
75+
show LOCK = "LOCK"
76+
show UNLOCK = "UNLOCK"
77+
show PATCH = "PATCH"
78+
79+
newtype CustomMethod = CustomMethod String
80+
81+
runCustomMethod :: CustomMethod -> String
82+
runCustomMethod (CustomMethod m) = m
83+
84+
derive instance genericCustomMethod :: Generic CustomMethod
85+
86+
instance eqCustomMethod :: Eq CustomMethod where
87+
eq (CustomMethod m1) (CustomMethod m2) = m1 == m2
88+
89+
instance ordCustomMethod :: Ord CustomMethod where
90+
compare = gCompare
91+
92+
instance showCustomMethod :: Show CustomMethod where
93+
show (CustomMethod m) = "CustomMethod " <> show m
94+
95+
fromString :: String -> Either Method CustomMethod
96+
fromString s =
97+
case Str.toUpper s of
98+
"OPTIONS" -> Left OPTIONS
99+
"GET" -> Left GET
100+
"HEAD" -> Left HEAD
101+
"POST" -> Left POST
102+
"PUT" -> Left PUT
103+
"DELETE" -> Left DELETE
104+
"TRACE" -> Left TRACE
105+
"CONNECT" -> Left CONNECT
106+
"PROPFIND" -> Left PROPFIND
107+
"PROPPATCH" -> Left PROPPATCH
108+
"MKCOL" -> Left MKCOL
109+
"COPY" -> Left COPY
110+
"MOVE" -> Left MOVE
111+
"LOCK" -> Left LOCK
112+
"UNLOCK" -> Left UNLOCK
113+
m -> Right (CustomMethod m)
114+
115+
print :: Either Method CustomMethod -> String
116+
print = either show runCustomMethod

0 commit comments

Comments
 (0)