telerivet 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e007f7fdf619163a3b1d610beae5e36b69ba9909
4
- data.tar.gz: a000f816faa4178b51db9da1ccf3aaec5894a184
3
+ metadata.gz: 318bae0777cbacdccba67044f107f9f2a468b6d5
4
+ data.tar.gz: 005116ddbd32e76a91feafe5794ff3f13ec3503b
5
5
  SHA512:
6
- metadata.gz: 406bc716da9060357f419317d31553f0ae691cfaf1e20e69a09e91d9cf86f86bf2d93fc199c5a92803cef6df3dbc3fa38f89f597ecaec19330c144ffde49eafc
7
- data.tar.gz: 301f2207986379871faae42ab3aeb7694cd27b38c36df049dfee1aba597cb9dcdc12fc64a919e0e36a1755b8e51ab0e22e4b473c22df225c6b2b8329b64eb62a
6
+ metadata.gz: 7a6de21710242c4db07004bd23ba4ee6730457a4c03389d34e5bc1d92b4e15fb953003319198e61dd923b20c2a9a1abbfe741109e5cdc156e0dfd07742a760b2
7
+ data.tar.gz: cd1d5bf58e26fe7e3b5fe6cde3b4152ff8e8d515437fb24cec4440198bf42161d7acb019b252266f4bfa51a535495e76bc56d0b090993e682bee2dfc56b37d9c
data/lib/telerivet.rb CHANGED
@@ -5,13 +5,10 @@ require_relative 'telerivet/apicursor'
5
5
 
6
6
  module Telerivet
7
7
 
8
- #
9
- #
10
- #
11
8
  class API
12
9
  attr_reader :num_requests
13
10
 
14
- @@client_version = '1.0.2'
11
+ @@client_version = '1.1.0'
15
12
 
16
13
  #
17
14
  # Initializes a client handle to the Telerivet REST API.
@@ -89,7 +86,7 @@ class API
89
86
  return res
90
87
  end
91
88
  end
92
-
89
+
93
90
  #
94
91
  # Retrieves the Telerivet project with the given ID.
95
92
  #
@@ -103,9 +100,25 @@ class API
103
100
  #
104
101
  def get_project_by_id(id)
105
102
  require_relative 'telerivet/project'
106
- Project.new(self, {'id' => id}, false)
103
+ Project.new(self, self.do_request("GET", get_base_api_path() + "/projects/#{id}"))
107
104
  end
108
-
105
+
106
+ #
107
+ # Initializes the Telerivet project with the given ID without making an API request.
108
+ #
109
+ # Arguments:
110
+ # - id
111
+ # * ID of the project -- see <https://telerivet.com/dashboard/api>
112
+ # * Required
113
+ #
114
+ # Returns:
115
+ # Telerivet::Project
116
+ #
117
+ def init_project_by_id(id)
118
+ require_relative 'telerivet/project'
119
+ return Project.new(self, {'id' => id}, false)
120
+ end
121
+
109
122
  #
110
123
  # Queries projects accessible to the current user account.
111
124
  #
@@ -140,8 +153,13 @@ class API
140
153
  #
141
154
  def query_projects(options = nil)
142
155
  require_relative 'telerivet/project'
143
- cursor(Project, '/projects', options)
156
+ self.cursor(Project, get_base_api_path() + "/projects", options)
157
+ end
158
+
159
+ def get_base_api_path()
160
+ ""
144
161
  end
162
+
145
163
 
146
164
  def cursor(item_cls, path, options)
147
165
  APICursor.new(self, item_cls, path, options)
@@ -59,7 +59,7 @@ class Contact < Entity
59
59
  # bool
60
60
  #
61
61
  def is_in_group?(group)
62
- load_data()
62
+ load()
63
63
  return @group_ids_set.has_key?(group.id)
64
64
  end
65
65
 
@@ -4,8 +4,8 @@ module Telerivet
4
4
  #
5
5
  # Represents a custom data table that can store arbitrary rows.
6
6
  #
7
- # For example, poll services use data tables to store a row for each response.
8
- #
7
+ # For example, poll services use data tables to store a row for each
8
+ # response.
9
9
  #
10
10
  # DataTables are schemaless -- each row simply stores custom variables. Each
11
11
  # variable name is equivalent to a different "column" of the data table.
@@ -103,8 +103,6 @@ class DataTable < Entity
103
103
  #
104
104
  # Retrieves the row in the given table with the given ID.
105
105
  #
106
- # Note: This does not make any API requests until you access a property of the DataRow.
107
- #
108
106
  # Arguments:
