Class: CmQuiz::Factory::Idea

Inherits:
Object
  • Object
show all
Defined in:
lib/cm_quiz/factory/idea.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_api:, jwt:, idea_params: {}) ⇒ Idea

Returns a new instance of Idea.



6
7
8
9
10
# File 'lib/cm_quiz/factory/idea.rb', line 6

def initialize(project_api:, jwt:, idea_params: {})
  @project_api = project_api
  @jwt = jwt
  @idea_params = idea_params
end

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cm_quiz/factory/idea.rb', line 12

def create
  default_idea_params = {
    content: 'the-content',
    impact: 7,
    ease: 8,
    confidence: 9
  }

  options = {
    headers: {
      'x-access-token' => @jwt
    },
    body: default_idea_params.merge(@idea_params)
  }

  res = @project_api.request(:post, '/ideas', options)
  JSON.parse(res.body)
rescue => e
  raise StandardError, "Create test idea failed, reason: #{e.message}"
end