Class: SpyriApi::Subscriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/spyri_api/subscriptions.rb

Constant Summary collapse

BASEPATH =
'/subscriptions'.freeze
SEARCHABLE_ATTRIBUTES =
[:erp_id, :user_id].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ Subscriptions

Returns a new instance of Subscriptions.



11
12
13
# File 'lib/spyri_api/subscriptions.rb', line 11

def initialize(api_client)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



9
10
11
# File 'lib/spyri_api/subscriptions.rb', line 9

def api_client
  @api_client
end

Instance Method Details

#create(subscription_object) ⇒ Object



29
30
31
32
# File 'lib/spyri_api/subscriptions.rb', line 29

def create(subscription_object)
  path = BASEPATH
  @api_client.call_api(:POST, path, body: { subscription: subscription_object })
end

#get(id) ⇒ Object



24
25
26
27
# File 'lib/spyri_api/subscriptions.rb', line 24

def get(id)
  path = "#{BASEPATH}/#{id}"
  @api_client.call_api(:GET, path)
end

#search(opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/spyri_api/subscriptions.rb', line 15

def search(opts = {})
  query_params = {}
  SEARCHABLE_ATTRIBUTES.each do |key|
    query_params[key.to_s] = opts[key] if !opts[key].nil?
  end
  path = BASEPATH
  @api_client.call_api(:GET, path, query_params: query_params)
end

#terminate(id) ⇒ Object



39
40
41
42
# File 'lib/spyri_api/subscriptions.rb', line 39

def terminate(id)
  path = "#{BASEPATH}/#{id}/terminate"
  @api_client.call_api(:PATCH, path)
end

#update(id, subscription_object) ⇒ Object



34
35
36
37
# File 'lib/spyri_api/subscriptions.rb', line 34

def update(id, subscription_object)
  path = "#{BASEPATH}/#{id}"
  @api_client.call_api(:PATCH, path, body: { subscription: subscription_object })
end