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,114 @@
1
+ module Textmagic
2
+ module REST
3
+ class Senderids < ListResource
4
+ ##
5
+ # Get senderid by ID.
6
+ # Returns Senderid object.
7
+ #
8
+ # uid:: Senderid ID. Required.
9
+ #
10
+ # Example:
11
+ #
12
+ # @senderid = client.senderids.get 1123
13
+ #
14
+ def get(uid)
15
+ super uid
16
+ end
17
+
18
+ ##
19
+ # Create new Senderid.
20
+ # Returns Senderid object contains id and link to new Senderid.
21
+ #
22
+ # The following *params* keys are supported:
23
+ #
24
+ # sender_id:: Alphanumeric Sender ID (maximum 11 characters). Required.
25
+ #
26
+ # explanation:: Explain why do you need this Sender ID. Required.
27
+ #
28
+ # Example:
29
+ #
30
+ # @senderid = client.senderids.create {:sender_id => 'MYSENDERID', :explanation => 'For Testing'}
31
+ #
32
+ def create(params={})
33
+ super params
34
+ end
35
+
36
+ ##
37
+ # Get all user sender ids.
38
+ # Returns PaginateResource object, contains array of Senderid objects.
39
+ #
40
+ # The following *params* keys are supported:
41
+ #
42
+ # page:: Fetch specified results page. Defaults 1
43
+ #
44
+ # limit:: How many results on page. Defaults 10
45
+ #
46
+ # Example:
47
+ #
48
+ # @senderids = client.senderids.list
49
+ #
50
+ def list(params={})
51
+ [:search, 'search'].each do |search|
52
+ params.delete search
53
+ end
54
+ super params
55
+ end
56
+
57
+ ##
58
+ # Updating is not supported.
59
+ #
60
+ def update(uid, params={})
61
+ raise '`update` method is not supported for this resource.'
62
+ end
63
+
64
+ ##
65
+ # Delete senderid by ID. Returns *true* if success.
66
+ #
67
+ # uid:: Senderid ID. Required.
68
+ #
69
+ # Example:
70
+ #
71
+ # r = client.senderids.delete 192881
72
+ #
73
+ def delete(uid)
74
+ super uid
75
+ end
76
+ end
77
+
78
+ ##
79
+ # A Senderid resource.
80
+ #
81
+ # ==== @id
82
+ #
83
+ # ==== @sender_id
84
+ #
85
+ # ==== @status
86
+ #
87
+ # ==== @user
88
+ #
89
+ # Hash like this
90
+ # {
91
+ # "id": 11111,
92
+ # "username": "johndoe",
93
+ # "firstName": "John",
94
+ # "lastName": "Doe",
95
+ # "status": "A",
96
+ # "balance": 13.793,
97
+ # "company": "TextMagic",
98
+ # "currency": {
99
+ # "id": "GBP",
100
+ # "htmlSymbol": "&pound;"
101
+ # },
102
+ # "timezone": {
103
+ # "id": 2,
104
+ # "area": "Pacific",
105
+ # "dst": 0,
106
+ # "offset": -39600,
107
+ # "timezone": "Pacific/Midway"
108
+ # },
109
+ # "subaccountType": "P"
110
+ # }
111
+ #
112
+ class Senderid < InstanceResource; end
113
+ end
114
+ end
@@ -0,0 +1,109 @@
1
+ module Textmagic
2
+ module REST
3
+ class Sessions < ListResource
4
+
5
+ ##
6
+ # Get all user message sessions.
7
+ # Returns PaginateResource object, contains array of Session objects.
8
+ #
9
+ # The following *params* keys are supported:
10
+ #
11
+ # page:: Fetch specified results page. Defaults 1
12
+ #
13
+ # limit:: How many results on page. Defaults 10
14
+ #
15
+ # Example:
16
+ #
17
+ # @sessions = client.sessions.list
18
+ #
19
+ def list(params={})
20
+ [:search, 'search'].each do |search|
21
+ params.delete search
22
+ end
23
+ super params
24
+ end
25
+
26
+ ##
27
+ # Get session by ID.
28
+ # Returns Session object.
29
+ #
30
+ # uid:: Session ID. Required.
31
+ #
32
+ # Example:
33
+ #
34
+ # @session = client.sessions.get 123131
35
+ #
36
+ def get(uid)
37
+ super uid
38
+ end
39
+
40
+ ##
41
+ # Fetch messages by given session id.
42
+ # An useful synonym for "messages/search" command with provided `session_id` parameter.
43
+ # Returns PaginateResource object, contains array of Message objects.
44
+ #
45
+ # uid:: Session ID. Required.
46
+ #
47
+ # The following *params* keys are supported:
48
+ #
49
+ # page:: Fetch specified results page. Defaults 1
50
+ #
51
+ # limit:: How many results on page. Defaults 10
52
+ #
53
+ # Example:
54
+ #
55
+ # @messages = client.sessions.messages 123
56
+ #
57
+ def messages(uid, params={})
58
+ response = @client.get "#{@path}/#{uid}/messages", params
59
+ PaginateResource.new "#{@path}", @client, response, Textmagic::REST::Message
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
+
69
+ ##
70
+ # Creating is not supported.
71
+ #
72
+ def create(params={})
73
+ raise '`create` method is not supported for this resource.'
74
+ end
75
+
76
+ ##
77
+ # Delete session by ID. Returns *true* if success.
78
+ #
79
+ # uid:: Session ID. Required.
80
+ #
81
+ # Example:
82
+ #
83
+ # r = client.sessions.delete 123123
84
+ #
85
+ def delete(uid)
86
+ super uid
87
+ end
88
+ end
89
+
90
+ ##
91
+ # A Session resource.
92
+ #
93
+ # ==== @id
94
+ #
95
+ # ==== @start_time
96
+ #
97
+ # ==== @text
98
+ #
99
+ # ==== @source
100
+ #
101
+ # ==== @reference_id
102
+ #
103
+ # ==== @price
104
+ #
105
+ # ==== @numbers_count
106
+ #
107
+ class Session < InstanceResource; end
108
+ end
109
+ end
@@ -0,0 +1,135 @@
1
+ module Textmagic
2
+ module REST
3
+ class Subaccounts < ListResource
4
+
5
+ ##
6
+ # Get subaccount by ID.
7
+ # Returns Subaccount object.
8
+ #
9
+ # uid:: Subaccount ID. Required.
10
+ #
11
+ # Example:
12
+ #
13
+ # @subaccount = client.subaccounts.get 123131
14
+ #
15
+ def get(uid)
16
+ super uid
17
+ end
18
+
19
+ ##
20
+ # Get all user subaccounts.
21
+ # Returns PaginateResource object, contains array of Subaccount objects.
22
+ #
23
+ # The following *params* keys are supported:
24
+ #
25
+ # page:: Fetch specified results page. Defaults 1
26
+ #
27
+ # limit:: How many results on page. Defaults 10
28
+ #
29
+ # Example:
30
+ #
31
+ # @subaccounts = client.subaccounts.list
32
+ #
33
+ def list(params={})
34
+ [:search, 'search'].each do |search|
35
+ params.delete search
36
+ end
37
+ super params
38
+ end
39
+
40
+
41
+ ##
42
+ # Invite new subaccount.
43
+ # Returns True if success.
44
+ #
45
+ # The following *params* keys are supported:
46
+ #
47
+ # email:: Subaccount email. Required.
48
+ #
49
+ # role:: Subaccount role: `A` for administrator or `U` for regular user. Required.
50
+ #
51
+ # Example:
52
+ #
53
+ # @subaccount = client.subaccounts.create {:email => 'sub_email@gmail.com', :role => 'A'}
54
+ #
55
+ def create(params={})
56
+ self.send_invite params
57
+ end
58
+
59
+ ##
60
+ # Invite new subaccount. Alias for 'create' method.
61
+ # Returns True if success.
62
+ #
63
+ # The following *params* keys are supported:
64
+ #
65
+ # email:: Subaccount email. Required.
66
+ #
67
+ # role:: Subaccount role: `A` for administrator or `U` for regular user. Required.
68
+ #
69
+ # Example:
70
+ #
71
+ # @subaccount = client.subaccounts.send_invite {:email => 'sub_email@gmail.com', :role => 'A'}
72
+ #
73
+ def send_invite(params={})
74
+ response = @client.post "#{@path}", params
75
+ end
76
+
77
+ ##
78
+ # Updating is not supported.
79
+ #
80
+ def update(uid, params={})
81
+ raise '`update` method is not supported for this resource.'
82
+ end
83
+
84
+ ##
85
+ # Close the subaccount. Returns *true* if success.
86
+ #
87
+ # uid:: Subaccount ID. Required.
88
+ #
89
+ # Example:
90
+ #
91
+ # r = client.subaccounts.delete 123123
92
+ #
93
+ def delete(uid)
94
+ super uid
95
+ end
96
+ end
97
+
98
+ ##
99
+ # A Subaccount resource.
100
+ #
101
+ # ==== @id
102
+ #
103
+ # ==== @username
104
+ #
105
+ # ==== @first_name
106
+ #
107
+ # ==== @last_name
108
+ #
109
+ # ==== @balance
110
+ #
111
+ # ==== @company
112
+ #
113
+ # ==== @currency
114
+ #
115
+ # Hash like this:
116
+ # {
117
+ # "id": "GBP",
118
+ # "htmlSymbol": "&pound;"
119
+ # }
120
+ #
121
+ # ==== @timezone
122
+ #
123
+ # Hash like this:
124
+ # {
125
+ # "area": "Pacific",
126
+ # "dst": "0",
127
+ # "offset": "-39600",
128
+ # "timezone": "Pacific/Midway"
129
+ # }
130
+ #
131
+ # ==== @subaccount_type
132
+ #
133
+ class Subaccount < InstanceResource; end
134
+ end
135
+ end
@@ -0,0 +1,107 @@
1
+ module Textmagic
2
+ module REST
3
+ class Templates < ListResource
4
+ ##
5
+ # Get template by ID.
6
+ # Returns Template object.
7
+ #
8
+ # uid:: Template ID. Required.
9
+ #
10
+ # Example:
11
+ #
12
+ # @template = client.templates.get 987
13
+ #
14
+ def get(uid)
15
+ super uid
16
+ end
17
+
18
+ ##
19
+ # Create new Template.
20
+ # Returns Template object contains id and link to new Template.
21
+ #
22
+ # The following *params* keys are supported:
23
+ #
24
+ # name:: Template name. Required.
25
+ #
26
+ # content:: Template text. May contain tags inside braces. Required.
27
+ #
28
+ # Example:
29
+ #
30
+ # @template = client.templates.create {:name => 'MyTemplate'}
31
+ #
32
+ def create(params={})
33
+ super params
34
+ end
35
+
36
+ ##
37
+ # Get all user templates.
38
+ # Returns PaginateResource object, contains array of Template objects.
39
+ #
40
+ # The following *params* keys are supported:
41
+ #
42
+ # search:: If *true* then search templates using `name` and/or `content`. Defaults *false*.
43
+ #
44
+ # page:: Fetch specified results page. Defaults 1
45
+ #
46
+ # limit:: How many results on page. Defaults 10
47
+ #
48
+ # name:: Find template by name. Using with `search`=*true*.
49
+ #
50
+ # content:: Find template by content. Using with `search`=*true*..
51
+ #
52
+ # Example:
53
+ #
54
+ # @templates = client.templates.list
55
+ #
56
+ def list(params={})
57
+ super params
58
+ end
59
+
60
+ ##
61
+ # Updates the existing Template for the given unique id.
62
+ # Returns Template object contains id and link to updated Template.
63
+ #
64
+ # uid:: Template ID. Required.
65
+ #
66
+ # The following *params* keys are supported:
67
+ #
68
+ # name:: Template name. Required.
69
+ #
70
+ # content:: Template text. May contain tags inside braces. Required.
71
+ #
72
+ # Example:
73
+ #
74
+ # @template = client.templates.update 123, {:name => 'Updated Template'}
75
+ #
76
+ def update(uid, params={})
77
+ super uid, params
78
+ end
79
+
80
+ ##
81
+ # Delete template by ID. Returns *true* if success.
82
+ #
83
+ # uid:: Template ID. Required.
84
+ #
85
+ # Example:
86
+ #
87
+ # r = client.templates.delete 987
88
+ #
89
+ def delete(uid)
90
+ super uid
91
+ end
92
+ end
93
+
94
+ ##
95
+ # A Template resource.
96
+ #
97
+ # ==== @id
98
+ #
99
+ # ==== @name
100
+ #
101
+ # ==== @content
102
+ #
103
+ # ==== @last_modified
104
+ #
105
+ class Template < InstanceResource; end
106
+ end
107
+ end