Skip to content

Instantly share code, notes, and snippets.

@zachpendleton
Last active December 16, 2015 15:59
Show Gist options
  • Select an option

  • Save zachpendleton/5459877 to your computer and use it in GitHub Desktop.

Select an option

Save zachpendleton/5459877 to your computer and use it in GitHub Desktop.
require 'erb'
require 'json'
require 'net/https'
module Jira
class Service
JIRA_URL = 'https://instructure.atlassian.net/rest/api/2/search'
def initialize(username = ENV['JIRA_USERNAME'], password = ENV['JIRA_PASSWORD'])
self.username = username
self.password = password
end
def search(jql, max_results = 100)
uri = URI("#{JIRA_URL}?jql=#{ERB::Util.url_encode(jql)}&maxResults=#{max_results}")
request = Net::HTTP::Get.new(uri.request_uri)
request.basic_auth(username, password)
JSON.parse(client.request(request).body)
end
private
attr_accessor :username, :password
def client
unless @client
uri = URI(JIRA_URL)
@client = Net::HTTP.new(uri.hostname, uri.port)
@client.use_ssl = true
end
@client
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment