Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Work history, education and skills #28

Closed
wants to merge 1 commit into from

3 participants

@sorin

Hello,

First of all, congrats on a very useful and well written library. I'd like to contribute by developing a couple of new features we need:

Hybrid_Provider_Model->getUserWorkHistory()
Hybrid_Provider_Model->getUserEducation()
Hybrid_Provider_Model->getUserSkills()

These would work in a similar way to getUserProfile and getUserContacts. The initial implementation will be for Facebook/Linkedin

See the attached pull request.

Sorin

@mastermunj

@hybridauth, This seems a nice & helpful change. Do you think this could be merged in?

@AdwinTrave
Owner

Might be considered for 3.x branch, but I'm not sure how many people would utilize it.

@sorin

It's been 2 years since the original PR, I no longer use hybridauth (or PHP for that matter), so I dont know if that code even works anymore. If it's useful to anybody, feel free to use it, otherwise delete.

@AdwinTrave AdwinTrave closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 19, 2012
  1. Added work history, education and skills

    Sorin Neacsu authored
This page is out of date. Refresh to see the latest.
View
2  hybridauth/Hybrid/Auth.php 100644 → 100755
@@ -83,6 +83,8 @@ public static function initialize( $config )
require_once $config["path_base"] . "User_Profile.php";
require_once $config["path_base"] . "User_Contact.php";
require_once $config["path_base"] . "User_Activity.php";
+ require_once $config["path_base"] . "User_Work_History.php";
+ require_once $config["path_base"] . "User_Education.php";
// hash given config
Hybrid_Auth::$config = $config;
View
38 hybridauth/Hybrid/Provider_Model.php 100644 → 100755
@@ -131,7 +131,7 @@ function getUserProfile()
*/
function getUserContacts()
{
- Hybrid_Logger::error( "HybridAuth do not provide users contats list for {$this->providerId} yet." );
+ Hybrid_Logger::error( "HybridAuth do not provide users contacts list for {$this->providerId} yet." );
throw new Exception( "Provider does not support this feature.", 8 );
}
@@ -151,6 +151,42 @@ function getUserActivity( $stream )
// --------------------------------------------------------------------
/**
+ * get the user work history
+ */
+ function getUserWorkHistory()
+ {
+ Hybrid_Logger::error( "HybridAuth do not provide users work history for {$this->providerId} yet." );
+
+ throw new Exception( "Provider does not support this feature.", 8 );
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * get the user education
+ */
+ function getUserEducation()
+ {
+ Hybrid_Logger::error( "HybridAuth do not provide users education for {$this->providerId} yet." );
+
+ throw new Exception( "Provider does not support this feature.", 8 );
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * get the user skills
+ */
+ function getUserSkills()
+ {
+ Hybrid_Logger::error( "HybridAuth do not provide users skills for {$this->providerId} yet." );
+
+ throw new Exception( "Provider does not support this feature.", 8 );
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* return the user activity stream
*/
function setUserStatus( $status )
View
95 hybridauth/Hybrid/Providers/Facebook.php 100644 → 100755
@@ -265,4 +265,99 @@ function getUserActivity( $stream )
return $activities;
}
+
+ /**
+ * get the user work history
+ */
+ public function getUserWorkHistory()
+ {
+ try {
+ $response = $this->api->api('/me?fields=work');
+ } catch (FacebookApiException $e) {
+ throw new Exception("User work history request failed! {$this->providerId} returned an error: $e");
+ }
+
+ if (!$response || !count($response["work"])) {
+ return ARRAY();
+ }
+
+ $workHistory = array();
+ foreach ($response["work"] as $item){
+ $wh = new Hybrid_User_Work_History();
+ if (array_key_exists('position', $item) && array_key_exists('name', $item['position'])){
+ $wh->position = $item['position']['name'];
+ }
+ if (array_key_exists('employer', $item) && array_key_exists('name', $item['employer'])){
+ $wh->employer = $item['employer']['name'];
+ }
+ if (array_key_exists('location', $item) && array_key_exists('name', $item['location'])){
+ $wh->location = $item['location']['name'];
+ }
+ if (array_key_exists('start_date', $item)){
+ $t = strtotime($item['start_date']);
+ $wh->startYear = date('Y', $t);
+ $wh->startMonth = date('m', $t);
+ }
+ if (array_key_exists('end_date', $item)){
+ $t = strtotime($item['end_date']);
+ $wh->endYear = date('Y', $t);
+ $wh->endMonth = date('m', $t);
+ }
+ if (array_key_exists('description', $item)){
+ $wh->description = $item['description'];
+ }
+ $workHistory[] = $wh;
+ }
+
+ return $workHistory;
+ }
+
+ /**
+ * get the user education
+ */
+ public function getUserEducation()
+ {
+ try {
+ $response = $this->api->api('/me?fields=education');
+ } catch (FacebookApiException $e) {
+ throw new Exception("User education request failed! {$this->providerId} returned an error: $e");
+ }
+
+ $educations = array();
+
+ if (!$response || !count($response["education"])){
+ return $educations;
+ }
+
+ foreach ($response["education"] as $item) {
+ $edu = new Hybrid_User_Education();
+ if (array_key_exists('school', $item) && array_key_exists('name', $item['school'])){
+ $edu->school = $item['school']['name'];
+ }
+ if (array_key_exists('degree', $item) && array_key_exists('name', $item['degree'])){
+ $edu->degree = $item['degree']['name'];
+ }
+ if (array_key_exists('year', $item) && array_key_exists('name', $item['year'])){
+ $edu->endYear = $item['year']['name'];
+ }
+ //concentration is an array
+ if (array_key_exists('concentration', $item) && count($item['concentration'])){
+ $concentrations = array();
+ foreach ($item['concentration'] as $c){
+ if (array_key_exists('name', $c)){
+ $concentrations[] = $c['name'];
+ }
+ }
+ $edu->field = implode(', ', $concentrations);
+ }
+ if (array_key_exists('type', $item)){
+ $edu->type = $item['type'];
+ }
+
+ $educations[] = $edu;
+ }
+
+ return $educations;
+ }
+
}
View
115 hybridauth/Hybrid/Providers/LinkedIn.php 100644 → 100755
@@ -241,4 +241,119 @@ function getUserActivity( $stream )
return $activities;
}
+
+ /**
+ * get the user work history
+ */
+ public function getUserWorkHistory()
+ {
+ try {
+ // http://developer.linkedin.com/docs/DOC-1061
+ $response = $this->api->profile('~:(positions)');
+ } catch (LinkedInException $e) {
+ throw new Exception("User work history request failed! {$this->providerId} returned an error: $e", 6);
+ }
+
+ if (isset($response['success']) && $response['success'] === TRUE){
+ $positions = @ new SimpleXMLElement($response['linkedin']);
+
+ if (!is_object($positions)){
+ throw new Exception("User work history request failed! {$this->providerId} returned an invalid xml data.", 6);
+ }
+
+ $workHistory = array();
+ foreach ($positions->positions->position as $position){
+ $wh = new Hybrid_User_Work_History();
+ $wh->position = (string) $position->title;
+ $wh->employer = (string) $position->company->name;
+ $wh->description = (string) $position->summary;
+ if( $position->{'start-date'}){
+ $wh->startDay = (string) $position->{'start-date'}->day;
+ $wh->startMonth = (string) $position->{'start-date'}->month;
+ $wh->startYear = (string) $position->{'start-date'}->year;
+ }
+ if( $position->{'end-date'} ) {
+ $wh->endDay = (string) $position->{'end-date'}->day;
+ $wh->endMonth = (string) $position->{'end-date'}->month;
+ $wh->endYear = (string) $position->{'end-date'}->year;
+ }
+ $workHistory[] = $wh;
+ }
+
+ return $workHistory;
+ }else{
+ throw new Exception("User work history request failed! {$this->providerId} returned an invalid response.", 6);
+ }
+ }
+
+ /**
+ * get the user education
+ */
+ public function getUserEducation()
+ {
+ try{
+ // http://developer.linkedin.com/docs/DOC-1061
+ $response = $this->api->profile('~:(educations)');
+ } catch (LinkedInException $e) {
+ throw new Exception("User education request failed! {$this->providerId} returned an error: $e", 6);
+ }
+
+ if (isset($response['success']) && $response['success'] === TRUE) {
+ $educations = @ new SimpleXMLElement($response['linkedin']);
+
+ if (!is_object($educations)) {
+ throw new Exception("User education request failed! {$this->providerId} returned an invalid xml data.", 6);
+ }
+
+ $result = array();
+ foreach ($educations->educations->education as $education) {
+ $edu = new Hybrid_User_Education();
+ $edu->degree = (string) $education->degree;
+ $edu->school = (string) $education->{'school-name'};
+ $edu->field = (string) $education->{'field-of-study'};
+ if( $education->{'start-date'} ) {
+ $edu->startYear = (string) $education->{'start-date'}->year;
+ }
+ if( $education->{'end-date'} ) {
+ $edu->endYear = (string) $education->{'end-date'}->year;
+ }
+ $result[] = $edu;
+ }
+
+ return $result;
+ } else {
+ throw new Exception("User education request failed! {$this->providerId} returned an invalid response.", 6);
+ }
+ }
+
+ /**
+ * get the user skills
+ */
+ public function getUserSkills()
+ {
+ try{
+ // http://developer.linkedin.com/docs/DOC-1061
+ $response = $this->api->profile('~:(skills)');
+ } catch (LinkedInException $e){
+ throw new Exception("User skills request failed! {$this->providerId} returned an error: $e", 6);
+ }
+
+ if (isset($response['success']) && $response['success'] === TRUE){
+ $skills = @ new SimpleXMLElement($response['linkedin']);
+
+ if (!is_object($skills)){
+ throw new Exception("User skills request failed! {$this->providerId} returned an invalid xml data.", 6);
+ }
+
+ $result = array();
+ foreach ($skills->skills->skill as $skill){
+ $result[] = (string) $skill->skill->name;
+ }
+
+ return $result;
+ } else{
+ throw new Exception("User skills request failed! {$this->providerId} returned an invalid response.", 6);
+ }
+ }
+
}
View
44 hybridauth/Hybrid/User_Education.php
@@ -0,0 +1,44 @@
+<?php
+/*!
+* HybridAuth
+* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
+* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
+*/
+
+/**
+ * Hybrid_User_Education
+ *
+ * used to provider the connected user education on a standardized structure across supported social apis.
+ */
+class Hybrid_User_Education
+{
+ /* School name */
+ public $school = NULL;
+
+ /* School field */
+ public $field = NULL;
+
+ /* Degree obtained */
+ public $degree = NULL;
+
+ /* School type (college, high school, etc.) */
+ public $type = NULL;
+
+ /* School start day */
+ public $startDay = NULL;
+
+ /* School start month */
+ public $startMonth = NULL;
+
+ /* School start year */
+ public $startYear = NULL;
+
+ /* School end day */
+ public $endDay = NULL;
+
+ /* School end month */
+ public $endMonth = NULL;
+
+ /* School end year */
+ public $endYear = NULL;
+}
View
44 hybridauth/Hybrid/User_Work_History.php
@@ -0,0 +1,44 @@
+<?php
+/*!
+* HybridAuth
+* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
+* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
+*/
+
+/**
+ * Hybrid_User_Work_History
+ *
+ * used to provider the connected user work history on a standardized structure across supported social apis.
+ */
+class Hybrid_User_Work_History
+{
+ /* The employer name */
+ public $employer = NULL;
+
+ /* The position name */
+ public $position = NULL;
+
+ /* The user's work history location */
+ public $location = NULL;
+
+ /* The user's work history start day */
+ public $startDay = NULL;
+
+ /* The user's work history start month */
+ public $startMonth = NULL;
+
+ /* The user's work history start year */
+ public $startYear = NULL;
+
+ /* The user's work history end day*/
+ public $endDay = NULL;
+
+ /* The user's work history end month */
+ public $endMonth = NULL;
+
+ /* The user's work history end year */
+ public $endYear = NULL;
+
+ /* The user's work history description */
+ public $description = NULL;
+}
Something went wrong with that request. Please try again.