Class: Asana::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/asana/client.rb,
lib/asana/client/configuration.rb

Overview

A client to interact with the Asana API. It exposes all the available resources of the Asana API in idiomatic Ruby.

Examples:

# Authentication with a personal access token
Asana::Client.new do |client|
  client.authentication :access_token, '...'
end
# OAuth2 with a plain bearer token (doesn't support auto-refresh)
Asana::Client.new do |client|
  client.authentication :oauth2, bearer_token: '...'
end
# OAuth2 with a plain refresh token and client credentials
Asana::Client.new do |client|
  client.authentication :oauth2,
                        refresh_token: '...',
                        client_id: '...',
                        client_secret: '...',
                        redirect_uri: '...'
end
# OAuth2 with an ::OAuth2::AccessToken object
Asana::Client.new do |client|
  client.authentication :oauth2, my_oauth2_access_token_object
end
# Use a custom Faraday network adapter
Asana::Client.new do |client|
  client.authentication ...
  client.adapter :typhoeus
end
# Use a custom user agent string
Asana::Client.new do |client|
  client.authentication ...
  client.user_agent '...'
end
# Pass in custom configuration to the Faraday connection
Asana::Client.new do |client|
  client.authentication ...
  client.configure_faraday { |conn| conn.use MyMiddleware }
end

Defined Under Namespace

Classes: Configuration, ResourceProxy

Instance Method Summary collapse

Constructor Details

#initialize { ... } ⇒ Client

Initializes a new client.

Yields:



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/asana/client.rb', line 77

def initialize(&block)
  config = Configuration.new.tap(&block).to_h
  @http_client =
    HttpClient.new(authentication: config.fetch(:authentication),
                   adapter: config[:faraday_adapter],
                   user_agent: config[:user_agent],
                   debug_mode: config[:debug_mode],
                   log_asana_change_warnings: config[:log_asana_change_warnings],
                   default_headers: config[:default_headers],
                   &config[:faraday_configuration])
end

Instance Method Details

#delete(url, **args) ⇒ Object

Performs a DELETE request against an arbitrary Asana URL. Allows for the user to interact with the API in ways that haven’t been reflected/foreseen in this library.



113
114
115
# File 'lib/asana/client.rb', line 113

def delete(url, **args)
  @http_client.delete(url, **args)
end

#get(url, **args) ⇒ Object

Performs a GET request against an arbitrary Asana URL. Allows for the user to interact with the API in ways that haven’t been reflected/foreseen in this library.



92
93
94
# File 'lib/asana/client.rb', line 92

def get(url, **args)
  @http_client.get(url, **args)
end

#post(url, **args) ⇒ Object

Performs a POST request against an arbitrary Asana URL. Allows for the user to interact with the API in ways that haven’t been reflected/foreseen in this library.



99
100
101
# File 'lib/asana/client.rb', line 99

def post(url, **args)
  @http_client.post(url, **args)
end

#put(url, **args) ⇒ Object

Performs a PUT request against an arbitrary Asana URL. Allows for the user to interact with the API in ways that haven’t been reflected/foreseen in this library.



106
107
108
# File 'lib/asana/client.rb', line 106

def put(url, **args)
  @http_client.put(url, **args)
end