Class: GetToWork::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/get_to_work/service.rb,
lib/get_to_work/service/harvest.rb,
lib/get_to_work/service/pivotal_tracker.rb

Direct Known Subclasses

Harvest, PivotalTracker

Defined Under Namespace

Classes: Harvest, PivotalTracker, UnauthorizedError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_hash = nil) ⇒ Service

Returns a new instance of Service.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/get_to_work/service.rb', line 26

def initialize(data_hash = nil)
  return if data_hash.nil?

  @data = data_hash[yaml_key]

  if @data
    @data.each do |name, value|
      instance_variable_set("@#{name}", value)
      self.class.class_eval { attr_reader(name.to_sym) }
    end
    authenticate_with_keychain
  end
end

Instance Attribute Details

#api_tokenObject (readonly)

Returns the value of attribute api_token.



6
7
8
# File 'lib/get_to_work/service.rb', line 6

def api_token
  @api_token
end

Class Method Details

.display_name(name = nil) ⇒ Object



9
10
11
# File 'lib/get_to_work/service.rb', line 9

def display_name(name = nil)
  @display_name = name || @display_name
end

Instance Method Details

#authenticate_with_keychainObject



51
52
# File 'lib/get_to_work/service.rb', line 51

def authenticate_with_keychain
end

#display_nameObject



22
23
24
# File 'lib/get_to_work/service.rb', line 22

def display_name
  self.class.display_name
end

#keychainObject



67
68
69
# File 'lib/get_to_work/service.rb', line 67

def keychain
  @keychain ||= GetToWork::Keychain.find(service: name).last
end

#nameObject



18
19
20
# File 'lib/get_to_work/service.rb', line 18

def name
  self.class.to_s.split("::").last
end

#save_config(opts) ⇒ Object



71
72
73
74
# File 'lib/get_to_work/service.rb', line 71

def save_config(opts)
  config_file = GetToWork::ConfigFile.instance
  config_file[yaml_key] = opts
end

#set_client_token(token) ⇒ Object



63
64
65
# File 'lib/get_to_work/service.rb', line 63

def set_client_token(token)
  # noop
end

#update_keychain(account:) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/get_to_work/service.rb', line 40

def update_keychain(account:)
  raise "@api_token not set for #{name}" if @api_token.nil?
  raise "@name not set for #{name}" if @api_token.nil?

  GetToWork::Keychain.new.update(
    service: name,
    account: ,
    password: @api_token
  )
end

#yaml_keyObject



14
15
16
# File 'lib/get_to_work/service.rb', line 14

def yaml_key
  name.underscore
end