Skip to content

Commit

Permalink
Refactors everything
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed Dec 5, 2015
1 parent 92fd3fa commit b79bdb6
Show file tree
Hide file tree
Showing 23 changed files with 598 additions and 837 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ lib-cov

# Coverage directory used by tools like istanbul
coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
Expand Down
184 changes: 95 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,88 @@
[![Build Status](https://travis-ci.org/zrrrzzt/edemokrati.svg?branch=master)](https://travis-ci.org/zrrrzzt/edemokrati)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
# edemokrati

Node.js module for the eDemokrati solution from [Sem & Stenersen Prokom](http://www.prokom.no/).
This first release targets the public journal part of [Lokaldemokrati24:7](http://www.prokom.no/Produkter/Portal/Lokaldemokrati247/).

## Installation

```
From npm
```sh
$ npm install edemokrati
```

From GitHub
```sh
$ git clone git@github.com:zrrrzzt/edemokrati.git
```

cd into directory and run setup
```sh
$ npm run setup
```

## Methods

### getPostlisteArkivdeler
### journals.getDokumenter

Returns the attached documents for a specific journal.

Pass an options object with the params.

**host**: The url of the host **(required)**

**journalpostid**: The id for the journal **(required)**

```javascript
var edm = require('edemokrati')
var options = {
'host': 'https://www.porsgrunn.kommune.no',
'journalpostid': '455040'
}

edm.journals.getDokumenter(options, function (error, data) {
if (error) {
console.error(error)
} else {
console.log(data)
}
})
```

### journals.getPostlisteArkivdeler

Returns a list of different archive units.

Pass an options object with the params.

**host**: The url of the host **(required)**

**fraDato**: Search from date. Timestampformatted like '\/Date(1413410400000)\/' **(required)**
**fraDato**: Search from date. Timestampformatted like '\/Date(1449097200000)\/' **(required)**

**tilDato**: Search to date. Timestampformatted like '\/Date(1413410400000)\/' **(required)**
**tilDato**: Search to date. Timestampformatted like '\/Date(1449097200000)\/' **(required)**

**søkestreng**: Search string. **(optional)**

```
```javascript
var edm = require('edemokrati')
, opts = {
'host': 'https://www.porsgrunn.kommune.no',
'fraDato': '\/Date(1413410400000)\/',
'tilDato': '\/Date(1413410400000)\/',
'søkestreng': ''
}
;
edm.getPostlisteArkivdeler(opts, function(err, data){
if(err){
console.error(err);
var options = {
'host': 'https://www.porsgrunn.kommune.no',
'fraDato': '\/Date(1449097200000)\/',
'tilDato': '\/Date(1449097200000)\/',
'søkestreng': ''
}

edm.journals.getPostlisteArkivdeler(options, function (error, data) {
if (error) {
console.error(error)
} else {
console.log(data);
console.log(data)
}
});
})
```

### getPostlisteDokumenttyper
### journals.getPostlisteDokumenttyper

Returns a list of different document types.

Expand All @@ -63,25 +100,24 @@ Pass an options object with the params.

```javascript
var edm = require('edemokrati')
, opts = {
'host': 'https://www.porsgrunn.kommune.no',
'fraDato': '\/Date(1449097200000)\/',
'tilDato': '\/Date(1449097200000)\/',
'arkivdel': '_',
'søkestreng': ''
}
;

edm.getPostlisteDokumenttyper(opts, function(err, data){
if(err){
console.error(err);
var options = {
'host': 'https://www.porsgrunn.kommune.no',
'fraDato': '\/Date(1449097200000)\/',
'tilDato': '\/Date(1449097200000)\/',
'arkivdel': '_',
'søkestreng': ''
}

edm.journals.getPostlisteDokumenttyper(options, function (error, data) {
if (error) {
console.error(error)
} else {
console.log(data);
console.log(data)
}
});
})
```

### getPostlisteSok
### journals.getPostlisteSok

Returns a list of journals.

Expand All @@ -101,26 +137,25 @@ Pass an options object with the params.

```javascript
var edm = require('edemokrati')
, opts = {
'host': 'https://www.porsgrunn.kommune.no',
'fraDato': '\/Date(1413410400000)\/',
'tilDato': '\/Date(1413410400000)\/',
'søkestreng': 'Kragerø',
'arkivdel': '_',
'dokumenttype': 'I'
}
;

edm.getPostlisteSok(opts, function(err, data){
if(err){
console.error(err);
var options = {
'host': 'https://www.porsgrunn.kommune.no',
'fraDato': '\/Date(1449097200000)\/',
'tilDato': '\/Date(1449097200000)\/',
'søkestreng': 'bolig',
'arkivdel': '_',
'dokumenttype': 'I'
}

edm.journals.getPostlisteSok(options, function (error, data) {
if (error) {
console.error(error)
} else {
console.log(data);
console.log(data)
}
});
})
```

### getPostlisteObjekt
### journals.getPostlisteObjekt

Returns one specific journal.

Expand All @@ -132,48 +167,19 @@ Pass an options object with the params.

```javascript
var edm = require('edemokrati')
, opts = {
'host': 'https://www.porsgrunn.kommune.no',
'id': '267478'
}
;

edm.getPostlisteObjekt(opts, function(err, data){
if(err){
console.error(err);
var options = {
'host': 'https://www.porsgrunn.kommune.no',
'id': '267478'
}

edm.journals.getPostlisteObjekt(options, function (error, data) {
if (error) {
console.error(error)
} else {
console.log(data);
console.log(data)
}
});
})
```

### getDokumenter

Returns the attached document for a specific journal.

Pass an options object with the params.

**host**: The url of the host **(required)**

**journalpostid**: The id for the journal **(required)**

```javascript
var edm = require('edemokrati')
, opts = {
'host': 'https://www.porsgrunn.kommune.no',
'journalpostid': '267478'
}
;

edm.getDokumenter(opts, function(err, data){
if(err){
console.error(err);
} else {
console.log(data);
}
});
```

## Disclaimer

This is not an official API for eDemokrati. I'm not affiliated with Sem & Stenersen Prokom.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# changelog

## 2.0.0 - Bigger than Love
Refactors all methods to separate modules under journals
Switches form mocha to tap
Implements JavaScript standard codestyle

## 1.0.0
Initial release
15 changes: 3 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
'use strict';
'use strict'

var postlister = require('./lib/postlister')
;
var journals = require('./lib/journals')

module.exports.getPostlisteSok = postlister.getPostlisteSok;

module.exports.getPostlisteArkivdeler = postlister.getPostlisteArkivdeler;

module.exports.getPostlisteDokumenttyper = postlister.getPostlisteDokumenttyper;

module.exports.getPostlisteObjekt = postlister.getPostlisteObjekt;

module.exports.getDokumenter = postlister.getDokumenter;
module.exports.journals = journals
34 changes: 34 additions & 0 deletions lib/journals/getDokumenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

var request = require('request')
var config = require('../../config')

function getDokumenter (options, callback) {
if (!options) {
return callback(new Error('Missing required input: options object'), null)
}

if (!options.host) {
return callback(new Error('Missing required input: options.host'), null)
}

if (!options.journalpostid) {
return callback(new Error('Missing required input: options.journalpostid'), null)
}

var requestOptions = {
uri: options.host + config.TEMPLATES_ENDPOINT + 'GetDokumenter',
method: 'POST',
json: options
}

request(requestOptions, function (error, response, body) {
if (error) {
return callback(error, null)
} else {
return callback(null, body.d)
}
})
}

module.exports = getDokumenter
41 changes: 41 additions & 0 deletions lib/journals/getPostlisteArkivdeler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict'

var request = require('request')
var config = require('../../config')

function getPostlisteArkivdeler (options, callback) {
if (!options) {
return callback(new Error('Missing required input: options object'), null)
}

if (!options.host) {
return callback(new Error('Missing required input: options.host'), null)
}

if (!options.fraDato) {
return callback(new Error('Missing required input: options.fraDato'), null)
}

if (!options.tilDato) {
return callback(new Error('Missing required input: options.tilDato'), null)
}

// Fixes inconsistent original API
options.dato = options.fraDato

var requestOptions = {
uri: options.host + config.TEMPLATES_ENDPOINT + 'GetPostlisteArkivdeler',
method: 'POST',
json: options
}

request(requestOptions, function (error, response, body) {
if (error) {
return callback(error, null)
} else {
return callback(null, body.d)
}
})
}

module.exports = getPostlisteArkivdeler

0 comments on commit b79bdb6

Please sign in to comment.