Class: MyAsk::Api::ProjectHelper
- Inherits:
-
Object
- Object
- MyAsk::Api::ProjectHelper
- Defined in:
- lib/myask/api/project_helper.rb
Instance Method Summary collapse
-
#initialize(global_options, options, args) ⇒ ProjectHelper
constructor
A new instance of ProjectHelper.
- #project_id_from_selection ⇒ Object
- #select_project(projects) ⇒ Object
- #show_project_info(project_id) ⇒ Object
Constructor Details
#initialize(global_options, options, args) ⇒ ProjectHelper
Returns a new instance of ProjectHelper.
5 6 7 8 9 10 11 12 |
# File 'lib/myask/api/project_helper.rb', line 5 def initialize(, , args) = = @args = args @api_host = [:api_host] @api_key = [:api_key] end |
Instance Method Details
#project_id_from_selection ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/myask/api/project_helper.rb', line 14 def project_id_from_selection uri = URI("#{@api_host}/api/projects") response = MyAsk::Api::Helper.make_request('Get', uri, @api_key) projects = JSON.parse(response.body) if projects.empty? puts 'No projects found.' exit end select_project(projects) end |
#select_project(projects) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/myask/api/project_helper.rb', line 27 def select_project(projects) prompt = TTY::Prompt.new selected_project = prompt.select( "Select MyAsk Project:", projects.map { |project| {"#{project["name"]}": project["id"]} } ) end |
#show_project_info(project_id) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/myask/api/project_helper.rb', line 35 def show_project_info(project_id) uri = URI("#{@api_host}/api/projects/#{project_id}") response = MyAsk::Api::Helper.make_request('Get', uri, @api_key) project_info = JSON.parse(response.body) puts JSON.pretty_generate(project_info.except("question_ids")) project_info.except("question_ids") end |