<commit_before>## Ruby Gem For Creating Cedilla Services

### Overview
This is a ruby gem that can be used to help you build out services for your implementation of services used within the larger Cedilla ecosystem: https://github.com/cdlib/cedilla.  

The gem provides you with a uniform way of parsing JSON messages from cedilla and serializing JSON messages back to cedilla. It also provides you with a standardized data model (Request, Citation, Author, and Resource) and a service which makes a call to your HTTP endpoint. 

The gem allows you to quickly create a cedilla service without having to worry about parsing JSON requests from Cedilla, serializing JSON messages sent back to cedilla, or dealing with HTTP calls, redirects, and error handling. You can spend your time focused on dealing with what's important, managing the format of the querystring or form data being passed to the endpoint and handling responses from the endpoint.

For a concrete example of this Gem being used to ease the work needed to build your cedilla services, look at the cedilla_services project: https://github.com/cdlib/cedilla_services. That project uses this Ruby gem as a base for services used to communicate with SFX, Internet Archive, CoverThing, Worldcat Discovery, etc.
__

#### Build Status:
[![Build Status](https://secure.travis-ci.org/cdlib/cedilla_service_commons.png?branch=master)](http://travis-ci.org/cdlib/cedilla_service_commons)

#### Installation 
##### If you use Git and want Git to help you manage this gem's codebase
```
> cd [project root]
> git submodule add https://github.com/cdlib/cedilla_service_commons.git vendor/cedilla_service_commons
> cd vendor/cedilla_service_commons
> gem build cedilla.gemspec
> gem install cedilla-[version].gem
``` 

##### If you don't use Git or don't want the gem as part of your project
```
> git clone https://github.com/cdlib/cedilla_service_commons.git
> cd cedilla_service_commons
> gem build cedilla.gemspec
> gem install cedilla-[version].gem
```

##### If you're just looking to hack on the codebase:
Just clone the code per normal and have fun. If you're making generic changes that you think might be useful to the larger community, please send us a Pull Request and share your innovations with the rest of the community!


#### Usage
For this example we use the lightweight [http://www.sinatrarb.com/intro.html](Sinatra) framework to create a web server that we will use to expose our service implementation. This will require the installation of the sinatra gem.

The example consists of 3 files, the root project file that acts as your Sinatra Application or the web app's controller. It receives the incoming web request and sends it along to your service implementation for processing. The service requires a configuration YAML file, and we include it here so that you can see how it is incorporated. This example however overrides any interaction with the configuration settings since we are not actually calling an external endpoint. 

To get started, use the install instructions above to downaload and install the Cedilla Gem, install the Sinatra gem, and then create a new directory to store your project. Once the gems are installed, create the following three files:

* The service: my_service.rb
```
require 'cedilla/service'
require 'cedilla/citation'

# -------------------------------------------------------------------------
# An Implementation of the CedillaService Gem
# -------------------------------------------------------------------------
class MyService < Cedilla::Service
  
  # --------------------------------------------------------------------------------
  # The service.process_request calls this function when it is finished. You 
  # MUST implement your own code here. The gem expects you to return either
  # a Cedilla:Citation or a Cedilla:Error from this method
  # --------------------------------------------------------------------------------
  def process_response
    # Just dumping the HTTP response information capture in process_request
    puts "HTTP Status from endpoint: #{@response_status}"
    puts "HTTP Headers from enpoint: #{@response_headers.inspect}"
    puts "HTTP Body from endpoint: "
    puts @response_body
    
    
    Cedilla::Citation.new({:publisher => 'Well known publishing house',
                           :publication_place => 'London',
                           :authors => [{:last_name => 'Dickens', :first_name => 'Charles'}]})
  end<commit_msg>Fixed issue in README<commit_after>## Ruby Gem For Creating Cedilla Services

### Overview
This is a ruby gem that can be used to help you build out services for your implementation of services used within the larger Cedilla ecosystem: https://github.com/cdlib/cedilla.  

The gem provides you with a uniform way of parsing JSON messages from cedilla and serializing JSON messages back to cedilla. It also provides you with a standardized data model (Request, Citation, Author, and Resource) and a service which makes a call to your HTTP endpoint. 

The gem allows you to quickly create a cedilla service without having to worry about parsing JSON requests from Cedilla, serializing JSON messages sent back to cedilla, or dealing with HTTP calls, redirects, and error handling. You can spend your time focused on dealing with what's important, managing the format of the querystring or form data being passed to the endpoint and handling responses from the endpoint.

For a concrete example of this Gem being used to ease the work needed to build your cedilla services, look at the cedilla_services project: https://github.com/cdlib/cedilla_services. That project uses this Ruby gem as a base for services used to communicate with SFX, Internet Archive, CoverThing, Worldcat Discovery, etc.
__

#### Build Status:
[![Build Status](https://secure.travis-ci.org/cdlib/cedilla_service_commons.png?branch=master)](http://travis-ci.org/cdlib/cedilla_service_commons)

#### Installation 
##### If you use Git and want Git to help you manage this gem's codebase
```
> cd [project root]
> git submodule add https://github.com/cdlib/cedilla_service_commons.git vendor/cedilla_service_commons
> cd vendor/cedilla_service_commons
> gem build cedilla.gemspec
> gem install cedilla-[version].gem
``` 

##### If you don't use Git or don't want the gem as part of your project
```
> git clone https://github.com/cdlib/cedilla_service_commons.git
> cd cedilla_service_commons
> gem build cedilla.gemspec
> gem install cedilla-[version].gem
```

##### If you're just looking to hack on the codebase:
Just clone the code per normal and have fun. If you're making generic changes that you think might be useful to the larger community, please send us a Pull Request and share your innovations with the rest of the community!


#### Usage
For this example we use the lightweight [http://www.sinatrarb.com/intro.html](Sinatra) framework to create a web server that we will use to expose our service implementation. This will require the installation of the sinatra gem.

The example consists of 3 files, the root project file that acts as your Sinatra Application or the web app's controller. It receives the incoming web request and sends it along to your service implementation for processing. The service requires a configuration YAML file, and we include it here so that you can see how it is incorporated. This example however overrides any interaction with the configuration settings since we are not actually calling an external endpoint. 

To get started, use the install instructions above to downaload and install the Cedilla Gem, install the Sinatra gem, and then create a new directory to store your project. Once the gems are installed, create the following three files:

* The service: my_service.rb
```
require 'cedilla/service'
require 'cedilla/citation'

# -------------------------------------------------------------------------
# An Implementation of the CedillaService Gem
# -------------------------------------------------------------------------
class MyService < Cedilla::Service
  
  # --------------------------------------------------------------------------------
  # The service.process_request calls this function when it is finished. You 
  # MUST implement your own code here. The gem expects you to return either
  # a Cedilla:Citation or a Cedilla:Error from this method
  # --------------------------------------------------------------------------------
  def process_response
    # Just dumping the HTTP response information capture in process_request
    puts "HTTP Status from endpoint: #{@response_status}"
    puts "HTTP Headers from enpoint: #{@response_headers.inspect}"
    puts "HTTP Body from endpoint: "
    puts @response_body
    
    Cedilla::Citation.new({:publisher => 'Well known publishing house',
                           :publication_place => 'London',
                           :authors => [{:last_name => 'Dickens', :first_name => 'Charles'}]})
  end
{'fraction_non_alphanumeric': 0.12807662323198574, 'fraction_numerical': 0.00022274195344693172, 'mean_word_length': 3.117377349839523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1129948', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2096, 'n_words': 1090}