Class: Courier::Profiles

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/profiles.rb

Constant Summary collapse

KEY =
"/profiles"

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Profiles

Returns a new instance of Profiles.



5
6
7
# File 'lib/trycourier/profiles.rb', line 5

def initialize(session)
  @session = session
end

Instance Method Details

#add(recipient_id:, profile:) ⇒ Object



27
28
29
# File 'lib/trycourier/profiles.rb', line 27

def add(recipient_id:, profile:)
  replace(recipient_id: recipient_id, profile: profile)
end

#get(recipient_id:) ⇒ Object



9
10
11
12
13
# File 'lib/trycourier/profiles.rb', line 9

def get(recipient_id:)
  path = "#{KEY}/#{recipient_id}"
  res = @session.send(path, "GET")
  ErrorHandler.check_err(res)
end

#get_subscriptions(recipient_id:, cursor: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/trycourier/profiles.rb', line 15

def get_subscriptions(recipient_id:, cursor: nil)
  path = "#{KEY}/#{recipient_id}/subscriptions"

  params = {}
  if cursor
    params["cursor"] = cursor
  end

  res = @session.send(path, "GET", params: params)
  ErrorHandler.check_err(res)
end

#merge(recipient_id:, profile:, idempotency_key: nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/trycourier/profiles.rb', line 42

def merge(recipient_id:, profile:, idempotency_key: nil)
  path = "#{KEY}/#{recipient_id}"
  payload = {
    'profile': profile
  }
  headers = {}
  if idempotency_key
    headers["Idempotency-Key"] = idempotency_key
  end
  res = @session.send(path, "POST", body: payload, headers: headers)
  ErrorHandler.check_err(res)
end

#patch(recipient_id:, operations:) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/trycourier/profiles.rb', line 55

def patch(recipient_id:, operations:)
  path = "#{KEY}/#{recipient_id}"
  payload = {
    'patch': operations
  }
  res = @session.send(path, "PATCH", body: payload)
  ErrorHandler.check_err(res)
end

#replace(recipient_id:, profile:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/trycourier/profiles.rb', line 31

def replace(recipient_id:, profile:)
  path = "#{KEY}/#{recipient_id}"

  payload = {
    'profile': profile
  }

  res = @session.send(path, "PUT", body: payload)
  ErrorHandler.check_err_non_json(res)
end