VIAWARN

Massachusetts DOT

Fetching data from Massachusetts DOT with Airbyte and Python.

Description

This Airbyte Connector uses the HTTP API provided by the Massachusetts DOT in Python. With this connector, data is easily pulled from Massachusetts DOT and loaded into the ViaWarn Postgres database, and are available in the ViaWarn app.

The connector is built on top of the Airbyte open-source platform, which provides a standardized way of integrating data sources and destinations. It is designed to be simple and easy to use. The required configuration is show in the the sections below. 

The pulled resources from the Massachusetts DOT API are the following:

Requirements and Installation

Find the requirements and steps to create the connector in the Airbyte documentation.

Customized files

After creating the Airbyte connector template, modify the next files to retrieve data from Massachusetts DOT .

spec.yaml

Location: source-viawarn-us-ma-dot/spec.yaml
Access API: SECURED
In this case, the connector password is specified in the spec file.
spec.yaml:
				
					documentationUrl: https://docsurl.com
connectionSpecification:
  $schema: http://json-schema.org/draft-07/schema#
  title: VIAWARN USA MA DOT - Spec
  description: Credentials obtained from https://api-signup.massgotime.com/
  type: object
  required:
    - username
    - password
    - secret
  properties:
    username:
      type: string
    password:
      type: string
      airbyte_secret: true
    secret:
      type: string
      airbyte_secret: true

				
			

config.json

Location: secrets/config.json
This file is ignore by git.

SECURED

config.json:
				
					{
"username":"[username]"
"password":"[password]"
"secret":"[secret}"
}
				
			

configure_catalog.json

Location: integration_tests/configure_catalog.json
List of Streams that describes the data in the data store that a Source represents. It also declares the sync modes supported by each stream (full refresh or incremental).
configure_catalog.json:
				
					{ 
"streams": 
    [
    {
        "stream": {
            "name": [STREAM_NAME],
            "json_schema": {},
            "supported_sync_modes": ["full_refresh"] 
            },
        "sync_mode": "full_refresh", "destination_sync_mode": "overwrite" 
        } 
    ]
}
				
			

source.py

Location: source-viawarn-ma-dot/source.py

etree_to_dict()
return a nested dictionary from an XML.

class ViawarnUsMaDotAuthenticator()

  • __init__()
This is a constructor method used to initialize the class.  
  • get_token()
Create a token.
return string
  • get_bearer()
Create a string containing the encoded authentication information to connect to the API.

class ViawarnUsMaDotStream()

Create a stream to represent the data that will be pull from the API. It contains all the common API functionalities:
  •  url_base

This field is the common part of the URL for all streams, if it does not exist, add it in each stream method.

String

  • next_page_token()

Pagination is not provided by this API.

return None

  • request_params()

return an empty dictionary

  • parse_response()

It is a placeholder to store the request.response object and constructs the appropriate mapping object for each parsed element by each Stream class.

yields an empty dictionary.

class Event()

This method extends the ViawarnUsMaDotStream() method to specified unique behavior for this stream.
  • primary_key

Unique field required in the stream associate to each output record.

String

  • path()

subdomain to pass into the URL.

return a string

  • parse_response()

Definition of how a response is parsed.

Set a definition to: primary key and ewkt fields.

return an iterable containing each record in the response.

Create classes Sign() and SignInv() similar to Event()

class SourceViawarnUsMaDot()

  • check_connection()

Set up a test to verify the connection between the connector and the API. This test should return two variables: the first one is a boolean that indicates the status of the connection, while the second one shows a log message if the connection fails.

return True, None

  • streams()
Set up the stream in the source that will be parsed.
return List of streams

[STREAM_NAME].json

Location: source-viawarn-us-ma-dot/schemas/[STREAM_NAME].json
Declare schemas for each stream by adding json files. Each file is a JsonSchema describing the output from that stream.
Streams name: event, sign, sign_inv
Previous
Next

support@viawarn.com