RubyMarks

RubyMarks lets you interact with TextMarks (textmarks.com) in Ruby. Here is how to get started and a few of things you can do with RubyMarks.

Installation

Add the GitHub gem source if you haven’t done so already.

gem sources -a http://gems.github.com

And then…

gem install definitialize-rubymarks

To include RubyMarks in your program:

require 'rubymarks'

You may also need to require 'rubygems' if necessary.

Starting RubyMarks

To use RubyMarks, you need your TextMarks username (or phone number), password, keyword, and your API key. Here we are instantiating the RubyMarks class to a local variable:

r = RubyMarks.new(
  :user => 'myusername',
  :password => 'mypassword',
  :keyword => 'mykeyword', # The keyword you chose when you signed up for TextMarks
  :api_key => 'mysite_com_123456'
)

Inviting people to your group

People need to be subscribed to your group before they can receive text messages. To send an invitation:

r.send :invite, :to => '2065551414'

This will send a text message to (206) 555-1414 asking the person to reply “Y” if they want to be subscribed. If they subscribe, you can now send text messages to them.

Sending a text message

r.send :message, :to => '2065551414', :message => 'Hi there! TextMarks is pretty cool, huh?'

This will send the message “Hi there! TextMarks is pretty cool, huh?” to the number supplied to :to. You can also supply :to with a TextMarks username, if they’re registered.

Sending an alert

An alert is a text message that is sent to all of your subscribers.

r.send :alert, :message => "Change of plans! We're all now going to meet at the hot dog stand."

Retrieving messages

You can use the messages method to return an array of the public messages in your group (these include alerts sent out and messages your subscribes may have sent back to your group):

r.messages
=> [{"msg"=>"Change of plans! We're all now going to meet at the hot dog stand.", "time"=>1241680837, "nick"=>"group_leader", "id"=>123456,
"phone"=>"+12065551414"},
    {"msg"=>"But I don't like hot dogs.", "time"=>1241638161, "nick"=>"User123", "id"=>867750, "phone"=>"+12065552323"}]

r.messages.size
=> 2

Retrieving members

You can use the members method to return an array of everyone subscribed to your group:

r.members
=> [{"time"=>1241682280, "nick"=>"group_leader", "phone"=>"+12065551414"},
    {"time"=>1241685492, "nick"=>"User123", "phone"=>"+12065552323"},
    {"time"=>1241682332, "nick"=>"User456", "phone"=>"+12065557979"}]

r.members.size
=> 3

r.members.last['nick']
=> "User456"

See if someone is subscribed

Use the is_member? method to check if someone is subscribed to your group. Supply either a 10 digit phone number or a username:

r.is_member? '2065552323'
=> true

r.is_member? 'random_dude'
=> false

Additional information

  • RubyMarks uses TextMark’s latest V2 Alpha API. RubyMarks will be updated when the API gets updated (if necessary).

  • Every method (except for is_member?) returns the API’s response in JSON format.