Class: TestingBot::Api

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

Constant Summary collapse

VERSION =
1
API_URL =
"https://api.testingbot.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key = nil, secret = nil, options = {}) ⇒ Api

Returns a new instance of Api.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/testingbot/api.rb', line 13

def initialize(key = nil, secret = nil, options = {})
  @key = key
  @secret = secret
  @options = {
    :debug => false
  }.merge(options)
  if @key.nil? || @secret.nil?
    cached_credentials = load_config_file
    @key, @secret = cached_credentials unless cached_credentials.nil?
  end

  if @key.nil? || @secret.nil?
    @key = ENV["TESTINGBOT_KEY"] if ENV["TESTINGBOT_KEY"]
    @secret = ENV["TESTINGBOT_SECRET"] if ENV["TESTINGBOT_SECRET"]
  end

  if @key.nil? || @secret.nil?
    @key = ENV["TB_KEY"] if ENV["TB_KEY"]
    @secret = ENV["TB_SECRET"] if ENV["TB_SECRET"]
  end

  raise "Please supply a TestingBot Key" if @key.nil?
  raise "Please supply a TestingBot Secret" if @secret.nil?
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/testingbot/api.rb', line 11

def key
  @key
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/testingbot/api.rb', line 11

def options
  @options
end

#secretObject (readonly)

Returns the value of attribute secret.



11
12
13
# File 'lib/testingbot/api.rb', line 11

def secret
  @secret
end

Instance Method Details

#create_user_in_team(user = {}) ⇒ Object



66
67
68
# File 'lib/testingbot/api.rb', line 66

def create_user_in_team(user = {})
  post("/team-management/users/", user)
end

#delete_build(build_identifier) ⇒ Object



122
123
124
# File 'lib/testingbot/api.rb', line 122

def delete_build(build_identifier)
  delete("/builds/#{build_identifier}")
end

#delete_test(test_id) ⇒ Object



104
105
106
107
# File 'lib/testingbot/api.rb', line 104

def delete_test(test_id)
  response = delete("/tests/#{test_id}")
  response["success"]
end

#delete_tunnel(tunnel_identifier) ⇒ Object



142
143
144
# File 'lib/testingbot/api.rb', line 142

def delete_tunnel(tunnel_identifier)
  delete("/tunnel/#{tunnel_identifier}")
end

#delete_uploaded_file(app_url) ⇒ Object



180
181
182
183
# File 'lib/testingbot/api.rb', line 180

def delete_uploaded_file(app_url)
  response = delete("/storage/#{app_url.gsub(/tb:\/\//, '')}")
  response["success"]
end

#get_authentication_hash(identifier) ⇒ Object



146
147
148
# File 'lib/testingbot/api.rb', line 146

def get_authentication_hash(identifier)
  Digest::MD5.hexdigest("#{@key}:#{@secret}:#{identifier}")
end

#get_available_devicesObject



50
51
52
# File 'lib/testingbot/api.rb', line 50

def get_available_devices
  get("/devices/available")
end

#get_browsersObject



42
43
44
# File 'lib/testingbot/api.rb', line 42

def get_browsers
  get("/browsers")
end

#get_build(build_identifier) ⇒ Object



118
119
120
# File 'lib/testingbot/api.rb', line 118

def get_build(build_identifier)
  get("/builds/#{build_identifier}")
end

#get_builds(offset = 0, count = 10) ⇒ Object



114
115
116
# File 'lib/testingbot/api.rb', line 114

def get_builds(offset = 0, count = 10)
  get("/builds?offset=#{offset}&count=#{count}")
end

#get_devicesObject



46
47
48
# File 'lib/testingbot/api.rb', line 46

def get_devices
  get("/devices")
end

#get_screenshots(screenshots_id) ⇒ Object



134
135
136
# File 'lib/testingbot/api.rb', line 134

def get_screenshots(screenshots_id)
  get("/screenshots/#{screenshots_id}")
end

#get_screenshots_history(offset = 0, count = 10) ⇒ Object



130
131
132
# File 'lib/testingbot/api.rb', line 130

