Giter Club home page Giter Club logo

hackernews's Introduction

hackernews

Hackage Hackage Dependencies Haskell Programming Language MIT License Build Status

Hacker News API for Haskell

Documentation

https://github.com/HackerNews/API

Now it supports GHCJS and can be used in the browser! Just install it using:

cabal install --ghcjs

Tests

cabal configure && cabal test
HackerNews API tests
  should round trip Updates JSON
  should round trip Item JSON
  should round trip User JSON
  should retrieve item
  should retrieve user
  should retrieve max item
  should retrieve top stories
  should retrieve new stories
  should retrieve best stories
  should retrieve ask stories
  should retrieve show stories
  should retrieve job stories
  should retrieve updates

  Finished in 1.2129 seconds
  13 examples, 0 failures

Usage

module Main where

import Network.HTTP.Client
import Network.HTTP.Client.TLS

import Web.HackerNews

main :: IO ()
main = do
 mgr <- newManager tlsManagerSettings
 print =<< getItem mgr (ItemId 1000)
 print =<< getUser mgr (UserId "dmjio")
 print =<< getMaxItem mgr
 print =<< getTopStories mgr
 print =<< getNewStories mgr
 print =<< getBestStories mgr
 print =<< getAskStories mgr
 print =<< getShowStories mgr
 print =<< getJobStories mgr
 print =<< getUpdates mgr
Right ( Item {
	 itemId = Just (ItemId 1000)
   , itemDeleted = Nothing
   , itemType = Story
   , itemBy = Just (UserName "python_kiss")
   , itemTime = Just (Time 1172394646)
   , itemText = Nothing
   , itemDead = Nothing
   , itemParent = Nothing
   , itemKids = Nothing
   , itemURL = Just (URL "http://www.netbusinessblog.com/2007/02/19/how-important-is-the-dot-com/")
   , itemScore = Just (Score 4)
   , itemTitle = Just (Title "How Important is the .com TLD?")
   , itemParts = Nothing
   , itemDescendants = Just (Descendants 0)
   })
Right (User {userId = UserId "dmjio"
		   , userDelay = Nothing
		   , userCreated = Created 1375807763
		   , userKarma = Karma 7
		   , userAbout = Nothing
		   , userSubmitted = Just (Submitted [11966297,9355613, ...])
		   })
Right (MaxItem 12695220)
Right (TopStories [12694004,12692190,12691597,...])
Right (NewStories [12695214,12695213,12695195,...])
Right (BestStories [12649414,12637126,12684980, ...])
Right (AskStories [12694706,12694401,12694038, ...])
Right (ShowStories [12694004,12692190,12695037, ...])
Right (JobStories [12693320,12691627,12690539,...])
Right (Updates { items = [12694916,12694478,12693674,..],
				 profiles = [UserName "stefano", UserName "chillydawg", ...]
			   })

hackernews's People

Contributors

cdepillabout avatar dmjio avatar latkins avatar manyoo avatar sengaya avatar zudov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hackernews's Issues

Core API change

@zudov, Right now the API I made is a little inflexible. It requires pattern matching on a Maybe every line when issuing a request.

hackerNews $ do 
  Just user1 <- getUser
  Just user2 <- getUser
  return (user1, user2)  

I'd rather have it do something like this:

hackerNews $ do 
  user1 <- getUser
  user2 <- getUser
  return (user1, user2)  

This can be accomplished by adding a MaybeT or an EitherT. I think we should go EitherT since I'd like to include some info about why a query failed.

So,

I propose:

data HackerNewsError = ConnectionError | ItemNotFound deriving (Show,Eq)
type HackerNews a = (FromJSON a, Show a) => EitherT HackerNewsError (ReaderT Connection IO) a

I'm going to add this today after I merge your changes @zudov, what do you think?

Command line executable for hackernews

Would be nice to have an interface like:

$ hackernews --topstories
> [123456, 987654, ....]

Might be a good use case for cmdtheline or optparse-applicative

Dead field

@zudov looks like there is also a 'dead' field we didn't add. I'm trying to get the exact usages it has on items.

Upgrade

Hey @zudov,

I'd like to rewrite this library w/ servant-client.

What do you think?

Test suite failure

> /tmp/stackage-build8/hackernews-0.5.0.1$ dist/build/tests/tests

Hacker News API Tests
  Retrieves all FAILED [1]

Failures:

  tests/Test.hs:23: 
  1) Hacker News API Tests Retrieves all
       predicate failed on: Left NotFound

Randomized with seed 66764037

Finished in 0.2176 seconds
1 example, 1 failure

ConnectionError

Not sure what I might be doing wrong, but:

main :: IO ()
main = do
  r <- hackerNews (getItem $ ItemId 10575270)
  print r

results in:

Left ConnectionError

Any idea why this might be?

Attribution

@zudov I added 100% haddock coverage. Can you go through each module you've touched and add your name to the maintainer list.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.