You are on page 1of 26

SnapLogic Snap Developer Tutorials

Document Release: May 2012

SnapLogic, Inc. 71 East Third Avenue San Mateo, California 94401 U.S.A.

www.snaplogic.com

Copyright Information 2012 SnapLogic, Inc. All Rights Reserved. Terms and conditions, pricing, and other information subject to change without notice. SnapLogic and SnapStore are among the trademarks of SnapLogic, Inc. All other product and company names and marks mentioned are the property of their respective owners and are mentioned for identification purposes only. SnapLogic is registered in the U.S. and Trademark Office.

Table of Contents
SnapLogic Snap Developer Tutorials Table of Contents Overview The Snap Development Model Types of Snaps Parts of a Snap Outline of Snap Creation Designing Connectivity Snaps Building a Peer Reader Component Building a Twitter Timeline Reader Component 1 3 5 5 5 6 6 9 11 19

-3-

SnapLogic Snap Developer Tutorials

-4-

1
Overview
Snaps are add-ons for the SnapLogic integration framework that are packaged for easy installation and distribution. These Snaps are usually sold through the SnapStore, but can also be distributed within an organization as private Snaps. In this tutorial, you will walk through the steps involved in creating a complete Snap, from the high level design down to the code and packaging. The Snap will add Twitter capabilities to SnapLogic. Twitter has a simple API and is easy to understand, while it's complex enough to highlight common patterns in Snap development.

The Snap Development Model


Developing Snaps for the SnapLogic platform is a straightforward process. Although Snaps vary in complexity and functionality, all Snaps follow the same pattern, use the same APIs, and take advantage of the common functions provided by the SnapLogic platform. However, developing Snaps is not the same as using SnapLogic. As a SnapLogic user, you are creating resources and assembling Pipelines from existing Components and resources you have already created. You are focusing on data flow and manipulation, not the lower level details. As a Snap developer, you have to view the problem differently. Rather than thinking about how to use existing capabilities, you have to view things from the perspective of how you can create Components and resources that others can use. In order to gain that perspective, a good Snap developer has to be familiar with using SnapLogic first, and must understand the main elements of SnapLogic: Resources and Components
l l l

Pipelines Data Services Data types

