source: extensions/oAuth/include/hybridauth/Hybrid/Providers/MySpace.php @ 20293

Last change on this file since 20293 was 20293, checked in by mistic100, 11 years ago

first commit of oAuth plugin, still in developpement

File size: 4.9 KB
Line 
1<?php
2/*!
3* HybridAuth
4* http://hybridauth.sourceforge.net | http://github.com/hybridauth/hybridauth
5* (c) 2009-2012, HybridAuth authors | http://hybridauth.sourceforge.net/licenses.html
6*/
7
8/**
9 * Hybrid_Providers_MySpace provider adapter based on OAuth1 protocol
10 *
11 * http://hybridauth.sourceforge.net/userguide/IDProvider_info_MySpace.html
12 */
13class Hybrid_Providers_MySpace extends Hybrid_Provider_Model_OAuth1
14{
15        /**
16        * IDp wrappers initializer
17        */
18        function initialize() 
19        {
20                parent::initialize();
21
22                // Provider api end-points
23                $this->api->api_endpoint_url  = "http://api.myspace.com/v1/";
24                $this->api->authorize_url     = "http://api.myspace.com/authorize";
25                $this->api->request_token_url = "http://api.myspace.com/request_token";
26                $this->api->access_token_url  = "http://api.myspace.com/access_token";
27        }
28
29        /**
30        * get the connected uid from myspace api
31        */
32        public function getCurrentUserId()
33        {
34                $response = $this->api->get( 'http://api.myspace.com/v1/user.json' );
35
36                if ( ! isset( $response->userId ) ){
37                        throw new Exception( "User id request failed! {$this->providerId} returned an invalid response." );
38                }
39
40                return $response->userId;
41        }
42
43        /**
44        * load the user profile from the IDp api client
45        */
46        function getUserProfile()
47        {
48                $userId = $this->getCurrentUserId();
49
50                $data = $this->api->get( 'http://api.myspace.com/v1/users/' . $userId . '/profile.json' );
51
52                if ( ! is_object( $data ) ){
53                        throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
54                }
55
56                $this->user->profile->identifier  = $userId;
57                $this->user->profile->displayName = $data->basicprofile->name;
58                $this->user->profile->description = $data->aboutme;
59                $this->user->profile->gender      = $data->basicprofile->gender;
60                $this->user->profile->photoURL    = $data->basicprofile->image;
61                $this->user->profile->profileURL  = $data->basicprofile->webUri;
62                $this->user->profile->age         = $data->age;
63                $this->user->profile->country     = $data->country;
64                $this->user->profile->region      = $data->region;
65                $this->user->profile->city        = $data->city;
66                $this->user->profile->zip         = $data->postalcode;
67
68                return $this->user->profile;
69        }
70
71        /**
72        * load the user contacts
73        */
74        function getUserContacts()
75        {
76                $userId = $this->getCurrentUserId();
77
78                $response = $this->api->get( "http://api.myspace.com/v1/users/" . $userId . "/friends.json" );
79
80                if ( ! is_object( $response ) ){
81                        throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
82                }
83
84                $contacts = ARRAY();
85
86                foreach( $response->Friends as $item ){ 
87                        $uc = new Hybrid_User_Contact();
88
89                        $uc->identifier   = $item->userId;
90                        $uc->displayName  = $item->name;
91                        $uc->profileURL   = $item->webUri;
92                        $uc->photoURL     = $item->image;
93                        $uc->description  = $item->status; 
94
95                        $contacts[] = $uc;
96                }
97
98                return $contacts;
99        }
100
101        /**
102        * update user status
103        */
104        function setUserStatus( $status )
105        {
106        // crappy myspace... gonna see this asaic
107                $userId = $this->getCurrentUserId();
108               
109                $parameters = array( 'status' => $status );
110
111                $response = $this->api->api( "http://api.myspace.com/v1/users/" . $userId . "/status", 'PUT', $parameters ); 
112
113                // check the last HTTP status code returned
114                if ( $this->api->http_code != 200 )
115                {
116                        throw new Exception( "Update user status failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $this->api->http_code ) );
117                }
118        }
119
120        /**
121        * load the user latest activity 
122        *    - timeline : all the stream
123        *    - me       : the user activity only 
124        */
125        function getUserActivity( $stream )
126        {
127                $userId = $this->getCurrentUserId();
128
129                if( $stream == "me" ){
130                        $response = $this->api->get( "http://api.myspace.com/v1/users/" . $userId . "/status.json" ); 
131                }                                                         
132                else{                                                     
133                        $response = $this->api->get( "http://api.myspace.com/v1/users/" . $userId . "/friends/status.json" );
134                }
135
136                if ( ! is_object( $response ) ){
137                        throw new Exception( "User profile request failed! {$this->providerId} returned an invalid response.", 6 );
138                }
139
140                $activities = ARRAY();
141
142                if( $stream == "me" ){
143                        // todo
144                }                                                         
145                else{                                                     
146                        foreach( $response->FriendsStatus as $item ){
147                                $ua = new Hybrid_User_Activity();
148
149                                $ua->id                 = $item->statusId;
150                                $ua->date               = NULL; // to find out!!
151                                $ua->text               = $item->status;
152
153                                $ua->user->identifier   = $item->user->userId;
154                                $ua->user->displayName  = $item->user->name;
155                                $ua->user->profileURL   = $item->user->uri;
156                                $ua->user->photoURL     = $item->user->image;
157
158                                $activities[] = $ua;
159                        }
160                } 
161
162                return $activities;
163        }
164}
Note: See TracBrowser for help on using the repository browser.