Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about google oauth client_id #50

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
56ae457
Updated schema to support parsing phone number when participant type …
wingc-china Feb 17, 2016
062eced
Added invitation status and updated test JSON file accordingly. Proto…
wingc-china Feb 17, 2016
71f7761
Add delivery medium information to be sent with message when replying…
wingc-china Feb 17, 2016
330a844
Introduced a new field BooleanField in pblite.coffee and used in new …
wingc-china Feb 19, 2016
29fc9b3
Merge branch 'ready-for-pr'
wingc-china Feb 20, 2016
ac646dd
Added a new method to get entity by phone number in e164. It could be…
wingc-china Feb 26, 2016
ec0dc83
Merged from ready-for-pr
wingc-china Apr 13, 2016
c3bb30b
Added some informaiton of image attachment from my investigation.
wingc-china Apr 13, 2016
0e0b15c
Added some informaiton of image attachment from my investigation.
wingc-china Apr 13, 2016
96c4f40
Added the necessary schema objects and the DictField class to be able…
Apr 14, 2016
8649cb4
Code review feedback
Apr 18, 2016
9b53287
Added a test for EMBED_ITEM
Apr 19, 2016
95cf4c6
Merge branch 'master' of https://github.com/algesten/hangupsjs
wingc-china Apr 19, 2016
d976367
Get rid of example of attachment as comment in code. The coffee-scrip…
wingc-china Apr 19, 2016
bb265dc
Merged with Evan's change to have photo attachment parsed out.
wingc-china Apr 19, 2016
d2aa2c0
Added a new method that takes file buffer as paramter directly to upl…
wingc-china May 27, 2016
37f6d3d
Merged with remote change.
wingc-china Nov 17, 2016
647e942
Merge remote-tracking branch 'upstream/master'
wingc-china Nov 17, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/client.coffee
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,15 @@ module.exports = class Client extends EventEmitter
max_results
]

# Return information from a phone number in e164
getentitybyphonenumber: (e164) ->
@chatreq.req('contacts/getentitybyid', [
@_requestBodyHeader()
None
[[null, null, null, e164, null, true]],
[1, 2]
], false).then (body) ->
CLIENT_GET_ENTITY_BY_ID_RESPONSE.parse body

# Return information about a list of chat_ids
getentitybyid: (chat_ids) ->
Expand Down Expand Up @@ -567,6 +576,44 @@ module.exports = class Client extends EventEmitter
log.debug 'image resume upload finished'
body?.sessionStatus?.additionalInfo?['uploader_service.GoogleRupioAdditionalInfo']?.completionInfo?.customerSpecificInfo?.photoid

# Uploads an image as buffer that can be later attached to a chat message.
#
# buffer is the buffer that contains the image file content.
#
# filename is the name of the file.
#
# returns an image_id that can be used in sendchatmessage
uploadimagebuffer: (buffer, filename, timeout=30000) =>
size = buffer.length;
puturl = null
chatreq = @chatreq
log.debug 'image resume upload prepare'
chatreq.baseReq IMAGE_UPLOAD_URL, 'application/x-www-form-urlencoded;charset=UTF-8'
, {
protocolVersion: "0.8"
createSessionRequest:
fields: [{
external: {
filename,
size,
put: {},
name: 'file'
}
}]
}
.then (body) ->
puturl = body?.sessionStatus?.externalFieldTransfers?[0]?.putInfo?.url
log.debug 'image resume upload to:', puturl
.then () ->
log.debug 'image resume uploading'
chatreq.baseReq puturl, 'application/octet-stream', buffer, true, timeout
.then (body) ->
log.debug 'image resume upload finished'
return Q.resolve body?.sessionStatus?.additionalInfo?['uploader_service.GoogleRupioAdditionalInfo']?.completionInfo?.customerSpecificInfo?.photoid
.fail (err) ->
log.error 'uploadImageBuffer failed', err
Q.reject err