(If you're just getting started with SnapLogic, you should read the SnapLogic user tutorials first, become familiar with the basic concepts, and then come back here.)

Types of Snaps
There are two general categories of Snaps:
l l

Connectivity Snaps Solution Snaps

-5-

SnapLogic Snap Developer Tutorials Connectivity Snaps add connectivity to an application or data source. The SalesForce.com, NetSuite, and SugarCRM Snaps are examples of this type of Snap. These Snaps normally include new Components that access the application API, and translate it to the SnapLogic API. Solution Snaps are higher level Snaps which implement the business logic for a specific integration scenario, such as 'quote to bill' between a CRM system and a financial system. Solution Snaps normally include Pipeline and resource definitions that implement business logic. They might also include Components, or might depend on connectivity Components provided by another Snap. This Twitter Snap will be a connectivity Snap; it will add Twitter read and write capabilities to SnapLogic, but will not provide any predefined Pipeline logic to process Tweets for a specific purpose.

Parts of a Snap
A Snap is composed of three parts:
l l l

Pipelines and Resources Components An installation program

All Snaps include an installation program. Connectivity Snaps will include primarily Components and resources, while solutions Snaps will be oriented towards Pipelines and resources. Since this tutorial builds a connectivity Snap, you will include an installer, Components, and some resources to get the users started.

Outline of Snap Creation


l l l l

Designing Connectivity Snaps Building a Peer Reader Component Building a Twitter Timeline Reader Component Building a Writer Component
l l l

Defining capabilities Defining output views Execution

Building a Transformer Component


l l l

Defining capabilities Defining views Execution

-6-

Overview
l

Packaging Snaps for distribution


l

Snap installer

Adding coolness
l l l

Implementing Suggest Implementing pass-through Error handling

Advanced packaging
l l

Including predefined resources Generating resources automatically

See Also
l l l

Submitting the Snap to the SnapLogic SnapStore Creating a Custom Component in Java Creating a Custom Component in Python

-7-

SnapLogic Snap Developer Tutorials

-8-

2
Designing Connectivity Snaps
The first step in designing a Snap is to shift perspective to being a potential user of the Snap. How will someone use your Snap? Use your knowledge of the application and how it's commonly integrated, to determine what should be exposed through your Snap, what should be handled with the existing platform capabilities, and how the Snap will fit into the data flow model. Some of the questions you should ask yourself are:
l l l l l l l

Which application objects should be exposed as data? What data access is needed? What data needs to be read? What data needs to be written or updated? What application functions might need to be called? What transformations are likely to be used with the data? What utility functions from the application should be exposed?

Based the answers to those questions, you can start creating a model of the Snap. Some of these capabilities will require new Components, others can be handled by creating Pipelines or resources. In general, a connectivity Snap will include a reader Component and a writer Component. There might also be one or two function Components. For example, in CRM integration, the 'convert' functionality isn't a data source or target, and is best implemented as a transformation or utility function. In this case, you have to decide how to expose Twitter, and how to translate that into Components others can use. Start with the Twitter API documentation to see what can be done. The Twitter API exposes a lot of functionality. However, much of that functionality is oriented towards building interactive Twitter clients. Since the users of this Snap are more likely to be interested in bulk data processing with Twitter, you want to expose the following Twitter data objects:
l l l l l l

Lists of friends Lists of followers Featured users Public timeline of tweets Tweets from a single user Tweets from a user's friends

-9-

SnapLogic Snap Developer Tutorials Most of this data is intended to be read. You may also want to write (post) tweets, individually or as a stream, so you will also implement that capability. Since Twitter supports reading user profile information, this tutorial will support that as well. Note: This tutorial does not implement any of the functions for managing Twitter profiles and attributes, since that is limited to an individual Twitter account, and would rarely be a batch operation. The operations you'll be exposing from Twitter are basic reading and writing; there are no application 'functions' that will be exposed (unlike the CRM 'convert' function.) For data transformation, most of the operations the users will want are basic data movement, and string or date processing. These can easily be handled by the existing transformations in SnapLogic. However, you will be adding a capability to make Twitter data processing simpler - parsing of the actual Twitter text into words and categories. This involves some natural language processing that isn't really data flow oriented, so it's best if you provide this as a separate utility function. In the end, this implementation of a Twitter Snap will include four Components:
l l l l l

A Twitter Peer Reader for friend, follower, and user lists. A Twitter Timeline Reader for reading actual tweets. A Twitter Search Component for reading search results. A Twitter Writer for posting tweets. A Tweet profiler for parsing and categorizing tweet text.

The decision to create four Components is influenced by how you want to create views, how you intend to manage properties, and general organization of the code for maintainability. Keep reading, and those decisions will become clearer as you drill into the implementation.

- 10 -

3
Building a Peer Reader Component
Components are implemented as Python or Java classes, which are derived from the SnapLogic Component API class. The SnapLogic Component API documentation contains all the information about the interface calls available to a Component author. Java class documentation can be found in the <version>/doc directory of the SnapLogic installation. Apart from the necessary language specific differences, the Component API for Java and Python components is the same. I am going to implement the essentials in this tutorial. You can also refer to the Creating a Component documentation for more detail on Component development. This tutorial uses Python for the Twitter Snap. Start with the peer reader Component, which will read lists of friends and followers from Twitter. There are several functions this Component will need to implement, as well as some boilerplate code needed for all components:
l l l l l l

Defining capabilities Defining a resource templates Defining properties Defining input views Validation Execution

Start with an empty template for the Component: from decimal import Decimal from urllib2 import HTTPError from snaplogic.common.snap_exceptions import SnapComponentError, SnapComponentConfigError from snaplogic.cc.component_api import ComponentAPI import snaplogic.cc.prop as prop from snaplogic.common import version_info from snaplogic.common.data_types import SnapString, SnapNumber, SnapDateTime from snaplogic.snapi_base import keys import twitter class PeerRead(ComponentAPI): ''' SnapLogic component that reads twitter peers - friends and followers ''' api_version = '1.0'

- 11 -

SnapLogic Snap Developer Tutorials component_version = '1.0' component_label = 'Twitter Peer Reader' component_description = 'Reads Twitter friends and followers timelines' #component_doc_uri = # 'https://www.snaplogic.org/trac/wiki/Documentation/%s/ComponentRef/' % \ # version_info % version_info.doc_uri_version capabilities = { ComponentAPI.CAPABILITY_INPUT_VIEW_LOWER_LIMIT ComponentAPI.CAPABILITY_INPUT_VIEW_UPPER_LIMIT ComponentAPI.CAPABILITY_OUTPUT_VIEW_LOWER_LIMIT ComponentAPI.CAPABILITY_OUTPUT_VIEW_UPPER_LIMIT } def __init__(self): pass def logmsg(self, msg): """Convenience method for logging a message.""" self.log(snap_log.LEVEL_INFO, msg) def debug(self, msg): """Convenience method for logging a debug message.""" self.log(snap_log.LEVEL_DEBUG, msg) def create_resource_template(self): pass

: : : :

0, 0, 1, 1,

def validate(self, err_obj): pass def suggest_resource_values(self, err_obj): pass def validate_runtime(self): """validation checks that are valid at design time and run time """ pass def execute(self, input_views, output_views): self.output_view.completed() # $Id: PeerRead.py 291 2009-05-29 01:01:53Z mikeyp $

- 12 -

Building a Peer Reader Component

from decimal import Decimal from urllib2 import HTTPError from snaplogic.common.snap_exceptions import SnapComponentError, SnapComponentConfigError from snaplogic.cc.component_api import ComponentAPI import snaplogic.cc.prop as prop from snaplogic.common import version_info from snaplogic.common.data_types import SnapString, SnapNumber, SnapDateTime from snaplogic.snapi_base import keys

import twitter class PeerRead(ComponentAPI): ''' SnapLogic component that reads twitter peers - friends and followers ''' api_version = '1.0' component_version = '1.0' component_label = 'Twitter Peer Reader' component_description = 'Reads Twitter friends and followers timelines' #component_doc_uri = # 'https://www.snaplogic.org/trac/wiki/Documentation/%s/ComponentRef/' % \ # version_info % version_info.doc_uri_version capabilities = { ComponentAPI.CAPABILITY_INPUT_VIEW_LOWER_LIMIT ComponentAPI.CAPABILITY_INPUT_VIEW_UPPER_LIMIT ComponentAPI.CAPABILITY_OUTPUT_VIEW_LOWER_LIMIT ComponentAPI.CAPABILITY_OUTPUT_VIEW_UPPER_LIMIT } def __init__(self): # The types of peer information we can read, and the functions to handle them self.peer_lists = {'Featured': self.readFeaturedPeers, 'User': self.readSinglePeer, 'Friends': self.readFriends, 'Followers': self.readFollowers } # predefined output view self.output_view_def = (

: : : :

0, 0, 1, 1,

- 13 -

SnapLogic Snap Developer Tutorials ('Id', SnapNumber, 'user ID'), ('Name', SnapString, ''), ('ScreenName', SnapString, ''), ('Location', SnapString, ''), ('Description', SnapString, ''), ('ProfileImageURL', SnapString, ''), ('BackgroundTile' , SnapString, ''), ('BackgroundImageURL' , SnapString, ''), ('ProfileSidebarColor' , SnapString, ''), ('ProfileBackgroundColor', SnapString, ''), ('ProfileLinkColor' , SnapString, ''), ('ProfileTextColor' , SnapString, ''), ('Protected', SnapString, ''), ('UTCOffset', SnapString, ''), ('TimeZone' , SnapString, ''), ('URL', SnapString, ''), ('StatusCount', SnapNumber, ''), ('FollowersCount', SnapNumber, ''), ('FriendsCount', SnapNumber, ''), ('FavouritesCount', SnapNumber, ''), ) def logmsg(self, msg): """Convenience method for logging a message.""" self.log(snap_log.LEVEL_INFO, msg) def debug(self, msg): """Convenience method for logging a debug message.""" self.log(snap_log.LEVEL_DEBUG, msg) def create_resource_template(self): p = prop.SimpleProp('Username', SnapString, 'Twitter user name', None, False) self.set_property_def('AuthUsername', p) p = prop.SimpleProp('Password', SnapString, 'Twitter password', {'obfuscate' : 0}, False) self.set_property_def('AuthPassword', p) p = prop.SimpleProp('Twitter User', SnapString, 'Twitter user of interest, defaults to Username', None, False) self.set_property_def('TwitterUser', p) p = prop.SimpleProp('Peer Information', SnapString, 'Twitter peer data to read',

- 14 -

Building a Peer Reader Component {'lov' : self.peer_lists.keys() }, False) self.set_property_def('PeerInformation', p) self.set_property_value('PeerInformation', 'Followers') self.add_record_output_view_def('Output', self.output_view_def, 'Twitter Peers', False) def validate(self, err_obj): pass def suggest_resource_values(self, err_obj): pass def validate_runtime(self): """validation checks that are valid at design time and run time """ pass def execute(self, input_views, output_views): self.output_view = output_views.values()[keys.SINGLE_VIEW] self.auth_user = self.get_property_value('AuthUsername') self.auth_pw= self.get_property_value('AuthPassword') self.twitter_user = self.get_property_value('TwitterUser') self.t = twitter.Api(self.auth_user, self.auth_pw) self.t.SetXTwitterHeaders('SnapLogic', 'http://www.snaplogic.com', version_info.server_version) self.peerlist_type = self.get_property_value('PeerInformation') self.peer_lists[self.peerlist_type]() def readFeaturedPeers(self): raise('NotImplemented') def readSinglePeer(self): raise('NotImplemented') def readFriends(self): try: for user in self.t.iterFriends(user=self.twitter_user, count=None):

