|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/') |
| 4 | +require 'messagebird' |
| 5 | + |
| 6 | +# ACCESS_KEY = '' |
| 7 | + |
| 8 | +unless defined?(ACCESS_KEY) |
| 9 | + puts 'You need to set an ACCESS_KEY constant in this file' |
| 10 | + exit 1 |
| 11 | +end |
| 12 | + |
| 13 | +begin |
| 14 | + # Create a MessageBird client with the specified ACCESS_KEY. |
| 15 | + client = MessageBird::Client.new(ACCESS_KEY) |
| 16 | + |
| 17 | + # Fetch the Conversation list |
| 18 | + offset = 0 |
| 19 | + limit = 10 |
| 20 | + conversations = client.conversation_list(limit, offset) |
| 21 | + |
| 22 | + # Print the object information. |
| 23 | + puts "The following information was returned as a Conversation list:" |
| 24 | + puts |
| 25 | + puts " count : #{conversations.count}" |
| 26 | + puts " limit : #{conversations.limit}" |
| 27 | + puts " offset : #{conversations.offset}" |
| 28 | + puts " totalCount : #{conversations.totalCount}" |
| 29 | + puts " links : #{conversations.links}" |
| 30 | + puts |
| 31 | + conversations.items.each do |conversation| |
| 32 | + puts "Conversation:" |
| 33 | + puts " id : #{conversation.id}" |
| 34 | + puts " status : #{conversation.status}" |
| 35 | + puts " createdDatetime : #{conversation.createdDatetime}" |
| 36 | + puts " updatedDatetime : #{conversation.updatedDatetime}" |
| 37 | + puts " lastReceivedDateklme : #{conversation.lastReceivedDatetime}" |
| 38 | + puts " lastUsedChannelId : #{conversation.lastUsedChannelId}" |
| 39 | + |
| 40 | + puts " Contact :" |
| 41 | + puts " id : #{conversation.contact.id}" |
| 42 | + puts " href : #{conversation.contact.href}" |
| 43 | + puts " msisdn : #{conversation.contact.msisdn}" |
| 44 | + puts " firstName : #{conversation.contact.firstName}" |
| 45 | + puts " lastName : #{conversation.contact.lastName}" |
| 46 | + puts " custom1 : #{conversation.contact.customDetails.custom1}" |
| 47 | + puts " custom2 : #{conversation.contact.customDetails.custom2}" |
| 48 | + puts " custom3 : #{conversation.contact.customDetails.custom3}" |
| 49 | + puts " custom4 : #{conversation.contact.customDetails.custom4}" |
| 50 | + puts " createdDatetime : #{conversation.contact.createdDatetime}" |
| 51 | + puts " updatedDatetime : #{conversation.contact.updatedDatetime}" |
| 52 | + |
| 53 | + puts " Channels :" |
| 54 | + conversation.channels.each do |channel| |
| 55 | + puts " id : #{channel.id}" |
| 56 | + puts " name : #{channel.name}" |
| 57 | + puts " platformId : #{channel.platformId}" |
| 58 | + puts " createdDatetime : #{channel.createdDatetime}" |
| 59 | + puts " updatedDatetime : #{channel.updatedDatetime}" |
| 60 | + puts |
| 61 | + end |
| 62 | + |
| 63 | + puts " Messages :" |
| 64 | + puts " href : #{conversation.messages.href}" |
| 65 | + puts " totalCount : #{conversation.messages.totalCount}" |
| 66 | + puts |
| 67 | + end |
| 68 | + |
| 69 | +rescue MessageBird::ErrorException => ex |
| 70 | + puts |
| 71 | + puts 'An error occured while creating a conversation:' |
| 72 | + puts |
| 73 | + |
| 74 | + ex.errors.each do |error| |
| 75 | + puts " code : #{error.code}" |
| 76 | + puts " description : #{error.description}" |
| 77 | + puts " parameter : #{error.parameter}" |
| 78 | + puts |
| 79 | + end |
| 80 | +end |
0 commit comments