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

#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



101
102
103
104
105
# File 'lib/appurify/client.rb', line 101

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



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/appurify/client.rb', line 88

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

#upload_app_from_url(app_url) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/appurify/client.rb', line 46

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

  post(url, data)
end

#upload_device_conditions(test_id, conditions) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/appurify/client.rb', line 69

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_from_url(test_url, test_type) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/appurify/client.rb', line 57

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

  post(url, data)
end