Skip to content

Commit

Permalink
Working on API call methods for Google PLus
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishal-Sahu committed Feb 25, 2012
1 parent 0323988 commit 481c0fd
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 8 deletions.
28 changes: 27 additions & 1 deletion grails-app/services/org/grails/plugins/GooglePlusService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import org.grails.plugins.googlePlus.GooglePlusData
import org.grails.plugins.googlePlus.Person.Person
import java.security.PublicKey
import org.grails.plugins.googlePlus.People
import grails.converters.JSON
import org.grails.plugins.googlePlus.Person.Image
import org.grails.plugins.googlePlus.Person.Name
import org.grails.plugins.googlePlus.GooglePlusException

class GooglePlusService {

static transactional = true

public String accessToken = ''
public String accessToken = 'ya29.AHES6ZTVl8pWlBmc4WH3G77rHgiHW6pFj8zerYVDiGCiQw'

private static final String BASE_URL = "https://www.googleapis.com/plus/"

Expand All @@ -19,9 +23,31 @@ class GooglePlusService {
return googlePlusData
}

void setAccessToken(String accessToken) {
this.accessToken = accessToken
}


public Person getCurrentUserProfile() {
Person person
try {
URL url = new URL("https://www.googleapis.com/oauth2/v1/userinfo?access_token=${accessToken}")
def jsonString = JSON.parse(url?.text)
person = Person.parseJSONForPerson(jsonString)
} catch (GooglePlusException e) {
e.printStackTrace()
}
return person
}

public People getPersonsList() {
People people = new People()
return people
}

// def apiCall(String accessToken) {
//
//
// URL url = new URL("${BASE_URL}${url}&acce")
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package org.grails.plugins.googlePlus.Activity

class Embed {
String url
String type
String type
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.plugins.googlePlus.Activity

class Plusoners {

Integer totalItems
String selfLink
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.plugins.googlePlus.Activity

class Replies {

Integer totalItems
String selfLink
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.plugins.googlePlus.Activity

class Resharers {

Integer totalItems
String selfLink
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.grails.plugins.googlePlus.Comment
import org.grails.plugins.googlePlus.Activity.Actor

class Comment {

String kind
String etag
String id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.plugins.googlePlus.Comment

class CommentObject {

String objectType
String content
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.plugins.googlePlus.Comment

class InReplyTo {

String id
String url
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.grails.plugins.googlePlus.Person

class LanguageSpoken {

String value
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.plugins.googlePlus.Person

class Name {

String formatted
String familyName
String givenName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.plugins.googlePlus.Person

public enum ObjectType {

PERSON('person'),
PAGE('page')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.grails.plugins.googlePlus.Person

class Organization {


String name
String department
String title
Expand Down
29 changes: 24 additions & 5 deletions src/groovy/org/grails/plugins/googlePlus/Person/Person.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package org.grails.plugins.googlePlus.Person

class Person {


String id
String etag
String displayName
Person.Name name
Name name
String nickname
String tagLine
String birthday
Expand All @@ -15,11 +14,31 @@ class Person {
String currentLocation
String relationshipStatus
String url
Person.Image image
List<Person.Email> emails = []
String locale
Image image
List<Email> emails = []
List<Url> urls = []
List<Organization> organizations = []
List<PlaceLived> placesLived = []
List<Person.LanguageSpoken> languagesSpoken = []
List<LanguageSpoken> languagesSpoken = []


static Person parseJSONForPerson(def json) {
Person person = new Person()
person.id = json?.id
person.displayName = json?.name
person.gender = json?.gender
person.locale = json?.locale
person.url = json?.link
Image image = new Image()
image.url = json?.picture
person.image = image
Name name = new Name()
name.familyName = json?.family_name
name.givenName = json?.given_name
name.middleName = json?.middle_name
person.name = name
return person
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.grails.plugins.googlePlus.Person

class PlaceLived {

String value
Boolean primary
}

0 comments on commit 481c0fd

Please sign in to comment.