appthwack 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Yzg4MjdmZDY3YWM1N2U4N2FjNzg5ZTQ5ZjI3ZWExOTY3ZGEyYmRjMw==
5
+ data.tar.gz: !binary |-
6
+ MzNiNDExYjc2ZmRjMTEyZGJiMDRhZWYxNmU4NGVhMTAwNmZmNzIyZA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDI1NTZiNDM1MjkxNWIzYTJlNDA3NjNmNDhlNGRmMTI4MWJlYzgzYTYyNDFm
10
+ YWNjMjI1NjkyMTcxNjRhNmExYmNiNmE2NzY1MjAxZjVkM2VmOTVjMGU0YmZl
11
+ NmZkMDBjN2JkNzdmMjkzZDhhM2YyMjI3MjhhMmQwNmMxM2NjODg=
12
+ data.tar.gz: !binary |-
13
+ YzUzNDMyYjc4Njc4NzZlYzUyZGI5NDI5YmI0MmE0YjVlOTAyZGI1ODIwN2Q4
14
+ NzMzZWI2MjUxZmMxOGUxOTZkNjJhNDg4MTYxZGQ0MTk0YmYxMmJhNmIyMTg3
15
+ ZWQ0ZGY0MmJjMjE2NzMzMmU1YzZkZmY4YTAyMGQxYWExNmJjMDA=
File without changes
@@ -0,0 +1,10 @@
1
+ require 'open-uri'
2
+ require 'json'
3
+ require 'net/https'
4
+ require 'rest-client'
5
+ require 'appthwack/version'
6
+ require 'appthwack/client'
7
+
8
+ module Appthwack
9
+ BASE_URL = "https://appthwack.com"
10
+ end
@@ -0,0 +1,96 @@
1
+ module Appthwack
2
+ class Client
3
+ attr_accessor :api_token, :base_url, :request_timeout, :open_timeout, :last_request
4
+
5
+ def initialize(api_token, options={})
6
+ @api_token = api_token
7
+
8
+ @base_url, @request_timeout, @open_timeout = {
9
+ base_url: BASE_URL,
10
+ request_timeout: 600,
11
+ open_timeout: 10
12
+ }.merge(options).values
13
+ end
14
+
15
+ def projects
16
+ get("#{@base_url}/api/project/")
17
+ end
18
+
19
+ def create_device_pool(name, device_ids)
20
+ payload = {
21
+ :name => name,
22
+ :devices => device_ids
23
+ }
24
+
25
+ post("#{@base_url}/api/devicepool", payload)
26
+ end
27
+
28
+ def device_pools(project_id)
29
+ get("#{@base_url}/api/devicepool/#{project_id}")
30
+ end
31
+
32
+ def devices
33
+ get("#{@base_url}/api/device")
34
+ end
35
+
36
+ def upload_file(name, file)
37
+ payload = {
38
+ :name => name,
39
+ :file => file
40
+ }
41
+
42
+ post("#{@base_url}/api/file", payload)
43
+ end
44
+
45
+ def schedule_test(name, project_id, app_file_id, opt={})
46
+ payload = {
47
+ :project => project_id,
48
+ :name => name,
49
+ :app => app_file_id
50
+ }.merge(opt)
51
+
52
+ post("#{@base_url}/api/run", payload)
53
+ end
54
+
55
+ def test_run_status(project_id, run_id)
56
+ get("#{@base_url}/api/run/#{project_id}/#{run_id}/status")
57
+ end
58
+
59
+ def test_run_results(project_id, run_id)
60
+ get("#{@base_url}/api/run/#{project_id}/#{run_id}")
61
+ end
62
+
63
+ private
64
+
65
+ def get(url, params={})
66
+ @last_request = {
67
+ url: url,
68
+ request: params
69
+ }
70
+
71
+ if params.empty?
72
+ query_string_params = ""
73
+ else
74
+ query_string_params = "?" + params.collect{ |p| "&#{p[0].to_s}=#{p[1].to_s}" }.join
75
+ end
76
+
77
+ result = RestClient::Request.execute(:method => :get, :url => "#{url}#{query_string_params}", :timeout => @request_timeout, :open_timeout => @open_timeout, :user => @api_token, :password => "")
78
+ @last_request[:response] = result
79
+
80
+ JSON.parse(result)
81
+ end
82
+
83
+ def post(url, data)
84
+ @last_request = {
85
+ url: url,
86
+ request: data
87
+ }
88
+
89
+ result = RestClient::Request.execute(:method => :post, :url => url, :payload => data, :timeout => @request_timeout, :open_timeout => @open_timeout, :user => @api_token, :password => "")
90
+ @last_request[:response] = result
91
+
92
+ JSON.parse(result)
93
+ end
94
+
95
+ end
96
+ end
@@ -0,0 +1,3 @@
1
+ module Appthwack
2
+ VERSION = '0.1'
3
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+ require 'fake_web'
3
+ require 'timecop'
4
+
5
+ describe Appthwack do
6
+
7
+ let(:api_token) { "DTOZZNWeCNWFWtuqqJEm14nnonVJMDXA9flmdvzg" }
8
+
9
+ before do
10
+ FakeWeb.allow_net_connect = false
11
+ end
12
+
13
+ describe "When configuring an Appthwack Client" do
14
+
15
+ it "should correctly configure the api_token" do
16
+ Appthwack::Client.new(api_token).api_token.should == api_token
17
+ end
18
+
19
+ it "should correctly configure connection options" do
20
+ options = {
21
+ base_url: "thwackbin.herokuapp.com",
22
+ request_timeout: 5,
23
+ open_timeout: 5
24
+ }
25
+
26
+ client = Appthwack::Client.new(api_token, options)
27
+ client.base_url.should == options[:base_url]
28
+ client.request_timeout.should == options[:request_timeout]
29
+ client.open_timeout.should == options[:open_timeout]
30
+ end
31
+
32
+ end
33
+
34
+ describe "When using an Appthwack Client" do
35
+
36
+ let (:client) { Appthwack::Client.new(api_token) }
37
+ let (:project_id) { 2 }
38
+ let (:run_id) { 3 }
39
+
40
+ before do
41
+ mock_projects_response(api_token)
42
+ mock_device_pools_response(api_token, project_id)
43
+ mock_upload_file_response(api_token)
44
+ mock_schedule_test_response(api_token)
45
+ mock_test_run_status_response(api_token, project_id, run_id)
46
+ mock_test_run_results_response(api_token, project_id, run_id)
47
+ end
48
+
49
+ it "should successfully retrieve projects" do
50
+ client.projects.count.should == 2
51
+ end
52
+
53
+ it "should successfully retrieve device pools for a project" do
54
+ client.device_pools(project_id).count.should == 2
55
+ end
56
+
57
+ it "should upload a file" do
58
+ f = File.open("spec/fixtures/files/com.actionbarsherlock.sample.demos.4.1.0.apk")
59
+ client.upload_file("myfile.apk", f)["file_id"].should_not be_nil
60
+ end
61
+
62
+ it "should schedule a test" do
63
+ client.schedule_test("my test", project_id, run_id)["run_id"].should_not be_nil
64
+ end
65
+
66
+ it "should retrieve test run status" do
67
+ client.test_run_status(project_id, run_id)["status"].should_not be_nil
68
+ end
69
+
70
+ it "should retrieve test run results" do
71
+ client.test_run_results(project_id, run_id)
72
+ end
73
+
74
+ end
75
+
76
+ end
Binary file
@@ -0,0 +1,43 @@
1
+ require 'rspec'
2
+ require 'appthwack'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ config.formatter = 'documentation'
7
+ end
8
+
9
+ def mock_projects_response(token)
10
+ url = "https://#{token}@appthwack.com/api/project/"
11
+ response = "[{\"name\": \"cisimple - ios\", \"url\": \"cisimple-ios\", \"id\": 4698}, {\"name\": \"cisimple - android\", \"url\": \"cisimple-android\", \"id\": 4697}]"
12
+ FakeWeb.register_uri(:get, url, :body => response, :status => 200)
13
+ end
14
+
15
+ def mock_device_pools_response(token, project_id)
16
+ url = "https://#{token}@appthwack.com/api/devicepool/#{project_id}"
17
+ response = "[{\"id\": 1, \"name\": \"All devices (25)\"}, {\"id\": 4, \"name\": \"Top 10 devices (10)\"}]"
18
+ FakeWeb.register_uri(:get, url, :body => response, :status => 200)
19
+ end
20
+
21
+ def mock_upload_file_response(token)
22
+ url = "https://#{token}@appthwack.com/api/file"
23
+ response = "{ \"file_id\": 42 }"
24
+ FakeWeb.register_uri(:post, url, :body => response, :status => 200)
25
+ end
26
+
27
+ def mock_schedule_test_response(token)
28
+ url = "https://#{token}@appthwack.com/api/run"
29
+ response = "{ \"run_id\": 43 }"
30
+ FakeWeb.register_uri(:post, url, :body => response, :status => 200)
31
+ end
32
+
33
+ def mock_test_run_status_response(token, project_id, run_id)
34
+ url = "https://#{token}@appthwack.com/api/run/#{project_id}/#{run_id}/status"
35
+ response = "{ \"status\": \"completed\" }"
36
+ FakeWeb.register_uri(:get, url, :body => response, :status => 200)
37
+ end
38
+
39
+ def mock_test_run_results_response(token, project_id, run_id)
40
+ url = "https://#{token}@appthwack.com/api/run/#{project_id}/#{run_id}"
41
+ response = "{ }"
42
+ FakeWeb.register_uri(:get, url, :body => response, :status => 200)
43
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: appthwack
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - cisimple
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fakeweb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.30'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.30'
55
+ - !ruby/object:Gem::Dependency
56
+ name: timecop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.60'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.60'
69
+ description: API client for Appthwack
70
+ email:
71
+ - team@cisimple.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - README.md
77
+ - lib/appthwack.rb
78
+ - lib/appthwack/client.rb
79
+ - lib/appthwack/version.rb
80
+ - spec/client/client_spec.rb
81
+ - spec/fixtures/.DS_Store
82
+ - spec/fixtures/files/.DS_Store
83
+ - spec/fixtures/files/com.actionbarsherlock.sample.demos.4.1.0.apk
84
+ - spec/spec_helper.rb
85
+ homepage: https://github.com/cisimple-team/appthwack
86
+ licenses: []
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options:
90
+ - --charset=UTF-8
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.1.11
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Run tests using Appthwack's mobile devices.
109
+ test_files:
110
+ - spec/client/client_spec.rb
111
+ - spec/fixtures/.DS_Store
112
+ - spec/fixtures/files/.DS_Store
113
+ - spec/fixtures/files/com.actionbarsherlock.sample.demos.4.1.0.apk
114
+ - spec/spec_helper.rb
115
+ has_rdoc: