Skip to content

Instantly share code, notes, and snippets.

@deekshithh
Last active December 11, 2023 20:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deekshithh/c22b3efe4673cec3d14362869664a80d to your computer and use it in GitHub Desktop.
Save deekshithh/c22b3efe4673cec3d14362869664a80d to your computer and use it in GitHub Desktop.
Ruby code on how to use the Httparty class for the consumption of jira external api.
module Jira
class User
include HTTParty
base_uri 'https://***.atlassian.net/rest/api/3/'
def initialize
jira_auth = Token.find_by(token_type: 'jira')
@options = { headers: {'Content-Type' => 'application/json'},
basic_auth: {:username => jira_auth.try(:username), :password => jira_auth.try(:secret)} }
raise ArgumentError.new("Jira token doesn't exist") unless jira_auth
end
def bulk(query)
@options[:query] = query
Retriable.with_context(:jira) do
response = self.class.get("/bulk", @options)
if response.code == 200
return response
else
raise response.body
end
end
end
end
end
Retriable.configure do |c|
c.contexts[:jira] = {
tries: 3,
base_interval: 5,
on_retry: Proc.new { puts 'Failed to reach Jira api. Retrying..' },
multiplier: 2
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment