Class: Hockey::App

Inherits:
Object
  • Object
show all
Defined in:
lib/hockeyhelper/app.rb

Overview

App on HockeyApp

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hashobj, networking) ⇒ App

Construct a new instance of Hockey::App



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hockeyhelper/app.rb', line 31

def initialize(hashobj, networking)
  @title = hashobj['title']
  @bundle_identifier = hashobj['bundle_identifier']
  @public_identifier = hashobj['public_identifier']
  @device_family = hashobj['device_family']
  @minimum_os_version = hashobj['minimum_os_version']
  @release_type = hashobj['release_type']
  @status = hashobj['status']
  @platform = hashobj['platform']
  @original_hash = hashobj
  @net = networking
  @cached_users = nil
  @cached_versions = nil
end

Instance Attribute Details

#bundle_identifierObject (readonly)

Returns the value of attribute bundle_identifier.



11
12
13
# File 'lib/hockeyhelper/app.rb', line 11

def bundle_identifier
  @bundle_identifier
end

#device_familyObject (readonly)

Returns the value of attribute device_family.



13
14
15
# File 'lib/hockeyhelper/app.rb', line 13

def device_family
  @device_family
end

#minimum_os_versionObject (readonly)

Returns the value of attribute minimum_os_version.



14
15
16
# File 'lib/hockeyhelper/app.rb', line 14

def minimum_os_version
  @minimum_os_version
end

#netObject (readonly)

Returns the value of attribute net.



20
21
22
# File 'lib/hockeyhelper/app.rb', line 20

def net
  @net
end

#original_hashObject (readonly)

Returns the value of attribute original_hash.



18
19
20
# File 'lib/hockeyhelper/app.rb', line 18

def original_hash
  @original_hash
end

#platformObject (readonly)

Returns the value of attribute platform.



17
18
19
# File 'lib/hockeyhelper/app.rb', line 17

def platform
  @platform
end

#public_identifierObject (readonly)

Returns the value of attribute public_identifier.



12
13
14
# File 'lib/hockeyhelper/app.rb', line 12

def public_identifier
  @public_identifier
end

#release_typeObject (readonly)

Returns the value of attribute release_type.



15
16
17
# File 'lib/hockeyhelper/app.rb', line 15

def release_type
  @release_type
end

#statusObject (readonly)

Returns the value of attribute status.



16
17
18
# File 'lib/hockeyhelper/app.rb', line 16

def status
  @status
end

#titleObject (readonly)

Returns the value of attribute title.



10
11
12
# File 'lib/hockeyhelper/app.rb', line 10

def title
  @title
end

Class Method Details

.create_from(hashobj, networking) ⇒ Object

Construct a new instance of Hockey::App

Parameters:

  • hashobj (Hash)

    an instance of app receiving from HockeyApp

  • networking (Hockey::Networking)

    an instance of Hockey::Networking object



26
27
28
# File 'lib/hockeyhelper/app.rb', line 26

def self.create_from(hashobj, networking)
  self.new hashobj, networking
end

Instance Method Details

#crash_reasons(page: 1, symbolicated: true, sort: :date, order: :asc) ⇒ Object

List all crash groups for an app. return an Array of CrashReason objects.

sort parameter:

:date, :class, :number_of_crashes, :last_crash_at

order parameter:

:asc, :desc


115
116
117
118
119
120
121
122
123
124
# File 'lib/hockeyhelper/app.rb', line 115

def crash_reasons(page: 1, symbolicated: true, sort: :date, order: :asc)
  obj = @net.get_object "/api/2/apps/#{@public_identifier}/crash_reasons"

  cr = []
  obj['crash_reasons'].each do |hashobj|
    cr << CrashReason.create_from(hashobj, @net)
  end

  cr
end

#crashes_histogram(date: Date.today, version: nil) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/hockeyhelper/app.rb', line 126

def crashes_histogram(date: Date.today, version: nil)
  start = date.strftime
  url = "/api/2/apps/#{@public_identifier}"
  if version
    url += "/app_versions/#{version.id}/crashes/histogram?start_date=#{start}&end_date=#{start}"
  else
    url += "/crashes/histogram?start_date=#{start}&end_date=#{start}"
  end
  obj = @net.get_object url
  histogram ||= {}
  obj['histogram'].each do |arr|
    histogram = {:date=>arr[0], :count=>arr[1]}
  end

  histogram
end

#inspectObject Also known as: to_s



46
47
48
# File 'lib/hockeyhelper/app.rb', line 46

def inspect
  "#{@title}, #{@bundle_identifier}, #{@platform}, #{@public_identifier}"
end

#invite_user(email: '') ⇒ Object

Invite a user to an app. return a User object.



69
70
71
72
73
74
75
# File 'lib/hockeyhelper/app.rb', line 69

def invite_user(email: '')
  obj = @net.post_object "/api/2/apps/#{@public_identifier}/app_users", {:email=>email, :role=>1}

  user = User.create_from(obj, @net)

  user
end

#remove_user(email: nil) ⇒ Object

Remove a user from an app on HockeyApp.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/hockeyhelper/app.rb', line 78

def remove_user(email: nil)
  begin
    total_pages = users().total_pages
  rescue => e
    return
  end

  1.upto(total_pages) do |page|
    user = users(page: page).find {|u| u.email == email }
    if user
      @net.delete "/api/2/apps/#{@public_identifier}/app_users/#{user.id}"
    end
  end
end

#users(page: 1) ⇒ Array<User>

List all users of an app on HockeyApp.

Returns:

  • (Array<User>)

    fetched User objects from HockeyApp.



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hockeyhelper/app.rb', line 54

def users(page: 1)
  @cached_users ||= []

  if @cached_users.empty?
    obj = @net.get_object "/api/2/apps/#{@public_identifier}/app_users"
    obj['app_users'].each do |hashobj|
      @cached_users << User.create_from(hashobj, @net)
    end
  end

  PagingArray.paginate with: @cached_users, page: page
end

#versions(page: 1) ⇒ Object

List all versions of an app. The endpoint returns all versions for developer and members, but only released versions for testers. return an Array of Version objects.



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/hockeyhelper/app.rb', line 95

def versions(page: 1)
  @cached_versions ||= []

  if @cached_versions.empty?
    obj = @net.get_object "/api/2/apps/#{@public_identifier}/app_versions"
    obj['app_versions'].each do |hashobj|
      @cached_versions << Version.create_from(hashobj, @net)
    end
  end

  PagingArray.paginate with: @cached_versions, page: page
end