109
107
  # - id
110
108
  # * ID of the row
@@ -114,6 +112,22 @@ class DataTable < Entity
114
112
  # Telerivet::DataRow
115
113
  #
116
114
  def get_row_by_id(id)
115
+ require_relative 'datarow'
116
+ DataRow.new(@api, @api.do_request("GET", get_base_api_path() + "/rows/#{id}"))
117
+ end
118
+
119
+ #
120
+ # Initializes the row in the given table with the given ID, without making an API request.
121
+ #
122
+ # Arguments:
123
+ # - id
124
+ # * ID of the row
125
+ # * Required
126
+ #
127
+ # Returns:
128
+ # Telerivet::DataRow
129
+ #
130
+ def init_row_by_id(id)
117
131
  require_relative 'datarow'
118
132
  return DataRow.new(@api, {'project_id' => self.project_id, 'table_id' => self.id, 'id' => id}, false)
119
133
  end
@@ -21,11 +21,13 @@ class Entity
21
21
  end
22
22
  end
23
23
 
24
- def load_data()
24
+ def load()
25
25
  if !@is_loaded
26
26
  @is_loaded = true
27
27
  set_data(@api.do_request('GET', get_base_api_path()))
28
+ @data.merge!(@dirty)
28
29
  end
30
+ self
29
31
  end
30
32
 
31
33
  def vars
@@ -34,21 +36,17 @@ class Entity
34
36
 
35
37
  def get(name)
36
38
  if @data.has_key?(name)
37
- return @data[name]
39
+ return @data[name]
38
40
  elsif @is_loaded
39
41
  return nil
40
42
  end
41
43
 
42
- load_data()
43
-
44
+ load()
45
+
44
46
  return @data[name]
45
- end
47
+ end
46
48
 
47
49
  def set(name, value)
48
- if !@is_loaded
49
- loadData()
50
- end
51
-
52
50
  @data[name] = value
53
51
  @dirty[name] = value
54
52
  end
@@ -81,7 +81,7 @@ module Telerivet
81
81
  # if available.
82
82
  # * Read-only
83
83
  #
84
- # - price
84
+ # - price (number)
85
85
  # * The price of this message, if known. By convention, message prices are negative.
86
86
  # * Read-only
87
87
  #
@@ -123,7 +123,7 @@ class Message < Entity
123
123
  # bool
124
124
  #
125
125
  def has_label?(label)
126
- load_data()
126
+ load()
127
127
  return @label_ids_set.has_key?(label.id)
128
128
  end
129
129
 
@@ -311,8 +311,6 @@ class Project < Entity
311
311
  #
312
312
  # Retrieves the contact with the given ID.
313
313
  #
314
- # Note: This does not make any API requests until you access a property of the Contact.
315
- #
316
314
  # Arguments:
317
315
  # - id
318
316
  # * ID of the contact
@@ -322,6 +320,22 @@ class Project < Entity
322
320
  # Telerivet::Contact
323
321
  #
324
322
  def get_contact_by_id(id)
323
+ require_relative 'contact'
324
+ Contact.new(@api, @api.do_request("GET", get_base_api_path() + "/contacts/#{id}"))
325
+ end
326
+
327
+ #
328
+ # Initializes the Telerivet contact with the given ID without making an API request.
329
+ #
330
+ # Arguments:
331
+ # - id
332
+ # * ID of the contact
333
+ # * Required
334
+ #
335
+ # Returns:
336
+ # Telerivet::Contact
337
+ #
338
+ def init_contact_by_id(id)
325
339
  require_relative 'contact'
326
340
  return Contact.new(@api, {'project_id' => self.id, 'id' => id}, false)
327
341
  end
@@ -377,8 +391,6 @@ class Project < Entity
377
391
  #
378
392
  # Retrieves the phone with the given ID.
379
393
  #
380
- # Note: This does not make any API requests until you access a property of the Phone.
381
- #
382
394
  # Arguments:
383
395
  # - id
384
396
  # * ID of the phone - see <https://telerivet.com/dashboard/api>
@@ -388,6 +400,22 @@ class Project < Entity
388
400
  # Telerivet::Phone
389
401
  #
390
402
  def get_phone_by_id(id)
403
+ require_relative 'phone'
404
+ Phone.new(@api, @api.do_request("GET", get_base_api_path() + "/phones/#{id}"))
405
+ end
406
+
407
+ #
408
+ # Initializes the phone with the given ID without making an API request.
409
+ #
410
+ # Arguments:
411
+ # - id
412
+ # * ID of the phone - see <https://telerivet.com/dashboard/api>
413
+ # * Required
414
+ #
415
+ # Returns:
416
+ # Telerivet::Phone
417
+ #
418
+ def init_phone_by_id(id)
391
419
  require_relative 'phone'