- 15 -

SnapLogic Snap Developer Tutorials out_record = self.output_view.create_record() out_record['Id'] = Decimal(user.id) out_record['Name'] = unicode(user.name) out_record['ScreenName'] = unicode(user.screen_name) out_record['Location'] = unicode(user.location) out_record['Description'] = unicode(user.description) out_record['ProfileImageURL'] = unicode(user.profile_image_ url) out_record['BackgroundTile'] = unicode(user.profile_ background_tile) out_record['BackgroundImageURL'] = unicode(user.profile_background_image_url) out_record['ProfileSidebarColor'] = unicode(user.profile_sidebar_fill_color) out_record['ProfileBackgroundColor'] = unicode(user.profile_background_color) out_record['ProfileLinkColor'] = unicode(user.profile_link_ color) out_record['ProfileTextColor'] = unicode(user.profile_text_ color) out_record['Protected'] = unicode(user.protected) out_record['UTCOffset'] = unicode(user.utc_offset) out_record['TimeZone'] = unicode(user.time_zone) out_record['URL'] = unicode(user.url) out_record['StatusCount'] = Decimal(user.statuses_count) out_record['FollowersCount'] = Decimal(user.followers_ count) out_record['FriendsCount'] = Decimal(user.friends_count) out_record['FavouritesCount'] = Decimal(user.favourites_ count) self.output_view.write_record(out_record) except HTTPError, e: if e.code == 401: raise SnapComponentError("Failed to log in to twitter ") else: raise (e) self.output_view.completed() def readFollowers(self): try: for user in self.t.iterFollowers(user=self.twitter_user, count=None): out_record = self.output_view.create_record() out_record['Id'] = Decimal(user.id) out_record['Name'] = unicode(user.name)

