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_Tumblr |
---|
10 | */ |
---|
11 | class Hybrid_Providers_Tumblr 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 = "http://api.tumblr.com/v2/"; |
---|
22 | $this->api->authorize_url = "http://www.tumblr.com/oauth/authorize"; |
---|
23 | $this->api->request_token_url = "http://www.tumblr.com/oauth/request_token"; |
---|
24 | $this->api->access_token_url = "http://www.tumblr.com/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 | try{ |
---|
36 | $profile = $this->api->get( 'user/info' ); |
---|
37 | |
---|
38 | foreach ( $profile->response->user->blogs as $blog ){ |
---|
39 | if( $blog->primary ){ |
---|
40 | $bloghostname = explode( '://', $blog->url ); |
---|
41 | $bloghostname = substr( $bloghostname[1], 0, -1); |
---|
42 | |
---|
43 | // store the user primary blog base hostname |
---|
44 | $this->token( "primary_blog" , $bloghostname ); |
---|
45 | |
---|
46 | $this->user->profile->identifier = $blog->url; |
---|
47 | $this->user->profile->displayName = $profile->response->user->name; |
---|
48 | $this->user->profile->profileURL = $blog->url; |
---|
49 | $this->user->profile->webSiteURL = $blog->url; |
---|
50 | $this->user->profile->description = strip_tags( $blog->description ); |
---|
51 | |
---|
52 | $avatar = $this->api->get( 'blog/'. $this->token( "primary_blog" ) .'/avatar' ); |
---|
53 | |
---|
54 | $this->user->profile->photoURL = $avatar->response->avatar_url; |
---|
55 | |
---|
56 | break; |
---|
57 | } |
---|
58 | } |
---|
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 tumblr |
---|
69 | */ |
---|
70 | function setUserStatus( $status ) |
---|
71 | { |
---|
72 | $parameters = array( 'type' => "text", 'body' => $status ); |
---|
73 | $response = $this->api->post( "blog/" . $this->token( "primary_blog" ) . '/post', $parameters ); |
---|
74 | |
---|
75 | if ( $response->meta->status != 201 ){ |
---|
76 | throw new Exception( "Update user status failed! {$this->providerId} returned an error. " . $this->errorMessageByStatus( $response->meta->status ) ); |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|