Editorial Workflows

Pocket Auth 1

unlisted workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: Part 1 of Pocket authentication. See mirimage.ca for full explanation of workflow.

Comments: Comment Feed (RSS)

Online sellers of cialis and viagra — 11 Jul 2014
vugiafejupsjbm.bqq, New drug cialis, QwLwubz, Viagra or cialis, FuPiItF, Female viagra, JFqjDYy, Cialis soft tabs half, KHiQkkg, What do viagra and cialis do if taken together, SfmAMBD, Cialis prices, HODheeZ.
Natural viagra alternatives — 12 Jul 2014
vmidkfejupsjbm.bqq, Generic viagra without prescription, oRCDPGB.
Where to buy viagra online — 14 Jul 2014
lkvnffejupsjbm.bqq, Natural viagra alternatives, JUJAzfl, Visual effects of viagra, KwlSDsN, Cheap viagra tablets, XxZDelD, Viagria vs cialis, dpJGdpF, Venta de cialis, TKulrJW, Alternative to viagra, ujukKAa.
Johnb593 — 04 Aug 2014
Keep working ,impressive job! ddkecekgckkk
Johng156 — 04 Aug 2014
I loved your blog article. Really Cool. eadegddegkdf
Johne313 — 04 Aug 2014
I appreciate, cause I found just what I was looking for. You have ended my 4 day long hunt! God Bless you man. Have a nice day. Bye kaakdagfbeaf
Johnd59 — 05 Aug 2014
It's a mammoth playground built of mountains, hills, lakes, defgekgaeegc
Johna65 — 05 Aug 2014
Hi, everything is going well here and ofcourse every one is sharing information, that's really fine, keep up writing. kefbegkbdgbg
unrpvp — 19 Aug 2014
edqpyoww
Johnd208 — 30 Aug 2014
Hello my family member! I want to say that this article is amazing, great written and come with almost all significant infos. Id like to peer extra posts like this . kddckgdaddcd
Johne316 — 30 Aug 2014
Enjoyed examining this, very good stuff, thankyou. Talk sense to a fool and he calls you foolish. by Euripides. keaggcgegbef
Johnk779 — 15 Sep 2014
I dugg some of you post as I cogitated they were very useful extremely helpful kbeeeaaaedac
Johnd998 — 23 Sep 2014
It is actually a nice and helpful piece of information. I am happy that you simply shared this helpful information with us. Please stay us informed like this. Thank you for sharing. geedcebbeedd
Johng882 — 02 Oct 2014
Fckin amazing things here. Im very glad to see your post. Thanks a lot and i'm looking forward to contact you. Will you kindly drop me a mail? bebkbkcffkfc
Johnd629 — 02 Oct 2014
I like this post, enjoyed this one thankyou for posting . eegbdgdgdkff
mrdwmahocv — 26 Oct 2014
joraofejupsjbm.bqq, wblhrrkmeh
Efren — 13 Feb 2018
best over the counter diet pills
best diet pills for weight loss
best weight loss products
best prescription weight loss medication
weight loss drug

+ Add Comment

Workflow Preview
Run Python Script ?
Source Code
# Editorial Pocket workflow by Jillian Crossley
# Python API wrapper from:https://github.com/tapanpandita/pocket
# Enter your developer key below.
# Change the redirect url if you change the name of the Pocket Auth 2 workflow


consumer_key ='Enter your developer key here'
redirect_uri = 'editorial://?command=Pocket%20Part%202'

import requests
import json
from functools import wraps


class PocketException(Exception):
    '''
    Base class for all pocket exceptions
    http://getpocket.com/developer/docs/errors

    '''
    pass


class InvalidQueryException(PocketException):
    pass


class AuthException(PocketException):
    pass


class RateLimitException(PocketException):
    '''
    http://getpocket.com/developer/docs/rate-limits

    '''
    pass


class ServerMaintenanceException(PocketException):
    pass

EXCEPTIONS = {
    400: InvalidQueryException,
    401: AuthException,
    403: RateLimitException,
    503: ServerMaintenanceException,
}


def method_wrapper(fn):

    @wraps(fn)
    def wrapped(self, *args, **kwargs):
        arg_names = list(fn.func_code.co_varnames)
        arg_names.remove('self')
        kwargs.update(dict(zip(arg_names, args)))

        url = self.api_endpoints[fn.__name__]
        payload = dict([(k, v) for k, v in kwargs.iteritems() if v is not None])
        payload.update(self._payload)

        return self._make_request(url, payload)

    return wrapped


