ctm 0.4.2 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ctm.gemspec +1 -1
- data/examples/sms.rb +26 -0
- data/lib/ctm.rb +2 -0
- data/lib/ctm/account.rb +8 -1
- data/lib/ctm/base.rb +11 -0
- data/lib/ctm/message.rb +21 -0
- data/lib/ctm/message_list.rb +18 -0
- metadata +5 -2
data/ctm.gemspec
CHANGED
data/examples/sms.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__),"..", "lib")))
|
2
|
+
require 'ctm'
|
3
|
+
|
4
|
+
access_token = CTM::Auth.authenticate(ENV['CTM_TOKEN'], ENV['CTM_SECRET'])
|
5
|
+
account = access_token.accounts.first
|
6
|
+
|
7
|
+
puts "all messages"
|
8
|
+
account.messages.each do|message|
|
9
|
+
if message.direction == 'outbound'
|
10
|
+
puts "Sent message to #{message.to} from #{message.from} -> #{message.body}"
|
11
|
+
elsif message.direction == 'inbound'
|
12
|
+
puts "Received message from #{message.from} to #{message.to} -> #{message.body}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
puts "Received messages"
|
17
|
+
# or just the messages we've received
|
18
|
+
account.messages(:direction => 'inbound').each do|message|
|
19
|
+
puts "Received message from #{message.from} to #{message.to} -> #{message.body}"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
# Send a message
|
24
|
+
# export TO_NUMBER='+1dddddddddd'
|
25
|
+
# export FROM_NUMBER='TPNC3C4B23ddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'
|
26
|
+
account.messages.send_message(ENV["TO_NUMBER"], ENV["FROM_NUMBER"], "Hello CallTrackingMetrics")
|
data/lib/ctm.rb
CHANGED
data/lib/ctm/account.rb
CHANGED
@@ -5,11 +5,14 @@ module CTM
|
|
5
5
|
|
6
6
|
def initialize(data, token=nil)
|
7
7
|
super(data, token)
|
8
|
+
puts data.inspect
|
8
9
|
@id = data['id']
|
9
10
|
@name = data['name']
|
10
11
|
@status = data['status']
|
11
12
|
@stats = data['stats']['calls']
|
12
|
-
|
13
|
+
if data['balance']
|
14
|
+
@balance = "$" + (data['balance']['cents'].to_i / 100).to_s + "." + (data['balance']['cents'].to_i % 100).to_s
|
15
|
+
end
|
13
16
|
end
|
14
17
|
|
15
18
|
def numbers(options={})
|
@@ -36,5 +39,9 @@ module CTM
|
|
36
39
|
CTM::List.new('Call', options.merge(account_id: @id), @token)
|
37
40
|
end
|
38
41
|
|
42
|
+
def messages(options={})
|
43
|
+
CTM::MessageList.new(options.merge(account_id: @id), @token)
|
44
|
+
end
|
45
|
+
|
39
46
|
end
|
40
47
|
end
|
data/lib/ctm/base.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
module CTM
|
2
2
|
class Base
|
3
|
+
class Location
|
4
|
+
attr_reader :street, :city, :state, :country, :zip
|
5
|
+
def initialize(street, city, state, country, zip)
|
6
|
+
@street = street
|
7
|
+
@city = city
|
8
|
+
@state = state
|
9
|
+
@country = country
|
10
|
+
@zip = zip
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
3
14
|
include HTTParty
|
4
15
|
base_uri ENV["CTM_URL"] || "api.calltrackingmetrics.com"
|
5
16
|
|
data/lib/ctm/message.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module CTM
|
2
|
+
class Message < Base
|
3
|
+
attr_reader :id, :account_id, :body, :callerid, :from, :to, :from_location, :to_location, :source_id, :direction
|
4
|
+
|
5
|
+
def initialize(data, token=nil)
|
6
|
+
super(data, token)
|
7
|
+
@id = data['id']
|
8
|
+
@account_id = data['account_id']
|
9
|
+
@body = data['body']
|
10
|
+
@to = data['to_number']
|
11
|
+
@from = data['from_number']
|
12
|
+
@callerid = data['callerid']
|
13
|
+
@from_location = CTM::Base::Location.new(nil, data['from_city'], data['from_state'], data['from_country'], data['from_zip'])
|
14
|
+
@to_location = CTM::Base::Location.new(nil, data['to_city'], data['to_state'], data['to_country'], data['to_zip'])
|
15
|
+
@source_id = data['tracking_source_id']
|
16
|
+
@direction = data['direction']
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module CTM
|
2
|
+
class MessageList < List
|
3
|
+
def initialize(options={}, token=nil)
|
4
|
+
super('Message', options, token)
|
5
|
+
@list_type_path = "accounts/#{@account_id}/sms"
|
6
|
+
end
|
7
|
+
|
8
|
+
def send_message(to, from, message)
|
9
|
+
options = {:to => to, :from => from, :msg => message}
|
10
|
+
path_str = "/api/v1/#{@list_type_path}.json"
|
11
|
+
res = self.class.post(path_str, :body => options.merge(:auth_token => @token))
|
12
|
+
data = res.parsed_response
|
13
|
+
puts data.inspect
|
14
|
+
(data["status"] == "processing")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ctm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-08-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: phony
|
@@ -145,6 +145,7 @@ files:
|
|
145
145
|
- examples/manage_users.rb
|
146
146
|
- examples/manage_webhooks.rb
|
147
147
|
- examples/record_sale.rb
|
148
|
+
- examples/sms.rb
|
148
149
|
- lib/ctm.rb
|
149
150
|
- lib/ctm/account.rb
|
150
151
|
- lib/ctm/auth.rb
|
@@ -153,6 +154,8 @@ files:
|
|
153
154
|
- lib/ctm/call.rb
|
154
155
|
- lib/ctm/error.rb
|
155
156
|
- lib/ctm/list.rb
|
157
|
+
- lib/ctm/message.rb
|
158
|
+
- lib/ctm/message_list.rb
|
156
159
|
- lib/ctm/number.rb
|
157
160
|
- lib/ctm/number_list.rb
|
158
161
|
- lib/ctm/receiving_number.rb
|