Class: Nylas::API

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logging
Defined in:
lib/nylas/api.rb

Overview

Methods to retrieve data from the Nylas API as Ruby objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, level, logger, logger=

Constructor Details

#initialize(client: nil, app_id: nil, app_secret: nil, access_token: nil, api_server: "https://api.nylas.com", service_domain: "api.nylas.com") ⇒ Nylas::API

rubocop:disable Metrics/ParameterLists

Parameters:

  • client (HttpClient) (defaults to: nil)

    Http Client to use for retrieving data

  • app_id (String) (defaults to: nil)

    Your application id from the Nylas Dashboard

  • app_secret (String) (defaults to: nil)

    Your application secret from the Nylas Dashboard

  • access_token (String) (defaults to: nil)

    (Optional) Your users access token.

  • api_server (String) (defaults to: "https://api.nylas.com")

    (Optional) Which Nylas API Server to connect to. Only change this if you're using a self-hosted Nylas instance.

  • service_domain (String) (defaults to: "api.nylas.com")

    (Optional) Host you are authenticating OAuth against.


19
20
21
22
23
24
# File 'lib/nylas/api.rb', line 19

def initialize(client: nil, app_id: nil, app_secret: nil, access_token: nil,
               api_server: "https://api.nylas.com", service_domain: "api.nylas.com")
  self.client = client || HttpClient.new(app_id: app_id, app_secret: app_secret,
                                         access_token: access_token, api_server: api_server,
                                         service_domain: service_domain)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client


4
5
6
# File 'lib/nylas/api.rb', line 4

def client
  @client
end

Instance Method Details

#contactsCollection<Contact>

Returns A queryable collection of Contacts.

Returns:


28
29
30
# File 'lib/nylas/api.rb', line 28

def contacts
  @contacts ||= Collection.new(model: Contact, api: self)
end

#current_accountCurrentAccount

Returns The account details for whomevers access token is set.

Returns:

  • (CurrentAccount)

    The account details for whomevers access token is set


33
34
35
36
# File 'lib/nylas/api.rb', line 33

def 
  prevent_calling_if_missing_access_token(:current_account)
  CurrentAccount.from_hash(client.execute(method: :get, path: "/account"), api: self)
end