def bulk_wrapper(fn):

    @wraps(fn)
    def wrapped(self, *args, **kwargs):
        arg_names = list(fn.func_code.co_varnames)
        arg_names.remove('self')
        kwargs.update(dict(zip(arg_names, args)))

        wait = kwargs.get('wait', True)
        query = dict(
            [(k, v) for k, v in kwargs.iteritems() if v is not None]
        )
        #TODO: Fix this hack
        query['action'] = 'add' if fn.__name__ == 'bulk_add' else fn.__name__

        if wait:
            self._bulk_query.append(query)
            return self
        else:
            url = self.api_endpoints['send']
            payload = {
                'actions': [query],
            }
            payload.update(self._payload)
            return self._make_request(url, json.dumps(payload), headers={'content-type': 'application/json'})

    return wrapped


class Pocket(object):
    '''
    This class implements a basic python wrapper around the pocket api. For a
    detailed documentation of the methods and what they do please refer the
    official pocket api documentation at http://getpocket.com/developer/docs/overview

    '''
    api_endpoints = dict(
        (method, 'https://getpocket.com/v3/%s' % method)
        for method in "add,send,get".split(",")
    )

    statuses = {
        200: 'Request was successful',
        400: 'Invalid request, please make sure you follow the '
             'documentation for proper syntax',
        401: 'Problem authenticating the user',
        403: 'User was authenticated, but access denied due to lack of '
             'permission or rate limiting',
        503: 'Pocket\'s sync server is down for scheduled maintenance.',
    }

    def __init__(self, consumer_key, access_token):
        self.consumer_key = consumer_key
        self.access_token = access_token
        self._bulk_query = []

        self._payload = {
            'consumer_key': self.consumer_key,
            'access_token': self.access_token,
        }

    @classmethod
    def _make_request(cls, url, payload, headers=None):
        r = requests.post(url, data=payload, headers=headers)
        if r.status_code > 399:
            error_msg = cls.statuses.get(r.status_code)
            extra_info = r.headers.get('X-Error')
            raise EXCEPTIONS.get(r.status_code, PocketException)(
                '%s. %s' % (error_msg, extra_info)
            )
        return r.json()

    @method_wrapper
    def add(self, url, title=None, tags=None, tweet_id=None):
        '''
        This method allows you to add a page to a user's list.
        In order to use the /v3/add endpoint, your consumer key must have the
        "Add" permission.
        http://getpocket.com/developer/docs/v3/add

        '''

    @method_wrapper
    def get(
        self, state=None, favorite=None, tag=None, contentType=None,
        sort=None, detailType=None, search=None, domain=None, since=None,
        count=None, offset=None
    ):
        '''
        This method allows you to retrieve a user's list. It supports
        retrieving items changed since a specific time to allow for syncing.
        http://getpocket.com/developer/docs/v3/retrieve

        '''

    @method_wrapper
    def send(self, actions):
        '''
        This method allows you to make changes to a user's list. It supports
        adding new pages, marking pages as read, changing titles, or updating
        tags. Multiple changes to items can be made in one request.
        http://getpocket.com/developer/docs/v3/modify

        '''

    @bulk_wrapper
    def bulk_add(
        self, item_id, ref_id=None, tags=None, time=None, title=None,
        url=None, wait=True
    ):
        '''
        Add a new item to the user's list
        http://getpocket.com/developer/docs/v3/modify#action_add

        '''

    @bulk_wrapper
    def archive(self, item_id, time=None, wait=True):
        '''
        Move an item to the user's archive
        http://getpocket.com/developer/docs/v3/modify#action_archive

        '''

    @bulk_wrapper
    def readd(self, item_id, time=None, wait=True):
        '''
        Re-add (unarchive) an item to the user's list
        http://getpocket.com/developer/docs/v3/modify#action_readd

        '''

    @bulk_wrapper
    def favorite(self, item_id, time=None, wait=True):
        '''
        Mark an item as a favorite
        http://getpocket.com/developer/docs/v3/modify#action_favorite

        '''

    @bulk_wrapper
    def unfavorite(self, item_id, time=None, wait=True):
        '''
        Remove an item from the user's favorites
        http://getpocket.com/developer/docs/v3/modify#action_unfavorite

        '''

    @bulk_wrapper
    def delete(self, item_id, time=None, wait=True):
        '''
        Permanently remove an item from the user's account
        http://getpocket.com/developer/docs/v3/modify#action_delete

        '''

    @bulk_wrapper
    def tags_add(self, item_id, tags, time=None, wait=True):
        '''
        Add one or more tags to an item
        http://getpocket.com/developer/docs/v3/modify#action_tags_add

        '''

    @bulk_wrapper
    def tags_remove(self, item_id, tags, time=None, wait=True):
        '''
        Remove one or more tags from an item
        http://getpocket.com/developer/docs/v3/modify#action_tags_remove

        '''

    @bulk_wrapper
    def tags_replace(self, item_id, tags, time=None, wait=True):
        '''
        Replace all of the tags for an item with one or more provided tags
        http://getpocket.com/developer/docs/v3/modify#action_tags_replace

        '''

    @bulk_wrapper
    def tags_clear(self, item_id, time=None, wait=True):
        '''
        Remove all tags from an item.
        http://getpocket.com/developer/docs/v3/modify#action_tags_clear

        '''

    @bulk_wrapper
    def tag_rename(self, item_id, old_tag, new_tag, time=None, wait=True):
        '''
        Rename a tag. This affects all items with this tag.
        http://getpocket.com/developer/docs/v3/modify#action_tag_rename

        '''

    def commit(self):
        '''
        This method executes the bulk query, flushes stored queries and
        returns the response

        '''
        url = self.api_endpoints['send']
        payload = {
            'actions': self._bulk_query,
        }
        payload.update(self._payload)
        self._bulk_query = []

        return self._make_request(url, json.dumps(payload), headers={'content-type': 'application/json'})

    @classmethod
    def get_request_token(
        cls, consumer_key, redirect_uri='http://example.com/', state=None
    ):
        '''
        Returns the request token that can be used to fetch the access token

        '''
        headers = {
            'X-Accept': 'application/json',
        }
        url = 'https://getpocket.com/v3/oauth/request'
        payload = {
            'consumer_key': consumer_key,
            'redirect_uri': redirect_uri,
        }
        

       	if state:
           payload['state'] = state
           
        return cls._make_request(url, payload, headers)['code']
  
    @classmethod
    def get_access_token(cls, consumer_key, code):
        '''
        Fetches access token from using the request token and consumer key

        '''
        headers = {
            'X-Accept': 'application/json',
        }
        url = 'https://getpocket.com/v3/oauth/authorize'
        payload = {
            'consumer_key': consumer_key,
            'code': code,
        }
        return cls._make_request(url, payload, headers)#[0]['access_token']

    @classmethod
    def get_auth_url(cls, code, redirect_uri='http://example.com'):
        auth_url = 'https://getpocket.com/auth/authorize?request_token=%s&redirect_uri=%s' % (code, redirect_uri)
        return auth_url

    @classmethod
    def auth(cls, consumer_key, redirect_uri='http://example.com/', state=None):
        '''
        This is a test method for verifying if oauth worked
        http://getpocket.com/developer/docs/authentication

        '''
        code = cls.get_request_token(consumer_key, redirect_uri, state)

        auth_url = 'https://getpocket.com/auth/authorize?request_token=%s&redirect_uri=%s' % (code, redirect_uri)
        raw_input('Please open %s in your browser to authorize the app and press enter:' % auth_url)

        return cls.get_access_token(consumer_key, code)
        
