Sha256: 015c246606b988eeb65d3f7a2a155d4bcb6e844915a455f137e8d15dd7c384b3

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 Bytes

Contents

require "study_management_client/version"
require 'faraday'
require 'json'

module StudyManagementClient

  def self.get_nodes_with_cost_code
		conn = get_connection
		filter(JSON.parse(conn.get('/api/v1/nodes/').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.1 lib/study_management_client.rb