Dreamstime

Tuesday 29 November 2016

Integrating Google's API Client Library Into The RavenPlus Source Code Repository

There is this problem with us programmers. We will not complain and will happily chug along when confronted with the toughest programming challenge ever. But when it comes to documenting our work, we will make excuses, drag our feet and create various alibi. I remember this joke that I've heard about programmers some 20 years ago:

"if it is so hard to write, it must be even harder to describe"

Yes, we programmers understand this perfectly. But still there should be no excuses for not documenting one's work; and this is something that I should bear in mind - always.

Unfortunately, I do get sloppy sometimes. Case in point:

I briefly mentioned that I might be integrating the "Google API Client Library for Python version 1.2" into RavenPlus some 11 months ago. Well in the end, I actually did.

Problem is now I can't remember why I made this decision. I can faintly recall problems I had between 'py2exe' and the newly installed libraries needed for Google OAuth2 authentication (most of them is installed, by default, in the '.egg' format).

Is this the main reason? I can't remember. If only I have written the reason down earlier - somewhere.

New Sub-Directory

Google's API Client Library Within the Raven+ Source Code Repository

Integrating the Google API Client Library for Python into RavenPlus is rather simple. All I did was to bung it under the blog publishing sub-system of RavenPlus at 'zoundry/blogpub'. Naming the new directory as 'blogger' seems appropriate and all Google Blogger's OAuth2 related modifications in RavenPlus (by me) are placed here and below its sub-directories; and this includes the picture uploading capabilities to Google's PicasaWeb ('zoundry/blogpub/blogger/gdataExtend' is where the modified gdata API resides).

The directories 'apiclient', 'oauth2client' and 'uritemplate', circled in RED in the picture above, are from the Google API Client Library itself. As mentioned previously, I only used a subset of this Client Library from Google.

More Edits - Pointing To The Right Library

Rather laborious but there are additional (and essential modifications) that must be made to the now localised API Client Library files found under 'zoundry/blogpub/blogger'. RavenPlus should use this localised API 'library' now rather than the one found in the standard Python library.

Note that it's not a bad idea to uninstall the Google API Client Library from the standard Python library, like what I did, (unless if you need them for your other Python projects of course). Otherwise, confusion may ensue.

Listed below are the details of the modifications that I have made.

1. Directory Name: zoundry/blogpub/blogger/apiclient

1.1 discovery.py

Replace these lines found beginning at line 55:


import uritemplate
from apiclient.errors import HttpError
from apiclient.errors import InvalidJsonError
from apiclient.errors import MediaUploadSizeError
from apiclient.errors import UnacceptableMimeTypeError
from apiclient.errors import UnknownApiNameOrVersion
from apiclient.errors import UnknownFileType
from apiclient.http import HttpRequest
from apiclient.http import MediaFileUpload
from apiclient.http import MediaUpload
from apiclient.model import JsonModel
from apiclient.model import MediaModel
from apiclient.model import RawModel
from apiclient.schema import Schemas
from oauth2client.anyjson import simplejson
from oauth2client.util import _add_query_parameter
from oauth2client.util import positional

with these:


from zoundry.blogpub.blogger import uritemplate
from zoundry.blogpub.blogger.apiclient.errors import HttpError
from zoundry.blogpub.blogger.apiclient.errors import InvalidJsonError
from zoundry.blogpub.blogger.apiclient.errors import MediaUploadSizeError
from zoundry.blogpub.blogger.apiclient.errors import UnacceptableMimeTypeError
from zoundry.blogpub.blogger.apiclient.errors import UnknownApiNameOrVersion
from zoundry.blogpub.blogger.apiclient.errors import UnknownFileType
from zoundry.blogpub.blogger.apiclient.http import HttpRequest
from zoundry.blogpub.blogger.apiclient.http import MediaFileUpload
from zoundry.blogpub.blogger.apiclient.http import MediaUpload
from zoundry.blogpub.blogger.apiclient.model import JsonModel
from zoundry.blogpub.blogger.apiclient.model import MediaModel
from zoundry.blogpub.blogger.apiclient.model import RawModel
from zoundry.blogpub.blogger.apiclient.schema import Schemas
from zoundry.blogpub.blogger.oauth2client.anyjson import simplejson
from zoundry.blogpub.blogger.oauth2client.util import _add_query_parameter
from zoundry.blogpub.blogger.oauth2client.util import positional

1.2 errors.py

Replace these lines found beginning at line 26:


from oauth2client import util
from oauth2client.anyjson import simplejson

with these:


from zoundry.blogpub.blogger.oauth2client import util
from zoundry.blogpub.blogger.oauth2client.anyjson import simplejson

1.3 http.py

Replace these lines found beginning at line 55:


from errors import BatchError
from errors import HttpError
from errors import InvalidChunkSizeError
from errors import ResumableUploadError
from errors import UnexpectedBodyError
from errors import UnexpectedMethodError
from model import JsonModel
from oauth2client import util
from oauth2client.anyjson import simplejson

with these:


from zoundry.blogpub.blogger.apiclient.errors import BatchError
from zoundry.blogpub.blogger.apiclient.errors import HttpError
from zoundry.blogpub.blogger.apiclient.errors import InvalidChunkSizeError
from zoundry.blogpub.blogger.apiclient.errors import ResumableUploadError
from zoundry.blogpub.blogger.apiclient.errors import UnexpectedBodyError
from zoundry.blogpub.blogger.apiclient.errors import UnexpectedMethodError
from zoundry.blogpub.blogger.apiclient.model import JsonModel
from zoundry.blogpub.blogger.oauth2client import util
from zoundry.blogpub.blogger.oauth2client.anyjson import simplejson

1.4 model.py

Replace these lines found beginning at line 30:


from apiclient import __version__
from errors import HttpError
from oauth2client.anyjson import simplejson

with these:


from zoundry.blogpub.blogger.apiclient import __version__
from zoundry.blogpub.blogger.apiclient.errors import HttpError
from zoundry.blogpub.blogger.oauth2client.anyjson import simplejson

1.5 schema.py

Replace these lines (found beginning at line 66):


from oauth2client import util
from oauth2client.anyjson import simplejson

with these:

from zoundry.blogpub.blogger.oauth2client import util
from zoundry.blogpub.blogger.oauth2client.anyjson import simplejson

2. Directory Name: zoundry/blogpub/blogger/oauth2client

2.1 client.py

Replace this lines found at line 23:


import clientsecrets

and these lines found at line 34:


from oauth2client import GOOGLE_AUTH_URI
from oauth2client import GOOGLE_REVOKE_URI
from oauth2client import GOOGLE_TOKEN_URI
from oauth2client import util
from oauth2client.anyjson import simplejson

with these:


from zoundry.blogpub.blogger.oauth2client import clientsecrets
from zoundry.blogpub.blogger.oauth2client import GOOGLE_AUTH_URI
from zoundry.blogpub.blogger.oauth2client import GOOGLE_REVOKE_URI
from zoundry.blogpub.blogger.oauth2client import GOOGLE_TOKEN_URI
from zoundry.blogpub.blogger.oauth2client import util
from zoundry.blogpub.blogger.oauth2client.anyjson import simplejson


2.2 clientsecrets.py

Replace this line found at line 24:


from anyjson import simplejson

with this:


from zoundry.blogpub.blogger.oauth2client.anyjson import simplejson


2.3 crypt.py

Replace this line found at line 23:


from anyjson import simplejson


with this:


from zoundry.blogpub.blogger.oauth2client.anyjson import simplejson


2.4 file.py

Replace these lines found beginning at line 27:


from anyjson import simplejson
from client import Storage as BaseStorage
from client import Credentials

with these:


from zoundry.blogpub.blogger.oauth2client.anyjson import simplejson
from zoundry.blogpub.blogger.oauth2client.client import Storage as BaseStorage
from zoundry.blogpub.blogger.oauth2client.client import Credentials


2.5 old_run.py

Replace these lines found beginning at line 26:


from oauth2client import client
from oauth2client import util
from tools import ClientRedirectHandler
from tools import ClientRedirectServer

with these:


from zoundry.blogpub.blogger.oauth2client import client
from zoundry.blogpub.blogger.oauth2client import util
from zoundry.blogpub.blogger.oauth2client.tools import ClientRedirectHandler
from zoundry.blogpub.blogger.oauth2client.tools import ClientRedirectServer


2.6 tools.py

Replace these lines found beginning at line 35:


from oauth2client import client
from oauth2client import file
from oauth2client import util

with these:


from zoundry.blogpub.blogger.oauth2client import client
from zoundry.blogpub.blogger.oauth2client import file
from zoundry.blogpub.blogger.oauth2client import util




0 comments:

Post a Comment