import workflow

request_token = Pocket.get_request_token(consumer_key)
workflow.set_output(request_token)
Set Variable ?
Variable Name
request_token
Value
Input
Set File Contents ?
File Name
pocket_request_token
In Dropbox
OFF
New Text
request_token
If File Does Not Exist
  • Create
  • Stop Workflow
Run Python Script ?
Source Code
import requests
import json
from functools import wraps


class PocketException(Exception):
    '''
    Base class for all pocket exceptions
    http://getpocket.com/developer/docs/errors

    '''
    pass


class InvalidQueryException(PocketException):
    pass


class AuthException(PocketException):
    pass


class RateLimitException(PocketException):
    '''
    http://getpocket.com/developer/docs/rate-limits

    '''
    pass


class ServerMaintenanceException(PocketException):
    pass

EXCEPTIONS = {
    400: InvalidQueryException,
    401: AuthException,
    403: RateLimitException,
    503: ServerMaintenanceException,
}


def method_wrapper(fn):

    @wraps(fn)
    def wrapped(self, *args, **kwargs):
        arg_names = list(fn.func_code.co_varnames)
        arg_names.remove('self')
        kwargs.update(dict(zip(arg_names, args)))

        url = self.api_endpoints[fn.__name__]
        payload = dict([(k, v) for k, v in kwargs.iteritems() if v is not None])
        payload.update(self._payload)

        return self._make_request(url, payload)

    return wrapped


