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,24 @@
1
+ require 'rubygems'
2
+ require 'textmagic-ruby'
3
+
4
+ puts ' *** Running bulk examples *** '
5
+
6
+ username = 'xxx'
7
+ token = 'xxx'
8
+
9
+ client = Textmagic::REST::Client.new username, token
10
+
11
+ sleep 0.5
12
+ bulks = client.bulks.list
13
+
14
+ puts bulks.respond_to? :page
15
+ puts bulks.respond_to? :limit
16
+ puts bulks.respond_to? :page_count
17
+ puts bulks.resources.length > 0
18
+
19
+ sleep 0.5
20
+ bulk = client.bulks.get(bulks.resources.first.id)
21
+
22
+ puts bulk.id == bulks.resources.first.id
23
+
24
+ puts ' *** Finish bulk examples *** '
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'textmagic-ruby'
3
+
4
+ puts ' *** Running chat examples *** '
5
+
6
+ username = 'xxx'
7
+ token = 'xxx'
8
+
9
+ client = Textmagic::REST::Client.new username, token
10
+
11
+ sleep 0.5
12
+
13
+ chats = client.chats.list()
14
+
15
+ puts !chats.page.nil?
16
+ puts !chats.limit.nil?
17
+ puts !chats.page_count.nil?
18
+ puts chats.resources.length > 0
19
+ puts chats.resources.first.instance_of? Textmagic::REST::Chat
20
+
21
+ sleep 0.5
22
+ chat_messages = client.chats.get_by_phone(chats.resources.first.phone)
23
+
24
+ puts !chat_messages.page.nil?
25
+ puts !chat_messages.limit.nil?
26
+ puts !chat_messages.page_count.nil?
27
+ puts chat_messages.resources.length > 0
28
+ puts chat_messages.resources.first.instance_of? Textmagic::REST::ChatMessage
29
+
30
+ puts ' *** Finish chat examples *** '
@@ -0,0 +1,116 @@
1
+ require 'rubygems'
2
+ require 'textmagic-ruby'
3
+
4
+ puts ' *** Running contact examples *** '
5
+
6
+ username = 'xxx'
7
+ token = 'xxx'
8
+
9
+ client = Textmagic::REST::Client.new username, token
10
+
11
+ list_name = "TextMagic Ruby Helper"
12
+ params = {
13
+ :name => list_name
14
+ }
15
+
16
+ sleep 0.5
17
+ new_list = client.lists.create(params)
18
+
19
+ sleep 0.5
20
+ list = client.lists.get(new_list.id)
21
+
22
+ puts list.name == list_name
23
+
24
+ params = {
25
+ :limit => 25
26
+ }
27
+
28
+ sleep 0.5
29
+ lists = client.lists.list params
30
+
31
+ puts lists.resources.length > 0
32
+ puts lists.page == 1
33
+ puts lists.page_count == 1
34
+
35
+ params = {
36
+ :search => true,
37
+ :ids => new_list.id
38
+ }
39
+
40
+ sleep 0.5
41
+ lists = client.lists.list params
42
+
43
+ puts lists.page == 1
44
+ puts lists.resources.length == 1
45
+ puts lists.resources.first.name == list_name
46
+
47
+ contact_phone = '19025552671'
48
+ params = {
49
+ :phone => contact_phone,
50
+ :lists => new_list.id
51
+ }
52
+
53
+ sleep 0.5
54
+ new_contact = client.contacts.create(params)
55
+
56
+ puts new_contact.id > 0
57
+ puts !new_contact.href.nil?
58
+
59
+ sleep 0.5
60
+ contact = client.contacts.get(new_contact.id)
61
+
62
+ puts contact.id == new_contact.id
63
+ puts contact.phone == contact_phone
64
+
65
+ params[:first_name] = 'Zigmund'
66
+ sleep 0.5
67
+ u = client.contacts.update(contact.id, params)
68
+
69
+ puts u.id == contact.id
70
+ puts !u.href.nil?
71
+
72
+ puts contact.first_name != 'Zigmund'
73
+
74
+ sleep 0.5
75
+ contact.refresh
76
+ puts contact.first_name == 'Zigmund'
77
+
78
+ sleep 0.5
79
+ contact = client.contacts.get(new_contact.id)
80
+ puts contact.first_name == 'Zigmund'
81
+
82
+ sleep 0.5
83
+ contact_list = client.contacts.list()
84
+
85
+ puts !contact_list.page.nil?
86
+ puts !contact_list.limit.nil?
87
+ puts !contact_list.page_count.nil?
88
+ puts contact_list.resources.length > 0
89
+
90
+ sleep 0.5
91
+ contact_list = client.contacts.list({:search=> true, :list_id => list.id})
92
+
93
+ puts !contact_list.page.nil?
94
+ puts !contact_list.limit.nil?
95
+ puts !contact_list.page_count.nil?
96
+ puts contact_list.resources.length == 1
97
+ puts contact_list.resources.first.id == contact.id
98
+
99
+ sleep 0.5
100
+ contact_lists = client.contacts.lists(contact.id)
101
+
102
+ puts !contact_lists.page.nil?
103
+ puts !contact_lists.limit.nil?
104
+ puts !contact_lists.page_count.nil?
105
+ puts contact_lists.resources.length == 1
106
+ puts contact_lists.resources.first.id == list.id
107
+
108
+ sleep 0.5
109
+ r = client.contacts.delete(new_contact.id)
110
+ puts r
111
+
112
+ sleep 0.5
113
+ r = client.lists.delete new_list.id
114
+ puts r
115
+
116
+ puts ' *** Finish contact examples *** '
@@ -0,0 +1,78 @@
1
+ require 'rubygems'
2
+ require 'textmagic-ruby'
3
+
4
+ puts ' *** Running custom field examples *** '
5
+
6
+ username = 'xxx'
7
+ token = 'xxx'
8
+
9
+ client = Textmagic::REST::Client.new username, token
10
+
11
+ field_name = 'Ruby Helper'
12
+ sleep 0.5
13
+ field_new = client.custom_fields.create({:name => field_name})
14
+
15
+ puts !field_new.id.nil?
16
+ puts !field_new.href.nil?
17
+
18
+ sleep 0.5
19
+ field = client.custom_fields.get(field_new.id)
20
+
21
+ puts field.id == field_new.id
22
+ puts field.name == field_name
23
+
24
+ sleep 0.5
25
+ field_list = client.custom_fields.list()
26
+
27
+ puts !field_list.page.nil?
28
+ puts !field_list.limit.nil?
29
+ puts !field_list.page_count.nil?
30
+ puts field_list.resources.length > 0
31
+
32
+ sleep 0.5
33
+ field_search_list = client.custom_fields.list({:search => true})
34
+
35
+ puts !field_search_list.page.nil?
36
+ puts !field_search_list.limit.nil?
37
+ puts !field_search_list.page_count.nil?
38
+ puts field_search_list.resources.length > 0
39
+
40
+ updated_field_name = 'Ruby Helper Updated'
41
+ sleep 0.5
42
+ updated_field = client.custom_fields.update(field.id, {:name => updated_field_name})
43
+
44
+ puts updated_field.id == field.id
45
+ puts updated_field.href == "/api/v2/customfields/#{updated_field.id}"
46
+
47
+ sleep 0.5
48
+ updated_field.refresh()
49
+
50
+ puts updated_field.id == field.id
51
+ puts updated_field.name == updated_field_name
52
+
53
+ sleep 0.5
54
+ list = client.lists.create({:name => 'Custom Field Update Value'})
55
+ sleep 0.5
56
+ contact = client.contacts.create({:phone => '99991738182', :lists => list.id})
57
+
58
+ sleep 0.5
59
+ updated_contact = client.custom_fields.update_value(field.id, {:contactId => contact.id, :value => 'new value'})
60
+
61
+ puts contact.id == updated_contact.id
62
+ puts !updated_contact.href.nil?
63
+
64
+ sleep 0.5
65
+ contact.refresh()
66
+
67
+ puts contact.custom_fields[0]['value'] == 'new value'
68
+
69
+ sleep 0.5
70
+ r = client.custom_fields.delete(field_new.id)
71
+ puts r
72
+
73
+ sleep 0.5
74
+ puts client.lists.delete(list.id)
75
+
76
+ sleep 0.5
77
+
78
+ puts ' *** Finish custom field examples *** '
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'textmagic-ruby'
3
+
4
+ puts ' *** Running invoice examples *** '
5
+
6
+ username = 'xxx'
7
+ token = 'xxx'
8
+
9
+ client = Textmagic::REST::Client.new username, token
10
+
11
+ sleep 0.5
12
+ invoices = client.invoices.list()
13
+
14
+ puts invoices.respond_to? :page
15
+ puts invoices.respond_to? :limit
16
+ puts invoices.respond_to? :page_count
17
+ puts invoices.resources.length > 0
18
+ puts invoices.resources.first.instance_of? Textmagic::REST::Invoice
19
+
20
+ puts invoices.resources.first.respond_to? :id
21
+ puts invoices.resources.first.respond_to? :bundle
22
+ puts invoices.resources.first.respond_to? :currency
23
+ puts invoices.resources.first.respond_to? :vat
24
+ puts invoices.resources.first.respond_to? :payment_method
25
+
26
+ puts ' *** Finish invoice examples *** '
@@ -0,0 +1,98 @@
1
+ require 'rubygems'
2
+ require 'textmagic-ruby'
3
+
4
+ puts ' *** Running list examples *** '
5
+
6
+ username = 'xxx'
7
+ token = 'xxx'
8
+
9
+ client = Textmagic::REST::Client.new username, token
10
+
11
+ list_name = 'new_list_ruby_test'
12
+ sleep 0.5
13
+ new_list = client.lists.create({:name => list_name})
14
+
15
+ puts new_list.instance_of? Textmagic::REST::List
16
+ puts !new_list.id.nil?
17
+ puts !new_list.href.nil?
18
+
19
+ sleep 0.5
20
+ lists = client.lists.list()
21
+
22
+ puts lists.instance_of?(Textmagic::REST::PaginateResource)
23
+ puts !lists.page.nil?
24
+ puts !lists.limit.nil?
25
+ puts !lists.page_count.nil?
26
+ puts lists.resources.length > 0
27
+ puts lists.resources.first.instance_of? Textmagic::REST::List
28
+
29
+ sleep 0.5
30
+ list = client.lists.get(new_list.id)
31
+
32
+ puts list.id == new_list.id
33
+ puts list.name == list_name
34
+ puts list.instance_of? Textmagic::REST::List
35
+
36
+ sleep 0.5
37
+ search_list = client.lists.list({:search => true, :ids => list.id})
38
+
39
+ puts lists.instance_of? Textmagic::REST::PaginateResource
40
+ puts !lists.page.nil?
41
+ puts !lists.limit.nil?
42
+ puts !lists.page_count.nil?
43
+ puts lists.resources.length > 0
44
+ puts lists.resources.first.instance_of? Textmagic::REST::List
45
+ puts lists.resources.first.name == list_name
46
+
47
+ sleep 0.5
48
+ updated_list_name = 'updated_list_ruby_test'
49
+ updated_list = client.lists.update(new_list.id, {:name => updated_list_name})
50
+
51
+ puts !updated_list.href.nil?
52
+
53
+ sleep 0.5
54
+ updated_list.refresh
55
+
56
+ puts updated_list.name == updated_list_name
57
+
58
+ sleep 0.5
59
+ contact = client.contacts.create({:phone => '99999999', :lists => updated_list.id})
60
+
61
+ sleep 0.5
62
+ contacts = client.lists.contacts(list.id)
63
+
64
+ puts contacts.page == 1
65
+ puts contacts.limit == 10
66
+ puts contacts.page_count == 1
67
+ puts contacts.resources.length == 1
68
+ puts contacts.resources.first.id == contact.id
69
+
70
+ sleep 0.5
71
+ r = client.lists.delete_contacts(list.id, {:contacts => contact.id})
72
+
73
+ puts r
74
+
75
+ sleep 0.5
76
+ contacts = client.lists.contacts(list.id)
77
+
78
+ puts contacts.resources.length == 0
79
+
80
+ sleep 0.5
81
+ contact = client.contacts.create({:phone => '999999990', :lists => list.id})
82
+
83
+ sleep 0.5
84
+ list = client.lists.put_contacts(list.id, {:contacts => contact.id})
85
+
86
+ puts list.id != 0
87
+ puts !list.href.nil?
88
+
89
+ sleep 0.5
90
+ contacts = client.lists.contacts(list.id)
91
+
92
+ puts contacts.resources.length == 1
93
+
94
+ sleep 0.5
95
+ r = client.lists.delete(list.id)
96
+ puts r
97
+
98
+ puts ' *** Finish list examples *** '
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+ require 'textmagic-ruby'
3
+
4
+ puts ' *** Running message examples *** '
5
+
6
+ username = 'xxx'
7
+ token = 'xxx'
8
+
9
+ client = Textmagic::REST::Client.new username, token
10
+
11
+ text = 'Hello from Ruby Api Helper'
12
+ phones = '999777777'
13
+ params = {
14
+ :text => text,
15
+ :phones => phones
16
+ }
17
+ sleep 0.5
18
+ new_message = client.messages.create(params)
19
+
20
+ puts new_message.id > 0
21
+ puts !new_message.href.nil?
22
+ puts !new_message.message_id.nil?
23
+ puts !new_message.session_id.nil?
24
+
25
+ sleep 0.5
26
+ message = client.messages.get(new_message.id)
27
+
28
+ puts message.id == new_message.id
29
+ puts message.text == text
30
+
31
+ params = {
32
+ :page => 2
33
+ }
34
+ sleep 0.5
35
+ messages = client.messages.list(params)
36
+
37
+ puts messages.page == 2
38
+ puts messages.page_count > 0
39
+ puts messages.resources.kind_of? Array
40
+ puts messages.resources.length == 10
41
+
42
+ sleep 0.5
43
+
44
+ params = {
45
+ :search => true,
46
+ :ids => new_message.id
47
+ }
48
+ messages_search = client.messages.list(params)
49
+
50
+ puts messages_search.page == 1
51
+ puts messages_search.page_count > 0
52
+ puts messages_search.resources.kind_of? Array
53
+ puts messages_search.resources.length == 1
54
+ puts messages_search.resources.first.id == new_message.id
55
+
56
+ sleep 0.5
57
+ r = client.messages.delete new_message.id
58
+ puts r
59
+
60
+ sleep 0.5
61
+ begin
62
+ message = client.messages.get(new_message.id)
63
+ rescue Textmagic::REST::RequestError => err
64
+ puts err.code == 404
65
+ end
66
+
67
+ sleep 0.5
68
+ price = client.messages.price({:text => 'Hello from Ruby Helper', :phones => '19025555555, 16465555555'})
69
+
70
+ puts price.total > 0
71
+ puts price.parts == 1
72
+
73
+ sleep 0.5
74
+
75
+ puts ' *** Finish message examples *** '