Giter Site home page Giter Site logo

iky / nameko-salesforce Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nameko/nameko-salesforce

0.0 2.0 0.0 77 KB

A Nameko extension with entrypoints for handling Salesforce Streaming API events and a dependency provider for easy communication with Salesforce REST API.

License: Other

Makefile 0.27% Python 99.73%

nameko-salesforce's Introduction

https://travis-ci.org/Overseas-Student-Living/nameko-salesforce.svg?branch=extract-from-internal-salesforce-lib

Nameko Salesforce

A Nameko extension with entrypoints for handling Salesforce Streaming API events and a dependency provider for easy communication with Salesforce REST API.

The Streaming API extension is based on Nameko Cometd Bayeux Client and the REST API dependency id based on Simple Salesforce.

Quick Start

Create a service which handles Salesforce Contact objects changes and also has an RPC endpoint for creating new Contact objects in Salesforce.

# service.py

from nameko.rpc import rpc
from nameko_salesforce.streaming import handle_sobject_notification
from nameko_salesforce.api import SalesforceAPI

class Service:

    name = 'some-service'

    salesforce = SalesforceAPI()

    @handle_sobject_notification('Contact', exclude_current_user=False)
    def handle_contact_updates(
        self, sobject_type, record_type, notification
    ):
    """ Handle Salesforce contacts updates
    """
    print(notification)

    @rpc
    def create_contact(self, last_name, email_address):
    """ Create a contact in Salesforce
    """
    self.salesforce.Contact.create(
        {'LastName': last_name,'Email': email_address})

Create a config file with essential settings:

# config.yaml

AMQP_URI: 'pyamqp://guest:guest@localhost'
SALESFORCE:
    USERNAME: ${SALESFORCE_USERNAME}
    PASSWORD: ${SALESFORCE_PASSWORD}
    SECURITY_TOKEN: ${SALESFORCE_SECURITY_TOKEN}
    SANDBOX: False

Run the service providing your Salesforce credentials:

$ SALESFORCE_USERNAME=rocky \
  SALESFORCE_PASSWORD=*** \
  SALESFORCE_SECURITY_TOKEN=*** \
  nameko run --config config.yaml service

Finally, open another shell and call the RPC endpoint to create a new user:

$ nameko shell --config config.yaml
In [1]: n.rpc['some-service'].create_contact('Yo', '[email protected]')

You should see a new contact created in Salesforce and your service should get a notification. In the first shell you'll find the notification printed:

{'event': {'replayId': 1, 'type': 'created' ...

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.