Class: Gitgut::Jira::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/gitgut/jira.rb

Overview

Wrapper around a JQL query for JIR

Constant Summary collapse

DEFAULT_OPTIONS =
{
  headers: { 'Content-Type' => 'application/json' }
}.freeze
JQL_PARAM_NAME =
'jql'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ Request

Returns a new instance of Request.



83
84
85
# File 'lib/gitgut/jira.rb', line 83

def initialize(query)
  @query = query
end

Instance Method Details

#auth_optionsObject



102
103
104
105
106
107
# File 'lib/gitgut/jira.rb', line 102

def auth_options
  {
    username: Settings.jira.username,
    password: Settings.jira.password
  }
end

#perform!Object

TODO: Maybe use a flag like performed? and store the response in an attr_reader



89
90
91
92
93
94
# File 'lib/gitgut/jira.rb', line 89

def perform!
  options = DEFAULT_OPTIONS.merge(
    basic_auth: auth_options
  )
  HTTParty.get(url, options)
end

#urlObject



96
97
98
99
100
# File 'lib/gitgut/jira.rb', line 96

def url
  url = URI.parse(Settings.jira.endpoint)
  url.query = "#{JQL_PARAM_NAME}=#{URI.escape(@query)}"
  url
end