392
420
  return Phone.new(@api, {'project_id' => self.id, 'id' => id}, false)
393
421
  end
@@ -459,8 +487,6 @@ class Project < Entity
459
487
  #
460
488
  # Retrieves the message with the given ID.
461
489
  #
462
- # Note: This does not make any API requests until you access a property of the Message.
463
- #
464
490
  # Arguments:
465
491
  # - id
466
492
  # * ID of the message
@@ -470,6 +496,22 @@ class Project < Entity
470
496
  # Telerivet::Message
471
497
  #
472
498
  def get_message_by_id(id)
499
+ require_relative 'message'
500
+ Message.new(@api, @api.do_request("GET", get_base_api_path() + "/messages/#{id}"))
501
+ end
502
+
503
+ #
504
+ # Initializes the Telerivet message with the given ID without making an API request.
505
+ #
506
+ # Arguments:
507
+ # - id
508
+ # * ID of the message
509
+ # * Required
510
+ #
511
+ # Returns:
512
+ # Telerivet::Message
513
+ #
514
+ def init_message_by_id(id)
473
515
  require_relative 'message'
474
516
  return Message.new(@api, {'project_id' => self.id, 'id' => id}, false)
475
517
  end
@@ -530,8 +572,6 @@ class Project < Entity
530
572
  #
531
573
  # Retrieves the group with the given ID.
532
574
  #
533
- # Note: This does not make any API requests until you access a property of the Group.
534
- #
535
575
  # Arguments:
536
576
  # - id
537
577
  # * ID of the group
@@ -541,6 +581,22 @@ class Project < Entity
541
581
  # Telerivet::Group
542
582
  #
543
583
  def get_group_by_id(id)
584
+ require_relative 'group'
585
+ Group.new(@api, @api.do_request("GET", get_base_api_path() + "/groups/#{id}"))
586
+ end
587
+
588
+ #
589
+ # Initializes the group with the given ID without making an API request.
590
+ #
591
+ # Arguments:
592
+ # - id
593
+ # * ID of the group
594
+ # * Required
595
+ #
596
+ # Returns:
597
+ # Telerivet::Group
598
+ #
599
+ def init_group_by_id(id)
544
600
  require_relative 'group'
545
601
  return Group.new(@api, {'project_id' => self.id, 'id' => id}, false)
546
602
  end
@@ -601,8 +657,6 @@ class Project < Entity
601
657
  #
602
658
  # Retrieves the label with the given ID.
603
659
  #
604
- # Note: This does not make any API requests until you access a property of the Label.
605
- #
606
660
  # Arguments:
607
661
  # - id
608
662
  # * ID of the label
@@ -612,6 +666,22 @@ class Project < Entity
612
666
  # Telerivet::Label
613
667
  #
614
668
  def get_label_by_id(id)
669
+ require_relative 'label'
670
+ Label.new(@api, @api.do_request("GET", get_base_api_path() + "/labels/#{id}"))
671
+ end
672
+
673
+ #
674
+ # Initializes the label with the given ID without making an API request.
675
+ #
676
+ # Arguments:
677
+ # - id
678
+ # * ID of the label
679
+ # * Required
680
+ #
681
+ # Returns:
682
+ # Telerivet::Label
683
+ #
684
+ def init_label_by_id(id)
615
685
  require_relative 'label'
616
686
  return Label.new(@api, {'project_id' => self.id, 'id' => id}, false)
617
687
  end
@@ -672,8 +742,6 @@ class Project < Entity
672
742
  #
673
743
  # Retrieves the data table with the given ID.
674
744
  #
675
- # Note: This does not make any API requests until you access a property of the DataTable.
676
- #
677
745
  # Arguments:
678
746
  # - id
679
747
  # * ID of the data table
@@ -683,6 +751,22 @@ class Project < Entity
683
751
  # Telerivet::DataTable
684
752
  #
685
753
  def get_data_table_by_id(id)
754
+ require_relative 'datatable'
755
+ DataTable.new(@api, @api.do_request("GET", get_base_api_path() + "/tables/#{id}"))
756
+ end
757
+
758
+ #
759
+ # Initializes the data table with the given ID without making an API request.
760
+ #
761
+ # Arguments:
762
+ # - id
763
+ # * ID of the data table
764
+ # * Required
765
+ #
766
+ # Returns:
767
+ # Telerivet::DataTable
768
+ #
769
+ def init_data_table_by_id(id)
686
770
  require_relative 'datatable'
