Class: Atlantis::Portal::CrashlyticsService
- Inherits:
-
Service
- Object
- Service
- Atlantis::Portal::CrashlyticsService
- Defined in:
- lib/Atlantis/portal/crashlytics/crashlyticsservice.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#csrf_token ⇒ Object
Returns the value of attribute csrf_token.
-
#developer_token ⇒ Object
Returns the value of attribute developer_token.
-
#login_data ⇒ Object
Returns the value of attribute login_data.
-
#team_id ⇒ Object
Returns the value of attribute team_id.
Instance Method Summary collapse
-
#bootstrap ⇒ Object
Handles login and CSRF tokens.
- #get(uri, parameters = [], referer = nil, headers = {}) ⇒ Object
-
#initialize ⇒ CrashlyticsService
constructor
A new instance of CrashlyticsService.
- #list_apps ⇒ Object
- #list_devices(group) ⇒ Object
- #list_groups ⇒ Object
- #list_people(group) ⇒ Object
- #list_testers(app_id) ⇒ Object
Constructor Details
#initialize ⇒ CrashlyticsService
Returns a new instance of CrashlyticsService.
15 16 17 18 19 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 15 def initialize super self.host = "crashlytics.com" end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
13 14 15 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 13 def access_token @access_token end |
#csrf_token ⇒ Object
Returns the value of attribute csrf_token.
13 14 15 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 13 def csrf_token @csrf_token end |
#developer_token ⇒ Object
Returns the value of attribute developer_token.
13 14 15 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 13 def developer_token @developer_token end |
#login_data ⇒ Object
Returns the value of attribute login_data.
13 14 15 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 13 def login_data @login_data end |
#team_id ⇒ Object
Returns the value of attribute team_id.
13 14 15 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 13 def team_id @team_id end |
Instance Method Details
#bootstrap ⇒ Object
Handles login and CSRF tokens
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 54 def bootstrap if (self.csrf_token.nil?) csrf! end # # First need developer token # if (self.developer_token.nil?) config! end # # Need to login too # if (self.access_token.nil?) login! end end |
#get(uri, parameters = [], referer = nil, headers = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 21 def get(uri, parameters = [], referer = nil, headers = {}) uri = ::File.join("https://#{self.host}", uri) unless /^https?/ === uri #puts "Requesting: #{uri}" unless (self.developer_token.nil?) headers['X-CRASHLYTICS-DEVELOPER-TOKEN'] = self.developer_token end unless (self.access_token.nil?) headers['X-CRASHLYTICS-ACCESS-TOKEN'] = self.access_token end unless (self.csrf_token.nil?) headers['X-CSRF-Token'] = self.csrf_token end headers['X-Requested-With'] = 'XMLHttpRequest' 3.times do agent.get(uri, parameters, referer, headers) return agent.page end raise NetworkError end |
#list_apps ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 106 def list_apps bootstrap page = get("/api/v2/organizations/#{self.team_id}/apps") apps = JSON.parse(page.body) return apps end |
#list_devices(group) ⇒ Object
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 101 102 103 104 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 75 def list_devices(distribution_list) people = list_people(distribution_list) people_list = [] people.each do |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.udid = dev.split(/\t/)[0] device.name = dev.split(/\t/)[1] devices << device end devices end |
#list_groups ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 202 def list_groups testers = list_people(nil) groups = {} testers.each do |id, tester| tester.groups.each do |group| groups[group.id] = group end end return groups.values end |
#list_people(group) ⇒ Object
125 126 127 128 129 130 131 132 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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 125 def list_people(group) bootstrap apps = list_apps all_testers = {} apps.each do |app| testers = list_testers (app['id']) # # For each tester go through it's devices and add them # testers.each do |tester| # # If tester is not yet in, create it # if all_testers[tester['id']].nil? person = Person.new person.id = tester['id'] person.name = tester['name'] person.email = tester['email'] person.groups = [] person.devices = {} add_group = false if tester['groups'] groups = tester['groups'] groups.each do |current_group| person_group = Group.new person_group.id = current_group['id'] person_group.name = current_group['name'] person_group.alias = current_group['alias'] person.groups << person_group if person_group.name == group or person_group.alias == group add_group = true end end end if (add_group == true or group.nil?) and !person.name.empty? all_testers[person.id] = person end else person = all_testers[tester['id']] end append_devices(person, tester['devices']) end end return all_testers end |
#list_testers(app_id) ⇒ Object
116 117 118 119 120 121 122 123 |
# File 'lib/Atlantis/portal/crashlytics/crashlyticsservice.rb', line 116 def list_testers(app_id) bootstrap page = get("/api/v2/organizations/#{self.team_id}/apps/#{app_id}/beta_distribution/testers_in_organization?include_developers=true") testers = JSON.parse(page.body) return testers['testers'] end |