Sha256: a4791edc3e395a63ae42ea8343b328203cffc0008eb9147d23e63f5bd152713b

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require_relative "set_service_client/version"
require 'faraday'
require 'json'

module SetServiceClient
	def self.post(submission_id)
		data = {:data=>{:type=>"sets", :attributes=>{:name=>submission_id}}}
		conn = get_connection
		JSON.parse(conn.post('/api/v1/sets', data.to_json).body)
	end

	def self.add_materials(set_uuid, materials)
		data = {:data => materials.compact.map{|m| {:id => m.uuid, :type => 'materials'}}}
		conn = get_connection
		conn.post('/api/v1/sets/'+set_uuid+'/relationships/materials', data.to_json)
	end

	def self.get_with_materials(set_uuid)
		conn = get_connection
		conn.headers = {'Accept' => 'application/vnd.api+json'}
		JSON.parse(conn.get('/api/v1/sets/'+set_uuid+'/relationships/materials').body)
	end

	def self.get_set(set_uuid)
		conn = get_connection
		conn.headers = {'Accept' => 'application/vnd.api+json'}
		JSON.parse(conn.get('/api/v1/sets/'+set_uuid).body)
	end

	def self.get_sets
		conn = get_connection
		conn.headers = {'Accept' => 'application/vnd.api+json'}
		JSON.parse(conn.get('/api/v1/sets').body)
	end

	private

	def self.get_connection
		conn = Faraday.new(:url => ENV['SET_URL']) do |faraday|
			# faraday.use ZipkinTracer::FaradayHandler, 'Set Service'
			faraday.proxy ENV['SET_URL']
			faraday.request  :url_encoded
			faraday.response :logger
			faraday.adapter  Faraday.default_adapter
		end
		conn.headers = {'Content-Type' => 'application/vnd.api+json'}
		conn
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
set_service_client-0.1.5 lib/set_service_client.rb