687
771
  return DataTable.new(@api, {'project_id' => self.id, 'id' => id}, false)
688
772
  end
@@ -735,9 +819,6 @@ class Project < Entity
735
819
  #
736
820
  # Retrieves the scheduled message with the given ID.
737
821
  #
738
- # Note: This does not make any API requests until you access a property of the
739
- # ScheduledMessage.
740
- #
741
822
  # Arguments:
742
823
  # - id
743
824
  # * ID of the scheduled message
@@ -747,6 +828,22 @@ class Project < Entity
747
828
  # Telerivet::ScheduledMessage
748
829
  #
749
830
  def get_scheduled_message_by_id(id)
831
+ require_relative 'scheduledmessage'
832
+ ScheduledMessage.new(@api, @api.do_request("GET", get_base_api_path() + "/scheduled/#{id}"))
833
+ end
834
+
835
+ #
836
+ # Initializes the scheduled message with the given ID without making an API request.
837
+ #
838
+ # Arguments:
839
+ # - id
840
+ # * ID of the scheduled message
841
+ # * Required
842
+ #
843
+ # Returns:
844
+ # Telerivet::ScheduledMessage
845
+ #
846
+ def init_scheduled_message_by_id(id)
750
847
  require_relative 'scheduledmessage'
751
848
  return ScheduledMessage.new(@api, {'project_id' => self.id, 'id' => id}, false)
752
849
  end
@@ -798,8 +895,6 @@ class Project < Entity
798
895
  #
799
896
  # Retrieves the service with the given ID.
800
897
  #
801
- # Note: This does not make any API requests until you access a property of the Service.
802
- #
803
898
  # Arguments:
804
899
  # - id
805
900
  # * ID of the service
@@ -809,6 +904,22 @@ class Project < Entity
809
904
  # Telerivet::Service
810
905
  #
811
906
  def get_service_by_id(id)
907
+ require_relative 'service'
908
+ Service.new(@api, @api.do_request("GET", get_base_api_path() + "/services/#{id}"))
909
+ end
910
+
911
+ #
912
+ # Initializes the service with the given ID without making an API request.
913
+ #
914
+ # Arguments:
915
+ # - id
916
+ # * ID of the service
917
+ # * Required
918
+ #
919
+ # Returns:
920
+ # Telerivet::Service
921
+ #
922
+ def init_service_by_id(id)
812
923
  require_relative 'service'
813
924
  return Service.new(@api, {'project_id' => self.id, 'id' => id}, false)
814
925
  end
@@ -871,9 +982,6 @@ class Project < Entity
871
982
  #
872
983
  # Retrieves the mobile money receipt with the given ID.
873
984
  #
874
- # Note: This does not make any API requests until you access a property of the
875
- # MobileMoneyReceipt.
876
- #
877
985
  # Arguments:
878
986
  # - id
879
987
  # * ID of the mobile money receipt
@@ -883,10 +991,95 @@ class Project < Entity
883
991
  # Telerivet::MobileMoneyReceipt
884
992
  #
885
993
  def get_receipt_by_id(id)
994
+ require_relative 'mobilemoneyreceipt'
995
+ MobileMoneyReceipt.new(@api, @api.do_request("GET", get_base_api_path() + "/receipts/#{id}"))
996
+ end
997
+
998
+ #
999
+ # Initializes the mobile money receipt with the given ID without making an API request.
1000
+ #
1001
+ # Arguments:
1002
+ # - id
1003
+ # * ID of the mobile money receipt
1004
+ # * Required
1005
+ #
1006
+ # Returns:
1007
+ # Telerivet::MobileMoneyReceipt
1008
+ #
1009
+ def init_receipt_by_id(id)
886
1010
  require_relative 'mobilemoneyreceipt'
887
1011
  return MobileMoneyReceipt.new(@api, {'project_id' => self.id, 'id' => id}, false)
888
1012
  end
889
1013
 
