textmagic-ruby 2.0.0

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 (70) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +9 -0
  6. data/LICENSE.txt +21 -0
  7. data/Makefile +8 -0
  8. data/README.md +41 -0
  9. data/Rakefile +10 -0
  10. data/conf/cacert.pem +3988 -0
  11. data/examples/bulk_examples.rb +24 -0
  12. data/examples/chat_examples.rb +30 -0
  13. data/examples/contact_examples.rb +116 -0
  14. data/examples/custom_field_examples.rb +78 -0
  15. data/examples/invoice_examples.rb +26 -0
  16. data/examples/list_examples.rb +98 -0
  17. data/examples/message_examples.rb +75 -0
  18. data/examples/number_examples.rb +72 -0
  19. data/examples/reply_examples.rb +32 -0
  20. data/examples/schedule_examples.rb +44 -0
  21. data/examples/senderid_examples.rb +52 -0
  22. data/examples/session_examples.rb +51 -0
  23. data/examples/subaccount_examples.rb +53 -0
  24. data/examples/template_examples.rb +61 -0
  25. data/examples/unsubscriber_examples.rb +56 -0
  26. data/examples/user_examples.rb +105 -0
  27. data/lib/textmagic-ruby.rb +31 -0
  28. data/lib/textmagic-ruby/rest/bulks.rb +89 -0
  29. data/lib/textmagic-ruby/rest/chats.rb +147 -0
  30. data/lib/textmagic-ruby/rest/client.rb +128 -0
  31. data/lib/textmagic-ruby/rest/contacts.rb +174 -0
  32. data/lib/textmagic-ruby/rest/custom_fields.rb +120 -0
  33. data/lib/textmagic-ruby/rest/errors.rb +14 -0
  34. data/lib/textmagic-ruby/rest/instance_resource.rb +33 -0
  35. data/lib/textmagic-ruby/rest/invoices.rb +73 -0
  36. data/lib/textmagic-ruby/rest/list_resource.rb +64 -0
  37. data/lib/textmagic-ruby/rest/lists.rb +166 -0
  38. data/lib/textmagic-ruby/rest/messages.rb +172 -0
  39. data/lib/textmagic-ruby/rest/numbers.rb +164 -0
  40. data/lib/textmagic-ruby/rest/paginate_resource.rb +20 -0
  41. data/lib/textmagic-ruby/rest/replies.rb +85 -0
  42. data/lib/textmagic-ruby/rest/scheduleds.rb +91 -0
  43. data/lib/textmagic-ruby/rest/senderids.rb +114 -0
  44. data/lib/textmagic-ruby/rest/sessions.rb +109 -0
  45. data/lib/textmagic-ruby/rest/subaccounts.rb +135 -0
  46. data/lib/textmagic-ruby/rest/templates.rb +107 -0
  47. data/lib/textmagic-ruby/rest/unsubscribers.rb +85 -0
  48. data/lib/textmagic-ruby/rest/users.rb +202 -0
  49. data/lib/textmagic-ruby/rest/utils.rb +48 -0
  50. data/lib/textmagic-ruby/rest/version.rb +5 -0
  51. data/spec/rest/client_spec.rb +57 -0
  52. data/spec/rest/contact_spec.rb +36 -0
  53. data/spec/rest/custom_fields_spec.rb +36 -0
  54. data/spec/rest/instance_resource_spec.rb +17 -0
  55. data/spec/rest/invoice_spec.rb +56 -0
  56. data/spec/rest/lists_spec.rb +35 -0
  57. data/spec/rest/message_spec.rb +40 -0
  58. data/spec/rest/numbers_spec.rb +66 -0
  59. data/spec/rest/reply_spec.rb +43 -0
  60. data/spec/rest/scheduled_spec.rb +43 -0
  61. data/spec/rest/senderid_spec.rb +39 -0
  62. data/spec/rest/session_spec.rb +43 -0
  63. data/spec/rest/subaccount_spec.rb +39 -0
  64. data/spec/rest/template_spec.rb +36 -0
  65. data/spec/rest/unsubscriber_spec.rb +40 -0
  66. data/spec/rest/user_spec.rb +92 -0
  67. data/spec/rest/utils_spec.rb +57 -0
  68. data/spec/spec_helper.rb +15 -0
  69. data/textmagic-ruby.gemspec +30 -0
  70. metadata +165 -0
