Class: Hashblue::API::Subscriber

Inherits:
Model
  • Object
show all
Defined in:
lib/hashblue/api/subscriber.rb

Overview

A Subscriber represents an individual phone number (MSISDN) within the Hashblue API, and is the object from which all other API information is made available.

Create a Subscriber using the ‘find’ method, and supplying your API subscriber ID:

subscriber = Hashblue::API::Subscriber.find("yourid")
subscriber.messages
subscriber.contacts.first.messages
# etc..

Collection Options

You can pass an options Hash to the collection methods. These can include:

:page

the page of messages to return

:per_page

the number of messages to return in a page. If the the page option is provided, but this is omitted, a default of 20 will be used by the API.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

from_json, #get, #id, #initialize, #method_missing, model_name, #post, #to_param

Constructor Details

This class inherits a constructor from Hashblue::API::Model

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hashblue::API::Model

Class Method Details

.find(id) ⇒ Object

Instantiate a Subscriber



26
27
28
# File 'lib/hashblue/api/subscriber.rb', line 26

def self.find(id)
  new("id" => id)
end

Instance Method Details

#contacts(options = {}) ⇒ Object

Returns an Array of Contact objects for the Subscriber.

Contacts are derived from the messages sent and received by a subscriber, and cannot be created or manipulated directly.

See above for possible options this method takes.



36
37
38
# File 'lib/hashblue/api/subscriber.rb', line 36

def contacts(options = {})
  Hashblue::API::Contact.from_json(get("#{_path}/contacts.json", options))
end

#deleted_messages(options = {}) ⇒ Object

Returns an Array of Message objects for the Subscriber.

All messages that have been deleted for all contacts are included in the returned Array.

See above for possible options this method takes.



65
66
67
# File 'lib/hashblue/api/subscriber.rb', line 65

def deleted_messages(options={})
  Hashblue::API::Message.from_json(get("#{_path}/messages/deleted.json", options))
end

#favourites(options = {}) ⇒ Object

Returns an Array of Message objects for the subscriber that are marked as favourites

All messages that are marked as favourites are included in the returned Array.

See above for possible options this method takes.



55
56
57
# File 'lib/hashblue/api/subscriber.rb', line 55

def favourites(options={})
  Hashblue::API::Message.from_json(get("#{_path}/favourites.json", options))
end

#messages(options = {}) ⇒ Object

Returns an Array of Message objects for the Subscriber.

All sent and received messages for all contacts are included in the returned Array.

See above for possible options this method takes.



46
47
48
# File 'lib/hashblue/api/subscriber.rb', line 46

def messages(options={})
  Hashblue::API::Message.from_json(get("#{_path}/messages.json", options))
end

#send_message(contact_msisdn, content) ⇒ Object

Send a message from the Subscriber to the given number.

The sent message will be returned if it was successfully sent. The contact_msisdn should be in the form “447#########”.



73
74
75
76
77
# File 'lib/hashblue/api/subscriber.rb', line 73

def send_message(contact_msisdn, content)
  result = post("#{_path}/messages.json", :message => {:content => content,
                :contact_msisdn => contact_msisdn} )
  Hashblue::API::Message.new(result)
end