1014
+ #
1015
+ # Queries custom routes that can be used to send messages (not including Phones).
1016
+ #
1017
+ # Arguments:
1018
+ # - options (Hash)
1019
+ #
1020
+ # - name
1021
+ # * Filter routes by name
1022
+ # * Allowed modifiers: name[ne], name[prefix], name[not_prefix], name[gte], name[gt],
1023
+ # name[lt], name[lte]
1024
+ #
1025
+ # - sort
1026
+ # * Sort the results based on a field
1027
+ # * Allowed values: default, name
1028
+ # * Default: default
1029
+ #
1030
+ # - sort_dir
1031
+ # * Sort the results in ascending or descending order
1032
+ # * Allowed values: asc, desc
1033
+ # * Default: asc
1034
+ #
1035
+ # - page_size (int)
1036
+ # * Number of results returned per page (max 200)
1037
+ # * Default: 50
1038
+ #
1039
+ # - offset (int)
1040
+ # * Number of items to skip from beginning of result set
1041
+ # * Default: 0
1042
+ #
1043
+ # Returns:
1044
+ # Telerivet::APICursor (of Telerivet::Route)
1045
+ #
1046
+ def query_routes(options = nil)
1047
+ require_relative 'route'
1048
+ @api.cursor(Route, get_base_api_path() + "/routes", options)
1049
+ end
1050
+
1051
+ #
1052
+ # Gets a custom route by ID
1053
+ #
1054
+ # Arguments:
1055
+ # - id
1056
+ # * ID of the route
1057
+ # * Required
1058
+ #
1059
+ # Returns:
1060
+ # Telerivet::Route
1061
+ #
1062
+ def get_route_by_id(id)
1063
+ require_relative 'route'
1064
+ Route.new(@api, @api.do_request("GET", get_base_api_path() + "/routes/#{id}"))
1065
+ end
1066
+
1067
+ #
1068
+ # Initializes a custom route by ID without making an API request.
1069
+ #
1070
+ # Arguments:
1071
+ # - id
1072
+ # * ID of the route
1073
+ # * Required
1074
+ #
1075
+ # Returns:
1076
+ # Telerivet::Route
1077
+ #
1078
+ def init_route_by_id(id)
1079
+ require_relative 'route'
1080
+ return Route.new(@api, {'project_id' => self.id, 'id' => id}, false)
1081
+ end
1082
+
890
1083
  #
891
1084
  # Saves any fields or custom variables that have changed for the project.
892
1085
  #
@@ -0,0 +1,57 @@
1
+
2
+ module Telerivet
3
+
4
+ #
5
+ # Represents a custom route that can be used to send messages via one or more Phones.
6
+ #
7
+ # Note: Routing rules can currently only be configured via Telerivet's web UI.
8
+ #
9
+ # Fields:
10
+ #
11
+ # - id (string, max 34 characters)
12
+ # * Telerivet's internal ID for the route
13
+ # * Read-only
14
+ #
15
+ # - name
16
+ # * The name of the route
17
+ # * Updatable via API
18
+ #
19
+ # - vars (Hash)
20
+ # * Custom variables stored for this route
21
+ # * Updatable via API
22
+ #
23
+ # - project_id
24
+ # * ID of the project this route belongs to
25
+ # * Read-only
26
+ #
27
+ class Route < Entity
28
+ #
29
+ # Saves any fields or custom variables that have changed for this route.
30
+ #
31
+ def save()
32
+ super
33
+ end
34
+
35
+ def id
36
+ get('id')
37
+ end
38
+
39
+ def name
40
+ get('name')
41
+ end
42
+
43
+ def name=(value)
44
+ set('name', value)
45
+ end
46
+
47
+ def project_id
48
+ get('project_id')
49
+ end
50
+
51
+ def get_base_api_path()
52
+ "/projects/#{get('project_id')}/routes/#{get('id')}"
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -72,7 +72,7 @@ module Telerivet
72
72
  # * Number of times this scheduled message has already been sent
73
73
  # * Read-only
74
74
  #
75
- # - is_template
75
+ # - is_template (bool)
76
76
  # * Set to true if Telerivet will render variables like [[contact.name]] in the message
77
77
  # content, false otherwise
78
78
  # * Read-only
@@ -102,6 +102,9 @@ class Service < Entity
102
102
  # - contact_id
103
103
  # * The ID of the contact this service is triggered for
104
104
  # * Required if context is 'contact'
105
+ #
106
+ # Returns:
107
+ # object
105
108
  #
106
109
  def invoke(options)
107
110
  invoke_result = @api.do_request('POST', get_base_api_path() + '/invoke', options)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telerivet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Young
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby client library for Telerivet REST API
14
14
  email: support@telerivet.com
@@ -30,6 +30,7 @@ files:
30
30
  - lib/telerivet/mobilemoneyreceipt.rb
31
31
  - lib/telerivet/phone.rb
32
32
  - lib/telerivet/project.rb
33
+ - lib/telerivet/route.rb
33
34
  - lib/telerivet/scheduledmessage.rb
34
35
  - lib/telerivet/service.rb
35
36
  homepage: http://telerivet.com