Class: Bonita::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bonita/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



55
56
57
58
59
60
# File 'lib/bonita/client.rb', line 55

def initialize(options = {})
  @url          = options[:url]
  @username     = options[:username]
  @password     = options[:password]
  @tenant       = options[:tenant]
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



4
5
6
# File 'lib/bonita/client.rb', line 4

def password
  @password
end

#redirect_urlObject (readonly)

Returns the value of attribute redirect_url.



4
5
6
# File 'lib/bonita/client.rb', line 4

def redirect_url
  @redirect_url
end

#tenantObject (readonly)

Returns the value of attribute tenant.



4
5
6
# File 'lib/bonita/client.rb', line 4

def tenant
  @tenant
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/bonita/client.rb', line 4

def url
  @url
end

#usernameObject (readonly)

Returns the value of attribute username.



4
5
6
# File 'lib/bonita/client.rb', line 4

def username
  @username
end

Class Method Details

.resourcesObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bonita/client.rb', line 7

def resources
  {
    customuserinfo: {
      definitions: Customuserinfo::DefinitionResource,
      users: Customuserinfo::UserResource,
      values: Customuserinfo::ValueResource,
    },
    bpm: {
      processes: Bpm::ProcessResource,
    },
    identity: {
      groups: Identity::GroupResource,
      memberships: Identity::MembershipResource,
      roles: Identity::RoleResource,
      users: Identity::UserResource,
    },
  }
end

.start(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/bonita/client.rb', line 26

def start(options = {})
  client = new(options)
  client.

  yield(client)
ensure
  client.logout
end

Instance Method Details

#connectionObject



81
82
83
84
85
86
87
88
89
# File 'lib/bonita/client.rb', line 81

def connection
  @faraday ||=
    Faraday.new connection_options do |conn|
      conn.use :cookie_jar
      conn.use Bonita::Middleware::CSRF
      conn.use Faraday::Request::UrlEncoded
      conn.adapter Faraday.default_adapter
    end
end

#loginObject

Raises:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/bonita/client.rb', line 62

def 
  response =
    connection.post '/bonita/loginservice' do |req|
      req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
      req.body = {
        username:     @username,
        password:     @password,
        tenant:       @tenant,
      }
    end

  raise Bonita::AuthError, 'Unable to log in' if response.body.include?('Unable to log in')
  true
end

#logoutObject



77
78
79
# File 'lib/bonita/client.rb', line 77

def logout
  connection.get '/bonita/logoutservice?redirect=false'
end