class Minitel::Client

Attributes

connection[RW]

Public Class Methods

new(telex_url) click to toggle source
# File lib/minitel/client.rb, line 8
def initialize(telex_url)
  unless telex_url.start_with? "https://"
    raise ArgumentError, "Bad Url"
  end
  self.connection = Excon.new(telex_url,
    :headers => {
      "User-Agent" => "minitel/#{Minitel::VERSION} excon/#{Excon::VERSION}",
      "Content-Type" => "application/json"
    }
  )
end

Public Instance Methods

add_followup(args) click to toggle source
# File lib/minitel/client.rb, line 36
def add_followup(args)
  StrictArgs.enforce(args, [:message_uuid, :body], [], :message_uuid)
  followup = { body: args[:body] }
  post("/producer/messages/#{args[:message_uuid]}/followups", followup)
end
notify_app(args) click to toggle source
# File lib/minitel/client.rb, line 20
def notify_app(args)
  StrictArgs.enforce(args, [:app_uuid, :body, :title], [:action], :app_uuid)
  if action = args[:action]
    StrictArgs.enforce(action, [:label, :url])
  end
  post_message('app', args[:app_uuid], args[:title], args[:body], action)
end
notify_user(args) click to toggle source
# File lib/minitel/client.rb, line 28
def notify_user(args)
  StrictArgs.enforce(args, [:user_uuid, :body, :title], [:action], :user_uuid)
  if action = args[:action]
    StrictArgs.enforce(action, [:label, :url])
  end
  post_message('user', args[:user_uuid], args[:title], args[:body], action)
end

Private Instance Methods

post(path, body) click to toggle source
# File lib/minitel/client.rb, line 58
def post(path, body)
  response = connection.post(
               path: path,
               body: MultiJson.dump(body),
               expects: 201)

  MultiJson.load(response.body)
end
post_message(type, id, title, body, action) click to toggle source
# File lib/minitel/client.rb, line 44
def post_message(type, id, title, body, action)
  message = {
    title: title,
    body: body,
    target: {type: type, id: id}
  }

  if action
    message.merge!(action: action)
  end

  post("/producer/messages", message)
end