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.
-
#oauth_token ⇒ Object
Returns the value of attribute oauth_token.
-
#raw_connection ⇒ Object
readonly
Returns the value of attribute raw_connection.
-
#stubs ⇒ Object
Returns the value of attribute stubs.
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.
- #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 23 |
# 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] @record_mode = [:record_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 |
#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 |
#raw_connection ⇒ Object (readonly)
Returns the value of attribute raw_connection.
3 4 5 |
# File 'lib/podio/client.rb', line 3 def raw_connection @raw_connection end |
#stubs ⇒ Object
Returns the value of attribute stubs.
4 5 6 |
# File 'lib/podio/client.rb', line 4 def stubs @stubs end |
Instance Method Details
#authenticate_with_app(app_id, app_token) ⇒ Object
Sign in as an app
65 66 67 68 69 70 71 72 73 |
# File 'lib/podio/client.rb', line 65 def authenticate_with_app(app_id, app_token) response = @oauth_connection.post do |req| req.url '/oauth/token', :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
43 44 45 46 47 48 49 50 51 |
# File 'lib/podio/client.rb', line 43 def authenticate_with_auth_code(, redirect_uri) response = @oauth_connection.post do |req| req.url '/oauth/token', :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
54 55 56 57 58 59 60 61 62 |
# File 'lib/podio/client.rb', line 54 def authenticate_with_credentials(username, password) response = @oauth_connection.post do |req| req.url '/oauth/token', :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
89 90 91 92 93 94 95 96 97 |
# File 'lib/podio/client.rb', line 89 def authenticate_with_openid(identifier, type) response = @oauth_connection.post do |req| req.url '/oauth/token_by_openid', :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
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/podio/client.rb', line 76 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['new_user_created']] end |
#authorize_url(params = {}) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/podio/client.rb', line 33 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
114 115 116 117 118 119 120 121 |
# File 'lib/podio/client.rb', line 114 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 if @test_mode headers end |
#log(env, &block) ⇒ Object
25 26 27 |
# File 'lib/podio/client.rb', line 25 def log(env, &block) @logger.log(env, &block) end |
#refresh_access_token ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/podio/client.rb', line 104 def refresh_access_token response = @oauth_connection.post do |req| req.url '/oauth/token', :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
29 30 31 |
# File 'lib/podio/client.rb', line 29 def reset setup_connections end |