Class: Atlantis::Portal::Agent

Inherits:
Mechanize
  • Object
show all
Defined in:
lib/Atlantis/portal/agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAgent

Returns a new instance of Agent.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/Atlantis/portal/agent.rb', line 13

def initialize
  super

  self.user_agent_alias = 'Mac Safari'

  self.log ||= Logger.new(STDOUT)
  self.log.level = Logger::ERROR

  if ENV['HTTP_PROXY']
    uri = URI.parse(ENV['HTTP_PROXY'])
    user = ENV['HTTP_PROXY_USER'] if ENV['HTTP_PROXY_USER']
    password = ENV['HTTP_PROXY_PASSWORD'] if ENV['HTTP_PROXY_PASSWORD']

    set_proxy(uri.host, uri.port, user || uri.user, password || uri.password)
  end

  pw = Security::InternetPassword.find(:server => Atlantis::Portal::HOST)
  @username, @password = pw.attributes['acct'], pw.password if pw
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



11
12
13
# File 'lib/Atlantis/portal/agent.rb', line 11

def format
  @format
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/Atlantis/portal/agent.rb', line 11

def password
  @password
end

#teamObject

Returns the value of attribute team.



11
12
13
# File 'lib/Atlantis/portal/agent.rb', line 11

def team
  @team
end

#usernameObject

Returns the value of attribute username.



11
12
13
# File 'lib/Atlantis/portal/agent.rb', line 11

def username
  @username
end

Instance Method Details

#get(uri, parameters = [], referer = nil, headers = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/Atlantis/portal/agent.rb', line 40

def get(uri, parameters = [], referer = nil, headers = {})
  uri = ::File.join("https://#{Atlantis::Portal::HOST}", uri) unless /^https?/ === uri

  3.times do
    super(uri, parameters, referer, headers)

    #puts page.body

    return page unless page.respond_to?(:title)

    unless page.parser.at_css('#id_username').nil?
      #puts "Logging in"
      login! and next
    else
      if !@team.nil? && !@team.empty?
        select_team! and next
      else
        return page
      end
    end
  end

    raise UnsuccessfulAuthenticationError
end

#list_devices(distribution_list) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/Atlantis/portal/agent.rb', line 102

def list_devices(distribution_list)
  people = list_people(distribution_list)

  people_list = []

  people.each do |person|
    people_list << person.id
  end

  post('https://testflightapp.com/dashboard/team/export/devices/', { "members" => people_list.join('|'), "csrfmiddlewaretoken" => page.parser.css("[name='csrfmiddlewaretoken']")[0]['value'] } )

  device_list = page.body.split( /\r?\n/ )

  # Remove first one
  device_list.shift

  devices = []

  device_list.each do |dev|
    #puts dev

    device = Device.new
    device.udid = dev.split(/\t/)[0]
    device.name = dev.split(/\t/)[1]

    devices << device
  end

  devices
end

#list_listsObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/Atlantis/portal/agent.rb', line 133

def list_lists
  get('https://testflightapp.com/dashboard/team')

  lists = []

  page.parser.css("nav.vert-nav li a").each do |row|

    unless (row['href'].nil?)
      url = row['href'].split('/')

      #puts url.length

      if (url.length >= 5) && (url[4].is_i?)
        #puts url[3]

        list = DistributionList.new
        list.id = url[4]
        list.name = row.css('> text()').text.strip
        list.count = row.css('span').text.strip

        lists << list
      end

    end
  end

  lists
end

#list_people(distribution_list) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/Atlantis/portal/agent.rb', line 65

def list_people(distribution_list)

  if (distribution_list == 'all')
    get('https://testflightapp.com/dashboard/team')
  else
    lists = list_lists

    list = lists.find{|p| p.name == distribution_list}

    say_warning "No #{distribution_list} distribution list found." and abort if list.nil?

    get('https://testflightapp.com/dashboard/team/list/' + list.id)
  end

  people = []

  page.parser.css("table#member-table tr").each do |row|
    cols = row.css('td')

    #puts cols.length

    if (cols.length > 0)
      person = Person.new

      person.id = cols[0].css("input")[0]['value'];
      person.name = cols[1].text.strip.split.map(&:capitalize).join(' ')
      person.email = cols[2].text.strip
      person.devices = cols[3].text.strip

      people << person

    end
  end

  people
end

#list_teamsObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/Atlantis/portal/agent.rb', line 162

def list_teams
  teams = []

  # Selected team

  selected_team = page.parser.css('ul.dropdown-menu li div div.textcontain180 text()')

  team = Team.new
  team.name = selected_team

  teams << team

  all_teams = page.parser.css('ul.ddteamlist li a')
  all_teams.each do |row|
    team = Team.new
    team.id = row['data-team-id']
    team.name = row.text

    teams << team
  end

  teams
end