Class: Atlantis::Portal::TestFlightService

Inherits:
Service
  • Object
show all
Defined in:
lib/Atlantis/portal/testflight/testflightservice.rb

Instance Method Summary collapse

Constructor Details

#initializeTestFlightService

Returns a new instance of TestFlightService.



14
15
16
17
18
# File 'lib/Atlantis/portal/testflight/testflightservice.rb', line 14

def initialize
  super

  self.host = "testflightapp.com"
end

Instance Method Details

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/Atlantis/portal/testflight/testflightservice.rb', line 20

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

  3.times do
    agent.get(uri, parameters, referer, headers)

    #puts page.body

    return agent.page unless agent.page.respond_to?(:title)

    unless agent.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 agent.page
      end
    end
  end

  raise UnsuccessfulAuthenticationError
end

#list_devices(distribution_list) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/Atlantis/portal/testflight/testflightservice.rb', line 82

def list_devices(distribution_list)
  people = list_people(distribution_list)

  people_list = []

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

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

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

  # Remove first one
  device_list.shift

  devices = []

  device_list.each do |dev|
    #puts dev

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

    devices << device
  end

  devices
end

#list_groupsObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/Atlantis/portal/testflight/testflightservice.rb', line 113

def list_groups
  get('dashboard/team')

  lists = []

  agent.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 = Group.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(group) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/Atlantis/portal/testflight/testflightservice.rb', line 45

def list_people(group)

  if group.nil?
    get('/dashboard/team')
  else
    lists = list_groups

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

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

    get('/dashboard/team/list/' + list.id)
  end

  people = {}

  agent.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.id] = person

    end
  end

  return people
end

#list_teamsObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/Atlantis/portal/testflight/testflightservice.rb', line 142

def list_teams
  teams = []

  # Selected team

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

  team = Team.new
  team.name = selected_team

  teams << team

  all_teams = agent.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