Class: Appurify::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/appurify/client.rb', line 5

def initialize(key, secret, options={})
  @key = key
  @secret = secret

  @scheme, @host, @port, @request_timeout, @open_timeout = {
    scheme: "https",
    host: HOSTNAME,
    port: 443,
    request_timeout: 600,
    open_timeout: 10
  }.merge(options).values
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/appurify/client.rb', line 3

def host
  @host
end

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/appurify/client.rb', line 3

def key
  @key
end

#last_requestObject

Returns the value of attribute last_request.



3
4
5
# File 'lib/appurify/client.rb', line 3

def last_request
  @last_request
end

#open_timeoutObject

Returns the value of attribute open_timeout.



3
4
5
# File 'lib/appurify/client.rb', line 3

def open_timeout
  @open_timeout
end

#portObject

Returns the value of attribute port.



3
4
5
# File 'lib/appurify/client.rb', line 3

def port
  @port
end

#request_timeoutObject

Returns the value of attribute request_timeout.



3
4
5
# File 'lib/appurify/client.rb', line 3

def request_timeout
  @request_timeout
end

#schemeObject

Returns the value of attribute scheme.



3
4
5
# File 'lib/appurify/client.rb', line 3

def scheme
  @scheme
end

#secretObject

Returns the value of attribute secret.



3
4
5
# File 'lib/appurify/client.rb', line 3

def secret
  @secret
end

Instance Method Details

#access_tokenObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/appurify/client.rb', line 18

def access_token
  unless access_token_active?
    url = build_url("access_token", "generate")
    data = {
      :key => @key,
      :secret => @secret
    }

    #result = post(url, data, false)
    result = post(url, data)
    @access_token = result["access_token"]
    @access_token_ttl = result["ttl"]
    @access_token_created = Time.now
  end

  @access_token
end

#appsObject



46
47
48
49
# File 'lib/appurify/client.rb', line 46

def apps
  url = build_url("apps", "list")
  get(url)
end

#device_typesObject



36
37
38
39
# File 'lib/appurify/client.rb', line 36

def device_types
  url = build_url("devices", "list")
  get(url)
end

#monitor_test(test_run_id) ⇒ Object



141
142
143
144
145
# File 'lib/appurify/client.rb', line 141

def monitor_test(test_run_id)
  url = build_url("tests", "check")
  params = { test_run_id: test_run_id }
  get(url, params)
end

#network_conditionsObject



41
42
43
44
# File 'lib/appurify/client.rb', line 41

def network_conditions
  url = build_url("devices", "config/networks/list")
  get(url)
end

#run_test(device_type_id, app_id, test_id, async = 1) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/appurify/client.rb', line 128

def run_test(device_type_id, app_id, test_id, async=1)
  url = build_url("tests", "run")
  data = {
    :access_token => access_token,
    :device_type_id => device_type_id,
    :app_id => app_id,
    :test_id => test_id,
    :async => async
  }

  post(url, data)
end

#testsObject



51
52
53
54
# File 'lib/appurify/client.rb', line 51

def tests
  url = build_url("tests", "list")
  get(url)
end

#upload_app(source_type, source) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/appurify/client.rb', line 65

def upload_app(source_type, source)
  url = build_url("apps", "upload")
  data = {
    :access_token => access_token,
    :source_type => source_type,
    :source => source
  }

  post(url, data)
end

#upload_app_from_file(app_path) ⇒ Object



56
57
58
59
# File 'lib/appurify/client.rb', line 56

def upload_app_from_file(app_path)
  abort "App not found" unless File.exists? app_path
  upload_app("raw", File.new(app_path, 'rb'))
end

#upload_app_from_url(app_url) ⇒ Object



61
62
63
# File 'lib/appurify/client.rb', line 61

def upload_app_from_url(app_url)
  upload_app("url", app_url)
end

#upload_config(test_id, config_src) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/appurify/client.rb', line 97

def upload_config(test_id, config_src)
  abort "Config not found" unless File.exists? config_src
  url = build_url("config", "upload")
  data = {
    :access_token => access_token,
    :test_id => test_id,
    :source => File.new(config_src, 'rb')
  }

  post(url, data)
end

#upload_device_conditions(test_id, conditions) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/appurify/client.rb', line 109

def upload_device_conditions(test_id, conditions)
  url = build_url("config", "upload")
  file_data = "[appurify]\n" +  conditions.keys.collect{ |k| k.to_s + "=" + conditions[k].to_s }.join("\n")

  file = StringIO.new(file_data)
  file.class.class_eval { attr_accessor :name }
  file.class.class_eval { attr_accessor :path }
  file.name = "config.cnf"
  file.path = "config.cnf"

  data = {
    :access_token => access_token,
    :test_id => test_id,
    :source => file
  }

  post(url, data)
end

#upload_test(source_type, source, test_type) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/appurify/client.rb', line 85

def upload_test(source_type, source, test_type)
  url = build_url("tests", "upload")
  data = {
    :access_token => access_token,
    :source_type => source_type,
    :test_type => test_type,
    :source => source
  }

  post(url, data)
end

#upload_test_from_file(test_path, test_type) ⇒ Object



76
77
78
79
# File 'lib/appurify/client.rb', line 76

def upload_test_from_file(test_path, test_type)
  abort "Tests not found" unless File.exists? test_path
  upload_test("raw", File.new(test_path, 'rb'), test_type)
end

#upload_test_from_url(test_url, test_type) ⇒ Object



81
82
83
# File 'lib/appurify/client.rb', line 81

def upload_test_from_url(test_url, test_type)
  upload_test("url", test_url, test_type)
end