# aliases list
aliases = [
'logLevel',
Expand All @@ -590,7 +637,8 @@ aliases = [
'searchEntities',
'getEntityById',
'sendEasteregg',
'uploadImage'
'uploadImage',
'uploadImageBuffer'
]

# set aliases
Expand Down
16 changes: 15 additions & 1 deletion src/pblite.coffee
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ class EnumField
return k for k, v of @enms when input == v
return {}

class DictField
constructor: (dict) ->
return new DictField(dict) unless this instanceof DictField
@dict = dict
parse: (input) ->
return null unless input
return null if input == undefined
input = input.toString() if input instanceof Buffer
obj = if typeis input, 'string' then eval input else input
out = {}
for prop, val of @dict
out[prop] = val.parse obj[prop] if obj[prop]
out

class RepeatedField
constructor: (field) ->
return new RepeatedField(field) unless this instanceof RepeatedField
Expand Down Expand Up @@ -53,4 +67,4 @@ class Message
out[k] = v.parse val if k
out

module.exports = {Field, BooleanField, EnumField, RepeatedField, Message}
module.exports = {Field, BooleanField, EnumField, DictField, RepeatedField, Message}
60 changes: 54 additions & 6 deletions src/schema.coffee
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{Field, BooleanField, EnumField, RepeatedField, Message} = require './pblite'
{Field, BooleanField, EnumField, DictField, RepeatedField, Message} = require './pblite'

s = {}

Expand Down Expand Up @@ -61,19 +61,29 @@ s.ClientConversationStatus =
ACTIVE : 2
LEFT : 3


s.MessageActionType =

NONE : 0
ME_ACTION : 4


s.SegmentType =

TEXT : 0
LINE_BREAK : 1
LINK : 2

s.ItemType =

THING : 0
PLUS_PHOTO : 249 # Google Plus Photo
PLACE : 335 # Google Map Place
PLACE_V2 : 340 # Google Map Place v2

s.MediaType =

MEDIA_TYPE_UNKNOWN : 0
MEDIA_TYPE_PHOTO : 1
MEDIA_TYPE_ANIMATED_PHOTO : 4

s.MembershipChangeType =

Expand Down Expand Up @@ -258,11 +268,47 @@ s.MESSAGE_SEGMENT = Message([
])
])

s.PLUS_PHOTO_THUMBNAIL = Message([
'url', Field()
None, Field()
None, Field()
'image_url', Field()
None, Field()
None, Field()
None, Field()
None, Field()
None, Field()
'width_px', Field()
'height_px', Field()
])

s.PLUS_PHOTO = Message([
'thumbnail', s.PLUS_PHOTO_THUMBNAIL
'owner_obfuscated_id', Field()
'album_id', Field()
'photo_id', Field()
None, Field()
'url', Field()
None, Field()
None, Field()
None, Field()
'original_content_url', Field()
None, Field()
None, Field()
'media_type', EnumField(s.MediaType)
'stream_id', RepeatedField(Field())
])

# Special numbers make up the property names of things in the embedded item
s.EMBED_ITEM = DictField({
'27639957': s.PLUS_PHOTO,
'35825640': Field() # not supporting maps yet
})

s.MESSAGE_ATTACHMENT = Message([
'embed_item', Message([
# 249 (PLUS_PHOTO), 340, 335, 0
'type_', RepeatedField(Field())
'data', Field() # can be a dict
'type', RepeatedField(EnumField(s.ItemType))
'data', s.EMBED_ITEM # this is a dictionary, which is like an ordinary object that has members that need to be looked up using a tag number
])
])

Expand Down Expand Up @@ -469,6 +515,8 @@ s.CLIENT_GET_ENTITY_BY_ID_RESPONSE = Message([
None, Field() # 'cgebirp'
'response_header', s.CLIENT_RESPONSE_HEADER
'entities', RepeatedField(s.CLIENT_ENTITY)
'unknown', RepeatedField(Message([None, Field()
'entities', RepeatedField(s.CLIENT_ENTITY)]))
])

module.exports = s
12 changes: 11 additions & 1 deletion test/test-initparse.coffee
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ deql = assert.deepEqual

{CLIENT_GET_SELF_INFO_RESPONSE
INITIAL_CLIENT_ENTITIES,
CLIENT_CONVERSATION_STATE_LIST} = require '../src/schema'
CLIENT_CONVERSATION_STATE_LIST,
EMBED_ITEM} = require '../src/schema'

