class SearchKit::Clients::Subscribers

Attributes

connection[R]
token[R]

Public Class Methods

new() click to toggle source
# File lib/search_kit/clients/subscribers.rb, line 9
def initialize
  uri = [ SearchKit.config.app_uri, "subscribers" ].join("/")
  @connection = Faraday.new(uri)
  @token      = SearchKit.config.app_token
end

Public Instance Methods

create(options = {}) click to toggle source
# File lib/search_kit/clients/subscribers.rb, line 15
def create(options = {})
  options  = { data: { type: 'subscribers', attributes: options } }
  response = connection.post("", options)
  body     = JSON.parse(response.body, symbolize_names: true)

  fail Errors::BadRequest    if response.status == 400
  fail Errors::Unprocessable if response.status == 422

  SearchKit::Models::Subscriber.new body.fetch(:data, {})
end
info() click to toggle source
# File lib/search_kit/clients/subscribers.rb, line 26
def info
  response = connection.get("", token: token)
  body     = JSON.parse(response.body, symbolize_names: true)

  fail Errors::Unauthorized       if response.status == 401
  fail Errors::SubscriberNotFound if response.status == 404

  SearchKit::Models::Subscriber.new body.fetch(:data, {})
end
update(options = {}) click to toggle source
# File lib/search_kit/clients/subscribers.rb, line 36
def update(options = {})
  options  = {
    token: token, data: { type: 'subscribers', attributes: options }
  }

  response = connection.patch("", options)
  body     = JSON.parse(response.body, symbolize_names: true)

  fail Errors::BadRequest         if response.status == 400
  fail Errors::Unauthorized       if response.status == 401
  fail Errors::SubscriberNotFound if response.status == 404
  fail Errors::Unprocessable      if response.status == 422

  SearchKit::Models::Subscriber.new body.fetch(:data, {})
end