Class: Driftrock::Service::DriftrockModel::Channel

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Driftrock::Service::DriftrockModel

#get_from_api_method, included, #initialize, #post_to_api_method, #put_to_api_method

Instance Attribute Details

#channel_typeObject

Returns the value of attribute channel_type.



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

def channel_type
  @channel_type
end

#companyObject (readonly)

Returns the value of attribute company.



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

def company
  @company
end

#expires_inObject (readonly)

Returns the value of attribute expires_in.



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

def expires_in
  @expires_in
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#next_step_actionObject (readonly)

Returns the value of attribute next_step_action.



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

def next_step_action
  @next_step_action
end

#profile_idObject (readonly)

Returns the value of attribute profile_id.



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

def profile_id
  @profile_id
end

#refresh_tokenObject (readonly)

Returns the value of attribute refresh_token.



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

def refresh_token
  @refresh_token
end

#tokenObject (readonly)

Returns the value of attribute token.



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

def token
  @token
end

#token_expiryObject (readonly)

Returns the value of attribute token_expiry.



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

def token_expiry
  @token_expiry
end

Class Method Details

.channel_typesObject



50
51
52
53
54
55
56
57
# File 'lib/driftrock-service/driftrock_model/channel.rb', line 50

def self.channel_types
  object_arr = get_from_api_method.call(
    "/types"
  )
  object_arr.map do |object_hash|
    ChannelType.new(object_hash)
  end
end

.create_by_channel_type(type_name, channel_data) ⇒ Object



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

def self.create_by_channel_type(type_name, channel_data)
  ChannelType.find_by_name(type_name).create_channel(channel_data)
end

.find_by_channel_type_name(name) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/driftrock-service/driftrock_model/channel.rb', line 41

def self.find_by_channel_type_name(name)
  object_hsh = get_from_api_method.call(
    "/#{name}"
  )
  channel = new(object_hsh)
  channel.channel_type = ChannelType.find_by_name(name)
  channel
end

Instance Method Details

#has_profile?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/driftrock-service/driftrock_model/channel.rb', line 20

def has_profile?
  profile_id && !profile_id.strip.empty?
end

#set_profile_id(profile_id) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/driftrock-service/driftrock_model/channel.rb', line 11

def set_profile_id(profile_id)
  response = post_to_api_method.call(
    "/#{channel_type.name}/profile", {profile_id: profile_id}
  )
  success = response['status'] == 'success'
  @profile_id = profile_id if success
  success
end

#update_token(token_data) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/driftrock-service/driftrock_model/channel.rb', line 24

def update_token(token_data)
  response = put_to_api_method.call(
    "/#{channel_type.name}/profile", token_data
  )
  success = response['status'] == 'success'
  if success
    @token = token_data[:token]
    @token_expiry = token_data[:token_expiry]
    @expires_in = token_data[:expires_in]
  end
  success
end