Class: Dobedobedo::Connection
- Inherits:
-
Object
- Object
- Dobedobedo::Connection
- 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
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#client_id ⇒ Object
include Dobedobedo::Workspace.
-
#client_secret ⇒ Object
include Dobedobedo::Workspace.
-
#password ⇒ Object
include Dobedobedo::Workspace.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
-
#username ⇒ Object
include Dobedobedo::Workspace.
Instance Method Summary collapse
- #find_workspace_by_name(name) ⇒ Object (also: #by_name)
-
#initialize(config = {}) ⇒ Connection
constructor
A new instance of Connection.
- #workspaces ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/dobedobedo/connection.rb', line 6 def client @client end |
#client_id ⇒ Object
include Dobedobedo::Workspace
5 6 7 |
# File 'lib/dobedobedo/connection.rb', line 5 def client_id @client_id end |
#client_secret ⇒ Object
include Dobedobedo::Workspace
5 6 7 |
# File 'lib/dobedobedo/connection.rb', line 5 def client_secret @client_secret end |
#password ⇒ Object
include Dobedobedo::Workspace
5 6 7 |
# File 'lib/dobedobedo/connection.rb', line 5 def password @password end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
6 7 8 |
# File 'lib/dobedobedo/connection.rb', line 6 def token @token end |
#username ⇒ Object
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 |
#workspaces ⇒ Object
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 |