Class: Hashblue::API::Subscriber
- 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.
subscriber.contacts.first.
# 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
-
.find(id) ⇒ Object
Instantiate a Subscriber.
Instance Method Summary collapse
-
#contacts(options = {}) ⇒ Object
Returns an Array of Contact objects for the Subscriber.
-
#deleted_messages(options = {}) ⇒ Object
Returns an Array of Message objects for the Subscriber.
-
#favourites(options = {}) ⇒ Object
Returns an Array of Message objects for the subscriber that are marked as favourites.
-
#messages(options = {}) ⇒ Object
Returns an Array of Message objects for the Subscriber.
-
#send_message(contact_msisdn, content) ⇒ Object
Send a message from the Subscriber to the given number.
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( = {}) Hashblue::API::Contact.from_json(get("#{_path}/contacts.json", )) 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 (={}) Hashblue::API::Message.from_json(get("#{_path}/messages/deleted.json", )) 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(={}) Hashblue::API::Message.from_json(get("#{_path}/favourites.json", )) 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 (={}) Hashblue::API::Message.from_json(get("#{_path}/messages.json", )) 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 (contact_msisdn, content) result = post("#{_path}/messages.json", :message => {:content => content, :contact_msisdn => contact_msisdn} ) Hashblue::API::Message.new(result) end |