myask 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/bin/myask +1 -1
  4. data/html/App.html +116 -0
  5. data/html/MyAsk/Api/Helper.html +207 -0
  6. data/html/MyAsk/Api/Invitation.html +212 -0
  7. data/html/MyAsk/Api/Project.html +355 -0
  8. data/html/MyAsk/Api/ProjectHelper.html +299 -0
  9. data/html/MyAsk/Api/Question.html +261 -0
  10. data/html/MyAsk/Api.html +120 -0
  11. data/html/MyAsk/Config.html +195 -0
  12. data/html/MyAsk/ConfigHelper.html +251 -0
  13. data/html/MyAsk/Prompt.html +221 -0
  14. data/html/MyAsk/PromptHelper.html +330 -0
  15. data/html/MyAsk.html +114 -0
  16. data/html/README_rdoc.html +394 -0
  17. data/html/created.rid +14 -0
  18. data/html/css/fonts.css +167 -0
  19. data/html/css/rdoc.css +681 -0
  20. data/html/fonts/Lato-Light.ttf +0 -0
  21. data/html/fonts/Lato-LightItalic.ttf +0 -0
  22. data/html/fonts/Lato-Regular.ttf +0 -0
  23. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  24. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  25. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  26. data/html/images/add.png +0 -0
  27. data/html/images/arrow_up.png +0 -0
  28. data/html/images/brick.png +0 -0
  29. data/html/images/brick_link.png +0 -0
  30. data/html/images/bug.png +0 -0
  31. data/html/images/bullet_black.png +0 -0
  32. data/html/images/bullet_toggle_minus.png +0 -0
  33. data/html/images/bullet_toggle_plus.png +0 -0
  34. data/html/images/date.png +0 -0
  35. data/html/images/delete.png +0 -0
  36. data/html/images/find.png +0 -0
  37. data/html/images/loadingAnimation.gif +0 -0
  38. data/html/images/macFFBgHack.png +0 -0
  39. data/html/images/package.png +0 -0
  40. data/html/images/page_green.png +0 -0
  41. data/html/images/page_white_text.png +0 -0
  42. data/html/images/page_white_width.png +0 -0
  43. data/html/images/plugin.png +0 -0
  44. data/html/images/ruby.png +0 -0
  45. data/html/images/tag_blue.png +0 -0
  46. data/html/images/tag_green.png +0 -0
  47. data/html/images/transparent.png +0 -0
  48. data/html/images/wrench.png +0 -0
  49. data/html/images/wrench_orange.png +0 -0
  50. data/html/images/zoom.png +0 -0
  51. data/html/index.html +403 -0
  52. data/html/js/darkfish.js +120 -0
  53. data/html/js/navigation.js +105 -0
  54. data/html/js/navigation.js.gz +0 -0
  55. data/html/js/search.js +110 -0
  56. data/html/js/search_index.js +1 -0
  57. data/html/js/search_index.js.gz +0 -0
  58. data/html/js/searcher.js +229 -0
  59. data/html/js/searcher.js.gz +0 -0
  60. data/html/table_of_contents.html +257 -0
  61. data/lib/myask/version.rb +1 -1
  62. data/pkg/myask-0.0.1/Gemfile +10 -0
  63. data/pkg/myask-0.0.1/Gemfile.lock +70 -0
  64. data/pkg/myask-0.0.1/README.rdoc +6 -0
  65. data/pkg/myask-0.0.1/Rakefile +21 -0
  66. data/pkg/myask-0.0.1/bin/myask +101 -0
  67. data/pkg/myask-0.0.1/lib/myask/api/api_helper.rb +45 -0
  68. data/pkg/myask-0.0.1/lib/myask/api/invitation.rb +49 -0
  69. data/pkg/myask-0.0.1/lib/myask/api/project.rb +193 -0
  70. data/pkg/myask-0.0.1/lib/myask/api/project_helper.rb +46 -0
  71. data/pkg/myask-0.0.1/lib/myask/api/question.rb +99 -0
  72. data/pkg/myask-0.0.1/lib/myask/config.rb +37 -0
  73. data/pkg/myask-0.0.1/lib/myask/config_helper.rb +28 -0
  74. data/pkg/myask-0.0.1/lib/myask/prompt.rb +63 -0
  75. data/pkg/myask-0.0.1/lib/myask/prompt_helper.rb +80 -0
  76. data/pkg/myask-0.0.1/lib/myask/version.rb +3 -0
  77. data/pkg/myask-0.0.1/lib/myask.rb +28 -0
  78. data/pkg/myask-0.0.1/myask.gemspec +22 -0
  79. data/pkg/myask-0.0.1/myask.rdoc +138 -0
  80. data/pkg/myask-0.0.1/test/default_test.rb +14 -0
  81. data/pkg/myask-0.0.1/test/test_helper.rb +4 -0
  82. data/pkg/myask-0.0.1.gem +0 -0
  83. metadata +79 -1
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ myask (1.0.0)
5
+ gli (~> 2.22.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (12.0.0)
11
+ coderay (1.1.3)
12
+ date (3.4.1)
13
+ gli (2.22.2)
14
+ ostruct
15
+ json (2.10.2)
16
+ method_source (1.1.0)
17
+ minitest (5.25.5)
18
+ open-uri (0.5.0)
19
+ stringio
20
+ time
21
+ uri
22
+ ostruct (0.6.1)
23
+ pastel (0.8.0)
24
+ tty-color (~> 0.5)
25
+ pry (0.15.2)
26
+ coderay (~> 1.1)
27
+ method_source (~> 1.0)
28
+ pry-byebug (3.11.0)
29
+ byebug (~> 12.0)
30
+ pry (>= 0.13, < 0.16)
31
+ psych (5.2.3)
32
+ date
33
+ stringio
34
+ rake (13.2.1)
35
+ rdoc (6.13.0)
36
+ psych (>= 4.0.0)
37
+ stringio (3.1.6)
38
+ time (0.4.1)
39
+ date
40
+ tty-color (0.6.0)
41
+ tty-cursor (0.7.1)
42
+ tty-prompt (0.23.1)
43
+ pastel (~> 0.8)
44
+ tty-reader (~> 0.8)
45
+ tty-reader (0.9.0)
46
+ tty-cursor (~> 0.7)
47
+ tty-screen (~> 0.8)
48
+ wisper (~> 2.0)
49
+ tty-screen (0.8.2)
50
+ tty-spinner (0.9.3)
51
+ tty-cursor (~> 0.7)
52
+ uri (1.0.3)
53
+ wisper (2.0.1)
54
+
55
+ PLATFORMS
56
+ arm64-darwin-22
57
+
58
+ DEPENDENCIES
59
+ json (~> 2.10)
60
+ minitest
61
+ myask!
62
+ open-uri (~> 0.5.0)
63
+ pry-byebug (~> 3.11)
64
+ rake
65
+ rdoc
66
+ tty-prompt (~> 0.23.1)
67
+ tty-spinner (~> 0.9.3)
68
+
69
+ BUNDLED WITH
70
+ 2.4.22
@@ -0,0 +1,6 @@
1
+ = myask
2
+
3
+ Describe your project here
4
+
5
+ :include:myask.rdoc
6
+
@@ -0,0 +1,21 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+ Rake::RDocTask.new do |rd|
6
+ rd.main = "README.rdoc"
7
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
8
+ rd.title = 'Your application title'
9
+ end
10
+
11
+ spec = Gem::Specification.load("myask.gemspec")
12
+
13
+ Gem::PackageTask.new(spec) do |pkg|
14
+ end
15
+ require 'rake/testtask'
16
+ Rake::TestTask.new do |t|
17
+ t.libs << "test"
18
+ t.test_files = FileList['test/*_test.rb']
19
+ end
20
+
21
+ task :default => :test
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env ruby
2
+ require "gli"
3
+ require "myask"
4
+
5
+ class App
6
+ extend GLI::App
7
+
8
+ config_file ".myask.rc"
9
+
10
+ program_desc "Describe your application here"
11
+
12
+ version Myask::VERSION
13
+
14
+ subcommand_option_handling :normal
15
+ arguments :strict
16
+
17
+ desc "Silent Progress Spinner"
18
+ default_value false
19
+ switch [:silent]
20
+
21
+ desc "Format Output as JSON"
22
+ default_value false
23
+ switch [:json]
24
+
25
+ desc "Host for MyAsk API"
26
+ default_value "https://myask.io"
27
+ flag [:api_host], type: String
28
+
29
+ desc "API Key for MyAsk API"
30
+ flag [:api_key], type: String
31
+
32
+ desc "Current MyAsk Project"
33
+ flag [:project], type: String
34
+
35
+ desc "View current or set new MyAsk configuration values"
36
+ command :config do |c|
37
+ MyAsk::Config.new(c)
38
+ end
39
+
40
+ desc "Send a prompt to MyAsk API"
41
+ command :prompt do |c|
42
+ MyAsk::Prompt.new(c)
43
+ end
44
+
45
+ desc "Create/show/list/delete MyAsk Project"
46
+ command :project do |c|
47
+ MyAsk::Api::Project.new(c)
48
+ end
49
+
50
+ desc "Show/delete MyAsk Question"
51
+ command :question do |c|
52
+ MyAsk::Api::Question.new(c)
53
+ end
54
+
55
+ desc "Create/list MyAsk Invitations"
56
+ command :invitation do |c|
57
+ MyAsk::Api::Invitation.new(c)
58
+ end
59
+
60
+ pre do |global,command,options,args|
61
+ unless command&.parent&.name == :config
62
+ config = global
63
+ auth_token = config[:api_key]
64
+ project = options[:project] || config[:project]
65
+
66
+ if auth_token.nil?
67
+ puts "Missing MyAsk API token. Set it using \"myask config -k YOUR_AUTH_TOKEN\"."
68
+ exit
69
+ end
70
+
71
+ if project.nil?
72
+ puts "MyAsk Project Not Set. Set it using \"myask api:project:set\"."
73
+ exit
74
+ end
75
+ end
76
+ true # false to break command
77
+ end
78
+
79
+ post do |global,command,options,args|
80
+ # Post logic here
81
+ # Use skips_post before a command to skip this
82
+ # block on that command only
83
+ end
84
+
85
+ on_error do |exception|
86
+ case exception
87
+ when TTY::Reader::InputInterrupt
88
+ abort "\n\n--- User Exit ---\n"
89
+ when SystemExit
90
+ # abort "Exited"
91
+ when Errno::ECONNREFUSED
92
+ abort "API Error: #{exception}"
93
+ else # RuntimeError
94
+ puts exception.backtrace
95
+ # binding.pry
96
+ end
97
+ false # false to skip default error handling
98
+ end
99
+ end
100
+
101
+ exit App.run(ARGV)
@@ -0,0 +1,45 @@
1
+ module MyAsk
2
+ module Api
3
+ class Helper
4
+
5
+ def self.make_request(method, uri, api_key, payload = nil)
6
+ http = Net::HTTP.new(uri.host, uri.port)
7
+ http.use_ssl = true if uri.scheme == 'https'
8
+
9
+ if method == "Get"
10
+ request = Net::HTTP::Get.new(uri.request_uri)
11
+ request['Authorization'] = "Bearer #{api_key}"
12
+ request["Content-Type"] = "application/json"
13
+ response = http.request(request)
14
+ elsif method == "Delete"
15
+ request = Net::HTTP::Delete.new(uri.request_uri)
16
+ request['Authorization'] = "Bearer #{api_key}"
17
+ request["Content-Type"] = "application/json"
18
+ request.body = payload.to_json
19
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
20
+ http.request(request)
21
+ end
22
+ elsif method == "Patch"
23
+ request = Net::HTTP::Patch.new(uri.request_uri)
24
+ request['Authorization'] = "Bearer #{api_key}"
25
+ request["Content-Type"] = "application/json"
26
+ request.body = payload.to_json
27
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
28
+ http.request(request)
29
+ end
30
+ else
31
+ request = Net::HTTP::Post.new(uri.request_uri)
32
+ request['Authorization'] = "Bearer #{api_key}"
33
+ request["Content-Type"] = "application/json"
34
+ request.body = payload.to_json
35
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
36
+ http.request(request)
37
+ end
38
+ end
39
+
40
+ response
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,49 @@
1
+ module MyAsk
2
+ module Api
3
+ class Invitation
4
+
5
+ def initialize(c)
6
+ c.desc 'List MyAsk invitations.'
7
+ c.command :list do |c|
8
+ c.action do |global_options, _options, _args|
9
+ uri = URI("#{global_options[:api_host]}/api/invitations")
10
+ response = MyAsk::Api::Helper.make_request("Get", uri, global_options[:api_key])
11
+
12
+ puts "Invitation sent successfully:" unless global_options[:json]
13
+ puts JSON.pretty_generate(JSON.parse(response.body))
14
+ end
15
+ end
16
+
17
+ c.desc "Send MyAsk invitation to a new user"
18
+ c.command :send do |c|
19
+ c.desc "Send MyAsk invitation to a new user"
20
+ c.flag [:email], desc: "Email of the user to invite to MyAsk"
21
+
22
+ c.action do |global_options, options, args|
23
+ email = options[:email]
24
+
25
+ if !email
26
+ prompt = TTY::Prompt.new
27
+ email = prompt.ask('Enter invitee email:')
28
+ end
29
+
30
+ payload = {
31
+ invitation: {
32
+ email: email
33
+ }
34
+ }
35
+
36
+ uri = URI("#{global_options[:api_host]}/api/invitations")
37
+ response = MyAsk::Api::Helper.make_request("Post", uri, global_options[:api_key], payload)
38
+
39
+ puts "Invitation sent successfully:" unless global_options[:json]
40
+ puts JSON.pretty_generate(JSON.parse(response.body))
41
+ end
42
+ end
43
+
44
+ c.default_command :list
45
+ c
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,193 @@
1
+ module MyAsk
2
+ module Api
3
+ class Project
4
+
5
+ def initialize(c)
6
+ c.desc "Show MyAsk Project Details"
7
+ c.arg_name "project"
8
+ c.command :show do |c|
9
+ c.desc "List projects and select to view"
10
+ c.switch [:l, :list]
11
+
12
+ c.flag [:project], desc: "ID of project to display"
13
+
14
+ c.action do |global_options, options, args|
15
+ config = global_options
16
+ project = options[:project] || config[:project]
17
+
18
+ helper = MyAsk::Api::ProjectHelper.new(global_options, options, args)
19
+
20
+ project = if options[:list]
21
+ helper.project_id_from_selection
22
+ else
23
+ args[0] || project
24
+ end
25
+
26
+ helper.show_project_info(project)
27
+ end
28
+ end
29
+
30
+ c.desc "Set MyAsk Project"
31
+ c.arg_name "project"
32
+ c.command :set do |c|
33
+ c.desc "Set current MyAsk project"
34
+ c.switch [:l, :list]
35
+
36
+ c.flag [:project], desc: "ID of MyAsk Project to display"
37
+
38
+ c.action do |global_options, options, args|
39
+ config = global_options
40
+ project = options[:project] || config[:project]
41
+
42
+ helper = MyAsk::Api::ProjectHelper.new(global_options, options, args)
43
+
44
+ project = if options[:list]
45
+ helper.project_id_from_selection
46
+ else
47
+ args[0] || project
48
+ end
49
+
50
+ helper = MyAsk::ConfigHelper.new(global_options, options.merge(project: project), args)
51
+ response = helper.save_config
52
+ end
53
+ end
54
+
55
+ c.desc "Edit MyAsk Project"
56
+ c.arg_name "project"
57
+ c.command :edit do |c|
58
+ c.desc "Edit MyAsk project"
59
+ c.switch [:l, :list]
60
+
61
+ c.flag [:project], desc: "ID of MyAsk Project to Edit"
62
+
63
+ c.action do |global_options, options, args|
64
+ config = global_options
65
+ project = options[:project] || config[:project]
66
+
67
+ helper = MyAsk::Api::ProjectHelper.new(global_options, options, args)
68
+
69
+ project = if options[:list]
70
+ helper.project_id_from_selection
71
+ else
72
+ args[0] || project
73
+ end
74
+
75
+ payload = helper.show_project_info(project)
76
+
77
+ ai_models = ["gpt-4o-mini", "o3-mini", "o1-mini", "gpt-3.5-turbo", "gpt-4o", "chatgpt-4o-latest"]
78
+
79
+ prompt = TTY::Prompt.new
80
+
81
+ payload["project"]["name"] = prompt.read_line("Enter project name:", value: payload["project"]["name"]).strip
82
+ payload["project"]["description"] = prompt.read_line("Enter project description:", value: payload["project"]["description"]).strip
83
+
84
+ payload["project"]["ai_model"] = prompt.enum_select(
85
+ "Select an AI model for this project:",
86
+ ai_models,
87
+ default: payload["project"]["ai_model"]
88
+ )
89
+
90
+ payload["project"]["system_message"] = prompt.read_line(
91
+ "Enter project system_message (optional):",
92
+ value: payload["project"]["metadata"]["system_message"]["content"]
93
+ ).strip
94
+
95
+ puts payload
96
+
97
+ uri = URI("#{global_options[:api_host]}/api/projects/#{payload["project"]["id"]}")
98
+ response = MyAsk::Api::Helper.make_request("Patch", uri, global_options[:api_key], payload)
99
+
100
+ if response.is_a?(Net::HTTPSuccess)
101
+ puts "Project successfully edited:" unless global_options[:json]
102
+ puts JSON.pretty_generate(JSON.parse(response.body))
103
+ else
104
+ raise "Failed to edit project. Response code: #{response.code}, Body: #{response.body}"
105
+ end
106
+ end
107
+ end
108
+
109
+ c.desc "Create MyAsk Project"
110
+ c.command :create do |c|
111
+ c.flag [:name], desc: "Project Name"
112
+ c.flag [:description], desc: "Project Description"
113
+ c.flag [:ai_model], desc: "Project AI Model"
114
+ c.flag [:system_message], desc: "Project System Message"
115
+
116
+ c.action do |global_options, options, _args|
117
+ ai_models = ["gpt-4o-mini", "o3-mini", "o1-mini", "gpt-3.5-turbo", "gpt-4o", "chatgpt-4o-latest"]
118
+
119
+ prompt = TTY::Prompt.new
120
+
121
+ project_name = options[:name] || prompt.read_line("Enter project name:")
122
+ project_description = options[:description] || prompt.read_line("Enter project description:")
123
+
124
+ project_ai_model = options[:ai_model] || prompt.enum_select(
125
+ "Select an AI model for this project:",
126
+ ai_models
127
+ )
128
+
129
+ project_system_message = options[:system_message] || prompt.read_line(
130
+ "Enter project system_message (optional):"
131
+ )
132
+
133
+ payload = {
134
+ project: {
135
+ name: project_name.strip,
136
+ description: project_description.strip,
137
+ ai_model: project_ai_model,
138
+ system_message: { role: "developer", content: project_system_message.strip }
139
+ }
140
+ }
141
+
142
+ uri = URI("#{global_options[:api_host]}/api/projects")
143
+ response = MyAsk::Api::Helper.make_request("Post", uri, global_options[:api_key], payload)
144
+
145
+ if response.is_a?(Net::HTTPSuccess)
146
+ puts "Project created successfully:" unless global_options[:json]
147
+ puts JSON.pretty_generate(JSON.parse(response.body))
148
+ else
149
+ raise "Failed to create project. Response code: #{response.code}, Body: #{response.body}"
150
+ end
151
+ end
152
+ end
153
+
154
+ c.desc "Delete MyAsk Project"
155
+ c.command :delete do |c|
156
+ c.desc "List projects and select to view"
157
+ c.switch [:l, :list]
158
+
159
+ c.flag [:project], desc: "Project ID"
160
+
161
+ c.action do |global_options, options, args|
162
+ helper = MyAsk::Api::ProjectHelper.new(global_options, options, args)
163
+
164
+ project = if options[:list]
165
+ helper.project_id_from_selection
166
+ else
167
+ args[0] || project
168
+ end
169
+
170
+ payload = {
171
+ project: {
172
+ id: project
173
+ }
174
+ }
175
+
176
+ uri = URI("#{global_options[:api_host]}/api/projects/#{project}")
177
+ response = MyAsk::Api::Helper.make_request("Delete", uri, global_options[:api_key], payload)
178
+
179
+ if response.is_a?(Net::HTTPSuccess)
180
+ puts "Project deleted successfully:" unless global_options[:json]
181
+ puts JSON.pretty_generate(JSON.parse(response.body))
182
+ else
183
+ raise "Failed to delete project. Response code: #{response.code}, Body: #{response.body}"
184
+ end
185
+ end
186
+ end
187
+
188
+ c
189
+ end
190
+
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,46 @@
1
+ module MyAsk
2
+ module Api
3
+ class ProjectHelper
4
+
5
+ def initialize(global_options, options, args)
6
+ @global_options = global_options
7
+ @options = options
8
+ @args = args
9
+
10
+ @api_host = global_options[:api_host]
11
+ @api_key = global_options[:api_key]
12
+ end
13
+
14
+ def project_id_from_selection
15
+ uri = URI("#{@api_host}/api/projects")
16
+ response = MyAsk::Api::Helper.make_request('Get', uri, @api_key)
17
+
18
+ projects = JSON.parse(response.body)
19
+ if projects.empty?
20
+ puts 'No projects found.'
21
+ exit
22
+ end
23
+
24
+ select_project(projects)
25
+ end
26
+
27
+ def select_project(projects)
28
+ prompt = TTY::Prompt.new
29
+ selected_project = prompt.select(
30
+ "Select MyAsk Project:",
31
+ projects.map { |project| {"#{project["name"]}": project["id"]} }
32
+ )
33
+ end
34
+
35
+ def show_project_info(project_id)
36
+ uri = URI("#{@api_host}/api/projects/#{project_id}")
37
+ response = MyAsk::Api::Helper.make_request('Get', uri, @api_key)
38
+
39
+ project_info = JSON.parse(response.body)
40
+ puts JSON.pretty_generate(project_info.except("question_ids"))
41
+ project_info.except("question_ids")
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,99 @@
1
+ module MyAsk
2
+ module Api
3
+ class Question
4
+
5
+ def initialize(c)
6
+ c.desc "Show details for MyAsk question"
7
+ c.arg_name "question_id"
8
+
9
+ c.command :show do |c|
10
+ c.desc "List questions and select to view"
11
+ c.switch [:l, :list]
12
+
13
+ c.flag [:q, :question_id], desc: "ID of question to display"
14
+ c.switch [:skip_response], desc: "Do not include question response in output"
15
+
16
+ c.action do |global_options, options, args|
17
+ api_host = global_options[:api_host]
18
+ api_key = global_options[:api_key]
19
+
20
+ if options[:list]
21
+ response = MyAsk::Api::Helper.make_request("Get", URI("#{api_host}/api/questions"), api_key)
22
+ questions = JSON.parse(response.body).reverse
23
+
24
+ if questions.empty?
25
+ puts "No questions found."
26
+ exit
27
+ end
28
+
29
+ selected_question_id = TTY::Prompt.new.select("Select a question:", per_page: 10) do |menu|
30
+ questions.each do |q|
31
+ menu.choice "[#{q["id"]}] #{q["content"][0, 80]}", q["id"]
32
+ end
33
+ end
34
+
35
+ selected_question = selected_question_id
36
+ end
37
+
38
+ response = MyAsk::Api::Helper.make_request("Get", URI("#{api_host}/api/questions/#{selected_question || options[:question_id]}"), api_key)
39
+ response = JSON.parse(response.body)
40
+ response = response.except("response") if options[:skip_response]
41
+
42
+ puts "\n#{"\\" * 30} BEGIN Question (#{response["question"]["id"]}) #{"/" * 30}\n\n" unless global_options[:json]
43
+ puts global_options[:json] ? response.to_json : response["question"]["content"]
44
+ puts "\n#{"\\" * 35} END Question #{"/" * 35}\n" unless global_options[:json]
45
+
46
+ unless options[:skip_response] || global_options[:json] || response["response"].nil?
47
+ puts "\n\n#{"\\" * 30} BEGIN Response (#{response["response"]["id"]}) #{"/" * 30}\n\n" unless global_options[:json]
48
+ puts response["response"]["content"]
49
+ puts "\n#{"\\" * 35} END Response #{"/" * 35}\n" unless global_options[:json]
50
+ end
51
+ end
52
+ end
53
+
54
+ c.desc "Delete MyAsk question"
55
+ c.arg_name "question_id"
56
+
57
+ c.command :delete do |c|
58
+ c.desc "List questions and select to delete"
59
+ c.switch [:l, :list]
60
+
61
+ c.flag [:question_id], desc: "ID of question to delete"
62
+
63
+ c.action do |global_options, options, args|
64
+ api_host = global_options[:api_host]
65
+ api_key = global_options[:api_key]
66
+
67
+ if options[:list]
68
+ response = MyAsk::Api::Helper.make_request("Get", URI("#{api_host}/api/questions"), api_key)
69
+ questions = JSON.parse(response.body).reverse
70
+
71
+ if questions.empty?
72
+ puts "No questions found."
73
+ exit
74
+ end
75
+
76
+ selected_question_id = TTY::Prompt.new.select("Select a question:", per_page: 10) do |menu|
77
+ questions.each do |q|
78
+ menu.choice "[#{q["id"]}] #{q["content"][0, 80]}", q["id"]
79
+ end
80
+ end
81
+
82
+ selected_question = selected_question_id
83
+ end
84
+
85
+ response = MyAsk::Api::Helper.make_request("Delete", URI("#{api_host}/api/questions/#{selected_question || options[:question_id]}"), api_key)
86
+ response = JSON.parse(response.body)
87
+
88
+ puts JSON.pretty_generate(response["question"])
89
+
90
+ end
91
+ end
92
+
93
+ c.default_command :show
94
+ c
95
+ end
96
+
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,37 @@
1
+ module MyAsk
2
+ class Config
3
+
4
+ def initialize(c)
5
+ c.command :save do |c|
6
+ c.desc "Set MyAsk API URL"
7
+ c.flag [:api_host], type: String
8
+
9
+ c.desc "Set MyAsk API Key"
10
+ c.flag [:api_key], type: String
11
+
12
+ c.desc "Set MyAsk Project"
13
+ c.flag [:project], type: String
14
+
15
+ c.action do |global_options, options, args|
16
+ helper = MyAsk::ConfigHelper.new(global_options, options, args)
17
+ response = helper.save_config
18
+ puts response
19
+ response
20
+ end
21
+ end
22
+
23
+ c.command :show do |c|
24
+ c.action do |global_options, options, args|
25
+ helper = MyAsk::ConfigHelper.new(global_options, options, args)
26
+ response = helper.get_config
27
+ puts response
28
+ response
29
+ end
30
+ end
31
+
32
+ c.default_command :show
33
+ c
34
+ end
35
+
36
+ end
37
+ end