Class: Colleagues::Calendar::Command::ConfigParser
- Inherits:
-
Object
- Object
- Colleagues::Calendar::Command::ConfigParser
- Defined in:
- lib/colleagues/calendar/command/config.rb
Instance Attribute Summary collapse
-
#calendar_ids ⇒ Object
readonly
Returns the value of attribute calendar_ids.
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
-
#schedule_type ⇒ Object
readonly
Returns the value of attribute schedule_type.
Instance Method Summary collapse
-
#initialize ⇒ ConfigParser
constructor
A new instance of ConfigParser.
- #save ⇒ Object
Constructor Details
#initialize ⇒ ConfigParser
12 13 14 15 16 17 18 19 20 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 49 50 51 52 53 |
# File 'lib/colleagues/calendar/command/config.rb', line 12 def initialize begin config_path = File.("~/.colleagues-calendar-command.yaml") unless File.exist?(config_path) ="Configuration file:<\#{config_path}> not found.\nCreate \#{config_path}.\n\n Example:\n ---\n calendar_ids:\n John Smith: [email protected]\n\n" raise ConfigurationError, end @conf = YAML.load_file(config_path) @calendar_ids = @conf["calendar_ids"] @schedule_type = @conf["schedule_type"] @refresh_token = @conf["refresh_token"] secret_path = File.("~/.colleagues-calendar-command.secret.json") unless File.exist?(secret_path) ="Client secret file:<\#{secret_path}> not found.\n\n 1. Create project on https://console.developers.google.com/ for Google Calendar API\n 2. Download credential(OAuth client ID) file.\n\n" raise ConfigurationError, end open(secret_path) do |file| @secret = JSON.load(file) @client_id = @secret["installed"]["client_id"] @client_secret = @secret["installed"]["client_secret"] end rescue => e puts e. exit 1 end end |
Instance Attribute Details
#calendar_ids ⇒ Object (readonly)
Returns the value of attribute calendar_ids.
8 9 10 |
# File 'lib/colleagues/calendar/command/config.rb', line 8 def calendar_ids @calendar_ids end |
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
6 7 8 |
# File 'lib/colleagues/calendar/command/config.rb', line 6 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
7 8 9 |
# File 'lib/colleagues/calendar/command/config.rb', line 7 def client_secret @client_secret end |
#refresh_token ⇒ Object
Returns the value of attribute refresh_token.
10 11 12 |
# File 'lib/colleagues/calendar/command/config.rb', line 10 def refresh_token @refresh_token end |
#schedule_type ⇒ Object (readonly)
Returns the value of attribute schedule_type.
9 10 11 |
# File 'lib/colleagues/calendar/command/config.rb', line 9 def schedule_type @schedule_type end |
Instance Method Details
#save ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/colleagues/calendar/command/config.rb', line 55 def save @conf["refresh_token"] = @refresh_token config_path = File.("~/.colleagues-calendar-command.yaml") open(config_path, "w") do |file| file.puts(YAML.dump(@conf)) end end |