- 16 -

Building a Peer Reader Component out_record['ScreenName'] = unicode(user.screen_name) out_record['Location'] = unicode(user.location) out_record['Description'] = unicode(user.description) out_record['ProfileImageURL'] = unicode(user.profile_image_ url) out_record['BackgroundTile'] = unicode(user.profile_ background_tile) out_record['BackgroundImageURL'] = unicode(user.profile_background_image_url) out_record['ProfileSidebarColor'] = unicode(user.profile_sidebar_fill_color) out_record['ProfileBackgroundColor'] = unicode(user.profile_background_color) out_record['ProfileLinkColor'] = unicode(user.profile_link_ color) out_record['ProfileTextColor'] = unicode(user.profile_text_ color) out_record['Protected'] = unicode(user.protected) out_record['UTCOffset'] = unicode(user.utc_offset) out_record['TimeZone'] = unicode(user.time_zone) out_record['URL'] = unicode(user.url) out_record['StatusCount'] = Decimal(user.statuses_count) out_record['FollowersCount'] = Decimal(user.followers_ count) out_record['FriendsCount'] = Decimal(user.friends_count) out_record['FavouritesCount'] = Decimal(user.favourites_ count) self.output_view.write_record(out_record) except HTTPError, e: if e.code == 401: raise SnapComponentError("Failed to log in to twitter ") else: raise (e) self.output_view.completed()

