Sha256: cdb45a9ba97fdeab93fc410de974f7dacab321a630dd74bf748a8c728fef89a5

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

module ArtemisApi
  class Subscription < ArtemisApi::Model
    json_type 'subscriptions'

    def self.find(id:, facility_id:, client:, include: nil, force: false)
      client.find_one(self.json_type, id, facility_id: facility_id, include: include, force: force)
    end

    def self.find_all(facility_id:, client:, include: nil, filters: nil)
      client.find_all(self.json_type, facility_id: facility_id, include: include, filters: filters)
    end

    def self.create(facility_id:, subject:, destination:, client:)
      client.oauth_token.refresh! if client.oauth_token.expired?

      url = "#{client.options[:base_uri]}/api/v3/facilities/#{facility_id}/subscriptions"
      params = { body: { subscription: { subject: subject, destination: destination } } }

      response = client.oauth_token.post(url, params)

      response.status == 200 ? client.process_response(response, 'subscriptions') : false
    end

    def self.delete(id:, facility_id:, client:)
      client.oauth_token.refresh! if client.oauth_token.expired?

      url = "#{client.options[:base_uri]}/api/v3/facilities/#{facility_id}/subscriptions/#{id}"

      response = client.oauth_token.delete(url)
      client.remove_record('subscriptions', id) if response.status == 204
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
artemis_api-0.3.0 lib/artemis_api/subscription.rb
artemis_api-0.2.1 lib/artemis_api/subscription.rb
artemis_api-0.2.0 lib/artemis_api/subscription.rb