class Yapt::Request

Attributes

method[R]
params[R]
path[R]

Public Class Methods

base_url() click to toggle source
# File lib/yapt/request.rb, line 40
def self.base_url
  "https://www.pivotaltracker.com/
   services/v5/projects/#{Yapt.project_id}".gsub(/\s+/,'')
end
new(path, params = {}, method = :get) click to toggle source
# File lib/yapt/request.rb, line 7
def initialize(path, params = {}, method = :get)
  @method, @path, @params = method, path, params
end

Public Instance Methods

request(method, payload) click to toggle source
# File lib/yapt/request.rb, line 15
def request(method, payload)
  options = {
      "X-TrackerToken" => Yapt.api_token,
      "Content-Type" => "application/json"
    }
  response_handling = ->(response, request, result, &block) {
    case response.code
    when 200
      JSON.parse(response.to_s)
    else
      puts "Non-200 response!"
      puts response.to_s
    end
  }
  if method == :get
    RestClient.get(url, options.merge(params: payload), &response_handling)
  else
    RestClient.send(method, url, payload, options, &response_handling)
  end
end
result() click to toggle source
# File lib/yapt/request.rb, line 11
def result
  request(method, params)
end
url() click to toggle source
# File lib/yapt/request.rb, line 36
def url
  "#{self.class.base_url}/#{path}"
end