ctm 0.0.1 → 0.4.2

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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "ctm"
3
- s.version = "0.0.1"
3
+ s.version = "0.4.2"
4
4
  s.authors = ["CallTrackingMetrics", "Todd Fisher"]
5
5
  s.email = "info@calltrackingmetrics.com"
6
6
  s.files = `git ls-files`.split("\n")
@@ -4,6 +4,14 @@ require 'ctm'
4
4
  access_token = CTM::Auth.authenticate(ENV['CTM_TOKEN'], ENV['CTM_SECRET'])
5
5
  account = access_token.accounts.first
6
6
 
7
+ # look for toll free numbers
8
+ availble_numbers = account.numbers.search("US", :area_code => "888", :searchby => "tollfree")
9
+ availble_numbers.each do|num|
10
+ puts "#{num.friendly_name} -> #{num.phone_number}"
11
+ end
12
+ number_to_buy = availble_numbers.first
13
+
14
+ # look for local numbers
7
15
  availble_numbers = account.numbers.search("US", :area_code => "410")
8
16
  availble_numbers.each do|num|
9
17
  puts "#{num.friendly_name} -> #{num.phone_number}"
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__),"..", "lib")))
2
+ require 'ctm'
3
+ require 'set'
4
+
5
+ access_token = CTM::Auth.authenticate(ENV['CTM_TOKEN'], ENV['CTM_SECRET'])
6
+ account = access_token.accounts.first
7
+
8
+ call = account.calls.get(692389)
9
+
10
+ call.record_sale({value:100, conversion: true})
@@ -3,9 +3,6 @@ module CTM
3
3
  attr_reader :id
4
4
  attr_accessor :name, :status, :stats, :balance
5
5
 
6
- # {"id"=>25, "name"=>"CallTrackingMetrics", "user_role"=>"admin", "status"=>"active",
7
- # "stats"=>{"calls"=>{"2013-04-18"=>3, "2013-04-25"=>1}, "tracking_numbers"=>48},
8
- # "url"=>"http://ctmdev.co/api/v1/accounts/25.json", "balance"=>{"cents"=>23739, "currency"=>"USD", "precision"=>2}}
9
6
  def initialize(data, token=nil)
10
7
  super(data, token)
11
8
  @id = data['id']
@@ -16,23 +13,28 @@ module CTM
16
13
  end
17
14
 
18
15
  def numbers(options={})
19
- CTM::NumberList.new(options.merge(:account_id => @id), @token)
16
+ CTM::NumberList.new(options.merge(account_id: @id), @token)
20
17
  end
21
18
 
22
19
  def receiving_numbers(options={})
23
- CTM::List.new('ReceivingNumber', options.merge(:account_id => @id), @token)
20
+ CTM::List.new('ReceivingNumber', options.merge(account_id: @id), @token)
24
21
  end
25
22
 
26
23
  def sources(options={})
27
- CTM::List.new('Source', options.merge(:account_id => @id), @token)
24
+ CTM::List.new('Source', options.merge(account_id: @id), @token)
28
25
  end
29
26
 
30
27
  def users(options={})
31
- CTM::List.new('User', options.merge(:account_id => @id), @token)
28
+ CTM::List.new('User', options.merge(account_id: @id), @token)
32
29
  end
33
30
 
34
31
  def webhooks(options={})
35
- CTM::List.new('Webhook', options.merge(:account_id => @id), @token)
32
+ CTM::List.new('Webhook', options.merge(account_id: @id), @token)
36
33
  end
34
+
35
+ def calls(options={})
36
+ CTM::List.new('Call', options.merge(account_id: @id), @token)
37
+ end
38
+
37
39
  end
38
40
  end
@@ -20,6 +20,7 @@ module CTM
20
20
  def save(options={})
21
21
  puts "save: #{options.inspect}"
22
22
  path_str = "/api/v1/#{@list_type_path}/#{@id}.json"
23
+ puts path_str
23
24
  res = self.class.put(path_str, :body => options.merge(:auth_token => @token))
24
25
  end
25
26
 
@@ -34,7 +35,7 @@ module CTM
34
35
  account_id = options.delete(:account_id)
35
36
  token = options.delete(:token)
36
37
  path_str = "/api/v1/#{list_type_path}.json"
37
- puts "create: #{self} -> #{options.inspect}"
38
+ puts "create: #{self}(#{path_str}) -> #{options.inspect}"
38
39
  res = self.post(path_str, :body => options.merge(:auth_token => token))
39
40
  puts "result: #{res.parsed_response.inspect}"
40
41
  puts "properties: #{list_type_path.inspect} -> #{list_token_type.inspect} -> #{account_id}"
@@ -1,10 +1,48 @@
1
1
  module CTM
2
2
  class Call < Base
3
- attr_reader :id
3
+ ReadOnlyFields = [
4
+ :id, :account_id, :search, :referrer, :location, :source,
5
+ :likelihood, :duration, :talk_time, :ring_time, :called_at, :tracking_number, :business_number,
6
+ :dial_status, :caller_number_split, :excluded, :tracking_number_format, :business_number_format,
7
+ :caller_number_format, :audio, :tag_list, :latitude, :longitude, :extended_lookup, :sale
8
+ ]
9
+ ReadWriteFields = [
10
+ :name, :email, :street, :city, :state, :country, :postal_code, :notes
11
+ ]
12
+ attr_reader *ReadOnlyFields
13
+ attr_accessor *ReadWriteFields
4
14
 
15
+ # {"id":729485,"account_id":25,"name":"Escondido Ca","search":null,"referrer":null,"location":null,"source":"Facebook","source_id":36,"likelihood":null,"duration":25,
16
+ # "talk_time":10,"ring_time":15,"email":"tmacleod@stradegy.ca","street":"1600 Amphitheatre","city":"Escondido","state":"CA","country":"US","postal_code":"94043",
17
+ # "called_at":"2013-05-01 11:48 PM -04:00","tracking_number_id":41,"tracking_number":"+17203584118","tracking_label":null,"business_number":"+14109759000","business_label":"Main Office",
18
+ # "receiving_number_id":9,"dial_status":"completed","caller_number_split":["1","760","705","8888"],"excluded":false,"tracking_number_format":"(720) 358-4118",
19
+ #"business_number_format":"(410) 975-9000","caller_number_format":"(760) 705-8888","alternative_number":"(760) 705-8888","caller_number_complete":"+17607058888",
20
+ # "caller_number":"+17607058888","visitor":false,"audio":"https://calltrackingmetrics.com/accounts/ACe2a2cc9e29744544bfa706ba45ad9baf/recordings/RE18e40e5aad04e7a35da0b54ba47895da",
21
+ # "tag_list":["follow up"],"notes":"","latitude":33.0879,"longitude":-117.116,"extended_lookup_on":false,"extended_lookup":{"first_name":"","last_name":"","name_type":"","phone_type":"0","business_name":null,"street_number":"1600","street_name":"Amphitheatre","city":"Mountain View","state":"CA","zipcode":"94043"}}
5
22
  def initialize(data, token=nil)
6
23
  super(data, token)
7
- @id = data['id']
24
+ ReadOnlyFields.each do|field|
25
+ instance_variable_set("@#{field}", data[field.to_s])
26
+ end
27
+ ReadWriteFields.each do|field|
28
+ instance_variable_set("@#{field}", data[field.to_s])
29
+ end
30
+ end
31
+
32
+ def record_sale(sale_detail)
33
+ path_str = "/api/v1/#{@list_type_path}/#{self.id}/sale.json"
34
+ post_options = {}
35
+ sale_detail.each do|k,v|
36
+ if k.to_s == 'conversion'
37
+ v = v ? 'on' : 'off'
38
+ end
39
+ post_options[k] = v
40
+ end
41
+ res = self.class.post(path_str, :body => post_options.merge(:auth_token => @token))
42
+ (res && res['status'] == 'success')
43
+ end
44
+
45
+ def update_sale(sale_detail)
8
46
  end
9
47
 
10
48
  end
@@ -20,14 +20,13 @@ module CTM
20
20
  else
21
21
  @list_type_path = @list_token_type
22
22
  end
23
- if fetched_objects
24
- map_data(fetched_objects)
25
- else
26
- fetch_page(options)
27
- end
23
+
24
+ @fetched_objects = fetched_objects
25
+ @options = options
28
26
  end
29
27
 
30
28
  def each &block
29
+ load_records
31
30
  @objects.each do |obj|
32
31
  if block_given?
33
32
  block.call obj
@@ -38,10 +37,10 @@ module CTM
38
37
  end
39
38
 
40
39
  def create(options)
41
- @object_klass.create(options.merge(:list_type_path => @list_type_path,
42
- :list_token_type => @list_token_type,
43
- :account_id => @account_id,
44
- :token => @token))
40
+ @object_klass.create(options.merge(list_type_path: @list_type_path,
41
+ list_token_type: @list_token_type,
42
+ account_id: @account_id,
43
+ token: @token))
45
44
  end
46
45
 
47
46
  def find(options)
@@ -53,12 +52,27 @@ module CTM
53
52
  self
54
53
  end
55
54
 
55
+ def get(recordid, options={})
56
+ path_str = "/api/v1/#{@list_type_path}/#{recordid}.json"
57
+ res = self.class.get(path_str, query: options.merge(auth_token: @token))
58
+ data = res.parsed_response
59
+ @object_klass.new(data, @token)
60
+ end
61
+
56
62
  protected
57
63
 
64
+ def load_records
65
+ if @fetched_objects
66
+ map_data(@fetched_objects)
67
+ else
68
+ fetch_page(@options)
69
+ end
70
+ end
71
+
58
72
  def fetch_page(options={})
59
- options = {:per_page => 10, :page => 1}.merge(options)
73
+ options = {per_page: 10, page: 1}.merge(options)
60
74
  path_str = "/api/v1/#{@list_type_path}.json"
61
- res = self.class.get(path_str, :query => options.merge(:auth_token => @token))
75
+ res = self.class.get(path_str, query: options.merge(auth_token: @token))
62
76
  data = res.parsed_response
63
77
  if data["status"] && data["status"] == "error"
64
78
  puts data.inspect
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.0.1
4
+ version: 0.4.2
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-04-30 00:00:00.000000000 Z
13
+ date: 2013-07-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: phony
@@ -144,6 +144,7 @@ files:
144
144
  - examples/manage_sources.rb
145
145
  - examples/manage_users.rb
146
146
  - examples/manage_webhooks.rb
147
+ - examples/record_sale.rb
147
148
  - lib/ctm.rb
148
149
  - lib/ctm/account.rb
149
150
  - lib/ctm/auth.rb