Class: Dobedobedo::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/dobedobedo/connection.rb

Constant Summary collapse

SITE_URL =
"https://www.do.com"
TOKEN_URL =
"/oauth2/token"
AUTHORIZATION_URL =
"/oauth2/authorize"
GET_WORKSPACE_LIST =
'/workspaces'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Connection

Returns a new instance of Connection.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dobedobedo/connection.rb', line 12

def initialize(config = {})
  @client_id     = config[:client_id] unless config[:client_id].nil?
  @client_secret = config[:client_secret] unless config[:client_secret].nil?
  @username = config[:username] unless config[:username].nil?
  @password = config[:password] unless config[:password].nil?

  raise "Failed to set client id and client secret in constructor" if (@client_id.nil? || @client_secret.nil?)

  @client = OAuth2::Client.new(@client_id,
                               @client_secret,
                               :site => SITE_URL,
                               :token_url => TOKEN_URL,
                               :authorization_url => AUTHORIZATION_URL)

  raise "Failed to create client" if @client.nil?

  @token = @client.password.get_token(@username, @password)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/dobedobedo/connection.rb', line 6

def client
  @client
end

#client_idObject

include Dobedobedo::Workspace



5
6
7
# File 'lib/dobedobedo/connection.rb', line 5

def client_id
  @client_id
end

#client_secretObject

include Dobedobedo::Workspace



5
6
7
# File 'lib/dobedobedo/connection.rb', line 5

def client_secret
  @client_secret
end

#passwordObject

include Dobedobedo::Workspace



5
6
7
# File 'lib/dobedobedo/connection.rb', line 5

def password
  @password
end

#tokenObject (readonly)

Returns the value of attribute token.



6
7
8
# File 'lib/dobedobedo/connection.rb', line 6

def token
  @token
end

#usernameObject

include Dobedobedo::Workspace



5
6
7
# File 'lib/dobedobedo/connection.rb', line 5

def username
  @username
end

Instance Method Details

#find_workspace_by_name(name) ⇒ Object Also known as: by_name



35
36
37
# File 'lib/dobedobedo/connection.rb', line 35

def find_workspace_by_name(name)
  workspaces.select {|x| x.name == name}.first
end

#workspacesObject



31
32
33
# File 'lib/dobedobedo/connection.rb', line 31

def workspaces
  @token.get(GET_WORKSPACE_LIST).parsed.map {|w| Dobedobedo::Workspace.new(@token, w)}
end