Sha256: c698ef4797c09d17f2d12819d43e46fc68cf2f74dc35fb7eb1c9a93a80cea627

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require_relative "set_service_client/version"

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

	private

	def self.get_connection
		conn = Faraday.new(:url => Rails.application.config.set_url) do |faraday|
			# faraday.use ZipkinTracer::FaradayHandler, 'Set Service'
			faraday.proxy Rails.application.config.set_url_default_proxy
			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.3 lib/set_service_client.rb