@@ -0,0 +1,172 @@
1
+ module Textmagic
2
+ module REST
3
+ class Messages < ListResource
4
+ ##
5
+ # Get message by ID.
6
+ # Returns Message object.
7
+ #
8
+ # uid:: Message ID. Required.
9
+ #
10
+ # Example:
11
+ #
12
+ # @message = client.messages.get 987
13
+ #
14
+ def get(uid)
15
+ super uid
16
+ end
17
+
18
+ ##
19
+ # Send a new outbound Message or create Scheduled message when provide *sending_time* parameters
20
+ # Returns Message object contains next attributes: 'id', 'href', 'type',
21
+ # 'sessionId', 'bulkId', 'message_id', 'scheduled_id'.
22
+ #
23
+ # The following *params* keys are supported:
24
+ #
25
+ # text:: Message text. Required if template_id is not set.
26
+ #
27
+ # template_id:: Template used instead of message text. Required if text is not set.
28
+ #
29
+ # sending_time:: Message sending time in unix timestamp format. Default is now.
30
+ # Optional (required with recurrency_rule set).
31
+ # contacts:: Contacts ids, separated by comma, message will be sent to.
32
+ #
33
+ # lists:: Lists ids, separated by comma, message will be sent to.
34
+ #
35
+ # phones:: Phone numbers, separated by comma, message will be sent to.
36
+ #
37
+ # cut_extra:: Should sending method cut extra characters
38
+ # which not fit supplied parts_count or return 400 Bad request response instead.
39
+ # Default is false.
40
+ # parts_count:: Maximum message parts count (TextMagic allows sending 1 to 6 message parts).
41
+ # Default is 6.
42
+ # reference_id:: Custom message reference id which can be used in your application infrastructure.
43
+ #
44
+ # from:: One of allowed Sender ID (phone number or alphanumeric sender ID).
45
+ #
46
+ # rrule:: iCal RRULE parameter to create recurrent scheduled messages.
47
+ # When used, sending_time is mandatory as start point of sending.
48
+ # dummy:: If 1, just return message pricing. Message will not send.
49
+ #
50
+ # Example:
51
+ #
52
+ # @message = client.messages.create {:text => 'Hello from Ruby', :phones => '99900000, 99999999'}
53
+ #
54
+ def create(params={})
55
+ super params
56
+ end
57
+
58
+ ##
59
+ # Get all user messages.
60
+ # Returns PaginateResource object, contains array of Message objects.
61
+ #
62
+ # The following *params* keys are supported:
63
+ #
64
+ # search:: If *true* then search messages using `query`, `ids` and/or `session_id`. Defaults *false*.
65
+ #
66
+ # page:: Fetch specified results page. Defaults 1
67
+ #
68
+ # limit:: How many results on page. Defaults 10
69
+ #
70
+ # ids:: Find message by ID(s). Using with `search`=*true*.
71
+ #
72
+ # session_id:: Find message by Session ID. Using with `search`=*true*.
73
+ #
74
+ # query:: Find message by specified search query. Using with `search`=*true*..
75
+ #
76
+ # Example:
77
+ #
78
+ # @messages = client.messages.list
79
+ #
80
+ def list(params={})
81
+ super params
82
+ end
83
+
84
+ ##
85
+ # Check pricing for a new outbound message.
86
+ # An useful synonym for "message" command with "dummy" parameters set to *true*.
87
+ #
88
+ # The following *params* keys are supported:
89
+ #
90
+ # text:: Message text. Required if template_id is not set.
91
+ #
92
+ # template_id:: Template used instead of message text. Required if text is not set.
93
+ #
94
+ # sending_time:: Message sending time in unix timestamp format. Default is now.
95
+ # Optional (required with recurrency_rule set).
96
+ # contacts:: Contacts ids, separated by comma, message will be sent to.
97
+ #
98
+ # lists:: Lists ids, separated by comma, message will be sent to.
99
+ #
100
+ # phones:: Phone numbers, separated by comma, message will be sent to.
101
+ #
102
+ # cut_extra:: Should sending method cut extra characters
103
+ # which not fit supplied parts_count or return 400 Bad request response instead.
104
+ # Default is false.
105
+ # parts_count:: Maximum message parts count (TextMagic allows sending 1 to 6 message parts).
106
+ # Default is 6.
107
+ # reference_id:: Custom message reference id which can be used in your application infrastructure.
108
+ #
109
+ # from:: One of allowed Sender ID (phone number or alphanumeric sender ID).
110
+ #
111
+ # rrule:: iCal RRULE parameter to create recurrent scheduled messages.
112
+ # When used, sending_time is mandatory as start point of sending.
113
+ # Example:
114
+ #
115
+ # @message = client.messages.create {:text => 'Hello from Ruby', :phones => '99900000, 99999999'}
116
+ #
117
+ def price(params={})
118
+ response = @client.get "#{@path}/price", params
119
+ @instance_class.new "#{@path}", @client, response
120
+ end
121
+
122
+ ##
123
+ # Delete message by ID. Returns *true* if success.
124
+ #
125
+ # uid:: Message ID. Required.
126
+ #
127
+ # Example:
128
+ #
129
+ # r = client.messages.delete 1110
130
+ #
131
+ def delete(uid)
132
+ super uid
133
+ end
134
+ ##
135
+ # Updating is not supported.
136
+ #
137
+ def update(uid, params={})
138
+ raise '`update` method is not supported for this resource.'
139
+ end
140
+ end
141
+
142
+ ##
143
+ # A Message resource.
144
+ #
145
+ # ==== @id
146
+ #
147
+ # ==== @receiver
148
+ #
149
+ # ==== @message_time
150
+ #
151
+ # ==== @status
152
+ #
153
+ # ==== @text
154
+ #
155
+ # ==== @charset
156
+ #
157
+ # ==== @first_name
158
+ #
159
+ # ==== @last_name
160
+ #
161
+ # ==== @country
162
+ #
163
+ # ==== @sender
164
+ #
165
+ # ==== @price
166
+ #
167
+ # ==== @parts_count
168
+ #
169
+ class Message < InstanceResource; end
170
+ end
171
+ end
172
+
@@ -0,0 +1,164 @@
1
+ module Textmagic
2
+ module REST
3
+ class Numbers < ListResource
4
+ ##
5
+ # Get number by ID.
6
+ # Returns Number object.
7
+ #
8
+ # uid:: Number ID. Required.
9
+ #
10
+ # Example:
11
+ #
12
+ # @number = client.numbers.get 1123
13
+ #
14
+ def get(uid)
15
+ super uid
16
+ end
17
+
18
+ ##
19
+ # Get all user dedicated numbers.
20
+ # Returns PaginateResource object, contains array of Numbers objects.
21
+ #
22
+ # The following *params* keys are supported:
23
+ #
24
+ # page:: Fetch specified results page. Defaults 1
25
+ #
26
+ # limit:: How many results on page. Defaults 10
27
+ #
28
+ # Example:
29
+ #
30
+ # @numbers = client.numbers.list
31
+ #
32
+ def list(params={})
33
+ [:search, 'search'].each do |search|
34
+ params.delete search
35
+ end
36
+ super params
37
+ end
38
+
39
+ ##
40
+ # Find available dedicated numbers to buy.
41
+ # Returns AvailableNumber object, contains array of available numbers and price.
42
+ #
43
+ # The following *params* keys are supported:
44
+ #
45
+ # country:: Dedicated number country. Required.
46
+ #
47
+ # prefix:: Desired number prefix. Should include country code (i.e. 447 for GB).
48
+ #
49
+ # Example:
50
+ #
51
+ # @numbers = client.numbers.available {:country => 'US'}
52
+ #
53
+ def available(params={})
54
+ response = @client.get "#{@path}/available", params
55
+ AvailableNumber.new "#{@path}", @client, response
56
+ end
57
+
58
+ ##
59
+ # Buy a dedicated number and assign it to the specified account.
60
+ # Returns Number object, contains id and link to a new dedicated Number.
61
+ #
62
+ # The following *params* keys are supported:
63
+ #
64
+ # phone:: Desired dedicated phone number in international E.164 format. Required.
65
+ #
66
+ # country:: Dedicated number country. Required.
67
+ #
68
+ # user_id:: User ID this number will be assigned to. Required.
69
+ #
70
+ # Example:
71
+ #
72
+ # @number = client.numbers.buy {:phone => '19025555555', :country => 'US', :user_id => 1234}
73
+ #
74
+ def buy(params={})
75
+ self.create params
76
+ end
77
+
78
+ ##
79
+ # Updating is not supported
80
+ #
81
+ def update(uid, params={})
82
+ raise '`update` method is not supported for this resource.'
83
+ end
84
+
85
+ ##
86
+ # Cancel dedicated number subscription. Returns *true* if success.
87
+ #
88
+ # uid:: Number ID. Required.
89
+ #
90
+ # Example:
91
+ #
92
+ # r = client.numbers.delete 1290
93
+ #
94
+ def delete(uid)
95
+ super uid
96
+ end
97
+ end
98
+
99
+ ##
100
+ # A Number resource.
101
+ #
102
+ # ==== @id
103
+ #
104
+ # ==== @purchased_at
105
+ #
106
+ # ==== @expire_at
107
+ #
108
+ # ==== @phone
109
+ #
110
+ # ==== @status
111
+ #
112
+ # ==== @country
113
+ #
114
+ # Hash like this
115
+ # {
116
+ # "id" => "US",
117
+ # "name" => "United States",
118
+ # }
119
+ #
120
+ # ==== @user
121
+ #
122
+ # Hash like this
123
+ # {
124
+ # "id": 11111,
125
+ # "username": "johndoe",
126
+ # "firstName": "John",
127
+ # "lastName": "Doe",
128
+ # "status": "A",
129
+ # "balance": 13.793,
130
+ # "company": "TextMagic",
131
+ # "currency": {
132
+ # "id": "GBP",
133
+ # "htmlSymbol": "&pound;"
134
+ # },
135
+ # "timezone": {
136
+ # "id": 2,
137
+ # "area": "Pacific",
138
+ # "dst": 0,
139
+ # "offset": -39600,
140
+ # "timezone": "Pacific/Midway"
141
+ # },
142
+ # "subaccountType": "P"
143
+ # }
144
+ #
145
+ class Number < InstanceResource
146
+ def refresh
147
+ raise '`refresh` method is not supported for this resource.'
148
+ end
149
+ end
150
+
151
+ ##
152
+ # An AvailableNumber resource.
153
+ #
154
+ # ==== @numbers
155
+ #
156
+ # ==== @price
157
+ #
158
+ class AvailableNumber < InstanceResource
159
+ def refresh
160
+ raise '`refresh` method is not supported for this resource.'
161
+ end
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,20 @@
1
+ module Textmagic
2
+ module REST
3
+ class PaginateResource
4
+ include Utils
5
+
6
+ attr_reader :resources, :page, :page_count, :limit
7
+ def initialize(path, client, params={}, resource_class=nil)
8
+ @path = path
9
+ @client = client
10
+ %w(page limit pageCount).each do |attr|
11
+ self.instance_variable_set("@#{to_underscore_case(attr)}", params.fetch(attr))
12
+ end
13
+ @resources = Array.new
14
+ params['resources'].each do |r|
15
+ @resources << resource_class.new(@path, @client, r)
16
+ end if resource_class
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,85 @@
1
+ module Textmagic
2
+ module REST
3
+ class Replies < ListResource
4
+ ##
5
+ # Get reply by ID.
6
+ # Returns Reply object.
7
+ #
8
+ # uid:: Reply ID. Required.
9
+ #
10
+ # Example:
11
+ #
12
+ # @reply = client.replies.get 19011
13
+ #
14
+ def get(uid)
15
+ super uid
16
+ end
17
+
18
+ ##
19
+ # Get all user replies.
20
+ # Returns PaginateResource object, contains array of Reply objects.
21
+ #
22
+ # The following *params* keys are supported:
23
+ #
24
+ # search:: If *true* then search replies using `ids` and/or `query`. Defaults *false*.
25
+ #
26
+ # page:: Fetch specified results page. Defaults 1
27
+ #
28
+ # limit:: How many results on page. Defaults 10
29
+ #
30
+ # ids:: Find replies by ID(s). Using with `search`=*true*.
31
+ #
32
+ # query:: Find replies by specified search query. Using with `search`=*true*..
33
+ #
34
+ # Example:
35
+ #
36
+ # @replies = client.replies.list
37
+ #
38
+ def list(params={})
39
+ super params
40
+ end
41
+
42
+ ##
43
+ # Delete reply by ID. Returns *true* if success.
44
+ #
45
+ # uid:: Reply ID. Required.
46
+ #
47
+ # Example:
48
+ #
49
+ # r = client.replies.delete 28919
50
+ #
51
+ def delete(uid)
52
+ super uid
53
+ end
54
+
55
+ ##
56
+ # Creating is not supported
57
+ #
58
+ def create(params)
59
+ raise '`create` method is not supported for this resource'
60
+ end
61
+
62
+ ##
63
+ # Updating is not supported
64
+ #
65
+ def update(uid, params)
66
+ raise '`update` method is not supported for this resource'
67
+ end
68
+ end
69
+
70
+ ##
71
+ # A Reply resource.
72
+ #
73
+ # ==== @id
74
+ #
75
+ # ==== @sender
76
+ #
77
+ # ==== @message_time
78
+ #
79
+ # ==== @text
80
+ #
81
+ # ==== @receiver
82
+ #
83
+ class Reply < InstanceResource; end
84
+ end
85
+ end
@@ -0,0 +1,91 @@
1
+ module Textmagic
2
+ module REST
3
+ class Schedules < ListResource
4
+ ##
5
+ # Get Schedule by ID.
6
+ # Returns Schedule object.
7
+ #
8
+ # uid:: Schedule ID. Required.
9
+ #
10
+ # Example:
11
+ #
12
+ # @scheduled = client.schedules.get 19011
13
+ #
14
+ def get(uid)
15
+ super uid
16
+ end
17
+
18
+ ##
19
+ # Get all user scheduled messages.
20
+ # Returns PaginateResource object, contains array of Schedule objects.
21
+ #
22
+ # The following *params* keys are supported:
23
+ #
24
+ # page:: Fetch specified results page. Defaults 1
25
+ #
26
+ # limit:: How many results on page. Defaults 10
27
+ #
28
+ # Example:
29
+ #
30
+ # @schedules = client.schedules.list
31
+ #
32
+ def list(params={})
33
+ [:search, 'search'].each do |search|
34
+ params.delete search
35
+ end
36
+ super params
37
+ end
38
+
39
+ ##
40
+ # Updating is not supported
41
+ #
42
+ def update(uid, params={})
43
+ raise '`update` method is not supported for this resource.'
44
+ end
45
+
46
+ ##
47
+ # Delete scheduled message by ID. Returns *true* if success.
48
+ #
49
+ # uid:: Schedule message ID. Required.
50
+ #
51
+ # Example:
52
+ #
53
+ # r = client.schedules.delete 182981
54
+ #
55
+ def delete(uid)
56
+ super uid
57
+ end
58
+
59
+ ##
60
+ # Creating is not supported
61
+ #
62
+ def create(params={})
63
+ raise '`create` method is not supported for this resource.'
64
+ end
65
+ end
66
+
67
+ ##
68
+ # A Schedule resource.
69
+ #
70
+ # ==== @id
71
+ #
72
+ # ==== @next_send
73
+ #
74
+ # ==== @rrule
75
+ #
76
+ # ==== @session
77
+ #
78
+ # Hash like this:
79
+ # {
80
+ # "id": "34435949",
81
+ # "startTime": "2015-05-01T21:30:00+0000",
82
+ # "text": "Happy Birthday, dude!",
83
+ # "source": "O",
84
+ # "referenceId": "O_xxx_cb5e100e5a9a3e7f6d1fd97512215282_10580074905542fc46b9f157.39758261",
85
+ # "price": 0.03,
86
+ # "numbersCount": 1
87
+ # }
88
+ #
89
+ class Schedule < InstanceResource; end
90
+ end
91
+ end