Class: BeeiqAPI::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(webhook_url = nil, sender_email = nil) ⇒ Client

Returns a new instance of Client.

Raises:

  • (ArgumentError)


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

def initialize(webhook_url = nil, sender_email = nil)
  webhook_url ||= BeeiqAPI.configuration.webhook_url
  sender_email ||= BeeiqAPI.configuration.sender_email

  raise ArgumentError, 'Missing webhook url' if webhook_url.to_s.empty?
  raise ArgumentError, 'Missing sender_email' if sender_email.to_s.empty?

  @webhook_url = webhook_url
  @sender_email = sender_email
end

Instance Attribute Details

#sender_emailObject (readonly)

Returns the value of attribute sender_email.



14
15
16
# File 'lib/beeiq_api.rb', line 14

def sender_email
  @sender_email
end

#webhook_urlObject (readonly)

Returns the value of attribute webhook_url.



13
14
15
# File 'lib/beeiq_api.rb', line 13

def webhook_url
  @webhook_url
end

Instance Method Details

#build_payload(action, data) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/beeiq_api.rb', line 36

def build_payload(action, data)
  payload =
    case action
    when Config::ActionType::ADD_TICKET
      build_ticket_payload(data)
    end

  {
    senderUser: @sender_email,
    data: payload
  }
end

#build_ticket_payload(data) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/beeiq_api.rb', line 49

def build_ticket_payload(data)
  data.map do |item|
    ticket = BeeiqAPI::Ticket.new item
    {
      actionType: Config::ActionType::ADD_TICKET,
      data: ticket.payload
    }
  end
end

#create_many_ticket(data = []) ⇒ Object



31
32
33
34
# File 'lib/beeiq_api.rb', line 31

def create_many_ticket(data = [])
  payload = build_payload(Config::ActionType::ADD_TICKET, data)
  process(:post, payload)
end

#create_ticket(data = {}) ⇒ Object



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

def create_ticket(data = {})
  create_many_ticket([data])
end