Skip to content

Commit

Permalink
Words
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Sep 23, 2016
1 parent a8c1b9b commit 0f8e087
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 14 deletions.
60 changes: 51 additions & 9 deletions README.md
Expand Up @@ -6,7 +6,7 @@

![Uncle Clive](http://uncleclive.herokuapp.com/font/Uncle%20Clive.svg?colour=fa8100)

##Sinclair Spectrum Font as a Service
##Sinclair Spectrum Stuff as a Service

_v2.0.0_

Expand All @@ -16,31 +16,73 @@ You may see a more pointless Thing-as-a-Service today, but I hope not. Uncle Cli

This has now been completely rewritten to make use of my new [1982](http://sam.pikesley.org/projects/1982/) gem, and my [Skellington](http://sam.pikesley.org/projects/skellington/) Sinatra-app-generation tool

###Content negotiation
##API

###`/font/:text`

Will return content of the form _:text_, rendered in the 1982 Sinclair Spectrum character set.

####Content negotiation

Uncle-Clive will respond to the following _Accept_ values with appropriate content:

####`application/json` _[example](http://uncleclive.herokuapp.com/font/1982.json)_
#####`application/json` _[example](http://uncleclive.herokuapp.com/font/1982.json)_

Content will be returned as a JSON object

####`text/plain` _[example](http://uncleclive.herokuapp.com/font/1982.text)_
#####`text/plain` _[example](http://uncleclive.herokuapp.com/font/1982.text)_

Content will be returned as plain text

####`text/html` _[example](http://uncleclive.herokuapp.com/font/%C2%A9%201982%20Sinclair%20Research%20Ltd)_
#####`text/html` _[example](http://uncleclive.herokuapp.com/font/%C2%A9%201982%20Sinclair%20Research%20Ltd)_

Content will be returned as an HTML page with a Twitter Bootstrap Jumbotron containing the data rendered as a table

####`image/svg+xml` _[example](http://uncleclive.herokuapp.com/font/%C2%A9%201982%20Sinclair%20Research%20Ltd.svg?colour=fa8100)_
#####`image/svg+xml` _[example](http://uncleclive.herokuapp.com/font/%C2%A9%201982%20Sinclair%20Research%20Ltd.svg?colour=fa8100)_

Content will be returned as an SVG image

###API
---

####`/:text`
###`/colours/:colour`

Will return content of the form _:text_, rendered in the 1982 Sinclair Spectrum character set.
Will return the hex value of the requested colour

###`/colours/:COLOUR`

Will return the BRIGHT variant of the requested colour

####Content negotiation

Uncle-Clive will respond to the following _Accept_ values with appropriate content:

#####`application/json` _[example](http://uncleclive.herokuapp.com/colours/magenta)_

Content will be returned as a JSON object (this is the default if no _Accept_ header is sent)

#####`text/plain` _[example](http://uncleclive.herokuapp.com/colours/YELLOW.text)_

The hex value will be returned as plain text

---

###`/messages/:key`

Will return the Spectrum error message corresponding to _:key_

####Content negotiation

Uncle-Clive will respond to the following _Accept_ values with appropriate content:

#####`application/json` _[example](http://uncleclive.herokuapp.com/messages/r)_

Content will be returned as a JSON object (this is the default if no _Accept_ header is sent)

#####`text/plain` _[example](http://uncleclive.herokuapp.com/messages/C.text)_

The error message will be returned as plain text

---

###History

Expand Down
26 changes: 22 additions & 4 deletions lib/uncle_clive.rb
Expand Up @@ -123,7 +123,12 @@ class App < Sinatra::Base
headers 'Access-Control-Allow-Origin' => '*'

key = params.fetch 'key'
message = Nineteen::Eighty::Two::Messages[key]

begin
message = Nineteen::Eighty::Two::Messages[key]
rescue Nineteen::Eighty::Two::Exceptions::SpectrumException
halt 404
end

respond_to do |wants|
wants.text do
Expand All @@ -139,11 +144,24 @@ class App < Sinatra::Base
end
end



not_found do
status 404
erb :nope, layout: :default

respond_to do |wants|
wants.json do
{
'error': 'not found'
}.to_json
end

wants.html do
erb :nope, layout: :default
end

wants.other do
'404 Not Found'
end
end
end

# start the server if ruby file executed directly
Expand Down
10 changes: 10 additions & 0 deletions spec/uncle_clive/messages_spec.rb
Expand Up @@ -18,6 +18,16 @@ module UncleClive
expect(last_response.body).to eq '1 - NEXT without FOR'
end

it 'traps a duff key' do
get '/messages/CYAN', nil, JSON_HEADERS
expect(last_response.status).to eq 404
expect(JSON.parse last_response.body).to eq (
{
'error' => 'not found'
}
)
end

it 'serves ALL THE MESSAGES' do
get '/messages/'
expect(last_response).to be_ok
Expand Down
3 changes: 2 additions & 1 deletion spec/uncle_clive/uncle_clive_spec.rb
Expand Up @@ -3,7 +3,7 @@ module UncleClive
it 'has a homepage' do
get '/'
expect(last_response).to be_ok
expect(last_response.body).to match /Sinclair Spectrum Font as a Service/
expect(last_response.body).to match /Sinclair Spectrum Stuff as a Service/
end

it 'can take a custom line-separator' do
Expand Down Expand Up @@ -66,6 +66,7 @@ module UncleClive
it 'has a 404' do
get '/not/a/fnord' do
expect(last_response.status).to eq 404
expect(last_response.body).to match /Back to the start/
end
end
end
Expand Down

0 comments on commit 0f8e087

Please sign in to comment.