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.
- checksums.yaml +15 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +21 -0
- data/Makefile +8 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/conf/cacert.pem +3988 -0
- data/examples/bulk_examples.rb +24 -0
- data/examples/chat_examples.rb +30 -0
- data/examples/contact_examples.rb +116 -0
- data/examples/custom_field_examples.rb +78 -0
- data/examples/invoice_examples.rb +26 -0
- data/examples/list_examples.rb +98 -0
- data/examples/message_examples.rb +75 -0
- data/examples/number_examples.rb +72 -0
- data/examples/reply_examples.rb +32 -0
- data/examples/schedule_examples.rb +44 -0
- data/examples/senderid_examples.rb +52 -0
- data/examples/session_examples.rb +51 -0
- data/examples/subaccount_examples.rb +53 -0
- data/examples/template_examples.rb +61 -0
- data/examples/unsubscriber_examples.rb +56 -0
- data/examples/user_examples.rb +105 -0
- data/lib/textmagic-ruby.rb +31 -0
- data/lib/textmagic-ruby/rest/bulks.rb +89 -0
- data/lib/textmagic-ruby/rest/chats.rb +147 -0
- data/lib/textmagic-ruby/rest/client.rb +128 -0
- data/lib/textmagic-ruby/rest/contacts.rb +174 -0
- data/lib/textmagic-ruby/rest/custom_fields.rb +120 -0
- data/lib/textmagic-ruby/rest/errors.rb +14 -0
- data/lib/textmagic-ruby/rest/instance_resource.rb +33 -0
- data/lib/textmagic-ruby/rest/invoices.rb +73 -0
- data/lib/textmagic-ruby/rest/list_resource.rb +64 -0
- data/lib/textmagic-ruby/rest/lists.rb +166 -0
- data/lib/textmagic-ruby/rest/messages.rb +172 -0
- data/lib/textmagic-ruby/rest/numbers.rb +164 -0
- data/lib/textmagic-ruby/rest/paginate_resource.rb +20 -0
- data/lib/textmagic-ruby/rest/replies.rb +85 -0
- data/lib/textmagic-ruby/rest/scheduleds.rb +91 -0
- data/lib/textmagic-ruby/rest/senderids.rb +114 -0
- data/lib/textmagic-ruby/rest/sessions.rb +109 -0
- data/lib/textmagic-ruby/rest/subaccounts.rb +135 -0
- data/lib/textmagic-ruby/rest/templates.rb +107 -0
- data/lib/textmagic-ruby/rest/unsubscribers.rb +85 -0
- data/lib/textmagic-ruby/rest/users.rb +202 -0
- data/lib/textmagic-ruby/rest/utils.rb +48 -0
- data/lib/textmagic-ruby/rest/version.rb +5 -0
- data/spec/rest/client_spec.rb +57 -0
- data/spec/rest/contact_spec.rb +36 -0
- data/spec/rest/custom_fields_spec.rb +36 -0
- data/spec/rest/instance_resource_spec.rb +17 -0
- data/spec/rest/invoice_spec.rb +56 -0
- data/spec/rest/lists_spec.rb +35 -0
- data/spec/rest/message_spec.rb +40 -0
- data/spec/rest/numbers_spec.rb +66 -0
- data/spec/rest/reply_spec.rb +43 -0
- data/spec/rest/scheduled_spec.rb +43 -0
- data/spec/rest/senderid_spec.rb +39 -0
- data/spec/rest/session_spec.rb +43 -0
- data/spec/rest/subaccount_spec.rb +39 -0
- data/spec/rest/template_spec.rb +36 -0
- data/spec/rest/unsubscriber_spec.rb +40 -0
- data/spec/rest/user_spec.rb +92 -0
- data/spec/rest/utils_spec.rb +57 -0
- data/spec/spec_helper.rb +15 -0
- data/textmagic-ruby.gemspec +30 -0
- metadata +165 -0
@@ -0,0 +1,120 @@
|
|
1
|
+
module Textmagic
|
2
|
+
module REST
|
3
|
+
class CustomFields < ListResource
|
4
|
+
|
5
|
+
##
|
6
|
+
# Get CustomField by ID.
|
7
|
+
# Returns CustomField object.
|
8
|
+
#
|
9
|
+
# uid:: Custom Field ID. Required.
|
10
|
+
#
|
11
|
+
# Example:
|
12
|
+
#
|
13
|
+
# @custom_field = client.custom_fields.get 987
|
14
|
+
#
|
15
|
+
def get(uid)
|
16
|
+
super uid
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Create new CustomField.
|
21
|
+
# Returns CustomField object contains id and link to new CustomField.
|
22
|
+
#
|
23
|
+
# The following *params* keys are supported:
|
24
|
+
#
|
25
|
+
# name:: Name of custom field. Required.
|
26
|
+
#
|
27
|
+
# Example:
|
28
|
+
#
|
29
|
+
# @custom_field = client.custom_fields.create {:name => 'Birthday'}
|
30
|
+
#
|
31
|
+
def create(params={})
|
32
|
+
super params
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Get all user custom fields.
|
37
|
+
# Returns PaginateResource object, contains array of CustomField objects.
|
38
|
+
#
|
39
|
+
# The following *params* keys are supported:
|
40
|
+
#
|
41
|
+
# page:: Fetch specified results page. Defaults 1
|
42
|
+
#
|
43
|
+
# limit:: How many results on page. Defaults 10
|
44
|
+
#
|
45
|
+
# Example:
|
46
|
+
#
|
47
|
+
# @custom_fields = client.custom_fields.list
|
48
|
+
#
|
49
|
+
def list(params={})
|
50
|
+
[:search, 'search'].each do |search|
|
51
|
+
params.delete search
|
52
|
+
end
|
53
|
+
super params
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# Updates the existing CustomField for the given unique id.
|
58
|
+
# Returns CustomField object contains id and link to updated CustomField.
|
59
|
+
#
|
60
|
+
# uid:: Custom field ID. Required.
|
61
|
+
#
|
62
|
+
# The following *params* keys are supported:
|
63
|
+
#
|
64
|
+
# name:: Name of custom field. Required.
|
65
|
+
#
|
66
|
+
# Example:
|
67
|
+
#
|
68
|
+
# @custom_field = client.custom_fields.update 123, {:name => 'Updated'}
|
69
|
+
#
|
70
|
+
def update(uid, params={})
|
71
|
+
super uid, params
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Delete CustomField by ID. Returns *true* if success.
|
76
|
+
#
|
77
|
+
# uid:: CustomField ID. Required.
|
78
|
+
#
|
79
|
+
# Example:
|
80
|
+
#
|
81
|
+
# r = client.custom_fields.delete 987
|
82
|
+
#
|
83
|
+
def delete(uid)
|
84
|
+
super uid
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Updates contact's custom field value.
|
89
|
+
# Returns Contact object contains id and link to updated Contact.
|
90
|
+
#
|
91
|
+
# uid:: Custom field ID. Required.
|
92
|
+
#
|
93
|
+
# The following *params* keys are supported:
|
94
|
+
#
|
95
|
+
# contact_id:: The unique id of the Contact to update value. Required.
|
96
|
+
#
|
97
|
+
# value:: Value of CustomField. Required.
|
98
|
+
#
|
99
|
+
# Example:
|
100
|
+
#
|
101
|
+
# @custom_field = client.custom_fields.update 123, {:name => 'Updated'}
|
102
|
+
#
|
103
|
+
def update_value(uid, params={})
|
104
|
+
response = @client.put("#{@path}/#{uid}/update", params)
|
105
|
+
Textmagic::REST::Contact.new @client, @path, response
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# A Custom Field resource.
|
111
|
+
#
|
112
|
+
# ==== @id
|
113
|
+
#
|
114
|
+
# ==== @name
|
115
|
+
#
|
116
|
+
# ==== @created_at
|
117
|
+
#
|
118
|
+
class CustomField < InstanceResource; end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Textmagic
|
2
|
+
module REST
|
3
|
+
class InstanceResource
|
4
|
+
include Utils
|
5
|
+
|
6
|
+
def initialize(path, client, params={})
|
7
|
+
@path = path
|
8
|
+
@client = client
|
9
|
+
load_attributes params
|
10
|
+
end
|
11
|
+
|
12
|
+
def inspect # :nodoc:
|
13
|
+
"<#{self.class} @path=#{@path}>"
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_attributes(hash)
|
17
|
+
metaclass = class << self; self; end
|
18
|
+
hash.each do |k,v|
|
19
|
+
attr = to_underscore_case k
|
20
|
+
unless ['client', 'updated'].include? attr
|
21
|
+
metaclass.send :define_method, attr.to_sym, &lambda {v}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
@updated = !hash.keys.empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def refresh
|
28
|
+
load_attributes(@client.get("#{@path}/#{self.id}", {}))
|
29
|
+
self
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Textmagic
|
2
|
+
module REST
|
3
|
+
class Invoices < ListResource
|
4
|
+
##
|
5
|
+
# Get all user invoices.
|
6
|
+
# Returns PaginateResource object, contains array of Invoices objects.
|
7
|
+
#
|
8
|
+
# The following *params* keys are supported:
|
9
|
+
#
|
10
|
+
# page:: Fetch specified results page. Defaults 1
|
11
|
+
#
|
12
|
+
# limit:: How many results on page. Defaults 10
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
#
|
16
|
+
# @invoices = client.invoices.list
|
17
|
+
#
|
18
|
+
def list(params={})
|
19
|
+
[:search, 'search'].each do |search|
|
20
|
+
params.delete search
|
21
|
+
end
|
22
|
+
super params
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Creating is not supported.
|
27
|
+
#
|
28
|
+
def create(params={})
|
29
|
+
raise '`create` method is not supported for this resource.'
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Getting is not supported.
|
34
|
+
#
|
35
|
+
def get(uid)
|
36
|
+
raise '`get` method by ID is not supported for this resource.'
|
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
|
+
# Deleting is not supported.
|
48
|
+
#
|
49
|
+
def delete(uid)
|
50
|
+
raise '`delete` method is not supported for this resource.'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# An Invoice resource.
|
56
|
+
#
|
57
|
+
# ==== @id
|
58
|
+
#
|
59
|
+
# ==== @bundle
|
60
|
+
#
|
61
|
+
# ==== @currency
|
62
|
+
#
|
63
|
+
# ==== @vat
|
64
|
+
#
|
65
|
+
# ==== @payment_method
|
66
|
+
#
|
67
|
+
class Invoice < InstanceResource
|
68
|
+
def refresh
|
69
|
+
raise '`refresh` method is not supported for this resource.'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Textmagic
|
2
|
+
module REST
|
3
|
+
class ListResource
|
4
|
+
include Utils
|
5
|
+
|
6
|
+
def initialize(path, client)
|
7
|
+
custom_names = {
|
8
|
+
'Replies' => 'Reply'
|
9
|
+
}
|
10
|
+
@path, @client = path, client
|
11
|
+
resource_name = self.class.name.split('::')[-1]
|
12
|
+
instance_name = custom_names.fetch(resource_name, resource_name.chop)
|
13
|
+
|
14
|
+
parent_module = self.class.to_s.split('::')[-2]
|
15
|
+
full_module_path = if parent_module == 'REST'
|
16
|
+
Textmagic::REST
|
17
|
+
else
|
18
|
+
Textmagic::REST.const_get parent_module
|
19
|
+
end
|
20
|
+
|
21
|
+
@instance_class = full_module_path.const_get instance_name
|
22
|
+
@list_key, @instance_id_key = to_underscore_case(resource_name), 'id'
|
23
|
+
end
|
24
|
+
|
25
|
+
def inspect # :nodoc:
|
26
|
+
"<#{self.class} @path=#{@path}>"
|
27
|
+
end
|
28
|
+
|
29
|
+
def list(params={})
|
30
|
+
if params.key?('search') or params.key?(:search)
|
31
|
+
[:search, 'search'].each do |search|
|
32
|
+
params.delete(search)
|
33
|
+
end
|
34
|
+
path = "#{@path}" << '/search'
|
35
|
+
else
|
36
|
+
path = "#{@path}"
|
37
|
+
end
|
38
|
+
response = @client.get path, params
|
39
|
+
PaginateResource.new "#{@path}", @client, response, @instance_class
|
40
|
+
end
|
41
|
+
|
42
|
+
def get(uid, params={})
|
43
|
+
response = @client.get "#{@path}/#{uid}", params
|
44
|
+
@instance_class.new "#{@path}", @client, response
|
45
|
+
end
|
46
|
+
|
47
|
+
def create(params={})
|
48
|
+
response = @client.post "#{@path}", params
|
49
|
+
@instance_class.new "#{@path}", @client, response
|
50
|
+
end
|
51
|
+
|
52
|
+
def update(uid, params={})
|
53
|
+
response = @client.put "#{@path}/#{uid}", params
|
54
|
+
@instance_class.new "#{@path}", @client, response
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete(uid, params={})
|
58
|
+
raise "Can't delete a resource without a REST Client" unless @client
|
59
|
+
response = @client.delete "#{@path}/#{uid}", params
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
module Textmagic
|
2
|
+
module REST
|
3
|
+
class Lists < ListResource
|
4
|
+
##
|
5
|
+
# Get list by ID.
|
6
|
+
# Returns List object.
|
7
|
+
#
|
8
|
+
# uid:: List ID. Required.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
#
|
12
|
+
# @list = client.lists.get 987
|
13
|
+
#
|
14
|
+
def get(uid)
|
15
|
+
super uid
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Create new List.
|
20
|
+
# Returns List object contains id and link to new List.
|
21
|
+
#
|
22
|
+
# The following *params* keys are supported:
|
23
|
+
#
|
24
|
+
# name:: List name. Required.
|
25
|
+
#
|
26
|
+
# shared:: Should this list be shared with sub-accounts. Can be 1 or 0. Defaults 0
|
27
|
+
#
|
28
|
+
# Example:
|
29
|
+
#
|
30
|
+
# @list = client.lists.create {:name => 'MyList'}
|
31
|
+
#
|
32
|
+
def create(params={})
|
33
|
+
super params
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Get all user lists.
|
38
|
+
# Returns PaginateResource object, contains array of List objects.
|
39
|
+
#
|
40
|
+
# The following *params* keys are supported:
|
41
|
+
#
|
42
|
+
# search:: If *true* then search lists using `ids` and/or `query`. Defaults *false*.
|
43
|
+
#
|
44
|
+
# page:: Fetch specified results page. Defaults 1
|
45
|
+
#
|
46
|
+
# limit:: How many results on page. Defaults 10
|
47
|
+
#
|
48
|
+
# ids:: Find list by ID(s). Using with `search`=*true*.
|
49
|
+
#
|
50
|
+
# query:: Find list by specified search query. Using with `search`=*true*..
|
51
|
+
#
|
52
|
+
# Example:
|
53
|
+
#
|
54
|
+
# @lists = client.lists.list
|
55
|
+
#
|
56
|
+
def list(params={})
|
57
|
+
super params
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Updates the existing List for the given unique id.
|
62
|
+
# Returns List object contains id and link to updated List.
|
63
|
+
#
|
64
|
+
# uid:: List ID. Required.
|
65
|
+
#
|
66
|
+
# The following *params* keys are supported:
|
67
|
+
#
|
68
|
+
# name:: List name. Required.
|
69
|
+
#
|
70
|
+
# shared:: Should this list be shared with sub-accounts. Can be 1 or 0. Defaults 0
|
71
|
+
#
|
72
|
+
# Example:
|
73
|
+
#
|
74
|
+
# @list = client.lists.update 123, {:name => 'Updated List'}
|
75
|
+
#
|
76
|
+
def update(uid, params={})
|
77
|
+
super uid, params
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Delete list by ID. Returns *true* if success.
|
82
|
+
#
|
83
|
+
# uid:: List ID. Required.
|
84
|
+
#
|
85
|
+
# Example:
|
86
|
+
#
|
87
|
+
# r = client.lists.delete 987
|
88
|
+
#
|
89
|
+
def delete(uid)
|
90
|
+
super uid
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Fetch user contacts by given list id.
|
95
|
+
# An useful synonym for "contacts/search" command with provided "list_id" parameter.
|
96
|
+
# Returns PaginateResource object, contains array of Contact objects.
|
97
|
+
#
|
98
|
+
# uid:: List ID. Required.
|
99
|
+
#
|
100
|
+
# The following *params* keys are supported:
|
101
|
+
#
|
102
|
+
# page:: Fetch specified results page. Defaults 1
|
103
|
+
#
|
104
|
+
# limit:: How many results on page. Defaults 10
|
105
|
+
#
|
106
|
+
# Example:
|
107
|
+
#
|
108
|
+
# @lists = client.lists.contacts 123
|
109
|
+
#
|
110
|
+
def contacts(uid, params={})
|
111
|
+
response = @client.get "#{@path}/#{uid}/contacts", params
|
112
|
+
PaginateResource.new "#{@path}", @client, response, Textmagic::REST::Contact
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# Unassign contacts from the specified list.
|
117
|
+
# Returns *true* if success.
|
118
|
+
#
|
119
|
+
# uid:: List ID. Required.
|
120
|
+
#
|
121
|
+
# The following *params* keys are supported:
|
122
|
+
#
|
123
|
+
# contacts:: Contact ID(s), separated by comma.
|
124
|
+
#
|
125
|
+
# Example:
|
126
|
+
#
|
127
|
+
# r = client.lists.delete_contacts 123, {:contacts => '122, 1212, 12122'}
|
128
|
+
#
|
129
|
+
def delete_contacts(uid, params={})
|
130
|
+
response = @client.delete "#{@path}/#{uid}/contacts", params
|
131
|
+
end
|
132
|
+
|
133
|
+
##
|
134
|
+
# Assign contacts to the specified list.
|
135
|
+
# Returns List object contains id and link to updated List.
|
136
|
+
#
|
137
|
+
# uid:: List ID. Required.
|
138
|
+
#
|
139
|
+
# The following *params* keys are supported:
|
140
|
+
#
|
141
|
+
# contacts:: Contact ID(s), separated by comma.
|
142
|
+
#
|
143
|
+
# Example:
|
144
|
+
#
|
145
|
+
# r = client.lists.put_contacts 123, {:contacts => '122, 1212, 12122'}
|
146
|
+
#
|
147
|
+
def put_contacts(uid, params={})
|
148
|
+
response = @client.put "#{@path}/#{uid}/contacts", params
|
149
|
+
@instance_class.new "#{@path}", @client, response
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# A List resource.
|
155
|
+
#
|
156
|
+
# ==== @id
|
157
|
+
#
|
158
|
+
# ==== @name
|
159
|
+
#
|
160
|
+
# ==== @members_count
|
161
|
+
#
|
162
|
+
# ==== @shared
|
163
|
+
#
|
164
|
+
class List < InstanceResource; end
|
165
|
+
end
|
166
|
+
end
|