-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from messagebird/add-contacts
Add contacts
- Loading branch information
Showing
11 changed files
with
407 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/') | ||
require 'messagebird' | ||
|
||
# ACCESS_KEY = 'YOUR KEY HERE' | ||
# PHONE_NUMBER = 'YOUR PHONE NUMBER HERE' | ||
|
||
unless defined?(ACCESS_KEY) | ||
puts 'You need to set an ACCESS_KEY constant in this file' | ||
exit 1 | ||
end | ||
|
||
unless defined?(PHONE_NUMBER) | ||
puts 'You need to set an PHONE_NUMBER constant in this file' | ||
exit 1 | ||
end | ||
|
||
begin | ||
# Create a MessageBird client with the specified ACCESS_KEY. | ||
client = MessageBird::Client.new(ACCESS_KEY) | ||
|
||
# Create a new Contact object. | ||
contact = client.contact_create(PHONE_NUMBER, { :firstName => 'Foo', :lastName => 'Bar'}) | ||
|
||
# Print the object information. | ||
puts | ||
puts " Contact :" | ||
puts | ||
puts " id : #{contact.id}" | ||
puts " href : #{contact.href}" | ||
puts " msisdn : #{contact.msisdn}" | ||
puts " firstName : #{contact.firstName}" | ||
puts " lastName : #{contact.lastName}" | ||
puts " groups : #{contact.groups.href}" # contact.groups.totalCount is also available. | ||
puts " messages : #{contact.messages.href}" # contact.messages.totalCount is also available. | ||
puts " custom1 : #{contact.customDetails.custom1}" | ||
puts " custom2 : #{contact.customDetails.custom2}" | ||
puts " custom3 : #{contact.customDetails.custom3}" | ||
puts " custom4 : #{contact.customDetails.custom4}" | ||
puts | ||
|
||
rescue MessageBird::ErrorException => ex | ||
puts | ||
puts 'An error occurred while creating a contact:' | ||
puts | ||
|
||
ex.errors.each do |error| | ||
puts " code : #{error.code}" | ||
puts " description : #{error.description}" | ||
puts " parameter : #{error.parameter}" | ||
puts | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env ruby | ||
|
||
$:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib/') | ||
require 'messagebird' | ||
|
||
ACCESS_KEY = 'YOUR KEY HERE' | ||
|
||
unless defined?(ACCESS_KEY) | ||
puts 'You need to set an ACCESS_KEY constant in this file' | ||
exit 1 | ||
end | ||
|
||
begin | ||
# Create a MessageBird client with the specified ACCESS_KEY. | ||
client = MessageBird::Client.new(ACCESS_KEY) | ||
|
||
# Fetch the Contact list with pagination options (skip the first 5 objects and take 10). | ||
limit = 10 | ||
offset = 5 | ||
contacts = client.contact_list(limit, offset) | ||
|
||
# Print the object information. | ||
puts | ||
puts "The following information was returned as a Contact list:" | ||
puts | ||
puts " count : #{contacts.count}" | ||
puts " limit : #{contacts.limit}" | ||
puts " offset : #{contacts.offset}" | ||
puts " totalCount : #{contacts.totalCount}" | ||
puts " links : #{contacts.links}" | ||
|
||
unless contacts.items.empty? | ||
contact = contacts[0] # Equivalent to contacts.items[0] | ||
|
||
puts " Contact :" | ||
puts " id : #{contact.id}" | ||
puts " href : #{contact.href}" | ||
puts " msisdn : #{contact.msisdn}" | ||
puts " firstName : #{contact.firstName}" | ||
puts " lastName : #{contact.lastName}" | ||
puts " groups : #{contact.groups.href}" # contact.groups.totalCount is also available. | ||
puts " messages : #{contact.messages.href}" # contact.messages.totalCount is also available. | ||
puts " custom1 : #{contact.customDetails.custom1}" | ||
puts " custom2 : #{contact.customDetails.custom2}" | ||
puts " custom3 : #{contact.customDetails.custom3}" | ||
puts " custom4 : #{contact.customDetails.custom4}" | ||
|
||
end | ||
|
||
rescue MessageBird::ErrorException => ex | ||
puts | ||
puts 'An error occurred while listing your contacts:' | ||
puts | ||
|
||
ex.errors.each do |error| | ||
puts " code : #{error.code}" | ||
puts " description : #{error.description}" | ||
puts " parameter : #{error.parameter}" | ||
puts | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'messagebird/base' | ||
require 'messagebird/custom_details' | ||
require 'messagebird/group_reference' | ||
require 'messagebird/message_reference' | ||
|
||
module MessageBird | ||
class Contact < MessageBird::Base | ||
attr_accessor :id, :href, :msisdn, :firstName, :lastName, :customDetails, | ||
:groups, :messages, :createdDatetime, :updatedDatetime | ||
|
||
def customDetails=(value) | ||
@customDetails = MessageBird::CustomDetails.new(value) | ||
end | ||
|
||
def groups=(value) | ||
@groups = MessageBird::GroupReference.new(value) | ||
end | ||
|
||
def messages=(value) | ||
@messages = MessageBird::MessageReference.new(value) | ||
end | ||
|
||
def createdDatetime=(value) | ||
@createdDatetime = value_to_time(value) | ||
end | ||
|
||
def updatedDatetime=(value) | ||
@updatedDatetime = value_to_time(value) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'messagebird/base' | ||
|
||
module MessageBird | ||
class CustomDetails < MessageBird::Base | ||
# CustomDetails holds free-input fields for the Contact object. | ||
attr_accessor :custom1, :custom2, :custom3, :custom4 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'messagebird/base' | ||
|
||
module MessageBird | ||
class GroupReference < MessageBird::Base | ||
attr_accessor :href, :totalCount | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'messagebird/base' | ||
|
||
class List < MessageBird::Base | ||
|
||
attr_accessor :offset, :limit, :count, :totalCount, :links, :items | ||
|
||
# type will be used to create objects for the items, e.g. | ||
# List.new(Contact, {}). | ||
def initialize(type, json) | ||
@type = type | ||
|
||
super(json) | ||
end | ||
|
||
def items=(value) | ||
@items = value.map { |i| @type.new i } | ||
end | ||
|
||
def [](index) | ||
@items[index] | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'messagebird/base' | ||
|
||
module MessageBird | ||
class MessageReference < MessageBird::Base | ||
attr_accessor :href, :totalCount | ||
end | ||
end |
Oops, something went wrong.