Class: TestRail::APIClient

Inherits:
Object
  • Object
show all
Defined in:
lib/test_rail_integration/generator/API_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_data) ⇒ APIClient

Returns a new instance of APIClient.



24
25
26
27
28
29
30
31
32
# File 'lib/test_rail_integration/generator/API_client.rb', line 24

def initialize(connection_data)
  base_url = connection_data[:url]
  unless base_url.match(/\/$/)
    base_url += '/'
  end
  @url = base_url + 'index.php?/api/v2/'
  @user = connection_data[:username]
  @password = connection_data[:password]
end

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



22
23
24
# File 'lib/test_rail_integration/generator/API_client.rb', line 22

def password
  @password
end

#userObject

Returns the value of attribute user.



21
22
23
# File 'lib/test_rail_integration/generator/API_client.rb', line 21

def user
  @user
end

Instance Method Details

#send_get(uri) ⇒ Object

Send Get

Issues a GET request (read) against the API and returns the result (as Ruby hash).

Arguments:

uri The API method to call including parameters

(e.g. get_case/1)


45
46
47
# File 'lib/test_rail_integration/generator/API_client.rb', line 45

def send_get(uri)
  _send_request('GET', uri, nil)
end

#send_post(uri, data) ⇒ Object

Send POST

Issues a POST request (write) against the API and returns the result (as Ruby hash).

Arguments:

uri The API method to call including parameters

(e.g. add_case/1)

data The data to submit as part of the request (as

Ruby hash, strings must be UTF-8 encoded)


62
63
64
# File 'lib/test_rail_integration/generator/API_client.rb', line 62

def send_post(uri, data)
  _send_request('POST', uri, data)
end