def bulk_wrapper(fn):

    @wraps(fn)
    def wrapped(self, *args, **kwargs):
        arg_names = list(fn.func_code.co_varnames)
        arg_names.remove('self')
        kwargs.update(dict(zip(arg_names, args)))

        wait = kwargs.get('wait', True)
        query = dict(
            [(k, v) for k, v in kwargs.iteritems() if v is not None]
        )
        #TODO: Fix this hack
        query['action'] = 'add' if fn.__name__ == 'bulk_add' else fn.__name__

        if wait:
            self._bulk_query.append(query)
            return self
        else:
            url = self.api_endpoints['send']
            payload = {
                'actions': [query],
            }
            payload.update(self._payload)
            return self._make_request(url, json.dumps(payload), headers={'content-type': 'application/json'})

    return wrapped


class Pocket(object):
    '''
    This class implements a basic python wrapper around the pocket api. For a
    detailed documentation of the methods and what they do please refer the
    official pocket api documentation at http://getpocket.com/developer/docs/overview

    '''
    api_endpoints = dict(
        (method, 'https://getpocket.com/v3/%s' % method)
        for method in "add,send,get".split(",")
    )

    statuses = {
        200: 'Request was successful',
        400: 'Invalid request, please make sure you follow the '
             'documentation for proper syntax',
        401: 'Problem authenticating the user',
        403: 'User was authenticated, but access denied due to lack of '
             'permission or rate limiting',
        503: 'Pocket\'s sync server is down for scheduled maintenance.',
    }

    def __init__(self, consumer_key, access_token):
        self.consumer_key = consumer_key
        self.access_token = access_token
        self._bulk_query = []

        self._payload = {
            'consumer_key': self.consumer_key,
            'access_token': self.access_token,
        }

    @classmethod
    def _make_request(cls, url, payload, headers=None):
        r = requests.post(url, data=payload, headers=headers)
        print 'in cls'
        print(r)
        print(r.json())

        if r.status_code > 399:
            error_msg = cls.statuses.get(r.status_code)
            extra_info = r.headers.get('X-Error')
            raise EXCEPTIONS.get(r.status_code, PocketException)(
                '%s. %s' % (error_msg, extra_info)
            )
            print 'returning'

        return r.json()

    @method_wrapper
    def add(self, url, title=None, tags=None, tweet_id=None):
        '''
        This method allows you to add a page to a user's list.
        In order to use the /v3/add endpoint, your consumer key must have the
        "Add" permission.
        http://getpocket.com/developer/docs/v3/add

        '''

    @method_wrapper
    def get(
        self, state=None, favorite=None, tag=None, contentType=None,
        sort=None, detailType=None, search=None, domain=None, since=None,
        count=None, offset=None
    ):
        '''
        This method allows you to retrieve a user's list. It supports
        retrieving items changed since a specific time to allow for syncing.
        http://getpocket.com/developer/docs/v3/retrieve

        '''

    @method_wrapper
    def send(self, actions):
        '''
        This method allows you to make changes to a user's list. It supports
        adding new pages, marking pages as read, changing titles, or updating
        tags. Multiple changes to items can be made in one request.
        http://getpocket.com/developer/docs/v3/modify

        '''

    @bulk_wrapper
    def bulk_add(
        self, item_id, ref_id=None, tags=None, time=None, title=None,
        url=None, wait=True
    ):
        '''
        Add a new item to the user's list
        http://getpocket.com/developer/docs/v3/modify#action_add

        '''

    @bulk_wrapper
    def archive(self, item_id, time=None, wait=True):
        '''
        Move an item to the user's archive
        http://getpocket.com/developer/docs/v3/modify#action_archive

        '''

    @bulk_wrapper
    def readd(self, item_id, time=None, wait=True):
        '''
        Re-add (unarchive) an item to the user's list
        http://getpocket.com/developer/docs/v3/modify#action_readd

        '''

    @bulk_wrapper
    def favorite(self, item_id, time=None, wait=True):
        '''
        Mark an item as a favorite
        http://getpocket.com/developer/docs/v3/modify#action_favorite

        '''

    @bulk_wrapper
    def unfavorite(self, item_id, time=None, wait=True):
        '''
        Remove an item from the user's favorites
        http://getpocket.com/developer/docs/v3/modify#action_unfavorite

        '''

    @bulk_wrapper
    def delete(self, item_id, time=None, wait=True):
        '''
        Permanently remove an item from the user's account
        http://getpocket.com/developer/docs/v3/modify#action_delete

        '''

    @bulk_wrapper
    def tags_add(self, item_id, tags, time=None, wait=True):
        '''
        Add one or more tags to an item
        http://getpocket.com/developer/docs/v3/modify#action_tags_add

        '''

    @bulk_wrapper
    def tags_remove(self, item_id, tags, time=None, wait=True):
        '''
        Remove one or more tags from an item
        http://getpocket.com/developer/docs/v3/modify#action_tags_remove

        '''

    @bulk_wrapper
    def tags_replace(self, item_id, tags, time=None, wait=True):
        '''
        Replace all of the tags for an item with one or more provided tags
        http://getpocket.com/developer/docs/v3/modify#action_tags_replace

        '''

    @bulk_wrapper
    def tags_clear(self, item_id, time=None, wait=True):
        '''
        Remove all tags from an item.
        http://getpocket.com/developer/docs/v3/modify#action_tags_clear

        '''

    @bulk_wrapper
    def tag_rename(self, item_id, old_tag, new_tag, time=None, wait=True):
        '''
        Rename a tag. This affects all items with this tag.
        http://getpocket.com/developer/docs/v3/modify#action_tag_rename

        '''

    def commit(self):
        '''
        This method executes the bulk query, flushes stored queries and
        returns the response

        '''
        url = self.api_endpoints['send']
        payload = {
            'actions': self._bulk_query,
        }
        payload.update(self._payload)
        self._bulk_query = []

        return self._make_request(url, json.dumps(payload), headers={'content-type': 'application/json'})

    @classmethod
    def get_request_token(
        cls, consumer_key, redirect_uri='http://example.com/', state=None
    ):
        '''
        Returns the request token that can be used to fetch the access token

        '''
        headers = {
            'X-Accept': 'application/json',
        }
        url = 'https://getpocket.com/v3/oauth/request'
        payload = {
            'consumer_key': consumer_key,
            'redirect_uri': redirect_uri,
        }
        

       	if state:
           payload['state'] = state
           
        print('about to call')
        test= cls._make_request(url, payload, headers)['code']
        print 'before return'
        return test

    @classmethod
    def get_access_token(cls, consumer_key, code):
        '''
        Fetches access token from using the request token and consumer key

        '''
        headers = {
            'X-Accept': 'application/json',
        }
        url = 'https://getpocket.com/v3/oauth/authorize'
        payload = {
            'consumer_key': consumer_key,
            'code': code,
        }
        print('here')
        return cls._make_request(url, payload, headers)#[0]['access_token']

    @classmethod
    def get_auth_url(cls, code, redirect_uri='http://example.com'):
        auth_url = 'https://getpocket.com/auth/authorize?request_token=%s&redirect_uri=%s' % (code, redirect_uri)
        return auth_url

    @classmethod
    def auth(cls, consumer_key, redirect_uri='http://example.com/', state=None):
        '''
        This is a test method for verifying if oauth worked
        http://getpocket.com/developer/docs/authentication

        '''
        code = cls.get_request_token(consumer_key, redirect_uri, state)

        auth_url = 'https://getpocket.com/auth/authorize?request_token=%s&redirect_uri=%s' % (code, redirect_uri)
        raw_input('Please open %s in your browser to authorize the app and press enter:' % auth_url)

        return cls.get_access_token(consumer_key, code)
        
#import sys
#sys.path.append('pocket-api')
#import pocket
#from pocket import Pocket
import workflow

consumer_key ='17577-503da823e03dc806bd668afc'
redirect_uri = 'editorial://?command=Pocket%20Auth%202'
auth_url = Pocket.get_auth_url(workflow.get_variable('request_token'), redirect_uri)
action_out = auth_url
workflow.set_output(action_out)
Open URL ?
Open in
  • In-App Browser
  • Default App / Safari
URL
Input
Tab
  • Last-used Tab
  • New Tab
  • Tab with ID:
Unique identifier
Wait until Loaded
OFF
Reveal Browser Automatically
ON