Git Product home page Git Product logo

certify_messages's Introduction

CertifyMessages

Thin wrapper for the Messages API to handle basic GET and POST operations for message entries.

Table of Contents

Installation

Pulling from private geminabox (preferred)

Ensure you have the credentials configured with bundler, then add the following to your Gemfile:

source 'https://<domain-of-our-private-gem-server>/' do
  gem 'certify_messages'
end

Install from GitHub

Add the following to your Gemfile to bring in the gem from GitHub:

gem 'certify_messages', git: '[email protected]:USSBA/certify_messages.git', branch: 'develop'

This will pull the head of the develop branch in as a gem. If there are updates to the gem repository, you will need to run bundle update certify_messages to get them.

Using it locally

  • Clone this repository
  • Add it to the Gemfile with the path:
gem 'certify_messages', path: '<path-to-the-gem-on-your-system>'

Configuration

Within the host application, set the Certify Messages API URL in config/initializers, you probably also want to include a messages.yml under config to be able to specify the URL based on your environment.

CertifyMessages.configure do |config|
  config.api_key = "your_api_key"
  config.api_url = "http://localhost:3000"
  config.msg_api_version = 1
  config.excon_timeout = 5
end

The api_key is currently unused, but we anticipate adding in an API Gateway layer in the future.

With v1.2.0, the default Excon API connection timeout was lowered to 20 seconds. The gem user can also provide a timeout value in seconds as shown above in the configure block. This value is used for the Excon parameters connect_timeout, read_timeout, and write_timeout.

Methods

Refer to the Certify Messages API for more complete documentation and detailed examples of method responses.

Note: The Messages API has multiple versions that support different parameters. For example, v3 may require an application_uuid instead of an application_id. Refer to the API documentation to know which parameters to use depending on the version.

Conversations

Method Description
CertifyMessages::Conversation.find({application_id: 1}) Query for all conversations by application_id. This also applies for subject, user_1, user_2, and id. Conversations are organized in reverse chronological order by default. To change the order, pass in order:'ascending' with the request
CertifyMessages::Conversation.create({ user_1: <int>, user_2: <int>, application_id: <int>, subject: <string> }) Create a new conversation
CertifyMessages::Conversation.create_with_message({ user_1: <int>, user_2: <int>, application_id: <int>, subject: <string>, sender_id: <int>, recipient_id: <int>, body: <string>, priority_read_receipt: <boolean> (optional, default false) }) Create a conversation with a message
CertifyMessages::Conversation.create({ user_1: <int>, user_2: <int>, application_id: <int>, subject: <string>, conversation_type: 'official' }) Creating official conversation
CertifyMessages::Conversation.archive({ conversation_id: <int>, archived: <boolean> }) To archive or un-archive a conversation, you must specify the conversation_id, and archive. If archive is true the conversation will be archived. If archive is false, the conversation will be un-archived.
CertifyMessages::Conversation.unread_message_counts({ application_ids: "<int>,<int>,...", recipient_id: <int> }) Given a comma-separated list of application ID's, and the ID of the message recipient, returns the number of unread messages on each application.

Messages

Method Description
CertifyMessages::Message.find({conversation_id: 1}) Query for all conversations by conversation_id. Combining the above with other parameters (e.g, subject, sender_id), will query messages within that thread. Messages are returned in chronological order. To reverse the order, include the order parameter with 'ascending'
CertifyMessages::Message.create({ conversation_id: <int>, sender_id: <int>, recipient_id: <int>, body: <string>, priority_read_receipt: <boolean> (optional, default false) }) Create a new message
CertifyMessages::Message.update({ conversation_id: <int>, id: <int>, read: true }) Update a message. Ex. mark a message as read.

Error Handling

The Gem handles a few basic errors including:

  • Bad Request - Raised when API returns the HTTP status code 400
  • NotFound - Raised when API returns the HTTP status code 404
  • InternalServerError - Raised when API returns the HTTP status code 500
  • ServiceUnavailable - Raised when API returns the HTTP status code 503

Otherwise the gem will return more specific errors from the API. Refer to the API Docs for details around the specific error.

A typical error will look something like this:

{:body=>{"message"=>"No message found"}, :status=>404}

Logging

Along with returning status error messages for API connection issues, the gem will also log connection errors. The default behavior for this is to use the built in Ruby Logger and honor standard log level protocols. The default log level is set to debug and will output to STDOUT. This can also be configured by the gem user to use the gem consumer application's logger, including the app's environment specific log level.

# example implementation for a Rails app
CertifyMessages.configure do |config|
  config.logger = Rails.logger
  config.log_level = Rails.configuration.log_level
end

Development

After checking out the repo, run bundle install to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Use bin/console to access the pry console and add the API URL to the gem's config to be able to correctly test commands:

CertifyMessages.configuration.api_url="http://localhost:3001"

While working in the console, you can run reload! to reload any code in the gem so that you do not have to restart the console. This should not reset the manual edits to the configuration as noted above.

Publishing

To release a new version:

  1. Bump the version in lib/*/version.rb
  2. Merge into master (optional)
  3. Push a tag to GitHub in the form: X.Y.Z or X.Y.Z.pre.myPreReleaseTag

At this point, our CI process will kick-off, run the tests, and push the built gem into our Private Gem server.

Tests

RSpec Tests

To run the test suite, simply run:

rspec

or with verbose output:

rspec -f d

To view the coverage report, open

coverage/index.html

Rubocop

rubocop -D

Poirot Secrets Testing

A secrets pattern file poirot-patterns.txt is included with the app to assist with running Poirot to scan commit history for secrets. It is recommended to run this only the current branch only:

  poirot --patterns poirot-patterns.txt --revlist="develop^..HEAD"

Poirot will return an error status if it finds any secrets in the commit history between HEAD and develop. You can correct these by: removing the secrets and squashing commits or by using something like BFG.

Note that Poirot is hardcoded to run in case-insensitive mode and uses two different regex engines (git log --grep and a 3rd-party Python regex library https://pypi.python.org/pypi/regex/ ). Refer to Lines 121 and 195 in <python_path>/site-packages/poirot/poirot.py. The result is that the 'ssn' matcher will flag on: 'ssn', 'SSN', or 'ssN', etc., which also finds 'className', producing false positive errors in the full rev history. Initially we included the (?c) flag in the SSN matchers: .*(ssn)(?c).*[:=]\s*[0-9-]{9,11} however this is not compatible with all regex engines and causes an error in some cases. During the --revlist="all" full history Poirot runs, this pattern failed silently with the git --grep engine and therefore did not actually run. During the --staged Poirot runs, this pattern fails with a stack trace with the pypi/regex engine. The (?c) pattern has been removed entirely and so the ssn patterns can still flag on false positives like 'className'.

Changelog

Refer to the changelog for details on gem updates. CHANGELOG

License

Certify Message is licensed permissively under the Apache License v2.0. A copy of that license is distributed with this software.

Contributing

We welcome contributions. Please read CONTRIBUTING for how to contribute.

Code Of Conduct

We strive for a welcoming and inclusive environment for the Certify Message project.

Please follow this guidelines in all interactions:

  1. Be Respectful: use welcoming and inclusive language.
  2. Assume best intentions: seek to understand other's opinions.

Security Issues

Please do not submit an issue on GitHub for a security vulnerability. Please contact the development team through the Certify Help Desk at [email protected].

Be sure to include all the pertinent information.

The agency reserves the right to change this policy at any time.

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.