source: extensions/oAuth/include/hybridauth/Hybrid/Providers/px500.php @ 28826

Last change on this file since 28826 was 28826, checked in by mistic100, 10 years ago

fix Yahoo, add 500px

File size: 3.6 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_px500 (500px.com)
10*/
11class Hybrid_Providers_px500 extends Hybrid_Provider_Model_OAuth1
12{
13        /**
14        * IDp wrappers initializer
15        */
16        function initialize()
17        {
18                parent::initialize();
19
20                // provider api end-points
21                $this->api->api_base_url      = "https://api.500px.com/v1/";
22                $this->api->authorize_url     = "https://api.500px.com/v1/oauth/authorize";
23                $this->api->request_token_url = "https://api.500px.com/v1/oauth/request_token";
24                $this->api->access_token_url  = "https://api.500px.com/v1/oauth/access_token";
25
26                $this->api->curl_auth_header  = false;
27        }
28
29
30   /**
31        * load the user profile from the IDp api client
32        */
33        function getUserProfile()
34        { 
35       
36
37                try{ 
38                        $response = $this->api->get( 'users' );
39
40                        $this->user->profile->identifier    = (property_exists($response->user,'id'))?$response->user->id:"";
41                        $this->user->profile->displayName   = (property_exists($response->user,'username'))?$response->user->username:"";
42                        $this->user->profile->description   = (property_exists($response->user,'about'))?$response->user->about:"";
43                        $this->user->profile->firstName     = (property_exists($response->user,'firstname'))?$response->user->firstname:"";
44                        $this->user->profile->lastName      = (property_exists($response->user,'lastname'))?$response->user->lastname:""; 
45                        $this->user->profile->photoURL      = (property_exists($response->user,'userpic_url'))?$response->user->userpic_url:"";
46                        $this->user->profile->profileURL    = (property_exists($response->user,'domain'))?("http://".$response->user->domain):"";
47                        $this->user->profile->webSiteURL    = (property_exists($response->user->contacts,'website'))?$response->user->contacts->website:""; 
48                        $this->user->profile->city          = (property_exists($response->user,'city'))?$response->user->city:"";
49                        $this->user->profile->region        = (property_exists($response->user,'state'))?$response->user->state:"";
50                        $this->user->profile->country       = (property_exists($response->user,'country'))?$response->user->country:"";
51
52                        if(property_exists($response->user,'sex')){
53                                if($response->user->sex>0){
54                                        $this->user->profile->gender   = ($response->user->sex==1)?"male":"female";
55                                }
56                        }
57
58                        return $this->user->profile; 
59                }
60                catch( Exception $e ){
61                        throw new Exception( "User profile request failed! {$this->providerId} returned an error while requesting the user profile.", 6 );
62                }
63
64                return $this->user->profile;
65        }
66
67        /**
68        * post to 500px
69        */ 
70        function setUserStatus( $status )
71        {
72                // README : posting to a 500px.com blog requires the post's TITLE to be set somehow
73                // So it is strongly recommended that you submit status as an ARRAY, like :
74               
75                // setUserStatus( array( 'title'=>'YOUR TITLE HERE', 'body'=>'YOUR MESSAGE HERE' ) )
76               
77               
78                if(is_array($status) && isset($status['title']) && isset($status['body'])){
79                        $t = $status['title'];
80                        $b = $status['body'];
81                } else {
82                        $t = '...';
83                        $b = $status;   
84                }
85               
86                $parameters = array( 'title' => $t, 'body' => $b ); 
87                $response  = $this->api->post( 'blogs', $parameters ); 
88
89                if ( property_exists($response,'id') ){
90                        return $response->id;
91                } else {
92                        throw new Exception( "Update user status failed! {$this->providerId} returned an error. "  );   
93                }
94               
95                // this function is for 'plain' blog posting only :
96                // we will commit photo upload soon in an extra function, called setUpload -
97                // because 500px users can also get an additional Upload Key to upload pictures
98                // refer to  http://developers.500px.com/docs/upload-post  for now
99        }
100}
Note: See TracBrowser for help on using the repository browser.