Sha256: f947e37d4bbb14f6c28e791c8f098f27f767d6f7be2d22735307782ca43539f6
Contents?: true
Size: 990 Bytes
Versions: 1
Compression:
Stored size: 990 Bytes
Contents
require "study_management_client/version" require 'faraday' require 'json' module StudyManagementClient def self.get_proposals conn = get_connection filter(JSON.parse(conn.get('/api/v1/nodes/').body)) end def self.get_proposal(id) conn = get_connection filter(JSON.parse(conn.get('/api/v1/nodes?filter[id]='+id.to_s).body)) end private def self.get_connection conn = Faraday.new(:url => ENV['STUDY_URL']) do |faraday| faraday.proxy ENV['STUDY_URL'] faraday.request :url_encoded faraday.response :logger faraday.adapter Faraday.default_adapter end conn.headers = {'Content-Type' => 'application/vnd.api+json'} conn.headers = {'Accept' => 'application/vnd.api+json'} conn end def self.filter(obj) obj = obj["data"].reject{|k,v| k["attributes"]["cost-code"].to_s.empty?} obj.map { |item| filter_attrs(item) } end def self.filter_attrs(h) {id: h["id"], name: h["attributes"]["name"], cost_code: h["attributes"]["cost-code"]} end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
study_management_client-0.1.3 | lib/study_management_client.rb |