qst_client 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/qst_client.rb +10 -6
- metadata +3 -3
data/lib/qst_client.rb
CHANGED
@@ -11,8 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# client = QstClient.new 'service_url', 'username', 'psasword'
|
13
13
|
# last_id = client.put_messages [{'id' => '2', 'from' => 'sms://1234', 'to' => 'sms://5678', 'text' => 'Hello!', 'properties' => {'foo' => 'bar'}}]
|
14
|
-
# messages = client.get_messages
|
15
|
-
# messages = client.get_messages 'from_id'
|
14
|
+
# messages = client.get_messages :from_id => 'some_id', :max => 5
|
16
15
|
require 'rubygems'
|
17
16
|
require 'httparty'
|
18
17
|
require 'builder'
|
@@ -39,10 +38,16 @@ class QstClient
|
|
39
38
|
response['etag']
|
40
39
|
end
|
41
40
|
|
42
|
-
# Get messages from the server
|
41
|
+
# Get messages from the server.
|
43
42
|
# Returns an array of hashes similar to the one you would use to put_messages.
|
44
|
-
|
45
|
-
|
43
|
+
# Options:
|
44
|
+
# - :from_id: the id from which to return messages, exclusive
|
45
|
+
# - :max: the maximum amount of messages to get
|
46
|
+
def get_messages(options = {:max => 10})
|
47
|
+
params = {:basic_auth => @auth}
|
48
|
+
params[:headers] = {'if-none-match' => options[:from_id]} if options[:from_id]
|
49
|
+
|
50
|
+
response = self.class.get "#{@url}/outgoing?max=#{options[:max]}", params
|
46
51
|
raise QstClient::Exception.new response unless (200 ... 400).include? response.code
|
47
52
|
|
48
53
|
messages = []
|
@@ -110,7 +115,6 @@ class QstClient
|
|
110
115
|
|
111
116
|
response = self.class.post "#{@url}/incoming", :basic_auth => @auth, :body => xml.target!, :headers => {'Content-Type' => 'application/xml'}
|
112
117
|
raise QstClient::Exception.new response unless (200 ... 400).include? response.code
|
113
|
-
response['etag']
|
114
118
|
end
|
115
119
|
|
116
120
|
end
|
metadata
CHANGED