- 17 -

SnapLogic Snap Developer Tutorials

- 18 -

4
Building a Twitter Timeline Reader Component
# $Id: StatusRead.py 291 2009-05-29 01:01:53Z mikeyp $ from decimal import Decimal from urllib2 import HTTPError import datetime import twitter from snaplogic.common.snap_exceptions import SnapComponentError, SnapComponentConfigError from snaplogic.cc.component_api import ComponentAPI import snaplogic.cc.prop as propfrom snaplogic.common import version_ info from snaplogic.common.data_types import SnapString, SnapNumber, SnapDateTime from snaplogic.snapi_base import keys class StatusRead(ComponentAPI): ''' SnapLogic component that reads twitter status updates ''' api_version = '1.0' component_version = '1.0' component_label = 'Twitter Status Reader' component_description = 'Reads Twitter statuses and timelines' #component_doc_uri = # 'https://www.snaplogic.org/trac/wiki/Documentation/%s/ComponentRef/' % \ # version_info % version_info.doc_uri_version capabilities = { ComponentAPI.CAPABILITY_INPUT_VIEW_LOWER_LIMIT ComponentAPI.CAPABILITY_INPUT_VIEW_UPPER_LIMIT ComponentAPI.CAPABILITY_OUTPUT_VIEW_LOWER_LIMIT ComponentAPI.CAPABILITY_OUTPUT_VIEW_UPPER_LIMIT } def __init__(self): self.timelines = {'Public': self.readPublicTimeline, 'User': self.readUserTimeline,

: : : :

0, 0, 1, 1,

- 19 -

