Last active
December 11, 2023 20:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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