Class: Podio::Client
- Inherits:
-
Object
- Object
- Podio::Client
- Defined in:
- lib/podio/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
readonly
Returns the value of attribute api_secret.
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#current_http_client ⇒ Object
Returns the value of attribute current_http_client.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#oauth_token ⇒ Object
Returns the value of attribute oauth_token.
-
#stubs ⇒ Object
Returns the value of attribute stubs.
-
#trusted_connection ⇒ Object
readonly
Returns the value of attribute trusted_connection.
Instance Method Summary collapse
-
#authenticate_with_app(app_id, app_token) ⇒ Object
Sign in as an app.
-
#authenticate_with_auth_code(authorization_code, redirect_uri) ⇒ Object
sign in as a user using the server side flow.
-
#authenticate_with_credentials(username, password) ⇒ Object
Sign in as a user using credentials.
-
#authenticate_with_openid(identifier, type) ⇒ Object
Sign in with an OpenID, only available for Podio.
-
#authenticate_with_sso(attributes) ⇒ Object
Sign in with SSO.
-
#authenticate_with_transfer_token(transfer_token) ⇒ Object
Sign in with an transfer token, only available for Podio.
- #authorize_url(params = {}) ⇒ Object
- #configured_headers ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #log(env, &block) ⇒ Object
- #refresh_access_token ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/podio/client.rb', line 6 def initialize( = {}) @api_url = [:api_url] || 'https://api.podio.com' @api_key = [:api_key] @api_secret = [:api_secret] @logger = [:logger] || Podio::StdoutLogger.new([:debug]) @oauth_token = [:oauth_token] @headers = [:custom_headers] || {} @adapter = [:adapter] || Faraday.default_adapter if [:enable_stubs] @enable_stubs = true @stubs = Faraday::Adapter::Test::Stubs.new end @test_mode = [:test_mode] setup_connections end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/podio/client.rb', line 3 def api_key @api_key end |
#api_secret ⇒ Object (readonly)
Returns the value of attribute api_secret.
3 4 5 |
# File 'lib/podio/client.rb', line 3 def api_secret @api_secret end |
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
3 4 5 |
# File 'lib/podio/client.rb', line 3 def api_url @api_url end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
3 4 5 |
# File 'lib/podio/client.rb', line 3 def connection @connection end |
#current_http_client ⇒ Object
Returns the value of attribute current_http_client.
4 5 6 |
# File 'lib/podio/client.rb', line 4 def current_http_client @current_http_client end |
#headers ⇒ Object
Returns the value of attribute headers.
4 5 6 |
# File 'lib/podio/client.rb', line 4 def headers @headers end |
#oauth_token ⇒ Object
Returns the value of attribute oauth_token.
3 4 5 |
# File 'lib/podio/client.rb', line 3 def oauth_token @oauth_token end |
#stubs ⇒ Object
Returns the value of attribute stubs.
4 5 6 |
# File 'lib/podio/client.rb', line 4 def stubs @stubs end |
#trusted_connection ⇒ Object (readonly)
Returns the value of attribute trusted_connection.
3 4 5 |
# File 'lib/podio/client.rb', line 3 def trusted_connection @trusted_connection end |
Instance Method Details
#authenticate_with_app(app_id, app_token) ⇒ Object
Sign in as an app
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/podio/client.rb', line 68 def authenticate_with_app(app_id, app_token) response = @oauth_connection.post do |req| req.url '/oauth/token' req.headers['Content-Type'] = 'application/x-www-form-urlencoded' req.body = {:grant_type => 'app', :client_id => api_key, :client_secret => api_secret, :app_id => app_id, :app_token => app_token} end @oauth_token = OAuthToken.new(response.body) configure_oauth @oauth_token end |
#authenticate_with_auth_code(authorization_code, redirect_uri) ⇒ Object
sign in as a user using the server side flow
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/podio/client.rb', line 42 def authenticate_with_auth_code(, redirect_uri) response = @oauth_connection.post do |req| req.url '/oauth/token' req.headers['Content-Type'] = 'application/x-www-form-urlencoded' req.body = {:grant_type => 'authorization_code', :client_id => api_key, :client_secret => api_secret, :code => , :redirect_uri => redirect_uri} end @oauth_token = OAuthToken.new(response.body) configure_oauth @oauth_token end |
#authenticate_with_credentials(username, password) ⇒ Object
Sign in as a user using credentials
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/podio/client.rb', line 55 def authenticate_with_credentials(username, password) response = @oauth_connection.post do |req| req.url '/oauth/token' req.headers['Content-Type'] = 'application/x-www-form-urlencoded' req.body = {:grant_type => 'password', :client_id => api_key, :client_secret => api_secret, :username => username, :password => password} end @oauth_token = OAuthToken.new(response.body) configure_oauth @oauth_token end |
#authenticate_with_openid(identifier, type) ⇒ Object
Sign in with an OpenID, only available for Podio
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/podio/client.rb', line 106 def authenticate_with_openid(identifier, type) response = @oauth_connection.post do |req| req.url '/oauth/token_by_openid' req.headers['Content-Type'] = 'application/x-www-form-urlencoded' req.body = {:grant_type => type, :client_id => api_key, :client_secret => api_secret, :identifier => identifier} end @oauth_token = OAuthToken.new(response.body) configure_oauth @oauth_token end |
#authenticate_with_sso(attributes) ⇒ Object
Sign in with SSO
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/podio/client.rb', line 94 def authenticate_with_sso(attributes) response = @oauth_connection.post do |req| req.url '/oauth/token', :grant_type => 'sso', :client_id => api_key, :client_secret => api_secret req.body = attributes end @oauth_token = OAuthToken.new(response.body) configure_oauth [@oauth_token, response.body['new_user_created']] end |
#authenticate_with_transfer_token(transfer_token) ⇒ Object
Sign in with an transfer token, only available for Podio
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/podio/client.rb', line 81 def authenticate_with_transfer_token(transfer_token) response = @oauth_connection.post do |req| req.url '/oauth/token' req.headers['Content-Type'] = 'application/x-www-form-urlencoded' req.body = {:grant_type => 'transfer_token', :client_id => api_key, :client_secret => api_secret, :transfer_token => transfer_token} end @oauth_token = OAuthToken.new(response.body) configure_oauth @oauth_token end |
#authorize_url(params = {}) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/podio/client.rb', line 32 def (params={}) uri = URI.parse(@api_url) uri.host = uri.host.gsub('api.', '') uri.path = '/oauth/authorize' uri.query = Rack::Utils.build_query(params.merge(:client_id => api_key)) uri.to_s end |
#configured_headers ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/podio/client.rb', line 136 def configured_headers headers = @headers.dup headers['User-Agent'] = 'Podio Ruby Library' headers['authorization'] = "OAuth2 #{oauth_token.access_token}" if oauth_token headers['X-Podio-Dry-Run'] = @test_mode.to_s if @test_mode headers end |
#log(env, &block) ⇒ Object
24 25 26 |
# File 'lib/podio/client.rb', line 24 def log(env, &block) @logger.log(env, &block) end |
#refresh_access_token ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/podio/client.rb', line 124 def refresh_access_token response = @oauth_connection.post do |req| req.url '/oauth/token' req.headers['Content-Type'] = 'application/x-www-form-urlencoded' req.body = {:grant_type => 'refresh_token', :refresh_token => oauth_token.refresh_token, :client_id => api_key, :client_secret => api_secret} end @oauth_token = OAuthToken.new(response.body) @oauth_token.refreshed = true configure_oauth end |
#reset ⇒ Object
28 29 30 |
# File 'lib/podio/client.rb', line 28 def reset setup_connections end |