Class: TestingBot::Api
- Inherits:
-
Object
- Object
- TestingBot::Api
- Defined in:
- lib/testingbot/api.rb
Constant Summary collapse
- VERSION =
1- API_URL =
"https://api.testingbot.com"
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Instance Method Summary collapse
- #delete_test(test_id) ⇒ Object
- #delete_uploaded_file(app_url) ⇒ Object
- #get_authentication_hash(identifier) ⇒ Object
- #get_browsers ⇒ Object
- #get_build(build_identifier) ⇒ Object
- #get_builds(offset = 0, count = 10) ⇒ Object
- #get_test(test_id) ⇒ Object
- #get_tests(offset = 0, count = 10) ⇒ Object
- #get_tunnels ⇒ Object
- #get_uploaded_file(app_url) ⇒ Object
- #get_uploaded_files(offset = 0, count = 10) ⇒ Object
- #get_user_info ⇒ Object
-
#initialize(key = nil, secret = nil, options = {}) ⇒ Api
constructor
A new instance of Api.
- #stop_test(test_id) ⇒ Object
- #update_test(test_id, params = {}) ⇒ Object
- #update_user_info(params = {}) ⇒ Object
- #upload_local_file(file_path) ⇒ Object
- #upload_remote_file(url) ⇒ Object
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, = {}) @key = key @secret = secret @options = { :debug => false }.merge() 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
#key ⇒ Object (readonly)
Returns the value of attribute key.
11 12 13 |
# File 'lib/testingbot/api.rb', line 11 def key @key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/testingbot/api.rb', line 11 def @options end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
11 12 13 |
# File 'lib/testingbot/api.rb', line 11 def secret @secret end |
Instance Method Details
#delete_test(test_id) ⇒ Object
72 73 74 75 |
# File 'lib/testingbot/api.rb', line 72 def delete_test(test_id) response = delete("/tests/#{test_id}") response["success"] end |
#delete_uploaded_file(app_url) ⇒ Object
128 129 130 131 |
# File 'lib/testingbot/api.rb', line 128 def delete_uploaded_file(app_url) response = delete("/storage/#{app_url.gsub(/tb:\/\//, '')}") response["success"] end |
#get_authentication_hash(identifier) ⇒ Object
94 95 96 |
# File 'lib/testingbot/api.rb', line 94 def get_authentication_hash(identifier) Digest::MD5.hexdigest("#{@key}:#{@secret}:#{identifier}") end |
#get_browsers ⇒ Object
42 43 44 |
# File 'lib/testingbot/api.rb', line 42 def get_browsers get("/browsers") end |
#get_build(build_identifier) ⇒ Object
86 87 88 |
# File 'lib/testingbot/api.rb', line 86 def get_build(build_identifier) get("/builds/#{build_identifier}") end |
#get_builds(offset = 0, count = 10) ⇒ Object
82 83 84 |
# File 'lib/testingbot/api.rb', line 82 def get_builds(offset = 0, count = 10) get("/builds?offset=#{offset}&count=#{count}") end |
#get_test(test_id) ⇒ Object
59 60 61 |
# File 'lib/testingbot/api.rb', line 59 def get_test(test_id) get("/tests/#{test_id}") end |
#get_tests(offset = 0, count = 10) ⇒ Object
55 56 57 |
# File 'lib/testingbot/api.rb', line 55 def get_tests(offset = 0, count = 10) get("/tests?offset=#{offset}&count=#{count}") end |
#get_tunnels ⇒ Object
90 91 92 |
# File 'lib/testingbot/api.rb', line 90 def get_tunnels get("/tunnel/list") end |
#get_uploaded_file(app_url) ⇒ Object
124 125 126 |
# File 'lib/testingbot/api.rb', line 124 def get_uploaded_file(app_url) get("/storage/#{app_url.gsub(/tb:\/\//, '')}") end |
#get_uploaded_files(offset = 0, count = 10) ⇒ Object
120 121 122 |
# File 'lib/testingbot/api.rb', line 120 def get_uploaded_files(offset = 0, count = 10) get("/storage?offset=#{offset}&count=#{count}") end |
#get_user_info ⇒ Object
38 39 40 |
# File 'lib/testingbot/api.rb', line 38 def get_user_info get("/user") end |
#stop_test(test_id) ⇒ Object
77 78 79 80 |
# File 'lib/testingbot/api.rb', line 77 def stop_test(test_id) response = put("/tests/#{test_id}/stop") response["success"] end |
#update_test(test_id, params = {}) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/testingbot/api.rb', line 63 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_info(params = {}) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/testingbot/api.rb', line 46 def update_user_info(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
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/testingbot/api.rb', line 98 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
114 115 116 117 118 |
# File 'lib/testingbot/api.rb', line 114 def upload_remote_file(url) post("/storage/", { :url => url }) end |