SnapLogic Snap Developer Tutorials 'Friends': self.readFriendsTimeline, 'Single': self.readStatus, } 'The types of timelines we can read, and the functions to handle them' self.output_view_def = ( ('CreatedAt', SnapDateTime, 'Time of the Tweet '), ('TweetId', SnapNumber, 'Tweet ID '), ('Tweet', SnapString, 'The Tweet'), ('UserId', SnapNumber, 'Twitter user ID'), ('UserScreenName', SnapString, 'Twitter user screen name'), ('ReplyToId', SnapNumber, 'Reply to Tweet ID'), ('ToUserId', SnapNumber, 'Reply to Twitter user ID'), ('ToUserScreenName', SnapString, 'Reply to Twitter screen name'), ('Source', SnapString, 'Origin of the Tweet'), ('Location', SnapString, 'Location of the Tweet'), ('MinId', SnapNumber, 'The minimum Tweet id returned so far'), ('MaxId', SnapNumber, 'The maximum Tweet id returned so far'), ) 'predefined output view' def logmsg(self, msg): """Convenience method for logging a message.""" self.log(snap_log.LEVEL_INFO, msg) def debug(self, msg): """Convenience method for logging a debug message.""" self.log(snap_log.LEVEL_DEBUG, msg) def create_resource_template(self): p = prop.SimpleProp('Username', SnapString, 'Twitter user name', None, False) self.set_property_def('AuthUsername', p) p = prop.SimpleProp('Password', SnapString, 'Twitter password', {'obfuscate' : 0}, False) self.set_property_def('AuthPassword', p) p = prop.SimpleProp('Timeline', SnapString, 'Twitter timeline to read', {'lov' : self.timelines.keys() }, False) self.set_property_def('Timeline', p) self.set_property_value('Timeline', 'Public') p = prop.SimpleProp('Twitter User', SnapString, 'Twitter user of interest, defaults to Username ', None,

- 20 -

Building a Twitter Timeline Reader Component False) self.set_property_def('TwitterUser', p) p = prop.SimpleProp('After Id', SnapString, 'Read statuses with id greater than this.', None, False) self.set_property_def('SinceId', p) p = prop.SimpleProp('Before Id', SnapString, 'Read statuses with id less than or equal to this.', None, False) self.set_property_def('MaxId', p) self.add_record_output_view_def('Output', self.output_view_def, 'Twitter Tweets', False) def validate(self, err_obj): """validation checks that are valid at design time and run time """ # validation notes # public timeline accepts since # friends, user might require login # public timeline: since id # friends timeline: since id, since (date) # user timeline: : since id , since (date) public # single : since id , # XXX python-twitter supports dates, not documented in API? # XXX what is the precedence for since/max id, since they are # mutually exclusive pass def suggest_resource_values(self, err_obj): pass def validate_runtime(self): """validation checks which are deferred to run time """ pass def execute(self, input_views, output_views): self.output_view = output_views.values()[keys.SINGLE_VIEW] self.auth_user = self.get_property_value('AuthUsername') self.auth_pw= self.get_property_value('AuthPassword') self.twitter_user = self.get_property_value('TwitterUser')

- 21 -

SnapLogic Snap Developer Tutorials if self.twitter_user is None or len(self.twitter_user) == 0: self.twitter_user = self.auth_user self.timeline_type = self.get_property_value('Timeline') self.since_id = self.get_property_value('SinceId') self.max_id = self.get_property_value('MaxId') self.validate_runtime() self.t = twitter.Api(self.auth_user, self.auth_pw) self.t.SetXTwitterHeaders('SnapLogic', 'http://www.snaplogic.com', version_info.server_version) self.timelines[self.timeline_type]()

def readUserTimeline(self): """ proces timeline for an individual user """ try: for stat, min, max in \ self.t.iterUserTimeline(user=self.twitter_user, count=None, since_id=self.since_id, max_id = self.max_id): out_record = self.output_view.create_record() # <created_at> Wed Apr 22 10:33:40 +0000 2009 out_record['CreatedAt'] =\ datetime.datetime.strptime(stat.created_at, '%a %b %d %H:%M:%S +0000 %Y') out_record['TweetId'] = Decimal(stat.id) out_record['Tweet'] = unicode(stat.text) out_record['UserId'] = Decimal(stat.user.id) out_record['UserScreenName'] = unicode(stat.user.screen_name) if (stat.in_reply_to_status_id) is None: out_record['ReplyToId'] = None else: out_record['ReplyToId'] = Decimal(stat.in_reply_to_status_id) if (stat.in_reply_to_user_id is None): out_record['ToUserId'] = None else: out_record['ToUserId'] = Decimal(stat.in_reply_to_user_id) if (stat.in_reply_to_screen_name is None): out_record['ToUserScreenName'] = None else: out_record['ToUserScreenName'] = unicode(stat.in_reply_to_screen_name) out_record['Source'] = unicode(stat.source) out_record['Location'] = unicode(stat.user.location) out_record['MinId'] = Decimal(min) out_record['MaxId'] = Decimal(max)

