Code Monkey home page Code Monkey logo

pyresponse's Introduction

pyresponse

PureResponseClient
Python API wrapper for PureResponse PAINT

MIT License
Copyright (c) 2013 Mikael Kohlmyr, Triggered Messaging Ltd
[email protected]

Triggered Messaging,
Pure360

Examples

Import

from pyresponse import PureResponseClient as PureResponseClient

========== Initialise

pureresponse = PureResponseClient()

========== Authenticate

pureresponse.authenticate('username', 'password')

========== Create list

# with single record
pureresponse.create_list('new_list_name', 
                         {'email': '[email protected]', 'name': 'John Doe'})
# with multiple records
pureresponse.create_list('new_list_name', 
                         [{'email': '[email protected]', 'name': 'John Doe'}, 
                          {'email': '[email protected]', 'name': 'Jane Doe'}])

========== Add people to list

# single record
pureresponse.add_person('new_list_name', 
                        {'email': '[email protected]', 
                         'name': 'John Doe'})
# multiple records
pureresponse.add_people('new_list_name', 
                        [{'email': '[email protected]', 'name': 'John Doe'}, 
                         {'email': '[email protected]', 'name': 'Jane Doe'}])

========== Create message

pureresponse.create_message('new_message_name', 
                            'subject line', 
                            '<h1>Headline</h1><p>body of text</p>')

========== Send single message

pureresponse.send_to_person('new_message_name', '[email protected]')

========== Send campaign message

pureresponse.send_to_list('new_message_name', 'new_list_name')

========== Get person

# by email address
pureresponse.person_by_email('[email protected]')
# by person id
pureresponse.person_by_id('555555555')

========== Get list

# by list name
pureresponse.list_by_name('new_list_name')
# by list id
pureresponse.list_by_id('555555')

========== Get message

# by message name
pureresponse.message_by_name('new_message_name')
# by message id
pureresponse.message_by_id('555555')

For more readily available api calls, see helpers.py

========== Using constants

# e.g.
>>> pureresponse.Message.ID
'messageId'
>>> pureresponse.Upload.TYPE
'uploadTransactionType'
# for more constants see ./lib/core.py

========== Using core methods

# e.g.
# replicating behaviour of pureresponse.person_by_id('555555555')
pureresponse.api_core.load(pureresponse.Class.CAMPAIGN_PERSON, 
                           {pureresponse.Person.ID: '555555555'})
# replicating behaviour of pureresponse.person_by_email('[email protected]')
search_params = {pureresponse.Person.EMAIL: '[email protected]'}
loaded = pureresponse.api_core.load_search(pureresponse.Class.CAMPAIGN_PERSON, 
                                           search_params)
person = pureresponse.api_core.filter_loaded(loaded, search_params, None)
result = person[0] if len(person) else None
# both methods will return the same structure (a person record)

========== Putting calls together

# in this call we use an output filter on pureresponse.list_by_name, 
# instead of returning a list record, it will return a list id
key_filter = pureresponse.Filters.key_filter(pureresponse.List.ID)
my_list_id = pureresponse.list_by_name('my_list_name', 
                                       output_filter=key_filter)
# again we are using an output filter, this time we output only 
# the set of filter names rather than the set of full filter records
key_filter = pureresponse.Filters.key_filter(pureresponse.Filter.NAME)
list_filter_names = pureresponse.filters_for_list_id(my_list_id, 
                                                     output_filter=key_filter)

========== Output filters
An output filter is a closure where the inner function will operate on a dictionary "candidate" and return some subset of the information within

# e.g.
# reimplementing pureresopnse.Filters.key_filter
# only returns the value of the field (key) being filtered on
def key_filter(key):
    def closed(candidate):
        return candidate.get(key)
    return closed

Concepts and Internals

PureResponse Application Interface (PAINT)
PAINT is an interface to PureResponse which is accessed through the Simple Object Access Protocol.
However, unlike in a traditional SOAP implementation, all calls are made to the same handler which then dispatches calls internally to PureResponse. This means different calls are distinguished based on parameters which specify what data to operate on and how to operate on it, e.g. bus_facade_campaign_list and create.

context = self.api_context or self.api_translator.null()
bean = Core.Type.FACADE + '_' + bean_class
entity_data = self.api_translator.ensuds(entity_data)
process_data = self.api_translate.ensuds(process_data)
response = self.api_client.service.handleRequest(context,
                                                 bean,
                                                 bean_proc,
                                                 entity_data,
                                                 process_data)
result = self.api_translator.desuds(response)

========== Beans
The term bean is used in PureResponse to refer to logical entities that contain or manage data, not unlike objects.

Bean type Prefix Description
Entity bus_entity The representations of the core data in PureResponse.
Facade bus_facade Proxies for accessing and manipulating Entity and Search beans.
Search bus_search Define how entities are searchable and format results.

In essence all calls are made to a bus_facade beans and from there bus_entity and bus_search beans are used or manipulated.

========== Request queues
Some requests, such as creating lists and adding person records to lists are stored in request queues inside PureResponse rather than being executed immediately. This means you can not rely on processing for such tasks being finished when you do the next one. In cases like these, pyresponse will raise a Core.PendingError. A common example of where this might cause issues is if you upload many people to a list individually with little or no time between requests.

pyresponse's People

Contributors

dhendo avatar jake314159 avatar

Watchers

 avatar  avatar

pyresponse's Issues

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.