msg1 = ["cgsirp",[1,null,"","1950326504872917925",1430493729941000],[null,null,null,null,null,null,null,[1,0,[],null,null,null,null,null,[[]]],["102224360723365489932","102224360723365489932"],[1,"Bo Tenström","Bo","//lh5.googleusercontent.com/-99B0CMsSo68/AAAAAAAAAAI/AAAAAAAAABI/v8oOeHFwNSI/photo.jpg",["botenstrom2@gmail.com"],[],null,null,null,null,null,2,[],[]],null,null,2,null,0,0,0],0,[],[0,null,0],[0],[[],[],2],[[8,0],[9,1],[22,0],[19,1],[10,1],[11,1],[14,0],[20,0],[17,0],[16,0],[23,0],[24,0],[27,0],[5,1],[6,1],[1,0],[2,1],[7,1],[3,1],[4,1],[29,1],[13,0],[12,0],[15,0],[28,0]],[1],1,[1,1],[null,[],[[5,0],[4,0],[2,0],[6,1],[1,0],[3,1]]],1,1,0,2,[],1,["SE",46],[],null,[1]]

Expand Down Expand Up @@ -33,3 +34,12 @@ describe 'CLIENT_CONVERSATION_STATE_LIST', ->

it 'parses', ->
deql CLIENT_CONVERSATION_STATE_LIST.parse(msg3), cmp3

msg4 = { "27639957": [["https://plus.google.com/photos/albums/p16geqve3h5t3tqdn4odhtha2j5lqkale?pid=6275042227379600450&oid=103730981268153889186", null, null, "https://lh3.googleusercontent.com/-QUwpEWamKew/VxVtqMGJfEI/AAAAAAAAAFM/jeRZI6e_DUIZkUVdhXoNbQNiY8UxBGvwwCK8B/s0/2016-04-18.jpg", null, null, null, null, null, 768, 401], "103730981268153889186", "6272415246136908337", "6275042227379600450", null, "https://lh3.googleusercontent.com/-QUwpEWamKew/VxVtqMGJfEI/AAAAAAAAAFM/jeRZI6e_DUIZkUVdhXoNbQNiY8UxBGvwwCK8B/s0/2016-04-18.jpg", null, null, null, "https://lh3.googleusercontent.com/nUIH-qp7Cgeei1PAAdirnxrtS2Ryc6A2Tai2gzOdR0oIAPxhIj9BtSkTkYQWxalPvr4", null, null, 1, ["shared_group_6275042227379600450", "BABEL_STREAM_ID", "BABEL_UNIQUE_ID_1e30efc4-8f46-4f58-ab52-c2b8ec77a3a7"]] }

cmp4 = {"27639957":{"album_id":"6272415246136908337","media_type":"MEDIA_TYPE_PHOTO","original_content_url":"https://lh3.googleusercontent.com/nUIH-qp7Cgeei1PAAdirnxrtS2Ryc6A2Tai2gzOdR0oIAPxhIj9BtSkTkYQWxalPvr4","owner_obfuscated_id":"103730981268153889186","photo_id":"6275042227379600450","stream_id":["shared_group_6275042227379600450","BABEL_STREAM_ID","BABEL_UNIQUE_ID_1e30efc4-8f46-4f58-ab52-c2b8ec77a3a7"],"thumbnail":{"height_px":401,"image_url":"https://lh3.googleusercontent.com/-QUwpEWamKew/VxVtqMGJfEI/AAAAAAAAAFM/jeRZI6e_DUIZkUVdhXoNbQNiY8UxBGvwwCK8B/s0/2016-04-18.jpg","url":"https://plus.google.com/photos/albums/p16geqve3h5t3tqdn4odhtha2j5lqkale?pid=6275042227379600450&oid=103730981268153889186","width_px":768},"url":"https://lh3.googleusercontent.com/-QUwpEWamKew/VxVtqMGJfEI/AAAAAAAAAFM/jeRZI6e_DUIZkUVdhXoNbQNiY8UxBGvwwCK8B/s0/2016-04-18.jpg"}}

describe 'EMBED_ITEM', ->

it 'parses', ->
deql EMBED_ITEM.parse(msg4), cmp4