Class: UserAccount

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, access_key) ⇒ UserAccount

Returns a new instance of UserAccount.



4
5
6
7
8
9
10
11
# File 'lib/user_account.rb', line 4

def initialize username, access_key
  if validate_params username, access_key
    @username = username
    @access_key = access_key
  else
    raise Exception, "Invalid username/accesskey"
  end
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



2
3
4
# File 'lib/user_account.rb', line 2

def access_key
  @access_key
end

#usernameObject

Returns the value of attribute username.



2
3
4
# File 'lib/user_account.rb', line 2

def username
  @username
end

Instance Method Details

#create_worker(options) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/user_account.rb', line 22

def create_worker options
  require_params = %w(os os_version browser device browser_version timeout url name)
  optional_params = %w(build project)
  options.reject! { |o| !require_params.include?(o) && !optional_params.include?(o) }
  require_params.each { |param| raise Exception, "Parameter #{param} is required." if !options.include?(param) }
  uri = "http://api.browserstack.com/3/worker"
  response= post_at_browser_stack(uri, options)
  return JSON.parse(response.body)
end

#get_api_statusObject



53
54
55
56
57
# File 'lib/user_account.rb', line 53

def get_api_status 
 uri = "http://api.browserstack.com/3/status"
 response = get_from_browser_stack uri
 return JSON.parse(response.body)
end

#get_browsers(options) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/user_account.rb', line 14

def get_browsers options
  uri = "http://api.browserstack.com/3/browsers?"
  uri = uri + "flat=true" if options[:flat]
  uri = uri + "all=true" if options[:all]
  response = get_from_browser_stack uri
  return JSON.parse(response.body)
end

#get_worker_screen_shot(options) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/user_account.rb', line 32

def get_worker_screen_shot options
  require_params =%w(format worker_id)
  optional_params = %w()
  options.reject! { |o| !require_params.include?(o) && !optional_params.include?(o) }
  require_params.each { |param| raise Exception, "Parameter #{param} is required." if !options.include?(param) }
  uri = "http://api.browserstack.com/3/worker/#{options["worker_id"]}/screenshot.#{options["format"]}"
  response = get_from_browser_stack uri
  return JSON.parse(response.body)
end

#get_worker_status(options) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/user_account.rb', line 43

def get_worker_status options
 required_params  = %w(worker_id)
 optional_params  =  []
 options.reject! { |o| !required_params.include?(o) && !optional_params.include?(o) }
 required_params.each { |param| raise Exception, "Parameter #{param} is required." if !options.include?(param) }
 uri = "http://api.browserstack.com/3/worker/#{options["worker_id"]}"
 response = get_from_browser_stack uri
 return JSON.parse(response.body)
end