Class: BrowserStack::ApiRequest
- Inherits:
-
Object
- Object
- BrowserStack::ApiRequest
show all
- Defined in:
- lib/browser_stack/api_request.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
3
4
5
|
# File 'lib/browser_stack/api_request.rb', line 3
def config
@config
end
|
#http_client ⇒ Object
Returns the value of attribute http_client.
3
4
5
|
# File 'lib/browser_stack/api_request.rb', line 3
def http_client
@http_client
end
|
#params ⇒ Object
Returns the value of attribute params.
3
4
5
|
# File 'lib/browser_stack/api_request.rb', line 3
def params
@params
end
|
#request ⇒ Object
Returns the value of attribute request.
3
4
5
|
# File 'lib/browser_stack/api_request.rb', line 3
def request
@request
end
|
#response ⇒ Object
Returns the value of attribute response.
3
4
5
|
# File 'lib/browser_stack/api_request.rb', line 3
def response
@response
end
|
#uri ⇒ Object
Returns the value of attribute uri.
3
4
5
|
# File 'lib/browser_stack/api_request.rb', line 3
def uri
@uri
end
|
Instance Method Details
#api_error? ⇒ Boolean
34
35
36
|
# File 'lib/browser_stack/api_request.rb', line 34
def api_error?
@response.code == "422" || @response.code == "403"
end
|
#authenticate ⇒ Object
42
43
44
|
# File 'lib/browser_stack/api_request.rb', line 42
def authenticate
@request.basic_auth(@config.user_name,@config.password)
end
|
#commit(url, request_type = "get", params = {}) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/browser_stack/api_request.rb', line 5
def commit(url,request_type="get",params={})
@config = BrowserStack.configuration
@params = params
set_uri(url)
get_http_client
if request_type == "get"
@request = Net::HTTP::Get.new(@uri.request_uri)
elsif request_type=="post"
@request = Net::HTTP::Post.new(@uri.request_uri)
@request.set_form_data(params)
elsif request_type == "delete"
@request = Net::HTTP::Delete.new(@uri.request_uri)
end
authenticate
@response = http_client.request(@request)
end
|
#error_message ⇒ Object
38
39
40
|
# File 'lib/browser_stack/api_request.rb', line 38
def error_message
parse_response
end
|
#get_http_client ⇒ Object
50
51
52
|
# File 'lib/browser_stack/api_request.rb', line 50
def get_http_client
@http_client = Net::HTTP.new(@uri.host, @uri.port)
end
|
#parse_response ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/browser_stack/api_request.rb', line 26
def parse_response
if @response.code == "401"
@response.body
else
JSON.parse @response.body
end
end
|
#set_uri(url) ⇒ Object
46
47
48
|
# File 'lib/browser_stack/api_request.rb', line 46
def set_uri(url)
@uri = URI.parse("http://api.browserstack.com/#{@config.api_version}"+url)
end
|