Class: Infinite::Loop::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/infinite/loop/agent.rb

Constant Summary collapse

BASE_URL =
"https://rink.hockeyapp.net/api/2/"

Instance Method Summary collapse

Constructor Details

#initializeAgent

Returns a new instance of Agent.



9
10
11
12
# File 'lib/infinite/loop/agent.rb', line 9

def initialize
  netrc = Netrc.read
  @token = netrc[Infinite::HOSTNAME].first unless netrc[Infinite::HOSTNAME].nil?
end

Instance Method Details

#create_token(user, pass) ⇒ Object



33
34
35
36
37
# File 'lib/infinite/loop/agent.rb', line 33

def create_token(user, pass)
  response = RestClient::Request.new(:method => :post, :url => "#{BASE_URL}auth_tokens", :user => user, :password => pass).execute
  tokens = JSON.parse(response.to_str)["tokens"]
  tokens
end

#list_apps(release_type_string = nil) ⇒ Object



14
15
16
17
18
19
# File 'lib/infinite/loop/agent.rb', line 14

def list_apps(release_type_string = nil)
  response = RestClient.get "#{BASE_URL}apps", { "X-HockeyAppToken" => @token }
  apps = JSON.parse(response)["apps"]
  apps.reject! { |app| app["release_type"] != release_type(release_type_string) } unless release_type_string.nil?
  apps
end

#list_devices(app_id, unprovisioned = nil) ⇒ Object



21
22
23
24
25
# File 'lib/infinite/loop/agent.rb', line 21

def list_devices(app_id, unprovisioned = nil)
  response = RestClient.get "#{BASE_URL}apps/#{app_id}/devices?unprovisioned=#{unprovisioned.to_s == "unprovisioned" ? 1 : 0}", {"X-HockeyAppToken" => @token }
  devices = JSON.parse(response)["devices"]
  devices
end

#list_tokens(user, pass) ⇒ Object



27
28
29
30
31
# File 'lib/infinite/loop/agent.rb', line 27

def list_tokens(user, pass)
  response = RestClient::Request.new(:method => :get, :url => "#{BASE_URL}auth_tokens", :user => user, :password => pass).execute
  tokens = JSON.parse(response.to_str)["tokens"]
  tokens
end

#release_type(string) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/infinite/loop/agent.rb', line 39

def release_type(string)
  case string
  when "beta"
    0
  when "live"
    1
  when "alpha"
    2
  end
end

#release_type_string(value) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/infinite/loop/agent.rb', line 50

def release_type_string(value)
  case value.to_i
  when 0
    "beta"
  when 1
    "live" 
  when 2
    "alpha"
  end
end