definitialize-rubymarks 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/LICENSE +18 -0
  2. data/README.rdoc +92 -0
  3. data/lib/rubymarks.rb +137 -0
  4. metadata +65 -0
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2009 Definitalize, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,92 @@
1
+ = RubyMarks
2
+
3
+ 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.
4
+
5
+ = Installation
6
+
7
+ Add the GitHub gem source if you haven't done so already.
8
+
9
+ gem sources -a http://gems.github.com
10
+
11
+ And then...
12
+
13
+ gem install definitialize-rubymarks
14
+
15
+ To include RubyMarks in your program:
16
+
17
+ require 'rubymarks'
18
+
19
+ You may also need to <tt>require 'rubygems'</tt> if necessary.
20
+
21
+ = Starting RubyMarks
22
+
23
+ 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:
24
+
25
+ r = RubyMarks.new(
26
+ :user => 'myusername',
27
+ :password => 'mypassword',
28
+ :keyword => 'mykeyword', # The keyword you chose when you signed up for TextMarks
29
+ :api_key => 'mysite_com_123456'
30
+ )
31
+
32
+ = Inviting people to your group
33
+
34
+ People need to be subscribed to your group before they can receive text messages. To send an invitation:
35
+
36
+ r.send :invite, :to => '2065551414'
37
+
38
+ 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.
39
+
40
+ = Sending a text message
41
+
42
+ r.send :message, :to => '2065551414', :message => 'Hi there! TextMarks is pretty cool, huh?'
43
+
44
+ This will send the message "Hi there! TextMarks is pretty cool, huh?" to the number supplied to <tt>:to</tt>. You can also supply <tt>:to</tt> with a TextMarks username, if they're registered.
45
+
46
+ = Sending an alert
47
+
48
+ An alert is a text message that is sent to all of your subscribers.
49
+
50
+ r.send :alert, :message => "Change of plans! We're all now going to meet at the hot dog stand."
51
+
52
+ = Retrieving messages
53
+
54
+ You can use the <tt>messages</tt> 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):
55
+
56
+ r.messages
57
+ => [{"msg"=>"Change of plans! We're all now going to meet at the hot dog stand.", "time"=>1241680837, "nick"=>"group_leader", "id"=>123456,
58
+ "phone"=>"+12065551414"},
59
+ {"msg"=>"But I don't like hot dogs.", "time"=>1241638161, "nick"=>"User123", "id"=>867750, "phone"=>"+12065552323"}]
60
+
61
+ r.messages.size
62
+ => 2
63
+
64
+ = Retrieving members
65
+
66
+ You can use the <tt>members</tt> method to return an array of everyone subscribed to your group:
67
+
68
+ r.members
69
+ => [{"time"=>1241682280, "nick"=>"group_leader", "phone"=>"+12065551414"},
70
+ {"time"=>1241685492, "nick"=>"User123", "phone"=>"+12065552323"},
71
+ {"time"=>1241682332, "nick"=>"User456", "phone"=>"+12065557979"}]
72
+
73
+ r.members.size
74
+ => 3
75
+
76
+ r.members.last['nick']
77
+ => "User456"
78
+
79
+ = See if someone is subscribed
80
+
81
+ Use the <tt>is_member?</tt> method to check if someone is subscribed to your group. Supply either a 10 digit phone number or a username:
82
+
83
+ r.is_member? '2065552323'
84
+ => true
85
+
86
+ r.is_member? 'random_dude'
87
+ => false
88
+
89
+ = Additional information
90
+
91
+ * RubyMarks uses TextMark's latest V2 Alpha API. RubyMarks will be updated when the API gets updated (if necessary).
92
+ * Every method (except for <tt>is_member?</tt>) returns the API's response in JSON format.
@@ -0,0 +1,137 @@
1
+ require 'httparty'
2
+
3
+ class RubyMarks
4
+ include HTTParty
5
+ base_uri 'alpha.api2.textmarks.com'
6
+ format :json
7
+
8
+ # When instantiating RubyMarks, you need to supply your TextMarks username, password, keyword, and API key (all required).
9
+ # r = RubyMarks.new(
10
+ # :user => 'myusername',
11
+ # :password => 'mypassword',
12
+ # :keyword => 'mykeyword', # The keyword you chose when you signed up for TextMarks
13
+ # :api_key => 'mysite_com_123456'
14
+ # )
15
+ def initialize(options = {})
16
+ if [:user, :password, :keyword, :api_key].any? { |o| options[o].nil? }
17
+ raise ArgumentError, "Missing required argument(s). Requires :user, :password, :keyword, :api_key"
18
+ end
19
+
20
+ valid_api_key = self.class.get('/Test/test_api_key/', :query => { :api_key => options[:api_key] })['head']['rescode'] == 0
21
+ valid_user_info = self.class.get('/Test/test_auth_user/', :query => { :auth_user => options[:user], :auth_pass => options[:password] })['head']['rescode'] == 0
22
+ keyword_status = self.class.get('/Anybody/keyword_status/', :query => { :keyword => options[:keyword] })
23
+
24
+ if valid_api_key
25
+ if valid_user_info
26
+ if keyword_status['body']['available']
27
+ raise "Keyword '#{options[:keyword]}' hasn't been registered."
28
+ else
29
+ if keyword_status['body']['public_config']['manager']['nick'] == options[:user]
30
+ self.class.default_params :auth_user => options[:user], :auth_pass => options[:password], :tm => options[:keyword], :api_key => options[:api_key]
31
+ else
32
+ raise "Keyword doesn't belong to user '#{options[:user]}'"
33
+ end
34
+ end
35
+ else
36
+ raise "Invalid username or password."
37
+ end
38
+ else
39
+ raise "Invalid API key."
40
+ end
41
+ end
42
+
43
+ # Allows you to send invitations, messages, and alerts.
44
+ # To invite someone to your group:
45
+ # r.send :invite, :to => '2065551414'
46
+ # To send a regular message:
47
+ # r.send :message, :to =>'2065551414', :message => 'Hi there!'
48
+ # To send an alert (message that is sent to all of your subscribers):
49
+ # r.send :alert, :message => 'Important! A new episode of 30 Rock is on!'
50
+ def send(action, options = {})
51
+ raise ArgumentError, "Invalid messaging action: #{action}" unless [:invite, :message, :alert].member? action
52
+
53
+ case action
54
+ when :invite then send_invite(options)
55
+ when :message then send_message(options)
56
+ when :alert then send_alert(options)
57
+ end
58
+ end
59
+
60
+ # Returns an array of everyone subscribed to your group. (Can only return up to 100 members)
61
+ # r.members
62
+ # => [{"time"=>1241682280, "nick"=>"group_leader", "phone"=>"+12065551414"},
63
+ # {"time"=>1241685492, "nick"=>"User123", "phone"=>"+12065552323"},
64
+ # {"time"=>1241682332, "nick"=>"User456", "phone"=>"+12065557979"}]
65
+ #
66
+ # r.members.size
67
+ # => 3
68
+ #
69
+ # r.members.last['nick']
70
+ # => "User456"
71
+ def members
72
+ self.class.get('/GroupLeader/members/', :query => { :count => 100 })['body']['members']
73
+ end
74
+
75
+ # Check if someone is subscribed to your group. Supply either a 10 digit phone number or a username.
76
+ # r.is_member? 'User123'
77
+ # => true
78
+ #
79
+ # r.is_member? '2065552323'
80
+ # => true
81
+ #
82
+ # r.is_member? 'random_dude'
83
+ # => false
84
+ def is_member?(user)
85
+ self.class.get('/GroupLeader/has_member/', :query => { :user => user })['body']['member'] if user
86
+ end
87
+
88
+ # Deletes (unsubscribes) a member from your group. Supply either a 10 digit phone number or a username.
89
+ # r.delete_member '2065552323'
90
+ #
91
+ # r.delete_member 'User123'
92
+ def delete_member(user)
93
+ self.class.post('/GroupLeader/kick_member/', :query => { :user => user })
94
+ end
95
+
96
+ # Returns 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). (JSON format)
97
+ # r.messages
98
+ # => [{"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"},
99
+ # {"msg"=>"But I don't like hot dogs.", "time"=>1241638161, "nick"=>"User123", "id"=>867750, "phone"=>"+12065552323"}]
100
+ #
101
+ # r.messages.size
102
+ # => 2
103
+ #
104
+ # for message in r.messages
105
+ # p "#{message['nick']} said '#{message['msg']}'"
106
+ # end
107
+ # => "group_leader said 'Change of plans! We're all now going to meet at the hot dog stand.'"
108
+ # "User123 said 'But I don't like hot dogs.'"
109
+ def messages
110
+ self.class.get('/GroupLeader/messages/')['body']['messages']
111
+ end
112
+
113
+ # Deletes a message that is in your group.
114
+ # r.delete_message '123456' # Delete message with the id of 123456
115
+ #
116
+ # r.delete_message r.messages.first['id'] # Delete the first message in the group
117
+ def delete_message(message_id)
118
+ self.class.post('/GroupLeader/delete_message/', :query => { :msg_id => message_id })
119
+ end
120
+
121
+ protected
122
+
123
+ def send_invite(options)
124
+ raise ArgumentError, "Missing required argument(s). Requires :to" if options[:to].nil?
125
+ self.class.post('/Anybody/invite_to_group/', :query => { :user => options[:to] })
126
+ end
127
+
128
+ def send_message(options)
129
+ raise ArgumentError, "Missing required argument(s). Requires :message, :to" if options[:message].nil? or options[:to].nil?
130
+ self.class.post('/GroupLeader/send_one_message/', :query => { :msg => options[:message], :to => options[:to] })
131
+ end
132
+
133
+ def send_alert(options)
134
+ raise ArgumentError, "Missing required argument(s). Requires :message" if options[:message].nil?
135
+ self.class.post('/GroupLeader/broadcast_message/', :query => { :msg => options[:message] })
136
+ end
137
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: definitialize-rubymarks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Schaper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-01 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.4.3
24
+ version:
25
+ description: RubyMarks lets you interact with TextMarks (textmarks.com) in Ruby.
26
+ email: andrew@soshiku.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - LICENSE
35
+ - README.rdoc
36
+ - lib/rubymarks.rb
37
+ has_rdoc: true
38
+ homepage: http://definitialize.com/rubymarks
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --inline-source
42
+ - --charset=UTF-8
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: RubyMarks lets you interact with TextMarks (textmarks.com) in Ruby.
64
+ test_files: []
65
+