- 22 -

Building a Twitter Timeline Reader Component self.output_view.write_record(out_record) except HTTPError, e: if e.code == 401: raise SnapComponentError("Failed to log in to twitter ") else: raise (e) self.output_view.completed() def readPublicTimeline(self): """ process the public timeline """ try: for stat, min, max in \ self.t.iterPublicTimeline(count=None, since_id=self.since_id): out_record = self.output_view.create_record() # <created_at> Wed Apr 22 10:33:40 +0000 2009 out_record['CreatedAt'] =\ datetime.datetime.strptime(stat.created_at, '%a %b %d %H:%M:%S +0000 %Y') out_record['TweetId'] = Decimal(stat.id) out_record['Tweet'] = unicode(stat.text) out_record['UserId'] = Decimal(stat.user.id) out_record['UserScreenName'] = unicode(stat.user.screen_name) if (stat.in_reply_to_status_id) is None: out_record['ReplyToId'] = None else: out_record['ReplyToId'] = Decimal(stat.in_reply_to_status_id) if (stat.in_reply_to_user_id is None): out_record['ToUserId'] = None else: out_record['ToUserId'] = Decimal(stat.in_reply_to_user_id) if (stat.in_reply_to_screen_name is None): out_record['ToUserScreenName'] = None else: out_record['ToUserScreenName'] = unicode(stat.in_reply_to_screen_name) out_record['Source'] = unicode(stat.source) out_record['Location'] = unicode(stat.user.location) out_record['MinId'] = Decimal(min) out_record['MaxId'] = Decimal(max) self.output_view.write_record(out_record) except HTTPError, e: if e.code == 401: raise SnapComponentError("Failed to log in to twitter ") else: raise (e) self.output_view.completed()

- 23 -

SnapLogic Snap Developer Tutorials

def readFriendsTimeline(self): try: for stat, min, max in \ self.t.iterFriendsTimeline(count=None,user=self.twitter_user, since_id=self.since_id): out_record = self.output_view.create_record() # <created_at> Wed Apr 22 10:33:40 +0000 2009 out_record['CreatedAt'] =\ datetime.datetime.strptime(stat.created_at, '%a %b %d %H:%M:%S +0000 %Y') out_record['TweetId'] = Decimal(stat.id) out_record['Tweet'] = unicode(stat.text) out_record['UserId'] = Decimal(stat.user.id) out_record['UserScreenName'] = unicode(stat.user.screen_name) if (stat.in_reply_to_status_id) is None: out_record['ReplyToId'] = None else: out_record['ReplyToId'] = Decimal(stat.in_reply_to_status_id) if (stat.in_reply_to_user_id is None): out_record['ToUserId'] = None else: out_record['ToUserId'] = Decimal(stat.in_reply_to_user_id) if (stat.in_reply_to_screen_name is None): out_record['ToUserScreenName'] = None else: out_record['ToUserScreenName'] = unicode(stat.in_reply_to_screen_name) out_record['Source'] = unicode(stat.source) out_record['Location'] = unicode(stat.user.location) out_record['MinId'] = Decimal(min) out_record['MaxId'] = Decimal(max) self.output_view.write_record(out_record) except HTTPError, e: if e.code == 401: raise SnapComponentError("Failed to log in to twitter ") else: raise (e) self.output_view.completed() def readStatus(self): pass

- 24 -

Index
C
connectivity Snaps designing 9

S
Snaps designing connectivity Snaps 9 development model 5 parts 6 types 5

- 25 -

SnapLogic Snap Developer Tutorials

- 26 -

You might also like