def get_screenshots_history(offset = 0, count = 10)
  get("/screenshots?offset=#{offset}&count=#{count}")
end

#get_teamObject



54
55
56
# File 'lib/testingbot/api.rb', line 54

def get_team
  get("/team-management")
end

#get_test(test_id) ⇒ Object



91
92
93
# File 'lib/testingbot/api.rb', line 91

def get_test(test_id)
  get("/tests/#{test_id}")
end

#get_tests(offset = 0, count = 10) ⇒ Object



87
88
89
# File 'lib/testingbot/api.rb', line 87

def get_tests(offset = 0, count = 10)
  get("/tests?offset=#{offset}&count=#{count}")
end

#get_tunnelsObject



138
139
140
# File 'lib/testingbot/api.rb', line 138

def get_tunnels
  get("/tunnel/list")
end

#get_uploaded_file(app_url) ⇒ Object



176
177
178
# File 'lib/testingbot/api.rb', line 176

def get_uploaded_file(app_url)
  get("/storage/#{app_url.gsub(/tb:\/\//, '')}")
end

#get_uploaded_files(offset = 0, count = 10) ⇒ Object



172
173
174
# File 'lib/testingbot/api.rb', line 172

def get_uploaded_files(offset = 0, count = 10)
  get("/storage?offset=#{offset}&count=#{count}")
end

#get_user_in_team(user_id) ⇒ Object



62
63
64
# File 'lib/testingbot/api.rb', line 62

def get_user_in_team(user_id)
  get("/team-management/users/#{user_id}")
end

#get_user_infoObject



38
39
40
# File 'lib/testingbot/api.rb', line 38

def 
  get("/user")
end

#get_users_in_team(offset = 0, count = 10) ⇒ Object



58
59
60
# File 'lib/testingbot/api.rb', line 58

def get_users_in_team(offset = 0, count = 10)
  get("/team-management/users?offset=#{offset}&count=#{count}")
end

#reset_credentials(user_id) ⇒ Object



74
75
76
# File 'lib/testingbot/api.rb', line 74

def reset_credentials(user_id)
  post("/team-management/users/#{user_id}/reset-keys")
end

#stop_test(test_id) ⇒ Object



109
110
111
112
# File 'lib/testingbot/api.rb', line 109

def stop_test(test_id)
  response = put("/tests/#{test_id}/stop")
  response["success"]
end

#take_screenshots(configuration) ⇒ Object



126
127
128
# File 'lib/testingbot/api.rb', line 126

def take_screenshots(configuration)
  post("/screenshots", configuration)
end

#update_test(test_id, params = {}) ⇒ Object



95
96
97
98
99
100
101
102
# File 'lib/testingbot/api.rb', line 95

def update_test(test_id, params = {})
  new_params = {}
  params.keys.each do |key|
    new_params["test[#{key}]"] = params[key]
  end
  response = put("/tests/#{test_id}", new_params)
  response["success"]
end

#update_user_in_team(user_id, user = {}) ⇒ Object



70
71
72
# File 'lib/testingbot/api.rb', line 70

def update_user_in_team(user_id, user = {})
  put("/team-management/users/#{user_id}", user)
end

#update_user_info(params = {}) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/testingbot/api.rb', line 78

def (params = {})
  new_params = {}
  params.keys.each do |key|
    new_params["user[#{key}]"] = params[key]
  end
  response = put("/user", new_params)
  response["success"]
end

#upload_local_file(file_path) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/testingbot/api.rb', line 150

def upload_local_file(file_path)
  response = RestClient::Request.execute(
    method: :post,
    url: API_URL + "/v1/storage",
    user: @key,
    password: @secret,
    timeout: 600,
    payload: {
      multipart: true,
      file: File.new(file_path, 'rb')
    }
  )
  parsed = JSON.parse(response.body)
  parsed
end

#upload_remote_file(url) ⇒ Object



166
167
168
169
170
# File 'lib/testingbot/api.rb', line 166

def upload_remote_file(url)
  post("/storage/", {
    :url => url
  })
end