Class: Driftrock::Service::DriftrockModel::Company

Inherits:
Object
  • Object
show all
Includes:
Driftrock::Service::DriftrockModel
Defined in:
lib/driftrock-service/driftrock_model/company.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Driftrock::Service::DriftrockModel

#get_from_api_method, included, #post_to_api_method, #put_to_api_method

Constructor Details

#initialize(object_hash) ⇒ Company

Returns a new instance of Company.



8
9
10
11
12
13
14
15
# File 'lib/driftrock-service/driftrock_model/company.rb', line 8

def initialize(object_hash)
  super(object_hash)
  if @data_sources
    @channels = @data_sources.map do |channel_data|
      build_channel_from_data(channel_data)
    end
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/driftrock-service/driftrock_model/company.rb', line 6

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/driftrock-service/driftrock_model/company.rb', line 6

def name
  @name
end

Instance Method Details

#channel_by_type(channel_type) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/driftrock-service/driftrock_model/company.rb', line 41

def channel_by_type(channel_type)
  channels.find do |channel|
    channel_type = channel_type.to_s
    if channel_type == "adwords"
      channel_type = "google_adwords"
    end
    if channel_type == "conversion"
      channel_type = "google_analytics"
    end
    channel.channel_type.name == channel_type
  end
end

#channels(refresh = false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/driftrock-service/driftrock_model/company.rb', line 17

def channels(refresh=false)
  unless @channels && !refresh
    @channels = []
    response = get_from_api_method.call('/channels')
    response.each do |channel_data|
      @channels << build_channel_from_data(channel_data)
    end
  end
  @channels
end

#has_appropriate_channels_for_app?(app) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
# File 'lib/driftrock-service/driftrock_model/company.rb', line 55

def has_appropriate_channels_for_app?(app)
  found = [:facebook, :twitter, :user, :adwords, :conversion].find do |channel|
    requires = app.send("requires_#{channel}_data?")
    has = send("has_#{channel}_channel?")
    requires && !has
  end
  !found
end

#has_channel?(channel_type) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/driftrock-service/driftrock_model/company.rb', line 36

def has_channel?(channel_type)
  channel = channel_by_type(channel_type)
  channel && channel.has_profile?
end

#invite_user(email) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/driftrock-service/driftrock_model/company.rb', line 64

def invite_user(email)
  response = post_to_api_method.call(
    '/invite_user', {user_to_invite_email: email}
  )
  invitation = symbolise_keys(response)
  if invitation[:has_user].is_a?(String)
    invitation[:has_user] = !!(invitation[:has_user] =~ /true/i)
  end
  invitation
end